Listing 2. A Basic Implementation of pam_sm_authenticate()
PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags
,int argc, const char **argv)
{
unsigned int ctrl;
int retval;
const char *name, *p;
/* get the user'name' */
retval = pam_get_user(pamh, &name, "login: ");
if (retval == PAM_SUCCESS) {
printf("username [%s] obtained", name);
} else {
printf("trouble reading username\n");
pam_set_data(pamh, "unix_setcred_return", (void *) retval, NULL);
return retval;
}
/* get this user's authentication token */
retval = _read_password(pamh, ctrl, NULL, "Password: ", NULL
, UNIX_AUTHTOK, &p);
if (retval != PAM_SUCCESS) {
printf("could not read password for %s\n", name);
name = NULL;
pam_set_data(pamh, "unix_setcred_return", (void *) retval, NULL);
return retval;
}
/* verify the password of this user */
retval = _verify_password(pamh, name, p, ctrl);
name = p = NULL;
pam_set_data(pamh, "unix_setcred_return", (void *) retval, NULL);
return retval;
}
Copyright © 1994 - 2018 Linux Journal. All rights reserved.