sysinst simple mode: network, root password and user from the configuration menu
setup.c calls set_network/add_new_user (configmenu.c wrappers) and root_pw_setup while the target is mounted, instead of its own forms; ordinary users get the desktop groups afterwards. dup_file_into_target copies only a source that exists. Tests answer the new prompts. Not built yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c7125e6bd
commit
0b4d2a9e34
7 files changed
+99
-96
No files matched your search
+1
-1
@@ -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`
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+17
-7
@@ -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 <hostname>"; 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 <netdev>"; nasked=$((nasked + 1)) ;;
|
||||
*'Network media type'*|*'Your host name'*|*'Your DNS domain'*|*'Your name server'*)
|
||||
$V send '\r'; asked="$asked <net-enter>"; nasked=$((nasked + 1)) ;;
|
||||
*'Perform autoconfiguration'*|*'Are they OK'*|*'installed in /etc'*)
|
||||
key a; asked="$asked <net-yes>"; 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 <pw-again>"; nasked=$((nasked + 1)) ;;
|
||||
*'assword for the administrator'*|*'assword for your account'*)
|
||||
*'Retype new password'*|*'New password'*)
|
||||
$V send "$UPW\\r"; asked="$asked <pw>"; nasked=$((nasked + 1)) ;;
|
||||
*'Your full name'*)
|
||||
$V send 'Test User\r'; asked="$asked <fullname>"; nasked=$((nasked + 1)) ;;
|
||||
*'Login name'*)
|
||||
*'Username to add'*)
|
||||
$V send 'tester\r'; asked="$asked <login>"; nasked=$((nasked + 1)) ;;
|
||||
*'add this user to group wheel'*)
|
||||
key a; asked="$asked <wheel>"; nasked=$((nasked + 1)) ;;
|
||||
*'/bin/ksh'*)
|
||||
key b; asked="$asked <shell>"; nasked=$((nasked + 1)) ;;
|
||||
*'Hit enter to continue'*)
|
||||
$V send '\r'; asked="$asked <enter>"; nasked=$((nasked + 1)) ;;
|
||||
*"passphrase:"*)
|
||||
|
||||
+17
-7
@@ -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 <hostname>"; 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 <netdev>"; nasked=$((nasked + 1)) ;;
|
||||
*'Network media type'*|*'Your host name'*|*'Your DNS domain'*|*'Your name server'*)
|
||||
$V send '\r'; asked="$asked <net-enter>"; nasked=$((nasked + 1)) ;;
|
||||
*'Perform autoconfiguration'*|*'Are they OK'*|*'installed in /etc'*)
|
||||
key a; asked="$asked <net-yes>"; 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 <pw-again>"; nasked=$((nasked + 1)) ;;
|
||||
*'assword for the administrator'*|*'assword for your account'*)
|
||||
*'Retype new password'*|*'New password'*)
|
||||
$V send "$UPW\\r"; asked="$asked <pw>"; nasked=$((nasked + 1)) ;;
|
||||
*'Your full name'*)
|
||||
$V send 'Test User\r'; asked="$asked <fullname>"; nasked=$((nasked + 1)) ;;
|
||||
*'Login name'*)
|
||||
*'Username to add'*)
|
||||
$V send 'tester\r'; asked="$asked <login>"; nasked=$((nasked + 1)) ;;
|
||||
*'add this user to group wheel'*)
|
||||
key a; asked="$asked <wheel>"; nasked=$((nasked + 1)) ;;
|
||||
*'/bin/ksh'*)
|
||||
key b; asked="$asked <shell>"; nasked=$((nasked + 1)) ;;
|
||||
*'Hit enter to continue'*)
|
||||
$V send '\r'; asked="$asked <enter>"; nasked=$((nasked + 1)) ;;
|
||||
*'Install from'*|*'Bootblocks selection'*|*'correct geometry'*|*'Select your distribution'*)
|
||||
|
||||
Reference in new issue
Block a user