Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2000, International Business Machines Corporation and others. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | */ | |
9 | ||
10 | #include <afsconfig.h> | |
11 | #include <afs/param.h> | |
12 | ||
13 | #include <roken.h> | |
14 | ||
15 | #include <security/pam_appl.h> | |
16 | ||
17 | #include "afs_pam_msg.h" | |
18 | #include "afs_message.h" | |
19 | ||
20 | ||
21 | int | |
22 | pam_afs_printf(PAM_CONST struct pam_conv *pam_convp, int error, int fmt_msgid, ...) | |
23 | { | |
24 | va_list args; | |
25 | char buf[PAM_MAX_MSG_SIZE]; | |
26 | char *fmt_msg = NULL; | |
27 | int freeit; | |
28 | struct pam_message mesg; | |
29 | PAM_CONST struct pam_message *mesgp = &mesg; | |
30 | struct pam_response *resp = NULL; | |
31 | int errcode; | |
32 | ||
33 | if (pam_convp == NULL || pam_convp->conv == NULL) | |
34 | return PAM_CONV_ERR; | |
35 | ||
36 | fmt_msg = pam_afs_message(fmt_msgid, &freeit); | |
37 | va_start(args, fmt_msgid); | |
38 | vsprintf(buf, fmt_msg, args); | |
39 | va_end(args); | |
40 | if (freeit) | |
41 | free(fmt_msg); | |
42 | ||
43 | mesg.msg_style = error ? PAM_ERROR_MSG : PAM_TEXT_INFO; | |
44 | mesg.msg = buf; | |
45 | errcode = (*(pam_convp->conv)) (1, &mesgp, &resp, pam_convp->appdata_ptr); | |
46 | if (resp) { | |
47 | if (resp->resp) | |
48 | free(resp->resp); | |
49 | free(resp); | |
50 | } | |
51 | return errcode; | |
52 | } | |
53 | ||
54 | ||
55 | int | |
56 | pam_afs_prompt(PAM_CONST struct pam_conv *pam_convp, char **response, int echo, | |
57 | int fmt_msgid, ...) | |
58 | { | |
59 | va_list args; | |
60 | char buf[PAM_MAX_MSG_SIZE]; | |
61 | char *fmt_msg = NULL; | |
62 | int freeit; | |
63 | struct pam_message mesg; | |
64 | PAM_CONST struct pam_message *mesgp = &mesg; | |
65 | struct pam_response *resp = NULL; | |
66 | int errcode; | |
67 | ||
68 | if (pam_convp == NULL || pam_convp->conv == NULL || response == NULL) | |
69 | return PAM_CONV_ERR; | |
70 | ||
71 | *response = NULL; | |
72 | ||
73 | fmt_msg = pam_afs_message(fmt_msgid, &freeit); | |
74 | va_start(args, fmt_msgid); | |
75 | vsprintf(buf, fmt_msg, args); | |
76 | va_end(args); | |
77 | if (freeit) | |
78 | free(fmt_msg); | |
79 | ||
80 | mesg.msg_style = echo ? PAM_PROMPT_ECHO_ON : PAM_PROMPT_ECHO_OFF; | |
81 | mesg.msg = buf; | |
82 | ||
83 | errcode = (*(pam_convp->conv)) (1, &mesgp, &resp, pam_convp->appdata_ptr); | |
84 | if (resp) { | |
85 | *response = resp->resp; | |
86 | ||
87 | free(resp); /* but not resp->resp */ | |
88 | } | |
89 | return errcode; | |
90 | } |