From: nekral-guest Date: Sat, 20 Sep 2008 19:54:35 +0000 (+0000) Subject: * src/login.c: Copy the name of the user authenticated by PAM to X-Git-Tag: 4.1.3~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c813e692a23461067e0e6ab733e95017d44be177;p=thirdparty%2Fshadow.git * src/login.c: Copy the name of the user authenticated by PAM to username. This simplify later logging (avoid USE_PAM conditional). --- diff --git a/ChangeLog b/ChangeLog index 9db2e1a8d..68be08003 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2008-09-20 Nicolas François * src/login.c: Use a dynamic buffer for usernames. + * src/login.c: Copy the name of the user authenticated by PAM to + username. This simplify later logging (avoid USE_PAM + conditional). 2008-09-20 Nicolas François diff --git a/src/login.c b/src/login.c index 68ff64600..60964d3dc 100644 --- a/src/login.c +++ b/src/login.c @@ -787,11 +787,16 @@ int main (int argc, char **argv) First get the username that we are actually using, though. */ retcode = pam_get_item (pamh, PAM_USER, (const void **)ptr_pam_user); - pwd = xgetpwnam (pam_user); + if (NULL != username) { + free (username); + } + username = xstrdup (pam_user); + + pwd = xgetpwnam (username); if (NULL == pwd) { SYSLOG ((LOG_ERR, "xgetpwnam(%s) failed", getdef_bool ("LOG_UNKFAIL_ENAB") ? - pam_user : "UNKNOWN")); + username : "UNKNOWN")); exit (1); } @@ -1023,11 +1028,7 @@ int main (int argc, char **argv) addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */ } -#ifdef USE_PAM - setutmp (pam_user, tty, hostname); /* make entry in utmp & wtmp files */ -#else setutmp (username, tty, hostname); /* make entry in utmp & wtmp files */ -#endif if (pwent.pw_shell[0] == '*') { /* subsystem root */ pwent.pw_shell++; /* skip the '*' */ subsystem (&pwent); /* figure out what to execute */ @@ -1216,11 +1217,7 @@ int main (int argc, char **argv) if (0 == pwent.pw_uid) { SYSLOG ((LOG_NOTICE, "ROOT LOGIN %s", fromhost)); } else if (getdef_bool ("LOG_OK_LOGINS")) { -#ifdef USE_PAM - SYSLOG ((LOG_INFO, "'%s' logged in %s", pam_user, fromhost)); -#else SYSLOG ((LOG_INFO, "'%s' logged in %s", username, fromhost)); -#endif } closelog (); tmp = getdef_str ("FAKE_SHELL");