From 44e07509e7bea5c034d5159bafe1035ea2c7abe0 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Sun, 22 Oct 2006 19:19:01 +0000 Subject: [PATCH] Cleanup --- src/local.c | 22 +++++++--------------- src/local.h | 3 +-- src/pam.c | 12 +++++++++--- src/pusb_check.c | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/local.c b/src/local.c index c2cb13b..1b91711 100644 --- a/src/local.c +++ b/src/local.c @@ -22,31 +22,23 @@ #include "log.h" #include "conf.h" -int pusb_local_login(t_pusb_options *opts, const char *user, - const char *from) +int pusb_local_login(t_pusb_options *opts, const char *user) { struct utmp utsearch; struct utmp *utent; + const char *from; int i; log_debug("Checking whether the caller is local or not...\n"); + from = ttyname(STDIN_FILENO); if (!from || !(*from)) { - from = ttyname(STDIN_FILENO); - if (!from) - { - log_debug("Couldn't retrieve the tty name, aborting.\n"); - return (1); - } - if (!strncmp(from, "/dev/", strlen("/dev/"))) - from += strlen("/dev/"); + log_debug("Couldn't retrieve the tty name, aborting.\n"); + return (1); } + if (!strncmp(from, "/dev/", strlen("/dev/"))) + from += strlen("/dev/"); log_debug("Authentication request from tty %s\n", from); - if (!strcmp(from, "ssh")) - { - log_debug("SSH Authentication, aborting.\n"); - return (0); - } strncpy(utsearch.ut_line, from, sizeof(utsearch.ut_line)); setutent(); utent = getutline(&utsearch); diff --git a/src/local.h b/src/local.h index 87dd32b..ed796ea 100644 --- a/src/local.h +++ b/src/local.h @@ -18,7 +18,6 @@ #ifndef PUSB_LOCAL_H_ # define PUSB_LOCAL_H_ -int pusb_local_login(t_pusb_options *opts, const char *user, - const char *tty); +int pusb_local_login(t_pusb_options *opts, const char *user); #endif /* !PUSB_LOCAL_H_ */ diff --git a/src/pam.c b/src/pam.c index d257091..88a0932 100644 --- a/src/pam.c +++ b/src/pam.c @@ -67,9 +67,15 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, log_info("Authentication request for user \"%s\" (%s)\n", user, service); - if (pam_get_item(pamh, PAM_TTY, (const void **)&tty) != PAM_SUCCESS) - tty = NULL; - if (!pusb_local_login(&opts, user, tty)) + if (pam_get_item(pamh, PAM_TTY, (const void **)&tty) == PAM_SUCCESS) + { + if (!strcmp(tty, "ssh")) + { + log_debug("SSH Authentication, aborting.\n"); + return (0); + } + } + if (!pusb_local_login(&opts, user)) { log_error("Access denied.\n"); return (PAM_AUTH_ERR); diff --git a/src/pusb_check.c b/src/pusb_check.c index ad0710d..1a3258b 100644 --- a/src/pusb_check.c +++ b/src/pusb_check.c @@ -52,7 +52,7 @@ static int pusb_check_perform_authentication(t_pusb_options *opts, } log_info("Authentication request for user \"%s\" (%s)\n", user, service); - if (!pusb_local_login(opts, user, NULL)) + if (!pusb_local_login(opts, user)) { log_error("Access denied.\n"); return (0);