Browse Source

Try to guess the tty name using both pam_get_item() and ttyname()

Andrea Luzzardi 18 years ago
parent
commit
dd19a65a86
4 changed files with 17 additions and 7 deletions
  1. +11
    -4
      src/local.c
  2. +2
    -1
      src/local.h
  3. +3
    -1
      src/pam.c
  4. +1
    -1
      src/pusb_check.c

+ 11
- 4
src/local.c View File

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


+ 2
- 1
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_ */

+ 3
- 1
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;
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);


+ 1
- 1
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