diff options
-rw-r--r-- | epam.c | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ | |||
1 | /* gcc -o epam -lpam -lpam_misc epam.c -g */ | ||
2 | |||
3 | #include <security/pam_appl.h> | ||
4 | #include <security/pam_misc.h> | ||
5 | #include <stdio.h> | ||
6 | |||
7 | static struct pam_conv conv = { | ||
8 | misc_conv, | ||
9 | NULL | ||
10 | }; | ||
11 | |||
12 | int main (int argc, char *argv[]) | ||
13 | { | ||
14 | pam_handle_t *pamh = NULL; | ||
15 | int retval; | ||
16 | const char *user = "nobody"; | ||
17 | |||
18 | if (argc == 2) | ||
19 | user = argv[1]; | ||
20 | |||
21 | if (argc > 2) | ||
22 | { | ||
23 | fprintf (stderr, "Usage: check_user [username]\n"); | ||
24 | exit (1); | ||
25 | } | ||
26 | |||
27 | retval = pam_start ("elock", user, &conv, &pamh); | ||
28 | |||
29 | printf (":%s\n", pam_strerror (pamh, retval)); | ||
30 | |||
31 | if (retval == PAM_SUCCESS) | ||
32 | retval = pam_authenticate (pamh, 0); | ||
33 | printf (":%s\n", pam_strerror (pamh, retval)); | ||
34 | |||
35 | if (retval == PAM_SUCCESS) | ||
36 | retval = pam_acct_mgmt (pamh, 0); | ||
37 | printf (":%s\n", pam_strerror (pamh, retval)); | ||
38 | |||
39 | if (retval == PAM_SUCCESS) | ||
40 | fprintf (stdout, "Authenticated\n"); | ||
41 | else | ||
42 | fprintf (stdout, "Not Authenticated\n"); | ||
43 | printf (":%s\n", pam_strerror (pamh, retval)); | ||
44 | |||
45 | if (pam_end (pamh, retval) != PAM_SUCCESS) | ||
46 | { | ||
47 | pamh = NULL; | ||
48 | fprintf (stderr, "check_user: failed to release authenticator\n"); | ||
49 | exit (1); | ||
50 | } | ||
51 | printf (":%s\n", pam_strerror (pamh, retval)); | ||
52 | |||
53 | return (retval == PAM_SUCCESS ? 0 : 1); | ||
54 | } | ||