summaryrefslogtreecommitdiff
path: root/src/su.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-03-18 12:49:20 +0000
committerJim Meyering <jim@meyering.net>1997-03-18 12:49:20 +0000
commitbcdeccb6a3a4dc46f7edd4aa2f63d7f34593ff50 (patch)
treedcafddd001a8b8539ec8df5f078cada02a2306b9 /src/su.c
parent808a6a2308a10dfcfec080f9b66ff2663cc8894b (diff)
downloadcoreutils-bcdeccb6a3a4dc46f7edd4aa2f63d7f34593ff50.tar.xz
(log_su): Resort to getpwuid if getlogin fails.
If no tty name is found, use `none' in the log message. Based on a patch from Galen Hazelwood.
Diffstat (limited to 'src/su.c')
-rw-r--r--src/su.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/su.c b/src/su.c
index 5edd1348e..6f361161f 100644
--- a/src/su.c
+++ b/src/su.c
@@ -237,10 +237,15 @@ log_su (const struct passwd *pw, int successful)
the user, especially if someone su's from a su-shell. */
old_user = getlogin ();
if (old_user == NULL)
- old_user = "";
+ {
+ /* getlogin can fail -- usually due to lack of utmp entry.
+ Resort to getpwuid. */
+ struct passwd *pwd = getpwuid (getuid ());
+ old_user = (pwd ? pwd->pw_name : "");
+ }
tty = ttyname (2);
if (tty == NULL)
- tty = "";
+ tty = "none";
/* 4.2BSD openlog doesn't have the third parameter. */
openlog (basename (program_name), 0
#ifdef LOG_AUTH
@@ -317,8 +322,9 @@ modify_environment (const struct passwd *pw, const char *shell)
xputenv (concat ("SHELL", "=", shell));
xputenv (concat ("USER", "=", pw->pw_name));
xputenv (concat ("LOGNAME", "=", pw->pw_name));
- xputenv (concat ("PATH", "=", pw->pw_uid
- ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH));
+ xputenv (concat ("PATH", "=", (pw->pw_uid
+ ? DEFAULT_LOGIN_PATH
+ : DEFAULT_ROOT_LOGIN_PATH)));
}
else
{