]> granicus.if.org Git - linux-pam/blob - examples/vpass.c
Fix whitespace issues
[linux-pam] / examples / vpass.c
1
2 #include "config.h"
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <pwd.h>
8 #include <sys/types.h>
9 #include <security/pam_appl.h>
10
11 static int
12 test_conv (int num_msg UNUSED, const struct pam_message **msgm UNUSED,
13            struct pam_response **response UNUSED, void *appdata_ptr UNUSED)
14 {
15     return 0;
16 }
17
18 static struct pam_conv conv = {
19     test_conv,
20     NULL
21 };
22
23 int main(void)
24 {
25     char *user;
26     pam_handle_t *pamh;
27     struct passwd *pw;
28     uid_t uid;
29     int res;
30
31     uid = geteuid();
32     pw = getpwuid(uid);
33     if (pw) {
34         user = pw->pw_name;
35     } else {
36         fprintf(stderr, "Invalid userid: %lu\n", (unsigned long) uid);
37         exit(1);
38     }
39
40     pam_start("vpass", user, &conv, &pamh);
41     pam_set_item(pamh, PAM_TTY, "/dev/tty");
42     if ((res = pam_authenticate(pamh, 0)) != PAM_SUCCESS) {
43         fprintf(stderr, "Oops: %s\n", pam_strerror(pamh, res));
44         exit(1);
45     }
46
47     pam_end(pamh, res);
48     exit(0);
49 }