diff --git a/docs/NEXT.md b/docs/NEXT.md index 4dced883c1..d789d6036f 100644 --- a/docs/NEXT.md +++ b/docs/NEXT.md @@ -72,7 +72,7 @@ scheitern `cp /etc/wpa_supplicant.conf` und `cp /etc/resolv.conf` (`net.c: mnt_n ist**. Konrads Wunsch: im einfachen Ablauf, solange das Ziel eingehängt ist, die Menüpunkte des Config-Menüs aufrufen, statt eigene Formulare zu bauen. -Plan (Entwurf fertig, **nichts davon ist geschrieben**): +Stand 2026-11-09 abends: Schritte 1, 2, 3, 4, 5 sind geschrieben und committet (Syntaxprüfung mit dem Cross-gcc, `-Wall -Wextra`, sauber); **nicht gebaut, nicht getestet**. Kette `2026-11-09c` gestartet (Log `build/logs/x-*-2026-11-09c.log`). Offen: Schritt 6 (Doku) und ob die neuen Test-Antworten auf die echten Masken passen (Fehlerfall: Test hängt, Bildschirm mit `vmsh since` ansehen). Plan: 1. `configmenu.c` (am Ende) zwei nicht-statische Wrapper: `void makronix_config_network(void) { (void)set_network(NULL, NULL); }` und `void makronix_config_user(void) { (void)add_new_user(NULL, NULL); }`; Prototypen in `defs.h` diff --git a/overlay/usr.sbin/sysinst/configmenu.c b/overlay/usr.sbin/sysinst/configmenu.c index 1cdf82b15d..43faf4b2e2 100644 --- a/overlay/usr.sbin/sysinst/configmenu.c +++ b/overlay/usr.sbin/sysinst/configmenu.c @@ -717,3 +717,21 @@ do_time_and_date_setup(const char *header) process_menu(menu_no, &menu_arg); free_menu(menu_no); } + +/* + * Makronix simple installation (setup.c): the same entries of this menu, + * called while the target is still mounted. + */ +void +makronix_config_network(void) +{ + + (void)set_network(NULL, NULL); +} + +void +makronix_config_user(void) +{ + + (void)add_new_user(NULL, NULL); +} diff --git a/overlay/usr.sbin/sysinst/defs.h b/overlay/usr.sbin/sysinst/defs.h index 1a16beeeec..8d58d60290 100644 --- a/overlay/usr.sbin/sysinst/defs.h +++ b/overlay/usr.sbin/sysinst/defs.h @@ -1062,6 +1062,8 @@ void save_kb_encoding(void); /* from configmenu.c */ void do_configmenu(struct install_partition_desc*); void root_pw_setup(void); +void makronix_config_network(void); +void makronix_config_user(void); /* setup.c: Makronix, the last step of the simple installation */ void makronix_setup(void); void makronix_extras(void); diff --git a/overlay/usr.sbin/sysinst/setup.c b/overlay/usr.sbin/sysinst/setup.c index 8676cf9244..ff61df2d35 100644 --- a/overlay/usr.sbin/sysinst/setup.c +++ b/overlay/usr.sbin/sysinst/setup.c @@ -37,7 +37,6 @@ /* the groups of the user of the computer: all NetBSD groups of a desktop user */ /* wsrc: /usr/src, /usr/xsrc and /usr/msrc are root:wsrc, group-writable */ #define USER_GROUPS "wheel,operator,staff,users,dialer,games,wsrc" -#define USER_SHELL "/bin/ksh" /* dtlogin's rc script and PAM file come with the pkgsrc package as examples */ #define DT_RC_EXAMPLE "/usr/pkg/share/examples/rc.d/dtlogin" @@ -55,56 +54,6 @@ valid_hostname(const char *s) return true; } -/* a login name as useradd(8) takes it: [a-z_][a-z0-9_-]*, at most 31 */ -static bool -valid_login(const char *s) -{ - - if (*s == '\0' || strlen(s) > 31) - return false; - if (!islower((unsigned char)*s) && *s != '_') - return false; - for (; *s != '\0'; s++) - if (!islower((unsigned char)*s) && !isdigit((unsigned char)*s) && - *s != '-' && *s != '_') - return false; - return true; -} - -/* ask for a password twice, without echo, until both are the same */ -static void -ask_password(msg prompt, char *pw, size_t len) -{ - char again[STRSIZE]; - - for (;;) { - msg_prompt_noecho(prompt, "", pw, len - 1); - if (pw[0] == '\0') { - hit_enter_to_continue(MSG_setup_pw_empty, NULL); - continue; - } - msg_prompt_noecho(MSG_setup_pw_again, "", again, - sizeof again - 1); - if (strcmp(pw, again) == 0) - break; - hit_enter_to_continue(MSG_setup_pw_mismatch, NULL); - } - memset(again, 0, sizeof again); -} - -/* store the password of a user of the new system */ -static int -set_password(const char *user, const char *pw) -{ - int rv; - - setenv("MXPW", pw, 1); - rv = run_program(RUN_SILENT | RUN_CHROOT | RUN_ERROR_OK, - "sh -c 'usermod -p \"$(pwhash \"$MXPW\")\" %s'", user); - unsetenv("MXPW"); - return rv; -} - static void set_rc(const char *var, const char *value) { @@ -231,11 +180,42 @@ set_pkg_defaults(void) "sh -c 'echo fetch_pkg_vulnerabilities=YES >> /etc/daily.conf'"); } +/* + * add_new_user (configmenu.c) puts a user into wheel at most; give every + * ordinary user (uid 1000..59999, useradd.conf(5)) the groups of a desktop + * user and return the last name for the closing message. + */ +static void +user_groups(char *user, size_t len) +{ + FILE *f; + char line[STRSIZE], *name, *p; + long uid; + + user[0] = '\0'; + if ((f = fopen(target_expand("/etc/passwd"), "r")) == NULL) + return; + while (fgets(line, sizeof line, f) != NULL) { + name = line; + if ((p = strchr(name, ':')) == NULL) + continue; + *p++ = '\0'; + if ((p = strchr(p, ':')) == NULL) + continue; + uid = strtol(p + 1, NULL, 10); + if (uid < 1000 || uid > 59999) + continue; + run_program(RUN_SILENT | RUN_CHROOT | RUN_ERROR_OK, + "/usr/sbin/usermod -G " USER_GROUPS " %s", name); + strlcpy(user, name, len); + } + fclose(f); +} + void makronix_setup(void) { - char host[STRSIZE] = "", full[STRSIZE] = "", user[STRSIZE] = ""; - char pw[STRSIZE], *p; + char host[STRSIZE] = "", user[STRSIZE] = ""; msg_display(MSG_setup_intro); hit_enter_to_continue(NULL, NULL); @@ -250,38 +230,21 @@ makronix_setup(void) } set_rc("hostname", host); - /* the network */ - msg_display(MSG_setup_dhcp); - if (ask_yesno(NULL)) + /* net.c fills its form from gethostname() */ + (void)sethostname(host, strlen(host)); + + /* the network: the entry of the configuration menu (configmenu.c) */ + makronix_config_network(); + if (!network_up) set_rc("dhcpcd", "YES"); /* the time zone: sysinst's own list (util.c, set_timezone) */ (void)set_timezone(); - /* the administrator */ - ask_password(MSG_setup_rootpw, pw, sizeof pw); - if (set_password("root", pw) != 0) - hit_enter_to_continue(MSG_setup_failed, NULL); - - /* the user of the computer */ - msg_prompt(MSG_setup_fullname, "", full, sizeof full - 1); - for (p = full; *p != '\0'; p++) - if (*p == '\'' || *p == '\\' || *p == '"' || *p == '`' || - *p == '$') - *p = ' '; - for (;;) { - msg_prompt(MSG_setup_username, "", user, sizeof user - 1); - if (valid_login(user)) - break; - hit_enter_to_continue(MSG_setup_user_invalid, NULL); - } - ask_password(MSG_setup_userpw, pw, sizeof pw); - if (run_program(RUN_PROGRESS | RUN_CHROOT | RUN_ERROR_OK, - "/usr/sbin/useradd -m -s " USER_SHELL " -c '%s' -G " USER_GROUPS - " %s", full[0] != '\0' ? full : user, user) != 0 || - set_password(user, pw) != 0) - hit_enter_to_continue(MSG_setup_failed, NULL); - memset(pw, 0, sizeof pw); + /* the administrator and the user: the configuration menu again */ + root_pw_setup(); + makronix_config_user(); + user_groups(user, sizeof user); /* what a desktop computer runs at boot */ set_rc("ntpdate", "YES"); diff --git a/overlay/usr.sbin/sysinst/target.c b/overlay/usr.sbin/sysinst/target.c index dd242fc76c..6fc154136f 100644 --- a/overlay/usr.sbin/sysinst/target.c +++ b/overlay/usr.sbin/sysinst/target.c @@ -420,7 +420,7 @@ void dup_file_into_target(const char *filename) { - if (!target_already_root()) + if (!target_already_root() && access(filename, R_OK) == 0) cp_to_target(filename, filename); } diff --git a/tools/install-cgd.sh b/tools/install-cgd.sh index e608a997f3..41692c8bb0 100755 --- a/tools/install-cgd.sh +++ b/tools/install-cgd.sh @@ -131,18 +131,28 @@ while [ $i -lt 1500 ]; do # the questions of the simple mode's last step (setup.c) *'Name of this computer'*) $V send 'mxtest\r'; asked="$asked "; nasked=$((nasked + 1)) ;; - *'automatically (DHCP)'*) + # since 2026-11-09 the network, root and the user come from the entries + # of the configuration menu (configmenu.c, net.c, passwd -l) + *'Which network device'*) + key a; asked="$asked "; nasked=$((nasked + 1)) ;; + *'Network media type'*|*'Your host name'*|*'Your DNS domain'*|*'Your name server'*) + $V send '\r'; asked="$asked "; nasked=$((nasked + 1)) ;; + *'Perform autoconfiguration'*|*'Are they OK'*|*'installed in /etc'*) + key a; asked="$asked "; nasked=$((nasked + 1)) ;; + *'continue the install process anyway'*) key a ;; + *'problem in setting up the network'*) + key b ;; *'choose the timezone'*) key x ;; # the default (UTC) stays - *'ype the password again'*) - $V send "$UPW\\r"; asked="$asked "; nasked=$((nasked + 1)) ;; - *'assword for the administrator'*|*'assword for your account'*) + *'Retype new password'*|*'New password'*) $V send "$UPW\\r"; asked="$asked "; nasked=$((nasked + 1)) ;; - *'Your full name'*) - $V send 'Test User\r'; asked="$asked "; nasked=$((nasked + 1)) ;; - *'Login name'*) + *'Username to add'*) $V send 'tester\r'; asked="$asked "; nasked=$((nasked + 1)) ;; + *'add this user to group wheel'*) + key a; asked="$asked "; nasked=$((nasked + 1)) ;; + *'/bin/ksh'*) + key b; asked="$asked "; nasked=$((nasked + 1)) ;; *'Hit enter to continue'*) $V send '\r'; asked="$asked "; nasked=$((nasked + 1)) ;; *"passphrase:"*) diff --git a/tools/install-simple.sh b/tools/install-simple.sh index e913d52351..17c94b6ffc 100755 --- a/tools/install-simple.sh +++ b/tools/install-simple.sh @@ -192,18 +192,28 @@ while [ $i -lt 1500 ]; do # the questions of the simple mode's last step (setup.c) *'Name of this computer'*) $V send "$HOST\\r"; asked="$asked "; nasked=$((nasked + 1)) ;; - *'automatically (DHCP)'*) + # since 2026-11-09 the network, root and the user come from the entries + # of the configuration menu (configmenu.c, net.c, passwd -l) + *'Which network device'*) + key a; asked="$asked "; nasked=$((nasked + 1)) ;; + *'Network media type'*|*'Your host name'*|*'Your DNS domain'*|*'Your name server'*) + $V send '\r'; asked="$asked "; nasked=$((nasked + 1)) ;; + *'Perform autoconfiguration'*|*'Are they OK'*|*'installed in /etc'*) + key a; asked="$asked "; nasked=$((nasked + 1)) ;; + *'continue the install process anyway'*) key a ;; + *'problem in setting up the network'*) + key b ;; *'choose the timezone'*) key x ;; # the default (UTC) stays - *'ype the password again'*) - $V send "$UPW\\r"; asked="$asked "; nasked=$((nasked + 1)) ;; - *'assword for the administrator'*|*'assword for your account'*) + *'Retype new password'*|*'New password'*) $V send "$UPW\\r"; asked="$asked "; nasked=$((nasked + 1)) ;; - *'Your full name'*) - $V send 'Test User\r'; asked="$asked "; nasked=$((nasked + 1)) ;; - *'Login name'*) + *'Username to add'*) $V send 'tester\r'; asked="$asked "; nasked=$((nasked + 1)) ;; + *'add this user to group wheel'*) + key a; asked="$asked "; nasked=$((nasked + 1)) ;; + *'/bin/ksh'*) + key b; asked="$asked "; nasked=$((nasked + 1)) ;; *'Hit enter to continue'*) $V send '\r'; asked="$asked "; nasked=$((nasked + 1)) ;; *'Install from'*|*'Bootblocks selection'*|*'correct geometry'*|*'Select your distribution'*)