17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (c) 2000 Markus Friedl. All rights reserved. 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 57c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 67c478bd9Sstevel@tonic-gate * are met: 77c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 87c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 97c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 107c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 117c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 147c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 157c478bd9Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 167c478bd9Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 177c478bd9Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 187c478bd9Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 197c478bd9Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 207c478bd9Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 217c478bd9Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 227c478bd9Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate /* 25*9a8058b5Sjp161948 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 267c478bd9Sstevel@tonic-gate * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include "includes.h" 307c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth2-pubkey.c,v 1.2 2002/05/31 11:35:15 markus Exp $"); 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include "ssh2.h" 357c478bd9Sstevel@tonic-gate #include "xmalloc.h" 367c478bd9Sstevel@tonic-gate #include "packet.h" 377c478bd9Sstevel@tonic-gate #include "buffer.h" 387c478bd9Sstevel@tonic-gate #include "log.h" 397c478bd9Sstevel@tonic-gate #include "servconf.h" 407c478bd9Sstevel@tonic-gate #include "compat.h" 417c478bd9Sstevel@tonic-gate #include "bufaux.h" 427c478bd9Sstevel@tonic-gate #include "auth.h" 437c478bd9Sstevel@tonic-gate #include "key.h" 447c478bd9Sstevel@tonic-gate #include "pathnames.h" 457c478bd9Sstevel@tonic-gate #include "uidswap.h" 467c478bd9Sstevel@tonic-gate #include "auth-options.h" 477c478bd9Sstevel@tonic-gate #include "canohost.h" 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #ifdef USE_PAM 507c478bd9Sstevel@tonic-gate #include <security/pam_appl.h> 517c478bd9Sstevel@tonic-gate #include "auth-pam.h" 527c478bd9Sstevel@tonic-gate #endif /* USE_PAM */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* import */ 557c478bd9Sstevel@tonic-gate extern ServerOptions options; 567c478bd9Sstevel@tonic-gate extern u_char *session_id2; 577c478bd9Sstevel@tonic-gate extern int session_id2_len; 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate static void 607c478bd9Sstevel@tonic-gate userauth_pubkey(Authctxt *authctxt) 617c478bd9Sstevel@tonic-gate { 627c478bd9Sstevel@tonic-gate Buffer b; 637c478bd9Sstevel@tonic-gate Key *key = NULL; 647c478bd9Sstevel@tonic-gate char *pkalg; 657c478bd9Sstevel@tonic-gate u_char *pkblob, *sig; 667c478bd9Sstevel@tonic-gate u_int alen, blen, slen; 677c478bd9Sstevel@tonic-gate int have_sig, pktype; 687c478bd9Sstevel@tonic-gate int authenticated = 0; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate if (!authctxt || !authctxt->method) 717c478bd9Sstevel@tonic-gate fatal("%s: missing context", __func__); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate have_sig = packet_get_char(); 747c478bd9Sstevel@tonic-gate if (datafellows & SSH_BUG_PKAUTH) { 757c478bd9Sstevel@tonic-gate debug2("userauth_pubkey: SSH_BUG_PKAUTH"); 767c478bd9Sstevel@tonic-gate /* no explicit pkalg given */ 777c478bd9Sstevel@tonic-gate pkblob = packet_get_string(&blen); 787c478bd9Sstevel@tonic-gate buffer_init(&b); 797c478bd9Sstevel@tonic-gate buffer_append(&b, pkblob, blen); 807c478bd9Sstevel@tonic-gate /* so we have to extract the pkalg from the pkblob */ 817c478bd9Sstevel@tonic-gate pkalg = buffer_get_string(&b, &alen); 827c478bd9Sstevel@tonic-gate buffer_free(&b); 837c478bd9Sstevel@tonic-gate } else { 847c478bd9Sstevel@tonic-gate pkalg = packet_get_string(&alen); 857c478bd9Sstevel@tonic-gate pkblob = packet_get_string(&blen); 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate pktype = key_type_from_name(pkalg); 887c478bd9Sstevel@tonic-gate if (pktype == KEY_UNSPEC) { 897c478bd9Sstevel@tonic-gate /* this is perfectly legal */ 907c478bd9Sstevel@tonic-gate log("userauth_pubkey: unsupported public key algorithm: %s", 917c478bd9Sstevel@tonic-gate pkalg); 927c478bd9Sstevel@tonic-gate goto done; 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate key = key_from_blob(pkblob, blen); 957c478bd9Sstevel@tonic-gate if (key == NULL) { 967c478bd9Sstevel@tonic-gate error("userauth_pubkey: cannot decode key: %s", pkalg); 977c478bd9Sstevel@tonic-gate goto done; 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate if (key->type != pktype) { 1007c478bd9Sstevel@tonic-gate error("userauth_pubkey: type mismatch for decoded key " 1017c478bd9Sstevel@tonic-gate "(received %d, expected %d)", key->type, pktype); 1027c478bd9Sstevel@tonic-gate goto done; 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* Detect and count abandonment */ 1067c478bd9Sstevel@tonic-gate if (authctxt->method->method_data) { 1077c478bd9Sstevel@tonic-gate Key *prev_key; 1087c478bd9Sstevel@tonic-gate unsigned char *prev_pkblob; 1097c478bd9Sstevel@tonic-gate int prev_blen; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * Check for earlier test of a key that was allowed but 1137c478bd9Sstevel@tonic-gate * not followed up with a pubkey req for the same pubkey 1147c478bd9Sstevel@tonic-gate * and with a signature. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate prev_key = authctxt->method->method_data; 1177c478bd9Sstevel@tonic-gate if ((prev_blen = key_to_blob(prev_key, 1187c478bd9Sstevel@tonic-gate &prev_pkblob, NULL))) { 1197c478bd9Sstevel@tonic-gate if (prev_blen != blen || 1207c478bd9Sstevel@tonic-gate memcmp(prev_pkblob, pkblob, blen) != 0) { 1217c478bd9Sstevel@tonic-gate authctxt->method->abandons++; 1227c478bd9Sstevel@tonic-gate authctxt->method->attempts++; 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate key_free(prev_key); 1267c478bd9Sstevel@tonic-gate authctxt->method->method_data = NULL; 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate if (have_sig) { 1307c478bd9Sstevel@tonic-gate sig = packet_get_string(&slen); 1317c478bd9Sstevel@tonic-gate packet_check_eom(); 1327c478bd9Sstevel@tonic-gate buffer_init(&b); 1337c478bd9Sstevel@tonic-gate if (datafellows & SSH_OLD_SESSIONID) { 1347c478bd9Sstevel@tonic-gate buffer_append(&b, session_id2, session_id2_len); 1357c478bd9Sstevel@tonic-gate } else { 1367c478bd9Sstevel@tonic-gate buffer_put_string(&b, session_id2, session_id2_len); 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate /* reconstruct packet */ 1397c478bd9Sstevel@tonic-gate buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST); 1407c478bd9Sstevel@tonic-gate buffer_put_cstring(&b, authctxt->user); 1417c478bd9Sstevel@tonic-gate buffer_put_cstring(&b, 1427c478bd9Sstevel@tonic-gate datafellows & SSH_BUG_PKSERVICE ? 1437c478bd9Sstevel@tonic-gate "ssh-userauth" : 1447c478bd9Sstevel@tonic-gate authctxt->service); 1457c478bd9Sstevel@tonic-gate if (datafellows & SSH_BUG_PKAUTH) { 1467c478bd9Sstevel@tonic-gate buffer_put_char(&b, have_sig); 1477c478bd9Sstevel@tonic-gate } else { 1487c478bd9Sstevel@tonic-gate buffer_put_cstring(&b, "publickey"); 1497c478bd9Sstevel@tonic-gate buffer_put_char(&b, have_sig); 1507c478bd9Sstevel@tonic-gate buffer_put_cstring(&b, pkalg); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate buffer_put_string(&b, pkblob, blen); 1537c478bd9Sstevel@tonic-gate #ifdef DEBUG_PK 1547c478bd9Sstevel@tonic-gate buffer_dump(&b); 1557c478bd9Sstevel@tonic-gate #endif 1567c478bd9Sstevel@tonic-gate /* test for correct signature */ 157*9a8058b5Sjp161948 if (user_key_allowed(authctxt->pw, key) && 158*9a8058b5Sjp161948 key_verify(key, sig, slen, buffer_ptr(&b), 159*9a8058b5Sjp161948 buffer_len(&b)) == 1) { 1607c478bd9Sstevel@tonic-gate authenticated = 1; 161*9a8058b5Sjp161948 } 1627c478bd9Sstevel@tonic-gate authctxt->method->postponed = 0; 1637c478bd9Sstevel@tonic-gate buffer_clear(&b); 1647c478bd9Sstevel@tonic-gate xfree(sig); 1657c478bd9Sstevel@tonic-gate } else { 1667c478bd9Sstevel@tonic-gate debug("test whether pkalg/pkblob are acceptable"); 1677c478bd9Sstevel@tonic-gate packet_check_eom(); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* XXX fake reply and always send PK_OK ? */ 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * XXX this allows testing whether a user is allowed 1727c478bd9Sstevel@tonic-gate * to login: if you happen to have a valid pubkey this 1737c478bd9Sstevel@tonic-gate * message is sent. the message is NEVER sent at all 1747c478bd9Sstevel@tonic-gate * if a user is not allowed to login. is this an 1757c478bd9Sstevel@tonic-gate * issue? -markus 1767c478bd9Sstevel@tonic-gate */ 177*9a8058b5Sjp161948 if (user_key_allowed(authctxt->pw, key)) { 1787c478bd9Sstevel@tonic-gate packet_start(SSH2_MSG_USERAUTH_PK_OK); 1797c478bd9Sstevel@tonic-gate packet_put_string(pkalg, alen); 1807c478bd9Sstevel@tonic-gate packet_put_string(pkblob, blen); 1817c478bd9Sstevel@tonic-gate packet_send(); 1827c478bd9Sstevel@tonic-gate packet_write_wait(); 1837c478bd9Sstevel@tonic-gate authctxt->method->postponed = 1; 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * Remember key that was tried so we can 1867c478bd9Sstevel@tonic-gate * correctly detect abandonment. See above. 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate authctxt->method->method_data = (void *) key; 1897c478bd9Sstevel@tonic-gate key = NULL; 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate if (authenticated != 1) 1937c478bd9Sstevel@tonic-gate auth_clear_options(); 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate done: 1967c478bd9Sstevel@tonic-gate /* 1977c478bd9Sstevel@tonic-gate * XXX TODO: add config options for specifying users for whom 1987c478bd9Sstevel@tonic-gate * this userauth is insufficient and what userauths may 1997c478bd9Sstevel@tonic-gate * continue. 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate #ifdef USE_PAM 2027c478bd9Sstevel@tonic-gate if (authenticated) { 2037c478bd9Sstevel@tonic-gate if (!do_pam_non_initial_userauth(authctxt)) 2047c478bd9Sstevel@tonic-gate authenticated = 0; 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate #endif /* USE_PAM */ 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate debug2("userauth_pubkey: authenticated %d pkalg %s", authenticated, pkalg); 2097c478bd9Sstevel@tonic-gate if (key != NULL) 2107c478bd9Sstevel@tonic-gate key_free(key); 2117c478bd9Sstevel@tonic-gate xfree(pkalg); 2127c478bd9Sstevel@tonic-gate xfree(pkblob); 2137c478bd9Sstevel@tonic-gate #ifdef HAVE_CYGWIN 2147c478bd9Sstevel@tonic-gate if (check_nt_auth(0, authctxt->pw) == 0) 2157c478bd9Sstevel@tonic-gate return; 2167c478bd9Sstevel@tonic-gate #endif 2177c478bd9Sstevel@tonic-gate if (authenticated) 2187c478bd9Sstevel@tonic-gate authctxt->method->authenticated = 1; 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate /* return 1 if user allows given key */ 2227c478bd9Sstevel@tonic-gate static int 2237c478bd9Sstevel@tonic-gate user_key_allowed2(struct passwd *pw, Key *key, char *file) 2247c478bd9Sstevel@tonic-gate { 2257c478bd9Sstevel@tonic-gate char line[8192]; 2267c478bd9Sstevel@tonic-gate int found_key = 0; 2277c478bd9Sstevel@tonic-gate FILE *f; 2287c478bd9Sstevel@tonic-gate u_long linenum = 0; 2297c478bd9Sstevel@tonic-gate struct stat st; 2307c478bd9Sstevel@tonic-gate Key *found; 2317c478bd9Sstevel@tonic-gate char *fp; 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate if (pw == NULL) 2347c478bd9Sstevel@tonic-gate return 0; 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /* Temporarily use the user's uid. */ 2377c478bd9Sstevel@tonic-gate temporarily_use_uid(pw); 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate debug("trying public key file %s", file); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* Fail quietly if file does not exist */ 2427c478bd9Sstevel@tonic-gate if (stat(file, &st) < 0) { 2437c478bd9Sstevel@tonic-gate /* Restore the privileged uid. */ 2447c478bd9Sstevel@tonic-gate restore_uid(); 2457c478bd9Sstevel@tonic-gate return 0; 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate /* Open the file containing the authorized keys. */ 2487c478bd9Sstevel@tonic-gate f = fopen(file, "r"); 2497c478bd9Sstevel@tonic-gate if (!f) { 2507c478bd9Sstevel@tonic-gate /* Restore the privileged uid. */ 2517c478bd9Sstevel@tonic-gate restore_uid(); 2527c478bd9Sstevel@tonic-gate return 0; 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate if (options.strict_modes && 2557c478bd9Sstevel@tonic-gate secure_filename(f, file, pw, line, sizeof(line)) != 0) { 2567c478bd9Sstevel@tonic-gate (void) fclose(f); 2577c478bd9Sstevel@tonic-gate log("Authentication refused: %s", line); 2587c478bd9Sstevel@tonic-gate restore_uid(); 2597c478bd9Sstevel@tonic-gate return 0; 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate found_key = 0; 2637c478bd9Sstevel@tonic-gate found = key_new(key->type); 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate while (fgets(line, sizeof(line), f)) { 2667c478bd9Sstevel@tonic-gate char *cp, *options = NULL; 2677c478bd9Sstevel@tonic-gate linenum++; 2687c478bd9Sstevel@tonic-gate /* Skip leading whitespace, empty and comment lines. */ 2697c478bd9Sstevel@tonic-gate for (cp = line; *cp == ' ' || *cp == '\t'; cp++) 2707c478bd9Sstevel@tonic-gate ; 2717c478bd9Sstevel@tonic-gate if (!*cp || *cp == '\n' || *cp == '#') 2727c478bd9Sstevel@tonic-gate continue; 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate if (key_read(found, &cp) != 1) { 2757c478bd9Sstevel@tonic-gate /* no key? check if there are options for this key */ 2767c478bd9Sstevel@tonic-gate int quoted = 0; 2777c478bd9Sstevel@tonic-gate debug2("user_key_allowed: check options: '%s'", cp); 2787c478bd9Sstevel@tonic-gate options = cp; 2797c478bd9Sstevel@tonic-gate for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) { 2807c478bd9Sstevel@tonic-gate if (*cp == '\\' && cp[1] == '"') 2817c478bd9Sstevel@tonic-gate cp++; /* Skip both */ 2827c478bd9Sstevel@tonic-gate else if (*cp == '"') 2837c478bd9Sstevel@tonic-gate quoted = !quoted; 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate /* Skip remaining whitespace. */ 2867c478bd9Sstevel@tonic-gate for (; *cp == ' ' || *cp == '\t'; cp++) 2877c478bd9Sstevel@tonic-gate ; 2887c478bd9Sstevel@tonic-gate if (key_read(found, &cp) != 1) { 2897c478bd9Sstevel@tonic-gate debug2("user_key_allowed: advance: '%s'", cp); 2907c478bd9Sstevel@tonic-gate /* still no key? advance to next line*/ 2917c478bd9Sstevel@tonic-gate continue; 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate if (key_equal(found, key) && 2957c478bd9Sstevel@tonic-gate auth_parse_options(pw, options, file, linenum) == 1) { 2967c478bd9Sstevel@tonic-gate found_key = 1; 2977c478bd9Sstevel@tonic-gate debug("matching key found: file %s, line %lu", 2987c478bd9Sstevel@tonic-gate file, linenum); 2997c478bd9Sstevel@tonic-gate fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX); 3007c478bd9Sstevel@tonic-gate verbose("Found matching %s key: %s", 3017c478bd9Sstevel@tonic-gate key_type(found), fp); 3027c478bd9Sstevel@tonic-gate xfree(fp); 3037c478bd9Sstevel@tonic-gate break; 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate restore_uid(); 3077c478bd9Sstevel@tonic-gate (void) fclose(f); 3087c478bd9Sstevel@tonic-gate key_free(found); 3097c478bd9Sstevel@tonic-gate if (!found_key) 3107c478bd9Sstevel@tonic-gate debug2("key not found"); 3117c478bd9Sstevel@tonic-gate return found_key; 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate /* check whether given key is in .ssh/authorized_keys* */ 3157c478bd9Sstevel@tonic-gate int 3167c478bd9Sstevel@tonic-gate user_key_allowed(struct passwd *pw, Key *key) 3177c478bd9Sstevel@tonic-gate { 3187c478bd9Sstevel@tonic-gate int success; 3197c478bd9Sstevel@tonic-gate char *file; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate if (pw == NULL) 3227c478bd9Sstevel@tonic-gate return 0; 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate file = authorized_keys_file(pw); 3257c478bd9Sstevel@tonic-gate success = user_key_allowed2(pw, key, file); 3267c478bd9Sstevel@tonic-gate xfree(file); 3277c478bd9Sstevel@tonic-gate if (success) 3287c478bd9Sstevel@tonic-gate return success; 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate /* try suffix "2" for backward compat, too */ 3317c478bd9Sstevel@tonic-gate file = authorized_keys_file2(pw); 3327c478bd9Sstevel@tonic-gate success = user_key_allowed2(pw, key, file); 3337c478bd9Sstevel@tonic-gate xfree(file); 3347c478bd9Sstevel@tonic-gate return success; 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate static 3387c478bd9Sstevel@tonic-gate void 3397c478bd9Sstevel@tonic-gate userauth_pubkey_abandon(Authctxt *authctxt, Authmethod *method) 3407c478bd9Sstevel@tonic-gate { 3417c478bd9Sstevel@tonic-gate if (!authctxt || !method) 3427c478bd9Sstevel@tonic-gate return; 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate if (method->method_data) { 3457c478bd9Sstevel@tonic-gate method->abandons++; 3467c478bd9Sstevel@tonic-gate method->attempts++; 3477c478bd9Sstevel@tonic-gate key_free((Key *) method->method_data); 3487c478bd9Sstevel@tonic-gate method->method_data = NULL; 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate Authmethod method_pubkey = { 3537c478bd9Sstevel@tonic-gate "publickey", 3547c478bd9Sstevel@tonic-gate &options.pubkey_authentication, 3557c478bd9Sstevel@tonic-gate userauth_pubkey, 3567c478bd9Sstevel@tonic-gate userauth_pubkey_abandon, 3577c478bd9Sstevel@tonic-gate NULL, NULL, /* method data and hist data */ 3587c478bd9Sstevel@tonic-gate 0, /* not initial userauth */ 3597c478bd9Sstevel@tonic-gate 0, 0, 0, /* counters */ 3607c478bd9Sstevel@tonic-gate 0, 0, 0, 0, 0, 0 /* state */ 3617c478bd9Sstevel@tonic-gate }; 362