2 This program was contributed by Shane Watts
5 You need to add the following (or equivalent) to the /etc/pam.conf file.
7 check_user auth required /usr/lib/security/pam_unix_auth.so
8 check_user account required /usr/lib/security/pam_unix_acct.so
11 #include <security/pam_appl.h>
12 #include <security/pam_misc.h>
15 static struct pam_conv conv = {
20 int main(int argc, char *argv[])
22 pam_handle_t *pamh=NULL;
24 const char *user="nobody";
31 fprintf(stderr, "Usage: check_user [username]\n");
35 retval = pam_start("check_user", user, &conv, &pamh);
37 if (retval == PAM_SUCCESS)
38 retval = pam_authenticate(pamh, 0); /* is user really user? */
40 if (retval == PAM_SUCCESS)
41 retval = pam_acct_mgmt(pamh, 0); /* permitted access? */
43 /* This is where we have been authorized or not. */
45 if (retval == PAM_SUCCESS) {
46 fprintf(stdout, "Authenticated\n");
48 fprintf(stdout, "Not Authenticated\n");
51 if (pam_end(pamh,retval) != PAM_SUCCESS) { /* close Linux-PAM */
53 fprintf(stderr, "check_user: failed to release authenticator\n");
57 return ( retval == PAM_SUCCESS ? 0:1 ); /* indicate success */