Merge pull request #450 from lnussel/master

useradd: assume uid 0 == root as fallback
This commit is contained in:
Serge Hallyn 2021-12-04 22:21:37 -06:00 committed by GitHub
commit 535f54076c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2507,14 +2507,14 @@ int main (int argc, char **argv)
{ {
struct passwd *pampw; struct passwd *pampw;
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */ pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
if (pampw == NULL) { if (pampw == NULL && getuid ()) {
fprintf (stderr, fprintf (stderr,
_("%s: Cannot determine your user name.\n"), _("%s: Cannot determine your user name.\n"),
Prog); Prog);
fail_exit (1); 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) { if (PAM_SUCCESS == retval) {