Debian Codegraph @

src/ws/mock-pam-conv-mod.c

raw
1 #include "config.h"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <syslog.h>
7 #include <security/pam_appl.h>
8 #include <security/pam_modules.h>
9
10
11 /* this function is ripped from pam_unix/support.c, it lets us do IO via PAM */
12 static int
13 converse (pam_handle_t *pamh,
14 int nargs,
15 struct pam_message **message,
16 struct pam_response **response)
17 {
18 int res;
19 struct pam_conv *conv;
20
21 res = pam_get_item (pamh, PAM_CONV, (const void **) &conv);
22 if (res == PAM_SUCCESS)
23 {
24 res = conv->conv (nargs, (const struct pam_message **) message,
25 response, conv->appdata_ptr);
26 }
27
28 return res;
29 }
30
31
32 PAM_EXTERN int
33 pam_sm_authenticate (pam_handle_t *pamh,
34 int unused,
35 int argc,
36 const char **argv)
37 {
38 int res;
39
40 struct pam_message msg[1], *pmsg[1];
41 struct pam_response *resp = NULL;
42 const char *user;
43
44 /* Lookup the user */
45 res = pam_get_user (pamh, &user, NULL);
46 if (res != PAM_SUCCESS)
47 {
48 syslog (LOG_WARNING, "couldn't get pam user: %s", pam_strerror (pamh, res));
49 goto out;
50 }
51
52 /* Send message */
53 pmsg[0] = &msg[0];
54 msg[0].msg_style = PAM_PROMPT_ECHO_ON;
55 msg[0].msg = "The answer to life the universe and everything: ";
56
57 res = converse (pamh, 1 , pmsg, &resp);
58 if (res != PAM_SUCCESS)
59 {
60 syslog (LOG_WARNING, "couldn't send prompt: %s", pam_strerror (pamh, res));
61 goto out;
62 }
63
64 if (!resp)
65 {
66 syslog (LOG_WARNING, "missing response");
67 res = PAM_CONV_ERR;
68 goto out;
69 }
70 else if (resp[0].resp == NULL )
71 {
72 syslog (LOG_WARNING, "got null resp");
73 res = PAM_AUTH_ERR;
74 goto out;
75 }
76
77 if (strcmp (resp[0].resp, "42") == 0)
78 res = PAM_SUCCESS;
79 else
80 res = PAM_AUTH_ERR;
81
82 out:
83 if (resp)
84 free (resp);
85 return res;
86 }
87
88 PAM_EXTERN int
89 pam_sm_setcred (pam_handle_t *pamh,
90 int flags,
91 int argc,
92 const char *argv[])
93 {
94 return PAM_SUCCESS;
95 }