* src/su.c: If there are no root account, or if the root account
has an UID != 0, default to the first UID 0 account.
This commit is contained in:
parent
08a212ccae
commit
6b46161f2d
@ -1,3 +1,8 @@
|
||||
2009-04-12 Nicolas François <nicolas.francois@centraliens.net>
|
||||
|
||||
* src/su.c: If there are no root account, or if the root account
|
||||
has an UID != 0, default to the first UID 0 account.
|
||||
|
||||
2009-04-12 Nicolas François <nicolas.francois@centraliens.net>
|
||||
|
||||
* src/login.c: Restore the echoctl, echoke, onclr flags to the
|
||||
|
16
src/su.c
16
src/su.c
@ -305,7 +305,7 @@ static void usage (void)
|
||||
* su - switch user id
|
||||
*
|
||||
* su changes the user's ids to the values for the specified user. if
|
||||
* no new user name is specified, "root" is used by default.
|
||||
* no new user name is specified, "root" or UID 0 is used by default.
|
||||
*
|
||||
* Any additional arguments are passed to the user's shell. In
|
||||
* particular, the argument "-c" will cause the next argument to be
|
||||
@ -457,8 +457,18 @@ int main (int argc, char **argv)
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
if ('\0' == name[0]) { /* use default user ID */
|
||||
(void) strcpy (name, "root");
|
||||
if ('\0' == name[0]) { /* use default user */
|
||||
struct passwd *root_pw = getpwnam("root");
|
||||
if ((NULL != root_pw) && (0 == root_pw->pw_uid)) {
|
||||
(void) strcpy (name, "root");
|
||||
} else {
|
||||
struct passwd *root_pw = getpwuid(0);
|
||||
if (NULL == root_pw) {
|
||||
SYSLOG((LOG_CRIT, "There is no UID 0 user."));
|
||||
su_failure(tty);
|
||||
}
|
||||
(void) strcpy(name, root_pw->pw_name);
|
||||
}
|
||||
}
|
||||
|
||||
doshell = (argc == optind); /* any arguments remaining? */
|
||||
|
Loading…
Reference in New Issue
Block a user