4 This program was contributed by Shane Watts <shane@icarus.bofh.asn.au>
5 slight modifications by AGM.
7 You need to add the following (or equivalent) to the /etc/pam.conf file.
9 check auth required pam_unix_auth.so
10 check account required pam_unix_acct.so
13 #include <security/pam_appl.h>
14 #include <security/pam_misc.h>
17 static struct pam_conv conv = {
22 int main(int argc, char *argv[])
24 pam_handle_t *pamh=NULL;
26 const char *user="nobody";
33 fprintf(stderr, "Usage: check_user [username]\n");
37 retval = pam_start("check", user, &conv, &pamh);
39 if (retval == PAM_SUCCESS)
40 retval = pam_authenticate(pamh, 0); /* is user really user? */
42 if (retval == PAM_SUCCESS)
43 retval = pam_acct_mgmt(pamh, 0); /* permitted access? */
45 /* This is where we have been authorized or not. */
47 if (retval == PAM_SUCCESS) {
48 fprintf(stdout, "Authenticated\n");
50 fprintf(stdout, "Not Authenticated\n");
53 if (pam_end(pamh,retval) != PAM_SUCCESS) { /* close Linux-PAM */
55 fprintf(stderr, "check_user: failed to release authenticator\n");
59 return ( retval == PAM_SUCCESS ? 0:1 ); /* indicate success */