Browse Source

Improved local login detection

master
Andrea Luzzardi 18 years ago
parent
commit
e40f218446
4 changed files with 21 additions and 10 deletions
  1. +13
    -7
      pam_usb/src/local.c
  2. +2
    -1
      pam_usb/src/local.h
  3. +5
    -1
      pam_usb/src/pam.c
  4. +1
    -1
      pam_usb/src/pusb_check.c

+ 13
- 7
pam_usb/src/local.c View File

@ -22,20 +22,26 @@
#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 *from)
{
char *from;
struct utmp utsearch;
struct utmp *utent;
int i;
log_debug("Checking whether the caller is local or not...\n");
from = ttyname(STDIN_FILENO);
if (!from)
return (1);
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("Authentication request from tty %s\n", from);
if (!strncmp(from, "/dev/", strlen("/dev/")))
from += strlen("/dev/");
strncpy(utsearch.ut_line, from, sizeof(utsearch.ut_line));
setutent();
utent = getutline(&utsearch);


+ 2
- 1
pam_usb/src/local.h View File

@ -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_ */

+ 5
- 1
pam_usb/src/pam.c View File

@ -32,6 +32,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags,
t_pusb_options opts;
const char *service;
const char *user;
const char *tty;
char *conf_file = PUSB_CONF_FILE;
int retval;
@ -65,7 +66,10 @@ 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))
if (pam_get_item(pamh, PAM_TTY, (const void **)&tty) != PAM_SUCCESS)
tty = NULL;
if (!pusb_local_login(&opts, user, tty))
{
log_error("Access denied.\n");
return (PAM_AUTH_ERR);


+ 1
- 1
pam_usb/src/pusb_check.c View File

@ -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);


Loading…
Cancel
Save