40 |
|
|
41 |
if (ENABLE_FEATURE_SU_SYSLOG) { |
if (ENABLE_FEATURE_SU_SYSLOG) { |
42 |
/* The utmp entry (via getlogin) is probably the best way to identify |
/* The utmp entry (via getlogin) is probably the best way to identify |
43 |
the user, especially if someone su's from a su-shell. |
* the user, especially if someone su's from a su-shell. |
44 |
But getlogin can fail -- usually due to lack of utmp entry. |
* But getlogin can fail -- usually due to lack of utmp entry. |
45 |
in this case resort to getpwuid. */ |
* in this case resort to getpwuid. */ |
46 |
old_user = xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : ""); |
const char *user; |
47 |
tty = ttyname(2) ? : "none"; |
#if ENABLE_FEATURE_UTMP |
48 |
|
char user_buf[64]; |
49 |
|
user = user_buf; |
50 |
|
if (getlogin_r(user_buf, sizeof(user_buf)) != 0) |
51 |
|
#endif |
52 |
|
{ |
53 |
|
pw = getpwuid(cur_uid); |
54 |
|
user = pw ? pw->pw_name : ""; |
55 |
|
} |
56 |
|
old_user = xstrdup(user); |
57 |
|
tty = xmalloc_ttyname(2); |
58 |
|
if (!tty) { |
59 |
|
tty = "none"; |
60 |
|
} |
61 |
openlog(applet_name, 0, LOG_AUTH); |
openlog(applet_name, 0, LOG_AUTH); |
62 |
} |
} |
63 |
|
|
64 |
pw = getpwnam(opt_username); |
pw = xgetpwnam(opt_username); |
|
if (!pw) |
|
|
bb_error_msg_and_die("unknown id: %s", opt_username); |
|
65 |
|
|
66 |
/* Make sure pw->pw_shell is non-NULL. It may be NULL when NEW_USER |
/* Make sure pw->pw_shell is non-NULL. It may be NULL when NEW_USER |
67 |
is a username that is retrieved via NIS (YP), but that doesn't have |
is a username that is retrieved via NIS (YP), but that doesn't have |
104 |
change_identity(pw); |
change_identity(pw); |
105 |
/* setup_environment params: shell, clear_env, change_env, pw */ |
/* setup_environment params: shell, clear_env, change_env, pw */ |
106 |
setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw); |
setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw); |
107 |
USE_SELINUX(set_current_security_context(NULL);) |
IF_SELINUX(set_current_security_context(NULL);) |
108 |
|
|
109 |
/* Never returns */ |
/* Never returns */ |
110 |
run_shell(opt_shell, flags & SU_OPT_l, opt_command, (const char**)argv); |
run_shell(opt_shell, flags & SU_OPT_l, opt_command, (const char**)argv); |