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