]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: use login_context struct in audit stuff
authorKarel Zak <kzak@redhat.com>
Thu, 25 Aug 2011 15:54:59 +0000 (17:54 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 26 Oct 2011 21:17:16 +0000 (23:17 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/login.c

index a794d1817411866135a3de695c3fe435261b1115..e29fb43ec459d4bb3a65451dbbdfa6a0e7f50176 100644 (file)
@@ -251,8 +251,7 @@ static int is_consoletty(int fd)
  * 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;
@@ -282,6 +281,7 @@ logbtmp(struct login_context *cxt)
 
        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)
@@ -315,27 +315,31 @@ static void sig_handler(int signal)
 }
 
 #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 */
@@ -574,7 +578,7 @@ int main(int argc, char **argv)
                               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);
@@ -597,7 +601,7 @@ int main(int argc, char **argv)
                                       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);
@@ -811,7 +815,7 @@ int main(int argc, char **argv)
 #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,