* Must be called only with username the name of an actual user.
* The most common login failure is to give password instead of username.
*/
-static void
-logbtmp(struct login_context *cxt)
+static void logbtmp(struct login_context *cxt)
{
struct utmp ut;
struct timeval tv;
ut.ut_type = LOGIN_PROCESS; /* XXX doesn't matter */
ut.ut_pid = cxt->pid;
+
if (cxt->hostname) {
xstrncpy(ut.ut_host, cxt->hostname, sizeof(ut.ut_host));
if (cxt->hostaddress && *cxt->hostaddress)
}
#ifdef HAVE_LIBAUDIT
-static void
-logaudit(const char *tty, const char *username, const char *hostname,
- struct passwd *pwd, int status)
+static void log_audit(struct login_context *cxt, struct passwd *pwd, int status)
{
int audit_fd;
audit_fd = audit_open();
if (audit_fd == -1)
return;
- if (!pwd && username)
- pwd = getpwnam(username);
-
- audit_log_acct_message(audit_fd, AUDIT_USER_LOGIN,
- NULL, "login", username ? username : "(unknown)",
- pwd ? pwd->pw_uid : (unsigned int)-1, hostname,
- NULL, tty, status);
+ if (!pwd && cxt->username)
+ pwd = getpwnam(cxt->username);
+
+ audit_log_acct_message(audit_fd,
+ AUDIT_USER_LOGIN,
+ NULL,
+ "login",
+ cxt->username ? cxt->username : "(unknown)",
+ pwd ? pwd->pw_uid : (unsigned int) -1,
+ cxt->hostname,
+ NULL,
+ cxt->tty_name,
+ status);
close(audit_fd);
}
#else /* ! HAVE_LIBAUDIT */
-#define logaudit(tty, username, hostname, pwd, status)
+#define log_audit(cxt, pwd, status)
#endif /* HAVE_LIBAUDIT */
/* encapsulate stupid "void **" pam_get_item() API */
failcount, cxt.hostname, cxt.username, pam_strerror(pamh,
retcode));
logbtmp(&cxt);
- logaudit(cxt.tty_name, cxt.username, cxt.hostname, NULL, 0);
+ log_audit(&cxt, NULL, 0);
fprintf(stderr, _("Login incorrect\n\n"));
pam_set_item(pamh, PAM_USER, NULL);
cxt.hostname, cxt.username, pam_strerror(pamh,
retcode));
logbtmp(&cxt);
- logaudit(cxt.tty_name, cxt.username, cxt.hostname, NULL, 0);
+ log_audit(&cxt, NULL, 0);
fprintf(stderr, _("\nLogin incorrect\n"));
pam_end(pamh, retcode);
#endif
}
- logaudit(cxt.tty_name, cxt.username, cxt.hostname, pwd, 1);
+ log_audit(&cxt, pwd, 1);
dolastlog(&cxt, quietlog);
if (fchown(0, pwd->pw_uid,