Andrea Luzzardi 18 years ago
parent
commit
44e07509e7
4 changed files with 18 additions and 21 deletions
  1. +7
    -15
      src/local.c
  2. +1
    -2
      src/local.h
  3. +9
    -3
      src/pam.c
  4. +1
    -1
      src/pusb_check.c

+ 7
- 15
src/local.c View File

@ -22,31 +22,23 @@
#include "log.h" #include "log.h"
#include "conf.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 utsearch;
struct utmp *utent; struct utmp *utent;
const char *from;
int i; int i;
log_debug("Checking whether the caller is local or not...\n"); log_debug("Checking whether the caller is local or not...\n");
from = ttyname(STDIN_FILENO);
if (!from || !(*from)) 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); 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)); strncpy(utsearch.ut_line, from, sizeof(utsearch.ut_line));
setutent(); setutent();
utent = getutline(&utsearch); utent = getutline(&utsearch);


+ 1
- 2
src/local.h View File

@ -18,7 +18,6 @@
#ifndef PUSB_LOCAL_H_ #ifndef PUSB_LOCAL_H_
# define 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_ */ #endif /* !PUSB_LOCAL_H_ */

+ 9
- 3
src/pam.c View File

@ -67,9 +67,15 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags,
log_info("Authentication request for user \"%s\" (%s)\n", log_info("Authentication request for user \"%s\" (%s)\n",
user, service); 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"); log_error("Access denied.\n");
return (PAM_AUTH_ERR); 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", log_info("Authentication request for user \"%s\" (%s)\n",
user, service); user, service);
if (!pusb_local_login(opts, user, NULL))
if (!pusb_local_login(opts, user))
{ {
log_error("Access denied.\n"); log_error("Access denied.\n");
return (0); return (0);


Loading…
Cancel
Save