2 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 RCSID("$OpenBSD: sshconnect2.c,v 1.73 2001/05/18 14:13:29 markus Exp $");
28 #include <openssl/bn.h>
29 #include <openssl/md5.h>
30 #include <openssl/dh.h>
31 #include <openssl/hmac.h>
44 #include "myproposal.h"
46 #include "sshconnect.h"
59 extern char *client_version_string;
60 extern char *server_version_string;
61 extern Options options;
67 u_char *session_id2 = NULL;
68 int session_id2_len = 0;
71 struct sockaddr *xxx_hostaddr;
76 check_host_key_callback(Key *hostkey)
78 check_host_key(xxx_host, xxx_hostaddr, hostkey,
79 options.user_hostfile2, options.system_hostfile2);
84 ssh_kex2(char *host, struct sockaddr *hostaddr)
89 xxx_hostaddr = hostaddr;
91 if (options.ciphers == (char *)-1) {
92 log("No valid ciphers for protocol version 2 given, using defaults.");
93 options.ciphers = NULL;
95 if (options.ciphers != NULL) {
96 myproposal[PROPOSAL_ENC_ALGS_CTOS] =
97 myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
99 myproposal[PROPOSAL_ENC_ALGS_CTOS] =
100 compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
101 myproposal[PROPOSAL_ENC_ALGS_STOC] =
102 compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_STOC]);
103 if (options.compression) {
104 myproposal[PROPOSAL_COMP_ALGS_CTOS] =
105 myproposal[PROPOSAL_COMP_ALGS_STOC] = "zlib";
107 myproposal[PROPOSAL_COMP_ALGS_CTOS] =
108 myproposal[PROPOSAL_COMP_ALGS_STOC] = "none";
110 if (options.macs != NULL) {
111 myproposal[PROPOSAL_MAC_ALGS_CTOS] =
112 myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
114 if (options.hostkeyalgorithms != NULL)
115 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
116 options.hostkeyalgorithms;
118 /* start key exchange */
119 kex = kex_setup(myproposal);
120 kex->client_version_string=client_version_string;
121 kex->server_version_string=server_version_string;
122 kex->check_host_key=&check_host_key_callback;
126 dispatch_run(DISPATCH_BLOCK, &kex->done, kex);
128 session_id2 = kex->session_id;
129 session_id2_len = kex->session_id_len;
132 /* send 1st encrypted/maced/compressed message */
133 packet_start(SSH2_MSG_IGNORE);
134 packet_put_cstring("markus");
138 debug("done: ssh_kex2.");
145 typedef struct Authctxt Authctxt;
146 typedef struct Authmethod Authmethod;
148 typedef int sign_cb_fn(
149 Authctxt *authctxt, Key *key,
150 u_char **sigp, int *lenp, u_char *data, int datalen);
153 const char *server_user;
154 const char *local_user;
162 sign_cb_fn *last_key_sign;
164 AuthenticationConnection *agent;
170 char *name; /* string to compare against server's list */
171 int (*userauth)(Authctxt *authctxt);
172 int *enabled; /* flag in option struct that enables method */
173 int *batch_flag; /* flag in option struct that disables method */
176 void input_userauth_success(int type, int plen, void *ctxt);
177 void input_userauth_failure(int type, int plen, void *ctxt);
178 void input_userauth_banner(int type, int plen, void *ctxt);
179 void input_userauth_error(int type, int plen, void *ctxt);
180 void input_userauth_info_req(int type, int plen, void *ctxt);
181 void input_userauth_pk_ok(int type, int plen, void *ctxt);
183 int userauth_none(Authctxt *authctxt);
184 int userauth_pubkey(Authctxt *authctxt);
185 int userauth_passwd(Authctxt *authctxt);
186 int userauth_kbdint(Authctxt *authctxt);
187 int userauth_hostbased(Authctxt *authctxt);
189 void userauth(Authctxt *authctxt, char *authlist);
192 sign_and_send_pubkey(Authctxt *authctxt, Key *k,
193 sign_cb_fn *sign_callback);
194 void clear_auth_state(Authctxt *authctxt);
196 Authmethod *authmethod_get(char *authlist);
197 Authmethod *authmethod_lookup(const char *name);
198 char *authmethods_get(void);
200 Authmethod authmethods[] = {
203 &options.pubkey_authentication,
207 &options.password_authentication,
208 &options.batch_mode},
209 {"keyboard-interactive",
211 &options.kbd_interactive_authentication,
212 &options.batch_mode},
215 &options.hostbased_authentication,
221 {NULL, NULL, NULL, NULL}
225 ssh_userauth2(const char *local_user, const char *server_user, char *host,
226 Key **keys, int nkeys)
232 if (options.challenge_response_authentication)
233 options.kbd_interactive_authentication = 1;
235 debug("send SSH2_MSG_SERVICE_REQUEST");
236 packet_start(SSH2_MSG_SERVICE_REQUEST);
237 packet_put_cstring("ssh-userauth");
240 type = packet_read(&plen);
241 if (type != SSH2_MSG_SERVICE_ACCEPT) {
242 fatal("denied SSH2_MSG_SERVICE_ACCEPT: %d", type);
244 if (packet_remaining() > 0) {
245 char *reply = packet_get_string(&plen);
246 debug("service_accept: %s", reply);
249 debug("buggy server: service_accept w/o service");
252 debug("got SSH2_MSG_SERVICE_ACCEPT");
254 if (options.preferred_authentications == NULL)
255 options.preferred_authentications = authmethods_get();
257 /* setup authentication context */
258 authctxt.agent = ssh_get_authentication_connection();
259 authctxt.server_user = server_user;
260 authctxt.local_user = local_user;
261 authctxt.host = host;
262 authctxt.service = "ssh-connection"; /* service name */
263 authctxt.success = 0;
264 authctxt.method = authmethod_lookup("none");
265 authctxt.authlist = NULL;
266 authctxt.keys = keys;
267 authctxt.nkeys = nkeys;
268 if (authctxt.method == NULL)
269 fatal("ssh_userauth2: internal error: cannot send userauth none request");
271 /* initial userauth request */
272 userauth_none(&authctxt);
274 dispatch_init(&input_userauth_error);
275 dispatch_set(SSH2_MSG_USERAUTH_SUCCESS, &input_userauth_success);
276 dispatch_set(SSH2_MSG_USERAUTH_FAILURE, &input_userauth_failure);
277 dispatch_set(SSH2_MSG_USERAUTH_BANNER, &input_userauth_banner);
278 dispatch_run(DISPATCH_BLOCK, &authctxt.success, &authctxt); /* loop until success */
280 if (authctxt.agent != NULL)
281 ssh_close_authentication_connection(authctxt.agent);
283 debug("ssh-userauth2 successful: method %s", authctxt.method->name);
286 userauth(Authctxt *authctxt, char *authlist)
288 if (authlist == NULL) {
289 authlist = authctxt->authlist;
291 if (authctxt->authlist)
292 xfree(authctxt->authlist);
293 authctxt->authlist = authlist;
296 Authmethod *method = authmethod_get(authlist);
298 fatal("Permission denied (%s).", authlist);
299 authctxt->method = method;
300 if (method->userauth(authctxt) != 0) {
301 debug2("we sent a %s packet, wait for reply", method->name);
304 debug2("we did not send a packet, disable method");
305 method->enabled = NULL;
310 input_userauth_error(int type, int plen, void *ctxt)
312 fatal("input_userauth_error: bad message during authentication: "
316 input_userauth_banner(int type, int plen, void *ctxt)
319 debug3("input_userauth_banner");
320 msg = packet_get_string(NULL);
321 lang = packet_get_string(NULL);
322 fprintf(stderr, "%s", msg);
327 input_userauth_success(int type, int plen, void *ctxt)
329 Authctxt *authctxt = ctxt;
330 if (authctxt == NULL)
331 fatal("input_userauth_success: no authentication context");
332 if (authctxt->authlist)
333 xfree(authctxt->authlist);
334 clear_auth_state(authctxt);
335 authctxt->success = 1; /* break out */
338 input_userauth_failure(int type, int plen, void *ctxt)
340 Authctxt *authctxt = ctxt;
341 char *authlist = NULL;
344 if (authctxt == NULL)
345 fatal("input_userauth_failure: no authentication context");
347 authlist = packet_get_string(NULL);
348 partial = packet_get_char();
352 log("Authenticated with partial success.");
353 debug("authentications that can continue: %s", authlist);
355 clear_auth_state(authctxt);
356 userauth(authctxt, authlist);
359 input_userauth_pk_ok(int type, int plen, void *ctxt)
361 Authctxt *authctxt = ctxt;
364 int alen, blen, sent = 0;
365 char *pkalg, *pkblob, *fp;
367 if (authctxt == NULL)
368 fatal("input_userauth_pk_ok: no authentication context");
369 if (datafellows & SSH_BUG_PKOK) {
370 /* this is similar to SSH_BUG_PKAUTH */
371 debug2("input_userauth_pk_ok: SSH_BUG_PKOK");
372 pkblob = packet_get_string(&blen);
374 buffer_append(&b, pkblob, blen);
375 pkalg = buffer_get_string(&b, &alen);
378 pkalg = packet_get_string(&alen);
379 pkblob = packet_get_string(&blen);
383 debug("input_userauth_pk_ok: pkalg %s blen %d lastkey %p hint %d",
384 pkalg, blen, authctxt->last_key, authctxt->last_key_hint);
387 if (authctxt->last_key == NULL ||
388 authctxt->last_key_sign == NULL) {
389 debug("no last key or no sign cb");
392 if (key_type_from_name(pkalg) == KEY_UNSPEC) {
393 debug("unknown pkalg %s", pkalg);
396 if ((key = key_from_blob(pkblob, blen)) == NULL) {
397 debug("no key from blob. pkalg %s", pkalg);
400 fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
401 debug2("input_userauth_pk_ok: fp %s", fp);
403 if (!key_equal(key, authctxt->last_key)) {
404 debug("key != last_key");
407 sent = sign_and_send_pubkey(authctxt, key,
408 authctxt->last_key_sign);
417 clear_auth_state(authctxt);
418 dispatch_set(SSH2_MSG_USERAUTH_PK_OK, NULL);
420 /* try another method if we did not send a packet*/
422 userauth(authctxt, NULL);
427 userauth_none(Authctxt *authctxt)
429 /* initial userauth request */
430 packet_start(SSH2_MSG_USERAUTH_REQUEST);
431 packet_put_cstring(authctxt->server_user);
432 packet_put_cstring(authctxt->service);
433 packet_put_cstring(authctxt->method->name);
439 userauth_passwd(Authctxt *authctxt)
441 static int attempt = 0;
445 if (attempt++ >= options.number_of_password_prompts)
449 error("Permission denied, please try again.");
451 snprintf(prompt, sizeof(prompt), "%.30s@%.128s's password: ",
452 authctxt->server_user, authctxt->host);
453 password = read_passphrase(prompt, 0);
454 packet_start(SSH2_MSG_USERAUTH_REQUEST);
455 packet_put_cstring(authctxt->server_user);
456 packet_put_cstring(authctxt->service);
457 packet_put_cstring(authctxt->method->name);
459 packet_put_cstring(password);
460 memset(password, 0, strlen(password));
462 packet_inject_ignore(64);
468 clear_auth_state(Authctxt *authctxt)
470 /* XXX clear authentication state */
471 if (authctxt->last_key != NULL && authctxt->last_key_hint == -1) {
472 debug3("clear_auth_state: key_free %p", authctxt->last_key);
473 key_free(authctxt->last_key);
475 authctxt->last_key = NULL;
476 authctxt->last_key_hint = -2;
477 authctxt->last_key_sign = NULL;
481 sign_and_send_pubkey(Authctxt *authctxt, Key *k, sign_cb_fn *sign_callback)
484 u_char *blob, *signature;
490 debug3("sign_and_send_pubkey");
492 if (key_to_blob(k, &blob, &bloblen) == 0) {
493 /* we cannot handle this key */
494 debug3("sign_and_send_pubkey: cannot handle key");
497 /* data to be signed */
499 if (datafellows & SSH_OLD_SESSIONID) {
500 buffer_append(&b, session_id2, session_id2_len);
501 skip = session_id2_len;
503 buffer_put_string(&b, session_id2, session_id2_len);
504 skip = buffer_len(&b);
506 buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
507 buffer_put_cstring(&b, authctxt->server_user);
508 buffer_put_cstring(&b,
509 datafellows & SSH_BUG_PKSERVICE ?
512 if (datafellows & SSH_BUG_PKAUTH) {
513 buffer_put_char(&b, have_sig);
515 buffer_put_cstring(&b, authctxt->method->name);
516 buffer_put_char(&b, have_sig);
517 buffer_put_cstring(&b, key_ssh_name(k));
519 buffer_put_string(&b, blob, bloblen);
521 /* generate signature */
522 ret = (*sign_callback)(authctxt, k, &signature, &slen,
523 buffer_ptr(&b), buffer_len(&b));
532 if (datafellows & SSH_BUG_PKSERVICE) {
534 buffer_append(&b, session_id2, session_id2_len);
535 skip = session_id2_len;
536 buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
537 buffer_put_cstring(&b, authctxt->server_user);
538 buffer_put_cstring(&b, authctxt->service);
539 buffer_put_cstring(&b, authctxt->method->name);
540 buffer_put_char(&b, have_sig);
541 if (!(datafellows & SSH_BUG_PKAUTH))
542 buffer_put_cstring(&b, key_ssh_name(k));
543 buffer_put_string(&b, blob, bloblen);
547 /* append signature */
548 buffer_put_string(&b, signature, slen);
551 /* skip session id and packet type */
552 if (buffer_len(&b) < skip + 1)
553 fatal("userauth_pubkey: internal error");
554 buffer_consume(&b, skip + 1);
556 /* put remaining data from buffer into packet */
557 packet_start(SSH2_MSG_USERAUTH_REQUEST);
558 packet_put_raw(buffer_ptr(&b), buffer_len(&b));
566 send_pubkey_test(Authctxt *authctxt, Key *k, sign_cb_fn *sign_callback,
570 int bloblen, have_sig = 0;
572 debug3("send_pubkey_test");
574 if (key_to_blob(k, &blob, &bloblen) == 0) {
575 /* we cannot handle this key */
576 debug3("send_pubkey_test: cannot handle key");
579 /* register callback for USERAUTH_PK_OK message */
580 authctxt->last_key_sign = sign_callback;
581 authctxt->last_key_hint = hint;
582 authctxt->last_key = k;
583 dispatch_set(SSH2_MSG_USERAUTH_PK_OK, &input_userauth_pk_ok);
585 packet_start(SSH2_MSG_USERAUTH_REQUEST);
586 packet_put_cstring(authctxt->server_user);
587 packet_put_cstring(authctxt->service);
588 packet_put_cstring(authctxt->method->name);
589 packet_put_char(have_sig);
590 if (!(datafellows & SSH_BUG_PKAUTH))
591 packet_put_cstring(key_ssh_name(k));
592 packet_put_string(blob, bloblen);
599 load_identity_file(char *filename)
602 char prompt[300], *passphrase;
606 if (stat(filename, &st) < 0) {
607 debug3("no such identity: %s", filename);
610 private = key_load_private_type(KEY_UNSPEC, filename, "", NULL);
611 if (private == NULL) {
612 if (options.batch_mode)
614 snprintf(prompt, sizeof prompt,
615 "Enter passphrase for key '%.100s': ", filename);
616 for (i = 0; i < options.number_of_password_prompts; i++) {
617 passphrase = read_passphrase(prompt, 0);
618 if (strcmp(passphrase, "") != 0) {
619 private = key_load_private_type(KEY_UNSPEC, filename,
623 debug2("no passphrase given, try next key");
626 memset(passphrase, 0, strlen(passphrase));
628 if (private != NULL || quit)
630 debug2("bad passphrase given, try again...");
637 identity_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, int *lenp,
638 u_char *data, int datalen)
643 idx = authctxt->last_key_hint;
646 private = load_identity_file(options.identity_files[idx]);
649 ret = key_sign(private, sigp, lenp, data, datalen);
654 int agent_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, int *lenp,
655 u_char *data, int datalen)
657 return ssh_agent_sign(authctxt->agent, key, sigp, lenp, data, datalen);
660 int key_sign_cb(Authctxt *authctxt, Key *key, u_char **sigp, int *lenp,
661 u_char *data, int datalen)
663 return key_sign(key, sigp, lenp, data, datalen);
667 userauth_pubkey_agent(Authctxt *authctxt)
669 static int called = 0;
675 if (ssh_get_num_identities(authctxt->agent, 2) == 0)
676 debug2("userauth_pubkey_agent: no keys at all");
679 k = ssh_get_next_identity(authctxt->agent, &comment, 2);
681 debug2("userauth_pubkey_agent: no more keys");
683 debug("userauth_pubkey_agent: testing agent key %s", comment);
685 ret = send_pubkey_test(authctxt, k, agent_sign_cb, -1);
690 debug2("userauth_pubkey_agent: no message sent");
695 userauth_pubkey(Authctxt *authctxt)
702 if (authctxt->agent != NULL) {
704 sent = userauth_pubkey_agent(authctxt);
705 } while(!sent && authctxt->agent->howmany > 0);
707 while (!sent && idx < options.num_identity_files) {
708 key = options.identity_keys[idx];
709 filename = options.identity_files[idx];
711 debug("try privkey: %s", filename);
712 key = load_identity_file(filename);
714 sent = sign_and_send_pubkey(authctxt, key,
718 } else if (key->type != KEY_RSA1) {
719 debug("try pubkey: %s", filename);
720 sent = send_pubkey_test(authctxt, key,
721 identity_sign_cb, idx);
729 * Send userauth request message specifying keyboard-interactive method.
732 userauth_kbdint(Authctxt *authctxt)
734 static int attempt = 0;
736 if (attempt++ >= options.number_of_password_prompts)
739 debug2("userauth_kbdint");
740 packet_start(SSH2_MSG_USERAUTH_REQUEST);
741 packet_put_cstring(authctxt->server_user);
742 packet_put_cstring(authctxt->service);
743 packet_put_cstring(authctxt->method->name);
744 packet_put_cstring(""); /* lang */
745 packet_put_cstring(options.kbd_interactive_devices ?
746 options.kbd_interactive_devices : "");
749 dispatch_set(SSH2_MSG_USERAUTH_INFO_REQUEST, &input_userauth_info_req);
754 * parse INFO_REQUEST, prompt user and send INFO_RESPONSE
757 input_userauth_info_req(int type, int plen, void *ctxt)
759 Authctxt *authctxt = ctxt;
760 char *name, *inst, *lang, *prompt, *response;
761 u_int num_prompts, i;
764 debug2("input_userauth_info_req");
766 if (authctxt == NULL)
767 fatal("input_userauth_info_req: no authentication context");
769 name = packet_get_string(NULL);
770 inst = packet_get_string(NULL);
771 lang = packet_get_string(NULL);
772 if (strlen(name) > 0)
774 if (strlen(inst) > 0)
780 num_prompts = packet_get_int();
782 * Begin to build info response packet based on prompts requested.
783 * We commit to providing the correct number of responses, so if
784 * further on we run into a problem that prevents this, we have to
785 * be sure and clean this up and send a correct error response.
787 packet_start(SSH2_MSG_USERAUTH_INFO_RESPONSE);
788 packet_put_int(num_prompts);
790 debug2("input_userauth_info_req: num_prompts %d", num_prompts);
791 for (i = 0; i < num_prompts; i++) {
792 prompt = packet_get_string(NULL);
793 echo = packet_get_char();
795 response = cli_prompt(prompt, echo);
797 packet_put_cstring(response);
798 memset(response, 0, strlen(response));
802 packet_done(); /* done with parsing incoming message. */
804 packet_inject_ignore(64);
809 * this will be move to an external program (ssh-keysign) ASAP. ssh-keysign
810 * will be setuid-root and the sbit can be removed from /usr/bin/ssh.
813 userauth_hostbased(Authctxt *authctxt)
817 u_char *signature, *blob;
818 char *chost, *pkalg, *p;
821 int ok, i, len, found = 0;
823 p = get_local_name(packet_get_connection_in());
825 error("userauth_hostbased: cannot get local ipaddr/name");
829 chost = xmalloc(len);
830 strlcpy(chost, p, len);
831 strlcat(chost, ".", len);
832 debug2("userauth_hostbased: chost %s", chost);
833 /* check for a useful key */
834 for (i = 0; i < authctxt->nkeys; i++) {
835 private = authctxt->keys[i];
836 if (private && private->type != KEY_RSA1) {
838 /* we take and free the key */
839 authctxt->keys[i] = NULL;
847 if (key_to_blob(private, &blob, &blen) == 0) {
852 service = datafellows & SSH_BUG_HBSERVICE ? "ssh-userauth" :
854 pkalg = xstrdup(key_ssh_name(private));
857 buffer_put_string(&b, session_id2, session_id2_len);
858 buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
859 buffer_put_cstring(&b, authctxt->server_user);
860 buffer_put_cstring(&b, service);
861 buffer_put_cstring(&b, authctxt->method->name);
862 buffer_put_cstring(&b, pkalg);
863 buffer_put_string(&b, blob, blen);
864 buffer_put_cstring(&b, chost);
865 buffer_put_cstring(&b, authctxt->local_user);
869 debug2("xxx: chost %s", chost);
870 ok = key_sign(private, &signature, &slen, buffer_ptr(&b), buffer_len(&b));
874 error("key_sign failed");
879 packet_start(SSH2_MSG_USERAUTH_REQUEST);
880 packet_put_cstring(authctxt->server_user);
881 packet_put_cstring(authctxt->service);
882 packet_put_cstring(authctxt->method->name);
883 packet_put_cstring(pkalg);
884 packet_put_string(blob, blen);
885 packet_put_cstring(chost);
886 packet_put_cstring(authctxt->local_user);
887 packet_put_string(signature, slen);
888 memset(signature, 's', slen);
897 /* find auth method */
900 * given auth method name, if configurable options permit this method fill
901 * in auth_ident field and return true, otherwise return false.
904 authmethod_is_enabled(Authmethod *method)
908 /* return false if options indicate this method is disabled */
909 if (method->enabled == NULL || *method->enabled == 0)
911 /* return false if batch mode is enabled but method needs interactive mode */
912 if (method->batch_flag != NULL && *method->batch_flag != 0)
918 authmethod_lookup(const char *name)
920 Authmethod *method = NULL;
922 for (method = authmethods; method->name != NULL; method++)
923 if (strcmp(name, method->name) == 0)
925 debug2("Unrecognized authentication method name: %s", name ? name : "NULL");
929 /* XXX internal state */
930 static Authmethod *current = NULL;
931 static char *supported = NULL;
932 static char *preferred = NULL;
934 * Given the authentication method list sent by the server, return the
935 * next method we should try. If the server initially sends a nil list,
936 * use a built-in default list.
939 authmethod_get(char *authlist)
945 /* Use a suitable default if we're passed a nil list. */
946 if (authlist == NULL || strlen(authlist) == 0)
947 authlist = options.preferred_authentications;
949 if (supported == NULL || strcmp(authlist, supported) != 0) {
950 debug3("start over, passed a different list %s", authlist);
951 if (supported != NULL)
953 supported = xstrdup(authlist);
954 preferred = options.preferred_authentications;
955 debug3("preferred %s", preferred);
957 } else if (current != NULL && authmethod_is_enabled(current))
961 if ((name = match_list(preferred, supported, &next)) == NULL) {
962 debug("no more auth methods to try");
967 debug3("authmethod_lookup %s", name);
968 debug3("remaining preferred: %s", preferred);
969 if ((current = authmethod_lookup(name)) != NULL &&
970 authmethod_is_enabled(current)) {
971 debug3("authmethod_is_enabled %s", name);
972 debug("next auth method to try is %s", name);
981 authmethods_get(void)
983 Authmethod *method = NULL;
987 for (method = authmethods; method->name != NULL; method++) {
988 if (authmethod_is_enabled(method)) {
990 strlcat(buf, DELIM, sizeof buf);
991 strlcat(buf, method->name, sizeof buf);