*** 3000userlogin.c 2021-02-06 13:11:42.000000000 -0500 --- 3000userlogin-pam.c 2025-02-21 21:13:59.032226383 -0500 *************** *** 6,11 **** --- 6,18 ---- #include #include #include + #include + #include + + static struct pam_conv conv = { + misc_conv, + NULL + }; int main(int argc, char *argv[]) { *************** *** 14,19 **** --- 21,28 ---- char *username; extern char **environ; struct passwd *pw_entry; + pam_handle_t *ph = NULL; + int authenticated = 0; if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); *************** *** 24,30 **** getuid(), geteuid(), getgid(), getegid()); username = argv[1]; ! pw_entry = getpwnam(username); if (pw_entry == NULL) { fprintf(stderr, "Could not find user %s.\n", username); --- 33,59 ---- getuid(), geteuid(), getgid(), getegid()); username = argv[1]; ! ! result = pam_start("", username, &conv, &ph); ! if (result == PAM_SUCCESS) ! result = pam_authenticate(ph, 0); ! else { ! fprintf(stderr, "PAM session failed to start.\n"); ! exit(-2); ! } ! ! if (result != PAM_SUCCESS) ! fprintf(stderr, "Authentication failed.\n"); ! else ! authenticated = 1; ! ! if (pam_end(ph,result) != PAM_SUCCESS) { ! fprintf(stderr, "PAM session failed to end.\n"); ! exit(-2); ! } ! ! if (!authenticated) exit(-2); ! pw_entry = getpwnam(username); if (pw_entry == NULL) { fprintf(stderr, "Could not find user %s.\n", username);