17
|
1 #include <security/pam_appl.h> |
|
2 #include <security/pam_misc.h> |
|
3 #include <stdio.h> |
|
4 |
|
5 const struct pam_conv conv = { |
|
6 misc_conv, |
|
7 NULL |
|
8 }; |
|
9 |
|
10 int main(int argc, char *argv[]) { |
|
11 pam_handle_t* pamh = NULL; |
|
12 int retval; |
|
13 const char* user = "nobody"; |
|
14 |
|
15 if(argc != 2) { |
|
16 printf("Usage: app [username]\n"); |
|
17 exit(1); |
|
18 } |
|
19 |
|
20 user = argv[1]; |
|
21 |
|
22 retval = pam_start("sober-auth", user, &conv, &pamh); |
|
23 |
|
24 // Are the credentials correct? |
|
25 if (retval == PAM_SUCCESS) { |
34
|
26 printf("PAM module initialized\n"); |
17
|
27 retval = pam_authenticate(pamh, 0); |
|
28 } |
|
29 |
|
30 // Can the accound be used at this time? |
|
31 if (retval == PAM_SUCCESS) { |
34
|
32 printf("Credentials accepted.\n"); |
17
|
33 retval = pam_acct_mgmt(pamh, 0); |
|
34 } |
|
35 |
|
36 // Did everything work? |
|
37 if (retval == PAM_SUCCESS) { |
34
|
38 printf("Account is valid.\n"); |
17
|
39 printf("Authenticated\n"); |
|
40 } else { |
|
41 printf("Not Authenticated\n"); |
|
42 } |
|
43 |
|
44 // close PAM (end session) |
|
45 if (pam_end(pamh, retval) != PAM_SUCCESS) { |
|
46 pamh = NULL; |
|
47 printf("check_user: failed to release authenticator\n"); |
|
48 exit(1); |
|
49 } |
|
50 |
|
51 return retval == PAM_SUCCESS ? 0 : 1; |
|
52 } |
|
53 |