| 1 | /* conv.c - PAM conversation abstraction for Poldi. |
| 2 | Copyright (C) 2004, 2005, 2007, 2008 g10 Code GmbH |
| 3 | |
| 4 | This file is part of Poldi. |
| 5 | |
| 6 | Poldi is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | Poldi is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, see |
| 18 | <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <errno.h> |
| 26 | #include <stdarg.h> |
| 27 | |
| 28 | #include <gpg-error.h> |
| 29 | |
| 30 | #define PAM_SM_AUTHcxx . . $ `src/pam/auth-support/conv.c:30:9`! |
| 31 | #include <security/pam_modules.h> |
| 32 | |
| 33 | #include "util/util.h"cxx . . $ `<file>/src/util/util.h`/ |
| 34 | #include "conv.h"cxx . . $ `<file>/src/pam/auth-support/conv.h`/ |
| 35 | |
| 36 | |
| 37 | |
| 38 | struct conv_scxx . . $ conv_s# |
| 39 | { |
| 40 | const struct pam_convcxx . . $ pam_conv# *pam_convcxx . . $ conv_s#pam_conv.; |
| 41 | }; |
| 42 | |
| 43 | |
| 44 | |
| 45 | /* Create a new PAM conversation object based in PAM_CONV and store it |
| 46 | in *CONV. Returns proper error code. */ |
| 47 | gpg_error_tcxx . . $ gpg_error_t# |
| 48 | conv_createcxx . . $ conv_create(9d51085b6828a066). (conv_tcxx . . $ conv_t# *conv, const struct pam_convcxx . . $ pam_conv# *pam_conv) |
| 49 | { |
| 50 | conv_tcxx . . $ conv_t# conv_new; |
| 51 | gpg_error_tcxx . . $ gpg_error_t# err; |
| 52 | |
| 53 | err = 0; |
| 54 | |
| 55 | conv_new = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (*conv_new)); |
| 56 | if (!conv_new) |
| 57 | { |
| 58 | err = gpg_error_from_syserrorcxx . . $ gpg_error_from_syserror(db52760e79bf9054). (); |
| 59 | goto out; |
| 60 | } |
| 61 | |
| 62 | conv_new->pam_convcxx . . $ conv_s#pam_conv. = pam_conv; |
| 63 | *conv = conv_new; |
| 64 | |
| 65 | out: |
| 66 | |
| 67 | return err; |
| 68 | } |
| 69 | |
| 70 | /* Destroy the conv object CONV. */ |
| 71 | void |
| 72 | conv_destroycxx . . $ conv_destroy(1b6b60d1f1d216d8). (conv_tcxx . . $ conv_t# conv) |
| 73 | { |
| 74 | if (conv) |
| 75 | freecxx . . $ free(5d22bdacc48458e8). (conv); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |
| 80 | /* This function queries the PAM user for input through the |
| 81 | conversation function CONV; TEXT will be displayed as prompt, the |
| 82 | user's response will be stored in *RESPONSE. Returns proper error |
| 83 | code. */ |
| 84 | static gpg_error_tcxx . . $ gpg_error_t# |
| 85 | ask_usercxx . . $ ask_user(da034a4b481a0abe). (const struct pam_convcxx . . $ pam_conv# *conv, int secret, |
| 86 | const char *text, char **response) |
| 87 | { |
| 88 | struct pam_messagecxx . . $ pam_message# messages[1] = { { 0, text } }; |
| 89 | const struct pam_messagecxx . . $ pam_message# *pmessages[1] = { &messages[0] }; |
| 90 | struct pam_responsecxx . . $ pam_response# *responses = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 91 | char *response_new; |
| 92 | gpg_error_tcxx . . $ gpg_error_t# err; |
| 93 | int ret; |
| 94 | |
| 95 | if (secret) |
| 96 | messages[0].msg_stylecxx . . $ pam_message#msg_style. = PAM_PROMPT_ECHO_OFFcxx . . $ `<external>/1475977469199658974/_pam_types.h:229:9`!; |
| 97 | else |
| 98 | messages[0].msg_stylecxx . . $ pam_message#msg_style. = PAM_PROMPT_ECHO_ONcxx . . $ `<external>/1475977469199658974/_pam_types.h:230:9`!; |
| 99 | |
| 100 | response_new = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 101 | |
| 102 | ret = (*conv->convcxx . . $ pam_conv#conv.) (sizeof (messages) / (sizeof (*messages)), pmessages, |
| 103 | &responses, conv->appdata_ptrcxx . . $ pam_conv#appdata_ptr.); |
| 104 | if (ret != PAM_SUCCESScxx . . $ `<external>/1475977469199658974/_pam_types.h:29:9`!) |
| 105 | { |
| 106 | err = gpg_errorcxx . . $ gpg_error(6231b2685059dc28). (GPG_ERR_INTERNALcxx . . $ GPG_ERR_INTERNAL.); |
| 107 | goto out; |
| 108 | } |
| 109 | |
| 110 | if (response) |
| 111 | { |
| 112 | response_new = strdupcxx . . $ strdup(a8b8e32347182212). (responses[0].respcxx . . $ pam_response#resp.); |
| 113 | if (! response_new) |
| 114 | { |
| 115 | err = gpg_error_from_errnocxx . . $ gpg_error_from_errno(46cc46841198e427). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 116 | goto out; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | err = 0; |
| 121 | if (response) |
| 122 | *response = response_new; |
| 123 | |
| 124 | out: |
| 125 | |
| 126 | return err; |
| 127 | } |
| 128 | |
| 129 | /* This function queries the PAM user for input through the |
| 130 | conversation function CONV; TEXT will be displayed as prompt, the |
| 131 | user's response will be stored in *RESPONSE. Returns proper error |
| 132 | code. */ |
| 133 | static gpg_error_tcxx . . $ gpg_error_t# |
| 134 | tell_usercxx . . $ tell_user(b0803bfa9535de50). (const struct pam_convcxx . . $ pam_conv# *conv, const char *msg) |
| 135 | { |
| 136 | struct pam_messagecxx . . $ pam_message# messages[1] = { { PAM_TEXT_INFOcxx . . $ `<external>/1475977469199658974/_pam_types.h:232:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! } }; |
| 137 | const struct pam_messagecxx . . $ pam_message# *pmessages[1] = { &messages[0] }; |
| 138 | struct pam_responsecxx . . $ pam_response# *responses = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 139 | gpg_error_tcxx . . $ gpg_error_t# err; |
| 140 | int ret; |
| 141 | |
| 142 | messages[0].msgcxx . . $ pam_message#msg. = msg; |
| 143 | |
| 144 | ret = (*conv->convcxx . . $ pam_conv#conv.) (sizeof (messages) / (sizeof (*messages)), pmessages, |
| 145 | &responses, conv->appdata_ptrcxx . . $ pam_conv#appdata_ptr.); |
| 146 | if (ret != PAM_SUCCESScxx . . $ `<external>/1475977469199658974/_pam_types.h:29:9`!) |
| 147 | { |
| 148 | err = gpg_errorcxx . . $ gpg_error(6231b2685059dc28). (GPG_ERR_INTERNALcxx . . $ GPG_ERR_INTERNAL.); |
| 149 | goto out; |
| 150 | } |
| 151 | |
| 152 | err = 0; |
| 153 | |
| 154 | out: |
| 155 | |
| 156 | return err; |
| 157 | } |
| 158 | |
| 159 | gpg_error_tcxx . . $ gpg_error_t# |
| 160 | conv_tellcxx . . $ conv_tell(93874d2501936ebd). (conv_tcxx . . $ conv_t# conv, const char *fmt, ...) |
| 161 | { |
| 162 | gpg_error_tcxx . . $ gpg_error_t# err = 0; |
| 163 | char *msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 164 | va_listcxx . . $ va_list# ap; |
| 165 | int ret; |
| 166 | |
| 167 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`! (ap, fmt); |
| 168 | |
| 169 | ret = vasprintfcxx . . $ vasprintf(592150f15fbaad71). (&msg, fmt, ap); |
| 170 | if (ret < 0) |
| 171 | { |
| 172 | err = gpg_error_from_errnocxx . . $ gpg_error_from_errno(46cc46841198e427). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 173 | goto out; |
| 174 | } |
| 175 | |
| 176 | err = tell_usercxx . . $ tell_user(b0803bfa9535de50). (conv->pam_convcxx . . $ conv_s#pam_conv., msg); |
| 177 | |
| 178 | out: |
| 179 | |
| 180 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`! (ap); |
| 181 | freecxx . . $ free(5d22bdacc48458e8). (msg); |
| 182 | |
| 183 | return err; |
| 184 | } |
| 185 | |
| 186 | gpg_error_tcxx . . $ gpg_error_t# |
| 187 | conv_askcxx . . $ conv_ask(b7afd51fbbcedc98). (conv_tcxx . . $ conv_t# conv, int ask_secret, |
| 188 | char **response, const char *fmt, ...) |
| 189 | { |
| 190 | gpg_error_tcxx . . $ gpg_error_t# err = 0; |
| 191 | char *msg = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 192 | va_listcxx . . $ va_list# ap; |
| 193 | int ret; |
| 194 | |
| 195 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`! (ap, fmt); |
| 196 | |
| 197 | ret = vasprintfcxx . . $ vasprintf(592150f15fbaad71). (&msg, fmt, ap); |
| 198 | if (ret < 0) |
| 199 | { |
| 200 | err = gpg_error_from_errnocxx . . $ gpg_error_from_errno(46cc46841198e427). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 201 | goto out; |
| 202 | } |
| 203 | |
| 204 | err = ask_usercxx . . $ ask_user(da034a4b481a0abe). (conv->pam_convcxx . . $ conv_s#pam_conv., ask_secret, msg, response); |
| 205 | |
| 206 | out: |
| 207 | |
| 208 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`! (ap); |
| 209 | freecxx . . $ free(5d22bdacc48458e8). (msg); |
| 210 | |
| 211 | return err; |
| 212 | } |
| 213 | |
| 214 | /* END */ |