Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 1 | /* |
Ben Lindstrom | 92a2e38 | 2001-03-05 06:59:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2001 Markus Friedl. All rights reserved. |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 3 | * Copyright (c) 2001 Per Allansson. All rights reserved. |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | #include "includes.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 26 | |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 27 | #include "ssh2.h" |
| 28 | #include "auth.h" |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 29 | #include "buffer.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 30 | #include "packet.h" |
| 31 | #include "xmalloc.h" |
| 32 | #include "dispatch.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 33 | #include "log.h" |
Darren Tucker | 3c66080 | 2005-01-20 22:20:50 +1100 | [diff] [blame] | 34 | #include "servconf.h" |
| 35 | |
| 36 | /* import */ |
| 37 | extern ServerOptions options; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 38 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 39 | static int auth2_challenge_start(Authctxt *); |
| 40 | static int send_userauth_info_request(Authctxt *); |
Damien Miller | 630d6f4 | 2002-01-22 23:17:30 +1100 | [diff] [blame] | 41 | static void input_userauth_info_response(int, u_int32_t, void *); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef BSD_AUTH |
| 44 | extern KbdintDevice bsdauth_device; |
| 45 | #else |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 46 | #ifdef USE_PAM |
| 47 | extern KbdintDevice sshpam_device; |
| 48 | #endif |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 49 | #ifdef SKEY |
| 50 | extern KbdintDevice skey_device; |
| 51 | #endif |
| 52 | #endif |
| 53 | |
| 54 | KbdintDevice *devices[] = { |
| 55 | #ifdef BSD_AUTH |
| 56 | &bsdauth_device, |
| 57 | #else |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 58 | #ifdef USE_PAM |
| 59 | &sshpam_device, |
| 60 | #endif |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 61 | #ifdef SKEY |
| 62 | &skey_device, |
| 63 | #endif |
| 64 | #endif |
| 65 | NULL |
| 66 | }; |
| 67 | |
| 68 | typedef struct KbdintAuthctxt KbdintAuthctxt; |
| 69 | struct KbdintAuthctxt |
| 70 | { |
| 71 | char *devices; |
| 72 | void *ctxt; |
| 73 | KbdintDevice *device; |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 74 | u_int nreq; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Darren Tucker | 3c66080 | 2005-01-20 22:20:50 +1100 | [diff] [blame] | 77 | #ifdef USE_PAM |
| 78 | void |
| 79 | remove_kbdint_device(const char *devname) |
| 80 | { |
| 81 | int i, j; |
| 82 | |
| 83 | for (i = 0; devices[i] != NULL; i++) |
| 84 | if (strcmp(devices[i]->name, devname) == 0) { |
| 85 | for (j = i; devices[j] != NULL; j++) |
| 86 | devices[j] = devices[j+1]; |
| 87 | i--; |
| 88 | } |
| 89 | } |
| 90 | #endif |
| 91 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 92 | static KbdintAuthctxt * |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 93 | kbdint_alloc(const char *devs) |
| 94 | { |
| 95 | KbdintAuthctxt *kbdintctxt; |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 96 | Buffer b; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 97 | int i; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 98 | |
Darren Tucker | 3c66080 | 2005-01-20 22:20:50 +1100 | [diff] [blame] | 99 | #ifdef USE_PAM |
| 100 | if (!options.use_pam) |
| 101 | remove_kbdint_device("pam"); |
| 102 | #endif |
| 103 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 104 | kbdintctxt = xmalloc(sizeof(KbdintAuthctxt)); |
| 105 | if (strcmp(devs, "") == 0) { |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 106 | buffer_init(&b); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 107 | for (i = 0; devices[i]; i++) { |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 108 | if (buffer_len(&b) > 0) |
| 109 | buffer_append(&b, ",", 1); |
| 110 | buffer_append(&b, devices[i]->name, |
| 111 | strlen(devices[i]->name)); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 112 | } |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 113 | buffer_append(&b, "\0", 1); |
| 114 | kbdintctxt->devices = xstrdup(buffer_ptr(&b)); |
| 115 | buffer_free(&b); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 116 | } else { |
| 117 | kbdintctxt->devices = xstrdup(devs); |
| 118 | } |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 119 | debug("kbdint_alloc: devices '%s'", kbdintctxt->devices); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 120 | kbdintctxt->ctxt = NULL; |
| 121 | kbdintctxt->device = NULL; |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 122 | kbdintctxt->nreq = 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 123 | |
| 124 | return kbdintctxt; |
| 125 | } |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 126 | static void |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 127 | kbdint_reset_device(KbdintAuthctxt *kbdintctxt) |
| 128 | { |
| 129 | if (kbdintctxt->ctxt) { |
| 130 | kbdintctxt->device->free_ctx(kbdintctxt->ctxt); |
| 131 | kbdintctxt->ctxt = NULL; |
| 132 | } |
| 133 | kbdintctxt->device = NULL; |
| 134 | } |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 135 | static void |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 136 | kbdint_free(KbdintAuthctxt *kbdintctxt) |
| 137 | { |
| 138 | if (kbdintctxt->device) |
| 139 | kbdint_reset_device(kbdintctxt); |
| 140 | if (kbdintctxt->devices) { |
| 141 | xfree(kbdintctxt->devices); |
| 142 | kbdintctxt->devices = NULL; |
| 143 | } |
| 144 | xfree(kbdintctxt); |
| 145 | } |
| 146 | /* get next device */ |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 147 | static int |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 148 | kbdint_next_device(KbdintAuthctxt *kbdintctxt) |
| 149 | { |
| 150 | size_t len; |
| 151 | char *t; |
| 152 | int i; |
| 153 | |
| 154 | if (kbdintctxt->device) |
| 155 | kbdint_reset_device(kbdintctxt); |
| 156 | do { |
| 157 | len = kbdintctxt->devices ? |
| 158 | strcspn(kbdintctxt->devices, ",") : 0; |
| 159 | |
| 160 | if (len == 0) |
| 161 | break; |
| 162 | for (i = 0; devices[i]; i++) |
| 163 | if (strncmp(kbdintctxt->devices, devices[i]->name, len) == 0) |
| 164 | kbdintctxt->device = devices[i]; |
| 165 | t = kbdintctxt->devices; |
| 166 | kbdintctxt->devices = t[len] ? xstrdup(t+len+1) : NULL; |
| 167 | xfree(t); |
| 168 | debug2("kbdint_next_device: devices %s", kbdintctxt->devices ? |
Damien Miller | 0dc1bef | 2005-07-17 17:22:45 +1000 | [diff] [blame] | 169 | kbdintctxt->devices : "<empty>"); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 170 | } while (kbdintctxt->devices && !kbdintctxt->device); |
| 171 | |
| 172 | return kbdintctxt->device ? 1 : 0; |
| 173 | } |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 174 | |
| 175 | /* |
Ben Lindstrom | bdfb4df | 2001-10-03 17:12:43 +0000 | [diff] [blame] | 176 | * try challenge-response, set authctxt->postponed if we have to |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 177 | * wait for the response. |
| 178 | */ |
| 179 | int |
| 180 | auth2_challenge(Authctxt *authctxt, char *devs) |
| 181 | { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 182 | debug("auth2_challenge: user=%s devs=%s", |
| 183 | authctxt->user ? authctxt->user : "<nouser>", |
| 184 | devs ? devs : "<no devs>"); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 185 | |
Ben Lindstrom | 742e89e | 2001-06-09 01:17:23 +0000 | [diff] [blame] | 186 | if (authctxt->user == NULL || !devs) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 187 | return 0; |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 188 | if (authctxt->kbdintctxt == NULL) |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 189 | authctxt->kbdintctxt = kbdint_alloc(devs); |
| 190 | return auth2_challenge_start(authctxt); |
| 191 | } |
| 192 | |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 193 | /* unregister kbd-int callbacks and context */ |
| 194 | void |
| 195 | auth2_challenge_stop(Authctxt *authctxt) |
| 196 | { |
| 197 | /* unregister callback */ |
| 198 | dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL); |
| 199 | if (authctxt->kbdintctxt != NULL) { |
| 200 | kbdint_free(authctxt->kbdintctxt); |
| 201 | authctxt->kbdintctxt = NULL; |
| 202 | } |
| 203 | } |
| 204 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 205 | /* side effect: sets authctxt->postponed if a reply was sent*/ |
| 206 | static int |
| 207 | auth2_challenge_start(Authctxt *authctxt) |
| 208 | { |
| 209 | KbdintAuthctxt *kbdintctxt = authctxt->kbdintctxt; |
| 210 | |
| 211 | debug2("auth2_challenge_start: devices %s", |
| 212 | kbdintctxt->devices ? kbdintctxt->devices : "<empty>"); |
| 213 | |
| 214 | if (kbdint_next_device(kbdintctxt) == 0) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 215 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 216 | return 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 217 | } |
| 218 | debug("auth2_challenge_start: trying authentication method '%s'", |
| 219 | kbdintctxt->device->name); |
| 220 | |
| 221 | if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 222 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | if (send_userauth_info_request(authctxt) == 0) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 226 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 227 | return 0; |
| 228 | } |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 229 | dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, |
| 230 | &input_userauth_info_response); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 231 | |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 232 | authctxt->postponed = 1; |
| 233 | return 0; |
| 234 | } |
| 235 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 236 | static int |
| 237 | send_userauth_info_request(Authctxt *authctxt) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 238 | { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 239 | KbdintAuthctxt *kbdintctxt; |
| 240 | char *name, *instr, **prompts; |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 241 | u_int i, *echo_on; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 242 | |
| 243 | kbdintctxt = authctxt->kbdintctxt; |
| 244 | if (kbdintctxt->device->query(kbdintctxt->ctxt, |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 245 | &name, &instr, &kbdintctxt->nreq, &prompts, &echo_on)) |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 246 | return 0; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 247 | |
| 248 | packet_start(SSH2_MSG_USERAUTH_INFO_REQUEST); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 249 | packet_put_cstring(name); |
| 250 | packet_put_cstring(instr); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 251 | packet_put_cstring(""); /* language not used */ |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 252 | packet_put_int(kbdintctxt->nreq); |
| 253 | for (i = 0; i < kbdintctxt->nreq; i++) { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 254 | packet_put_cstring(prompts[i]); |
| 255 | packet_put_char(echo_on[i]); |
| 256 | } |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 257 | packet_send(); |
| 258 | packet_write_wait(); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 259 | |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 260 | for (i = 0; i < kbdintctxt->nreq; i++) |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 261 | xfree(prompts[i]); |
| 262 | xfree(prompts); |
| 263 | xfree(echo_on); |
| 264 | xfree(name); |
| 265 | xfree(instr); |
| 266 | return 1; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 269 | static void |
Damien Miller | 630d6f4 | 2002-01-22 23:17:30 +1100 | [diff] [blame] | 270 | input_userauth_info_response(int type, u_int32_t seq, void *ctxt) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 271 | { |
| 272 | Authctxt *authctxt = ctxt; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 273 | KbdintAuthctxt *kbdintctxt; |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 274 | int authenticated = 0, res, len; |
| 275 | u_int i, nresp; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 276 | char **response = NULL, *method; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 277 | |
| 278 | if (authctxt == NULL) |
| 279 | fatal("input_userauth_info_response: no authctxt"); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 280 | kbdintctxt = authctxt->kbdintctxt; |
| 281 | if (kbdintctxt == NULL || kbdintctxt->ctxt == NULL) |
| 282 | fatal("input_userauth_info_response: no kbdintctxt"); |
| 283 | if (kbdintctxt->device == NULL) |
| 284 | fatal("input_userauth_info_response: no device"); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 285 | |
| 286 | authctxt->postponed = 0; /* reset */ |
| 287 | nresp = packet_get_int(); |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 288 | if (nresp != kbdintctxt->nreq) |
| 289 | fatal("input_userauth_info_response: wrong number of replies"); |
| 290 | if (nresp > 100) |
| 291 | fatal("input_userauth_info_response: too many replies"); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 292 | if (nresp > 0) { |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 293 | response = xcalloc(nresp, sizeof(char *)); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 294 | for (i = 0; i < nresp; i++) |
| 295 | response[i] = packet_get_string(NULL); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 296 | } |
Damien Miller | 48b03fc | 2002-01-22 23:11:40 +1100 | [diff] [blame] | 297 | packet_check_eom(); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 298 | |
Darren Tucker | 611649e | 2005-01-20 11:05:34 +1100 | [diff] [blame] | 299 | res = kbdintctxt->device->respond(kbdintctxt->ctxt, nresp, response); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 300 | |
| 301 | for (i = 0; i < nresp; i++) { |
| 302 | memset(response[i], 'r', strlen(response[i])); |
| 303 | xfree(response[i]); |
| 304 | } |
| 305 | if (response) |
| 306 | xfree(response); |
| 307 | |
| 308 | switch (res) { |
| 309 | case 0: |
| 310 | /* Success! */ |
Darren Tucker | 611649e | 2005-01-20 11:05:34 +1100 | [diff] [blame] | 311 | authenticated = authctxt->valid ? 1 : 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 312 | break; |
| 313 | case 1: |
| 314 | /* Authentication needs further interaction */ |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 315 | if (send_userauth_info_request(authctxt) == 1) |
| 316 | authctxt->postponed = 1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 317 | break; |
| 318 | default: |
| 319 | /* Failure! */ |
| 320 | break; |
| 321 | } |
| 322 | |
| 323 | len = strlen("keyboard-interactive") + 2 + |
| 324 | strlen(kbdintctxt->device->name); |
| 325 | method = xmalloc(len); |
Damien Miller | 209ee4e | 2002-01-22 23:25:08 +1100 | [diff] [blame] | 326 | snprintf(method, len, "keyboard-interactive/%s", |
| 327 | kbdintctxt->device->name); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 328 | |
| 329 | if (!authctxt->postponed) { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 330 | if (authenticated) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 331 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 332 | } else { |
| 333 | /* start next device */ |
| 334 | /* may set authctxt->postponed */ |
| 335 | auth2_challenge_start(authctxt); |
| 336 | } |
| 337 | } |
Damien Miller | 5d57e50 | 2001-03-30 10:48:31 +1000 | [diff] [blame] | 338 | userauth_finish(authctxt, authenticated, method); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 339 | xfree(method); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 340 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 341 | |
| 342 | void |
| 343 | privsep_challenge_enable(void) |
| 344 | { |
Damien Miller | a6a7c19 | 2003-05-26 21:36:13 +1000 | [diff] [blame] | 345 | #if defined(BSD_AUTH) || defined(USE_PAM) || defined(SKEY) |
| 346 | int n = 0; |
| 347 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 348 | #ifdef BSD_AUTH |
| 349 | extern KbdintDevice mm_bsdauth_device; |
| 350 | #endif |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 351 | #ifdef USE_PAM |
| 352 | extern KbdintDevice mm_sshpam_device; |
| 353 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 354 | #ifdef SKEY |
| 355 | extern KbdintDevice mm_skey_device; |
| 356 | #endif |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 357 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 358 | #ifdef BSD_AUTH |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 359 | devices[n++] = &mm_bsdauth_device; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 360 | #else |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 361 | #ifdef USE_PAM |
| 362 | devices[n++] = &mm_sshpam_device; |
| 363 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 364 | #ifdef SKEY |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 365 | devices[n++] = &mm_skey_device; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 366 | #endif |
| 367 | #endif |
| 368 | } |