Home | History | Annotate | Line # | Download | only in sysinst
configmenu.c revision 1.2.2.2
      1  1.2.2.2  tls /* $NetBSD: configmenu.c,v 1.2.2.2 2014/08/10 07:00:24 tls Exp $ */
      2  1.2.2.2  tls 
      3  1.2.2.2  tls /*-
      4  1.2.2.2  tls  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      5  1.2.2.2  tls  * All rights reserved.
      6  1.2.2.2  tls  *
      7  1.2.2.2  tls  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.2.2  tls  * by Jeffrey C. Rizzo
      9  1.2.2.2  tls  *
     10  1.2.2.2  tls  * Redistribution and use in source and binary forms, with or without
     11  1.2.2.2  tls  * modification, are permitted provided that the following conditions
     12  1.2.2.2  tls  * are met:
     13  1.2.2.2  tls  * 1. Redistributions of source code must retain the above copyright
     14  1.2.2.2  tls  *    notice, this list of conditions and the following disclaimer.
     15  1.2.2.2  tls  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.2.2  tls  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.2.2  tls  *    documentation and/or other materials provided with the distribution.
     18  1.2.2.2  tls  *
     19  1.2.2.2  tls  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2.2.2  tls  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2.2.2  tls  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2.2.2  tls  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2.2.2  tls  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2.2.2  tls  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2.2.2  tls  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2.2.2  tls  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2.2.2  tls  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2.2.2  tls  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2.2.2  tls  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2.2.2  tls  */
     31  1.2.2.2  tls 
     32  1.2.2.2  tls /* configmenu.c -- post-installation system configuration menu. */
     33  1.2.2.2  tls 
     34  1.2.2.2  tls #include <stdio.h>
     35  1.2.2.2  tls #include <curses.h>
     36  1.2.2.2  tls #include <unistd.h>
     37  1.2.2.2  tls #include <errno.h>
     38  1.2.2.2  tls #include "defs.h"
     39  1.2.2.2  tls #include "msg_defs.h"
     40  1.2.2.2  tls #include "menu_defs.h"
     41  1.2.2.2  tls 
     42  1.2.2.2  tls 
     43  1.2.2.2  tls static int set_network(struct menudesc*, void *);
     44  1.2.2.2  tls static int set_timezone_menu(struct menudesc *, void *);
     45  1.2.2.2  tls static int set_root_shell(struct menudesc *, void *);
     46  1.2.2.2  tls static int change_root_password(struct menudesc *, void *);
     47  1.2.2.2  tls static int add_new_user(struct menudesc *, void *);
     48  1.2.2.2  tls static int set_binpkg(struct menudesc *, void *);
     49  1.2.2.2  tls static int set_pkgsrc(struct menudesc *, void *);
     50  1.2.2.2  tls static void config_list_init(void);
     51  1.2.2.2  tls static void get_rootsh(void);
     52  1.2.2.2  tls static int toggle_rcvar(struct menudesc *, void *);
     53  1.2.2.2  tls static void configmenu_hdr(struct menudesc *, void *);
     54  1.2.2.2  tls static int check_root_password(void);
     55  1.2.2.2  tls 
     56  1.2.2.2  tls char pkgpath[STRSIZE];
     57  1.2.2.2  tls char pkgsrcpath[STRSIZE];
     58  1.2.2.2  tls 
     59  1.2.2.2  tls extern const char *tz_default;
     60  1.2.2.2  tls 
     61  1.2.2.2  tls enum {
     62  1.2.2.2  tls 	CONFIGOPT_NETCONF,
     63  1.2.2.2  tls 	CONFIGOPT_TZ,
     64  1.2.2.2  tls 	CONFIGOPT_ROOTSH,
     65  1.2.2.2  tls 	CONFIGOPT_ROOTPW,
     66  1.2.2.2  tls 	CONFIGOPT_BINPKG,
     67  1.2.2.2  tls 	CONFIGOPT_PKGSRC,
     68  1.2.2.2  tls 	CONFIGOPT_SSHD,
     69  1.2.2.2  tls 	CONFIGOPT_NTPD,
     70  1.2.2.2  tls 	CONFIGOPT_NTPDATE,
     71  1.2.2.2  tls 	CONFIGOPT_MDNSD,
     72  1.2.2.2  tls 	CONFIGOPT_XDM,
     73  1.2.2.2  tls 	CONFIGOPT_CGD,
     74  1.2.2.2  tls 	CONFIGOPT_LVM,
     75  1.2.2.2  tls 	CONFIGOPT_RAIDFRAME,
     76  1.2.2.2  tls 	CONFIGOPT_ADDUSER,
     77  1.2.2.2  tls 	CONFIGOPT_LAST
     78  1.2.2.2  tls };
     79  1.2.2.2  tls 
     80  1.2.2.2  tls typedef struct configinfo {
     81  1.2.2.2  tls 	const char	*optname;
     82  1.2.2.2  tls 	uint		opt;
     83  1.2.2.2  tls 	const char	*rcvar;
     84  1.2.2.2  tls 	int		(*action)(struct menudesc *, void *);
     85  1.2.2.2  tls 	const char	*setting;
     86  1.2.2.2  tls } configinfo;
     87  1.2.2.2  tls 
     88  1.2.2.2  tls 
     89  1.2.2.2  tls configinfo config_list[] = {
     90  1.2.2.2  tls 	{MSG_Configure_network, CONFIGOPT_NETCONF, NULL, set_network, MSG_configure},
     91  1.2.2.2  tls 	{MSG_timezone, CONFIGOPT_TZ, NULL, set_timezone_menu, NULL},
     92  1.2.2.2  tls 	{MSG_Root_shell, CONFIGOPT_ROOTSH, NULL, set_root_shell, NULL},
     93  1.2.2.2  tls 	{MSG_change_rootpw, CONFIGOPT_ROOTPW, NULL, change_root_password, MSG_change},
     94  1.2.2.2  tls 	{MSG_enable_binpkg, CONFIGOPT_BINPKG, NULL, set_binpkg, MSG_install},
     95  1.2.2.2  tls 	{MSG_get_pkgsrc, CONFIGOPT_PKGSRC, NULL, set_pkgsrc, MSG_install},
     96  1.2.2.2  tls 	{MSG_enable_sshd, CONFIGOPT_SSHD, "sshd", toggle_rcvar, NULL},
     97  1.2.2.2  tls 	{MSG_enable_ntpd, CONFIGOPT_NTPD, "ntpd", toggle_rcvar, NULL},
     98  1.2.2.2  tls 	{MSG_run_ntpdate, CONFIGOPT_NTPDATE, "ntpdate", toggle_rcvar, NULL},
     99  1.2.2.2  tls 	{MSG_enable_mdnsd, CONFIGOPT_MDNSD, "mdnsd", toggle_rcvar, NULL},
    100  1.2.2.2  tls 	{MSG_enable_xdm, CONFIGOPT_XDM, "xdm", toggle_rcvar, NULL},
    101  1.2.2.2  tls 	{MSG_enable_cgd, CONFIGOPT_CGD, "cgd", toggle_rcvar, NULL},
    102  1.2.2.2  tls 	{MSG_enable_lvm, CONFIGOPT_LVM, "lvm", toggle_rcvar, NULL},
    103  1.2.2.2  tls 	{MSG_enable_raid, CONFIGOPT_RAIDFRAME, "raidframe", toggle_rcvar, NULL},
    104  1.2.2.2  tls 	{MSG_add_a_user, CONFIGOPT_ADDUSER, NULL, add_new_user, ""},
    105  1.2.2.2  tls 	{NULL,		CONFIGOPT_LAST,	NULL, NULL, NULL}
    106  1.2.2.2  tls };
    107  1.2.2.2  tls 
    108  1.2.2.2  tls static void
    109  1.2.2.2  tls config_list_init(void)
    110  1.2.2.2  tls {
    111  1.2.2.2  tls 	int i;
    112  1.2.2.2  tls 
    113  1.2.2.2  tls 	for (i=0; i < CONFIGOPT_LAST; i++) {
    114  1.2.2.2  tls 		switch (i) {
    115  1.2.2.2  tls 		case CONFIGOPT_TZ:
    116  1.2.2.2  tls 			get_tz_default();
    117  1.2.2.2  tls 			config_list[CONFIGOPT_TZ].setting = tz_default;
    118  1.2.2.2  tls 			break;
    119  1.2.2.2  tls 		case CONFIGOPT_ROOTSH:
    120  1.2.2.2  tls 			get_rootsh();
    121  1.2.2.2  tls 			break;
    122  1.2.2.2  tls 		case CONFIGOPT_ROOTPW:
    123  1.2.2.2  tls 			if (check_root_password())
    124  1.2.2.2  tls 				config_list[i].setting = MSG_password_set;
    125  1.2.2.2  tls 			else
    126  1.2.2.2  tls 				config_list[i].setting = MSG_empty;
    127  1.2.2.2  tls 			break;
    128  1.2.2.2  tls 		default:
    129  1.2.2.2  tls 			if (config_list[i].rcvar != NULL) {
    130  1.2.2.2  tls 				if (check_rcvar(config_list[i].rcvar))
    131  1.2.2.2  tls 					config_list[i].setting = MSG_YES;
    132  1.2.2.2  tls 				else
    133  1.2.2.2  tls 					config_list[i].setting = MSG_NO;
    134  1.2.2.2  tls 			}
    135  1.2.2.2  tls 			break;
    136  1.2.2.2  tls 		}
    137  1.2.2.2  tls 	}
    138  1.2.2.2  tls }
    139  1.2.2.2  tls 
    140  1.2.2.2  tls static void
    141  1.2.2.2  tls get_rootsh(void)
    142  1.2.2.2  tls {
    143  1.2.2.2  tls 	static char *buf = NULL;
    144  1.2.2.2  tls 
    145  1.2.2.2  tls 	if (buf != NULL)
    146  1.2.2.2  tls 		free(buf);
    147  1.2.2.2  tls 
    148  1.2.2.2  tls 	if (target_already_root())
    149  1.2.2.2  tls 		collect(T_OUTPUT, &buf,
    150  1.2.2.2  tls 		    "/usr/bin/awk -F: '$1==\"root\" { print $NF; exit }'"
    151  1.2.2.2  tls 		    " /etc/passwd");
    152  1.2.2.2  tls 	else
    153  1.2.2.2  tls 		collect(T_OUTPUT, &buf,
    154  1.2.2.2  tls 		    "chroot %s /usr/bin/awk -F: '$1==\"root\" { print $NF; exit }'"
    155  1.2.2.2  tls 		    " /etc/passwd",target_prefix());
    156  1.2.2.2  tls 
    157  1.2.2.2  tls 	config_list[CONFIGOPT_ROOTSH].setting = (const char *)buf;
    158  1.2.2.2  tls }
    159  1.2.2.2  tls 
    160  1.2.2.2  tls static void
    161  1.2.2.2  tls set_config(menudesc *menu, int opt, void *arg)
    162  1.2.2.2  tls {
    163  1.2.2.2  tls 	configinfo	**configp = arg;
    164  1.2.2.2  tls 	configinfo	*config = configp[opt];
    165  1.2.2.2  tls 	const char	*optname, *setting;
    166  1.2.2.2  tls 
    167  1.2.2.2  tls 	optname = config->optname;
    168  1.2.2.2  tls 	setting = msg_string(config->setting);
    169  1.2.2.2  tls 
    170  1.2.2.2  tls 	wprintw(menu->mw, "%-50s %-10s", msg_string(optname), setting);
    171  1.2.2.2  tls }
    172  1.2.2.2  tls 
    173  1.2.2.2  tls static int
    174  1.2.2.2  tls init_config_menu(configinfo *conf, menu_ent *me, configinfo **ce)
    175  1.2.2.2  tls {
    176  1.2.2.2  tls 	int	opt;
    177  1.2.2.2  tls 	int	configopts;
    178  1.2.2.2  tls 
    179  1.2.2.2  tls 	for (configopts = 0; ; conf++) {
    180  1.2.2.2  tls 		opt = conf->opt;
    181  1.2.2.2  tls 		if (opt == CONFIGOPT_LAST)
    182  1.2.2.2  tls 			break;
    183  1.2.2.2  tls 		*ce = conf;
    184  1.2.2.2  tls 		me->opt_menu = OPT_NOMENU;
    185  1.2.2.2  tls 		me->opt_flags = 0;
    186  1.2.2.2  tls 		me->opt_name = NULL;  /* NULL so set_config will draw */
    187  1.2.2.2  tls 		me->opt_action = conf->action;
    188  1.2.2.2  tls 		configopts++;
    189  1.2.2.2  tls 		ce++;
    190  1.2.2.2  tls 		me++;
    191  1.2.2.2  tls 	}
    192  1.2.2.2  tls 
    193  1.2.2.2  tls 	return configopts;
    194  1.2.2.2  tls }
    195  1.2.2.2  tls 
    196  1.2.2.2  tls static int
    197  1.2.2.2  tls /*ARGSUSED*/
    198  1.2.2.2  tls set_timezone_menu(struct menudesc *menu, void *arg)
    199  1.2.2.2  tls {
    200  1.2.2.2  tls 	configinfo **confp = arg;
    201  1.2.2.2  tls 	set_timezone();
    202  1.2.2.2  tls 	get_tz_default();
    203  1.2.2.2  tls 	confp[menu->cursel]->setting = tz_default;
    204  1.2.2.2  tls 	return 0;
    205  1.2.2.2  tls }
    206  1.2.2.2  tls 
    207  1.2.2.2  tls static int
    208  1.2.2.2  tls set_root_shell(struct menudesc *menu, void *arg)
    209  1.2.2.2  tls {
    210  1.2.2.2  tls 	configinfo **confp = arg;
    211  1.2.2.2  tls 
    212  1.2.2.2  tls 	process_menu(MENU_rootsh, &confp[menu->cursel]->setting);
    213  1.2.2.2  tls 	if (run_program(RUN_PROGRESS | RUN_CHROOT,
    214  1.2.2.2  tls 		"chpass -s %s root", confp[menu->cursel]->setting) != 0)
    215  1.2.2.2  tls 		confp[menu->cursel]->setting = MSG_failed;
    216  1.2.2.2  tls 	return 0;
    217  1.2.2.2  tls }
    218  1.2.2.2  tls 
    219  1.2.2.2  tls static int
    220  1.2.2.2  tls set_network(struct menudesc *menu, void *arg)
    221  1.2.2.2  tls {
    222  1.2.2.2  tls 	network_up = 0;
    223  1.2.2.2  tls 	if (config_network())
    224  1.2.2.2  tls 		mnt_net_config();
    225  1.2.2.2  tls 	return 0;
    226  1.2.2.2  tls }
    227  1.2.2.2  tls 
    228  1.2.2.2  tls static int
    229  1.2.2.2  tls check_root_password(void)
    230  1.2.2.2  tls {
    231  1.2.2.2  tls 	char *buf;
    232  1.2.2.2  tls 	int rval;
    233  1.2.2.2  tls 
    234  1.2.2.2  tls 	if (target_already_root())
    235  1.2.2.2  tls 		collect(T_OUTPUT, &buf, "getent passwd root | cut -d: -f2");
    236  1.2.2.2  tls 	else
    237  1.2.2.2  tls 		collect(T_OUTPUT, &buf, "chroot %s getent passwd root | "
    238  1.2.2.2  tls 		    "chroot %s cut -d: -f2",
    239  1.2.2.2  tls 		    target_prefix(), target_prefix());
    240  1.2.2.2  tls 
    241  1.2.2.2  tls 	if (logfp)
    242  1.2.2.2  tls 		fprintf(logfp,"buf %s strlen(buf) %zu\n", buf, strlen(buf));
    243  1.2.2.2  tls 
    244  1.2.2.2  tls 	if (strlen(buf) <= 1)  /* newline */
    245  1.2.2.2  tls 		rval = 0;
    246  1.2.2.2  tls 	else
    247  1.2.2.2  tls 		rval = 1;
    248  1.2.2.2  tls 	free(buf);
    249  1.2.2.2  tls 	return rval;
    250  1.2.2.2  tls }
    251  1.2.2.2  tls 
    252  1.2.2.2  tls static int
    253  1.2.2.2  tls add_new_user(struct menudesc *menu, void *arg)
    254  1.2.2.2  tls {
    255  1.2.2.2  tls 	char username[STRSIZE];
    256  1.2.2.2  tls 	int inwheel=0;
    257  1.2.2.2  tls 
    258  1.2.2.2  tls 	msg_prompt(MSG_addusername, NULL, username, sizeof username -1);
    259  1.2.2.2  tls 	process_menu(MENU_yesno, deconst(MSG_addusertowheel));
    260  1.2.2.2  tls 	inwheel = yesno;
    261  1.2.2.2  tls 	ushell = "/bin/csh";
    262  1.2.2.2  tls 	process_menu(MENU_usersh, NULL);
    263  1.2.2.2  tls 	if (inwheel)
    264  1.2.2.2  tls 		run_program(RUN_PROGRESS | RUN_CHROOT,
    265  1.2.2.2  tls 		    "/usr/sbin/useradd -m -s %s -G wheel %s",
    266  1.2.2.2  tls 		    ushell, username);
    267  1.2.2.2  tls 	else
    268  1.2.2.2  tls 		run_program(RUN_PROGRESS | RUN_CHROOT,
    269  1.2.2.2  tls 		    "/usr/sbin/useradd -m -s %s %s", ushell, username);
    270  1.2.2.2  tls 	run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    271  1.2.2.2  tls 	    "passwd -l %s", username);
    272  1.2.2.2  tls 	return 0;
    273  1.2.2.2  tls }
    274  1.2.2.2  tls 
    275  1.2.2.2  tls static int
    276  1.2.2.2  tls change_root_password(struct menudesc *menu, void *arg)
    277  1.2.2.2  tls {
    278  1.2.2.2  tls 	configinfo **confp = arg;
    279  1.2.2.2  tls 
    280  1.2.2.2  tls 	msg_display(MSG_rootpw);
    281  1.2.2.2  tls 	process_menu(MENU_yesno, NULL);
    282  1.2.2.2  tls 	if (yesno) {
    283  1.2.2.2  tls 		if (run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    284  1.2.2.2  tls 			"passwd -l root") == 0)
    285  1.2.2.2  tls 			confp[menu->cursel]->setting = MSG_password_set;
    286  1.2.2.2  tls 		else
    287  1.2.2.2  tls 			confp[menu->cursel]->setting = MSG_failed;
    288  1.2.2.2  tls 	}
    289  1.2.2.2  tls 	return 0;
    290  1.2.2.2  tls }
    291  1.2.2.2  tls 
    292  1.2.2.2  tls static int
    293  1.2.2.2  tls set_binpkg(struct menudesc *menu, void *arg)
    294  1.2.2.2  tls {
    295  1.2.2.2  tls 	configinfo **confp = arg;
    296  1.2.2.2  tls 	char additional_pkgs[STRSIZE] = {0};
    297  1.2.2.2  tls 	char pattern[STRSIZE];
    298  1.2.2.2  tls 	int allok = 0;
    299  1.2.2.2  tls 
    300  1.2.2.2  tls 	do {
    301  1.2.2.2  tls 		yesno = -1;
    302  1.2.2.2  tls 		process_menu(MENU_binpkg, additional_pkgs);
    303  1.2.2.2  tls 		if (yesno == SET_SKIP) {
    304  1.2.2.2  tls 			confp[menu->cursel]->setting = MSG_abandoned;
    305  1.2.2.2  tls 			return 0;
    306  1.2.2.2  tls 		}
    307  1.2.2.2  tls 
    308  1.2.2.2  tls 		make_url(pkgpath, &pkg, pkg_dir);
    309  1.2.2.2  tls 		if (run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    310  1.2.2.2  tls 			"pkg_add %s/pkgin", pkgpath) == 0) {
    311  1.2.2.2  tls 			allok = 1;
    312  1.2.2.2  tls 		}
    313  1.2.2.2  tls 	} while (allok == 0);
    314  1.2.2.2  tls 
    315  1.2.2.2  tls 	/* configure pkgin to use $pkgpath as a repository */
    316  1.2.2.2  tls 	snprintf(pattern, STRSIZE, "s,^[^#].*$,%s,", pkgpath);
    317  1.2.2.2  tls 	replace("/usr/pkg/etc/pkgin/repositories.conf", pattern);
    318  1.2.2.2  tls 
    319  1.2.2.2  tls 	run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    320  1.2.2.2  tls 		"/usr/pkg/bin/pkgin -y update");
    321  1.2.2.2  tls 
    322  1.2.2.2  tls 	if (strlen(additional_pkgs) > 0)
    323  1.2.2.2  tls 		run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    324  1.2.2.2  tls 		"/usr/pkg/bin/pkgin -y install %s", additional_pkgs);
    325  1.2.2.2  tls 
    326  1.2.2.2  tls 	msg_display(MSG_binpkg_installed);
    327  1.2.2.2  tls 	process_menu(MENU_ok, NULL);
    328  1.2.2.2  tls 
    329  1.2.2.2  tls 	confp[menu->cursel]->setting = MSG_DONE;
    330  1.2.2.2  tls 	return 0;
    331  1.2.2.2  tls }
    332  1.2.2.2  tls 
    333  1.2.2.2  tls static int
    334  1.2.2.2  tls set_pkgsrc(struct menudesc *menu, void *arg)
    335  1.2.2.2  tls {
    336  1.2.2.2  tls 	configinfo **confp = arg;
    337  1.2.2.2  tls 	distinfo dist;
    338  1.2.2.2  tls 
    339  1.2.2.2  tls 	dist.name = "pkgsrc";
    340  1.2.2.2  tls 	dist.set = SET_PKGSRC;
    341  1.2.2.2  tls 	dist.desc = "source for 3rd-party packages";
    342  1.2.2.2  tls 	dist.marker_file = NULL;
    343  1.2.2.2  tls 
    344  1.2.2.2  tls 	int status = SET_RETRY;
    345  1.2.2.2  tls 
    346  1.2.2.2  tls 	do {
    347  1.2.2.2  tls 		status = get_pkgsrc();
    348  1.2.2.2  tls 		if (status == SET_OK) {
    349  1.2.2.2  tls 			status = extract_file(&dist, 0);
    350  1.2.2.2  tls 			continue;
    351  1.2.2.2  tls 		} else if (status == SET_SKIP) {
    352  1.2.2.2  tls 			confp[menu->cursel]->setting = MSG_abandoned;
    353  1.2.2.2  tls 			return 0;
    354  1.2.2.2  tls 		}
    355  1.2.2.2  tls 		process_menu(MENU_yesno, deconst(MSG_retry_pkgsrc_network));
    356  1.2.2.2  tls 		if (!yesno) {
    357  1.2.2.2  tls 			confp[menu->cursel]->setting = MSG_abandoned;
    358  1.2.2.2  tls 			return 1;
    359  1.2.2.2  tls 		}
    360  1.2.2.2  tls 	}
    361  1.2.2.2  tls 	while (status == SET_RETRY);
    362  1.2.2.2  tls 
    363  1.2.2.2  tls 	confp[menu->cursel]->setting = MSG_DONE;
    364  1.2.2.2  tls 	return 0;
    365  1.2.2.2  tls }
    366  1.2.2.2  tls 
    367  1.2.2.2  tls static int
    368  1.2.2.2  tls toggle_rcvar(struct menudesc *menu, void *arg)
    369  1.2.2.2  tls {
    370  1.2.2.2  tls 	configinfo **confp = arg;
    371  1.2.2.2  tls 	int s;
    372  1.2.2.2  tls 	const char *setting, *varname;
    373  1.2.2.2  tls 	char pattern[STRSIZE];
    374  1.2.2.2  tls 	char buf[STRSIZE];
    375  1.2.2.2  tls 	char *cp;
    376  1.2.2.2  tls 	int found = 0;
    377  1.2.2.2  tls 	FILE *fp;
    378  1.2.2.2  tls 
    379  1.2.2.2  tls 	varname = confp[menu->cursel]->rcvar;
    380  1.2.2.2  tls 
    381  1.2.2.2  tls 	s = check_rcvar(varname);
    382  1.2.2.2  tls 
    383  1.2.2.2  tls 	/* we're toggling, so invert the sense */
    384  1.2.2.2  tls 	if (s) {
    385  1.2.2.2  tls 		confp[menu->cursel]->setting = MSG_NO;
    386  1.2.2.2  tls 		setting = "NO";
    387  1.2.2.2  tls 	} else {
    388  1.2.2.2  tls 		confp[menu->cursel]->setting = MSG_YES;
    389  1.2.2.2  tls 		setting = "YES";
    390  1.2.2.2  tls 	}
    391  1.2.2.2  tls 
    392  1.2.2.2  tls 	if (!(fp = fopen(target_expand("/etc/rc.conf"), "r"))) {
    393  1.2.2.2  tls 		msg_display(MSG_openfail, target_expand("/etc/rc.conf"), strerror(errno));
    394  1.2.2.2  tls 		process_menu(MENU_ok, NULL);
    395  1.2.2.2  tls 		return 0;
    396  1.2.2.2  tls 	}
    397  1.2.2.2  tls 
    398  1.2.2.2  tls 	while (fgets(buf, sizeof buf, fp) != NULL) {
    399  1.2.2.2  tls 		cp = buf + strspn(buf, " \t"); /* Skip initial spaces */
    400  1.2.2.2  tls 		if (strncmp(cp, varname, strlen(varname)) == 0) {
    401  1.2.2.2  tls 			cp += strlen(varname);
    402  1.2.2.2  tls 			if (*cp != '=')
    403  1.2.2.2  tls 				continue;
    404  1.2.2.2  tls 			buf[strlen(buf) - 1] = 0;
    405  1.2.2.2  tls 			snprintf(pattern, sizeof pattern,
    406  1.2.2.2  tls 					"s,^%s$,%s=%s,",
    407  1.2.2.2  tls 					buf, varname, setting);
    408  1.2.2.2  tls 			found = 1;
    409  1.2.2.2  tls 			break;
    410  1.2.2.2  tls 		}
    411  1.2.2.2  tls 	}
    412  1.2.2.2  tls 
    413  1.2.2.2  tls 	fclose(fp);
    414  1.2.2.2  tls 
    415  1.2.2.2  tls 	if (!found) {
    416  1.2.2.2  tls 		add_rc_conf("%s=%s\n", varname, setting);
    417  1.2.2.2  tls 		if (logfp) {
    418  1.2.2.2  tls 			fprintf(logfp, "adding %s=%s\n", varname, setting);
    419  1.2.2.2  tls 			fflush(logfp);
    420  1.2.2.2  tls 		}
    421  1.2.2.2  tls 	} else {
    422  1.2.2.2  tls 		if (logfp) {
    423  1.2.2.2  tls 			fprintf(logfp, "replacement pattern is %s\n", pattern);
    424  1.2.2.2  tls 			fflush(logfp);
    425  1.2.2.2  tls 		}
    426  1.2.2.2  tls 		replace("/etc/rc.conf", pattern);
    427  1.2.2.2  tls 	}
    428  1.2.2.2  tls 
    429  1.2.2.2  tls 	return 0;
    430  1.2.2.2  tls }
    431  1.2.2.2  tls 
    432  1.2.2.2  tls static void
    433  1.2.2.2  tls configmenu_hdr(struct menudesc *menu, void *arg)
    434  1.2.2.2  tls {
    435  1.2.2.2  tls 	msg_display(MSG_configmenu);
    436  1.2.2.2  tls }
    437  1.2.2.2  tls 
    438  1.2.2.2  tls void
    439  1.2.2.2  tls do_configmenu()
    440  1.2.2.2  tls {
    441  1.2.2.2  tls 	int		menu_no;
    442  1.2.2.2  tls 	int		opts;
    443  1.2.2.2  tls 	menu_ent	me[CONFIGOPT_LAST];
    444  1.2.2.2  tls 	configinfo	*ce[CONFIGOPT_LAST];
    445  1.2.2.2  tls 
    446  1.2.2.2  tls 	/* if the target isn't mounted already, figure it out. */
    447  1.2.2.2  tls 	if (target_mounted() == 0) {
    448  1.2.2.2  tls 		partman_go = 0;
    449  1.2.2.2  tls 		if (find_disks(msg_string(MSG_configure_prior)) < 0)
    450  1.2.2.2  tls 			return;
    451  1.2.2.2  tls 
    452  1.2.2.2  tls 		if (mount_disks() != 0)
    453  1.2.2.2  tls 			return;
    454  1.2.2.2  tls 	}
    455  1.2.2.2  tls 
    456  1.2.2.2  tls 	config_list_init();
    457  1.2.2.2  tls 	make_url(pkgpath, &pkg, pkg_dir);
    458  1.2.2.2  tls 	opts = init_config_menu(config_list, me, ce);
    459  1.2.2.2  tls 
    460  1.2.2.2  tls 	wrefresh(curscr);
    461  1.2.2.2  tls 	wmove(stdscr, 0, 0);
    462  1.2.2.2  tls 	wclear(stdscr);
    463  1.2.2.2  tls 	wrefresh(stdscr);
    464  1.2.2.2  tls 
    465  1.2.2.2  tls 	menu_no = new_menu(NULL, me, opts, 0, -4, 0, 70,
    466  1.2.2.2  tls 		MC_SCROLL | MC_NOBOX | MC_DFLTEXIT,
    467  1.2.2.2  tls 		configmenu_hdr, set_config, NULL, "XXX Help String",
    468  1.2.2.2  tls 		MSG_doneconfig);
    469  1.2.2.2  tls 
    470  1.2.2.2  tls 	process_menu(menu_no, ce);
    471  1.2.2.2  tls 	free_menu(menu_no);
    472  1.2.2.2  tls }
    473