]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: assume uid 0 == root as fallback 450/head
authorLudwig Nussel <ludwig.nussel@suse.de>
Tue, 30 Nov 2021 16:14:14 +0000 (17:14 +0100)
committerLudwig Nussel <ludwig.nussel@suse.de>
Tue, 30 Nov 2021 16:14:14 +0000 (17:14 +0100)
In absence of /etc/passwd, eg when bootstrapping a chroot, resolving
uid 0 to a name may not work. Therefore just assume "root".

src/useradd.c

index f7c979580205e411c73c380f57d412901d7dcac7..16447671ccfe38d3dc756fac70b70679f00e2486 100644 (file)
@@ -2507,14 +2507,14 @@ int main (int argc, char **argv)
        {
                struct passwd *pampw;
                pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
-               if (pampw == NULL) {
+               if (pampw == NULL && getuid ()) {
                        fprintf (stderr,
                                 _("%s: Cannot determine your user name.\n"),
                                 Prog);
                        fail_exit (1);
                }
 
-               retval = pam_start ("useradd", pampw->pw_name, &conv, &pamh);
+               retval = pam_start ("useradd", pampw?pampw->pw_name:"root", &conv, &pamh);
        }
 
        if (PAM_SUCCESS == retval) {