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