Some stylistic changes to su(1)

Also set errno to zero before calling getspnam().
This commit is contained in:
sin 2013-10-18 10:20:13 +01:00
parent f7fdd58972
commit 56ce9e8bff
1 changed files with 5 additions and 2 deletions

7
su.c
View File

@ -40,9 +40,12 @@ main(int argc, char **argv)
uid = getuid(); uid = getuid();
errno = 0;
spw = getspnam(usr); spw = getspnam(usr);
if (!spw) if (errno)
eprintf("getspnam: %s:", usr); eprintf("getspnam: %s:", usr);
else if (!spw)
enprintf(EXIT_FAILURE, "who are you?\n");
switch (spw->sp_pwdp[0]) { switch (spw->sp_pwdp[0]) {
case '!': case '!':
@ -74,7 +77,7 @@ main(int argc, char **argv)
if (errno) if (errno)
eprintf("getpwnam: %s", usr); eprintf("getpwnam: %s", usr);
else if (!pw) else if (!pw)
enprintf(EXIT_FAILURE, "getpwnam: %s: no such user\n", usr); enprintf(EXIT_FAILURE, "who are you?\n");
if (initgroups(usr, pw->pw_gid) < 0) if (initgroups(usr, pw->pw_gid) < 0)
eprintf("initgroups:"); eprintf("initgroups:");