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