Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modification to use pam_usb on account context #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion src/pam.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,72 @@ int pam_sm_setcred(pam_handle_t *pamh,int flags,int argc,
return (PAM_SUCCESS);
}

PAM_EXTERN
int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
int argc, const char **argv)
{
t_pusb_options opts;
const char *service;
const char *user;
const char *tty;
char *conf_file = PUSB_CONF_FILE;
int retval;

pusb_log_init(&opts);
retval = pam_get_item(pamh, PAM_SERVICE,
(const void **)(const void *)&service);
if (retval != PAM_SUCCESS)
{
log_error("Unable to retrieve the PAM service name.\n");
return (PAM_AUTH_ERR);
}

if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS || !user || !*user)
{
log_error("Unable to retrieve the PAM user name.\n");
return (PAM_AUTH_ERR);
}

if (argc > 1)
if (!strcmp(argv[0], "-c"))
conf_file = (char *)argv[1];
if (!pusb_conf_init(&opts))
return (PAM_AUTH_ERR);
if (!pusb_conf_parse(conf_file, &opts, user, service))
return (PAM_AUTH_ERR);

if (!opts.enable)
{
log_debug("Not enabled, exiting...\n");
return (PAM_IGNORE);
}

log_info("pam_usb v%s\n", PUSB_VERSION);
log_info("Account request for user \"%s\" (%s)\n",
user, service);

if (!pusb_local_login(&opts, user))
{
log_error("Access denied.\n");
return (PAM_AUTH_ERR);
}
if (pusb_device_check(&opts, user))
{
log_info("Access granted.\n");
return (PAM_SUCCESS);
}
log_error("Access denied.\n");
return (PAM_AUTH_ERR);
}


#ifdef PAM_STATIC

struct pam_module _pam_usb_modstruct = {
"pam_usb",
pam_sm_authenticate,
pam_sm_setcred,
NULL,
pam_sm_acct_mgmt,
NULL,
NULL,
NULL
Expand Down