*** 3000userlogin.c 2021-02-06 13:11:42.000000000 -0500 --- 3000userlogin-chpwd.c 2025-02-21 21:48:26.561460434 -0500 *************** *** 6,11 **** --- 6,19 ---- #include #include #include + #include + #include + #include + + static struct pam_conv conv = { + misc_conv, + NULL + }; int main(int argc, char *argv[]) { *************** *** 14,19 **** --- 22,29 ---- 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); --- 34,64 ---- getuid(), geteuid(), getgid(), getegid()); username = argv[1]; ! ! result = pam_start("", username, &conv, &ph); ! if (result == PAM_SUCCESS) { ! if (!strcmp(basename(argv[0]), "3000login")) ! result = pam_authenticate(ph, 0); ! else if (!strcmp(basename(argv[0]), "3000chpwd")) ! result = pam_chauthtok(ph, 0); ! } ! else { ! fprintf(stderr, "PAM session failed to start.\n"); ! exit(-2); ! } ! ! if (result != PAM_SUCCESS) ! fprintf(stderr, "Authentication failed. %d\n", result); ! 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);