From dd19a65a86ce09a4fd340c4059ffdcf853a45740 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Sun, 22 Oct 2006 16:18:16 +0000 Subject: [PATCH] Try to guess the tty name using both pam_get_item() and ttyname() --- src/local.c | 15 +++++++++++---- src/local.h | 3 ++- src/pam.c | 4 +++- src/pusb_check.c | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/local.c b/src/local.c index 0af461b..858204e 100644 --- a/src/local.c +++ b/src/local.c @@ -22,17 +22,24 @@ #include "log.h" #include "conf.h" -int pusb_local_login(t_pusb_options *opts, const char *user) +int pusb_local_login(t_pusb_options *opts, const char *user, + const char *tty) { - char *from; 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) + if (tty && *tty) + from = tty; + else + from = ttyname(STDIN_FILENO); + if (!from || !(*from)) + { + log_debug("Couldn't retrive the tty name, aborting..."); return (1); + } log_debug("Authentication request from tty %s\n", from); if (!strncmp(from, "/dev/", strlen("/dev/"))) from += strlen("/dev/"); diff --git a/src/local.h b/src/local.h index ed796ea..87dd32b 100644 --- a/src/local.h +++ b/src/local.h @@ -18,6 +18,7 @@ #ifndef PUSB_LOCAL_H_ # define PUSB_LOCAL_H_ -int pusb_local_login(t_pusb_options *opts, const char *user); +int pusb_local_login(t_pusb_options *opts, const char *user, + const char *tty); #endif /* !PUSB_LOCAL_H_ */ diff --git a/src/pam.c b/src/pam.c index c0b7e9c..0b71c00 100644 --- a/src/pam.c +++ b/src/pam.c @@ -32,6 +32,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, t_pusb_options opts; const char *service; const char *user; + char *tty; char *conf_file = PUSB_CONF_FILE; int retval; @@ -65,7 +66,8 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, log_info("pam_usb v.%s\n", PUSB_VERSION); log_info("Authentication request for user \"%s\" (%s)\n", user, service); - if (!pusb_local_login(&opts, user)) + pam_get_item(pamh, PAM_TTY, (const void**)&tty); + if (!pusb_local_login(&opts, user, tty)) { log_error("Access denied.\n"); return (PAM_AUTH_ERR); diff --git a/src/pusb_check.c b/src/pusb_check.c index 1a3258b..ad0710d 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)) + if (!pusb_local_login(opts, user, NULL)) { log_error("Access denied.\n"); return (0);