17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 37c478bd9Sstevel@tonic-gate * All rights reserved 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * As far as I am concerned, the code I have written for this software 67c478bd9Sstevel@tonic-gate * can be used freely for any purpose. Any derived versions of this 77c478bd9Sstevel@tonic-gate * software must be clearly marked as such, and if the derived work is 87c478bd9Sstevel@tonic-gate * incompatible with the protocol description in the RFC file, it must be 97c478bd9Sstevel@tonic-gate * called by a name other than "ssh" or "Secure Shell". 107c478bd9Sstevel@tonic-gate */ 117c478bd9Sstevel@tonic-gate /* 129b03ea0fSjp161948 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 137c478bd9Sstevel@tonic-gate * Use is subject to license terms. 147c478bd9Sstevel@tonic-gate */ 157c478bd9Sstevel@tonic-gate 167c478bd9Sstevel@tonic-gate #include "includes.h" 177c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: servconf.c,v 1.115 2002/09/04 18:52:42 stevesk Exp $"); 187c478bd9Sstevel@tonic-gate 197c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN 227c478bd9Sstevel@tonic-gate #include <deflt.h> 237c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #if defined(KRB4) 267c478bd9Sstevel@tonic-gate #include <krb.h> 277c478bd9Sstevel@tonic-gate #endif 287c478bd9Sstevel@tonic-gate #if defined(KRB5) 297c478bd9Sstevel@tonic-gate #ifdef HEIMDAL 307c478bd9Sstevel@tonic-gate #include <krb.h> 317c478bd9Sstevel@tonic-gate #else 327c478bd9Sstevel@tonic-gate /* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V 337c478bd9Sstevel@tonic-gate * keytab */ 347c478bd9Sstevel@tonic-gate #define KEYFILE "/etc/krb5.keytab" 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate #ifdef AFS 387c478bd9Sstevel@tonic-gate #include <kafs.h> 397c478bd9Sstevel@tonic-gate #endif 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include "ssh.h" 427c478bd9Sstevel@tonic-gate #include "log.h" 437c478bd9Sstevel@tonic-gate #include "servconf.h" 447c478bd9Sstevel@tonic-gate #include "xmalloc.h" 457c478bd9Sstevel@tonic-gate #include "compat.h" 467c478bd9Sstevel@tonic-gate #include "pathnames.h" 477c478bd9Sstevel@tonic-gate #include "tildexpand.h" 487c478bd9Sstevel@tonic-gate #include "misc.h" 497c478bd9Sstevel@tonic-gate #include "cipher.h" 507c478bd9Sstevel@tonic-gate #include "kex.h" 517c478bd9Sstevel@tonic-gate #include "mac.h" 527c478bd9Sstevel@tonic-gate #include "auth.h" 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate static void add_listen_addr(ServerOptions *, char *, u_short); 557c478bd9Sstevel@tonic-gate static void add_one_listen_addr(ServerOptions *, char *, u_short); 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /* AF_UNSPEC or AF_INET or AF_INET6 */ 587c478bd9Sstevel@tonic-gate extern int IPv4or6; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* Initializes the server options to their default values. */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate void 637c478bd9Sstevel@tonic-gate initialize_server_options(ServerOptions *options) 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate (void) memset(options, 0, sizeof(*options)); 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* Portable-specific options */ 687c478bd9Sstevel@tonic-gate options->pam_authentication_via_kbd_int = -1; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* Standard Options */ 717c478bd9Sstevel@tonic-gate options->num_ports = 0; 727c478bd9Sstevel@tonic-gate options->ports_from_cmdline = 0; 737c478bd9Sstevel@tonic-gate options->listen_addrs = NULL; 747c478bd9Sstevel@tonic-gate options->num_host_key_files = 0; 757c478bd9Sstevel@tonic-gate options->pid_file = NULL; 767c478bd9Sstevel@tonic-gate options->server_key_bits = -1; 777c478bd9Sstevel@tonic-gate options->login_grace_time = -1; 787c478bd9Sstevel@tonic-gate options->key_regeneration_time = -1; 797c478bd9Sstevel@tonic-gate options->permit_root_login = PERMIT_NOT_SET; 807c478bd9Sstevel@tonic-gate options->ignore_rhosts = -1; 817c478bd9Sstevel@tonic-gate options->ignore_user_known_hosts = -1; 827c478bd9Sstevel@tonic-gate options->print_motd = -1; 837c478bd9Sstevel@tonic-gate options->print_lastlog = -1; 847c478bd9Sstevel@tonic-gate options->x11_forwarding = -1; 857c478bd9Sstevel@tonic-gate options->x11_display_offset = -1; 867c478bd9Sstevel@tonic-gate options->x11_use_localhost = -1; 877c478bd9Sstevel@tonic-gate options->xauth_location = NULL; 887c478bd9Sstevel@tonic-gate options->strict_modes = -1; 897c478bd9Sstevel@tonic-gate options->keepalives = -1; 907c478bd9Sstevel@tonic-gate options->log_facility = SYSLOG_FACILITY_NOT_SET; 917c478bd9Sstevel@tonic-gate options->log_level = SYSLOG_LEVEL_NOT_SET; 927c478bd9Sstevel@tonic-gate options->rhosts_authentication = -1; 937c478bd9Sstevel@tonic-gate options->rhosts_rsa_authentication = -1; 947c478bd9Sstevel@tonic-gate options->hostbased_authentication = -1; 957c478bd9Sstevel@tonic-gate options->hostbased_uses_name_from_packet_only = -1; 967c478bd9Sstevel@tonic-gate options->rsa_authentication = -1; 977c478bd9Sstevel@tonic-gate options->pubkey_authentication = -1; 987c478bd9Sstevel@tonic-gate #ifdef GSSAPI 997c478bd9Sstevel@tonic-gate options->gss_authentication = -1; 1007c478bd9Sstevel@tonic-gate options->gss_keyex = -1; 1017c478bd9Sstevel@tonic-gate options->gss_store_creds = -1; 1027c478bd9Sstevel@tonic-gate options->gss_use_session_ccache = -1; 1037c478bd9Sstevel@tonic-gate options->gss_cleanup_creds = -1; 1047c478bd9Sstevel@tonic-gate #endif 1057c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 1067c478bd9Sstevel@tonic-gate options->kerberos_authentication = -1; 1077c478bd9Sstevel@tonic-gate options->kerberos_or_local_passwd = -1; 1087c478bd9Sstevel@tonic-gate options->kerberos_ticket_cleanup = -1; 1097c478bd9Sstevel@tonic-gate #endif 1107c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 1117c478bd9Sstevel@tonic-gate options->kerberos_tgt_passing = -1; 1127c478bd9Sstevel@tonic-gate #endif 1137c478bd9Sstevel@tonic-gate #ifdef AFS 1147c478bd9Sstevel@tonic-gate options->afs_token_passing = -1; 1157c478bd9Sstevel@tonic-gate #endif 1167c478bd9Sstevel@tonic-gate options->password_authentication = -1; 1177c478bd9Sstevel@tonic-gate options->kbd_interactive_authentication = -1; 1187c478bd9Sstevel@tonic-gate options->challenge_response_authentication = -1; 1197c478bd9Sstevel@tonic-gate options->permit_empty_passwd = -1; 1207c478bd9Sstevel@tonic-gate options->permit_user_env = -1; 1217c478bd9Sstevel@tonic-gate options->use_login = -1; 1227c478bd9Sstevel@tonic-gate options->compression = -1; 1237c478bd9Sstevel@tonic-gate options->allow_tcp_forwarding = -1; 1247c478bd9Sstevel@tonic-gate options->num_allow_users = 0; 1257c478bd9Sstevel@tonic-gate options->num_deny_users = 0; 1267c478bd9Sstevel@tonic-gate options->num_allow_groups = 0; 1277c478bd9Sstevel@tonic-gate options->num_deny_groups = 0; 1287c478bd9Sstevel@tonic-gate options->ciphers = NULL; 1297c478bd9Sstevel@tonic-gate options->macs = NULL; 1307c478bd9Sstevel@tonic-gate options->protocol = SSH_PROTO_UNKNOWN; 1317c478bd9Sstevel@tonic-gate options->gateway_ports = -1; 1327c478bd9Sstevel@tonic-gate options->num_subsystems = 0; 1337c478bd9Sstevel@tonic-gate options->max_startups_begin = -1; 1347c478bd9Sstevel@tonic-gate options->max_startups_rate = -1; 1357c478bd9Sstevel@tonic-gate options->max_startups = -1; 1367c478bd9Sstevel@tonic-gate options->banner = NULL; 1377c478bd9Sstevel@tonic-gate options->verify_reverse_mapping = -1; 1387c478bd9Sstevel@tonic-gate options->client_alive_interval = -1; 1397c478bd9Sstevel@tonic-gate options->client_alive_count_max = -1; 1407c478bd9Sstevel@tonic-gate options->authorized_keys_file = NULL; 1417c478bd9Sstevel@tonic-gate options->authorized_keys_file2 = NULL; 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate options->max_auth_tries = -1; 1447c478bd9Sstevel@tonic-gate options->max_auth_tries_log = -1; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate options->max_init_auth_tries = -1; 1477c478bd9Sstevel@tonic-gate options->max_init_auth_tries_log = -1; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate options->lookup_client_hostnames = -1; 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN 1537c478bd9Sstevel@tonic-gate /* 1547c478bd9Sstevel@tonic-gate * Reads /etc/default/login and defaults several ServerOptions: 1557c478bd9Sstevel@tonic-gate * 1567c478bd9Sstevel@tonic-gate * PermitRootLogin 1577c478bd9Sstevel@tonic-gate * PermitEmptyPasswords 1587c478bd9Sstevel@tonic-gate * LoginGraceTime 1597c478bd9Sstevel@tonic-gate * 1607c478bd9Sstevel@tonic-gate * CONSOLE=* -> PermitRootLogin=without-password 1617c478bd9Sstevel@tonic-gate * #CONSOLE=* -> PermitRootLogin=yes 1627c478bd9Sstevel@tonic-gate * 1637c478bd9Sstevel@tonic-gate * PASSREQ=YES -> PermitEmptyPasswords=no 1647c478bd9Sstevel@tonic-gate * PASSREQ=NO -> PermitEmptyPasswords=yes 1657c478bd9Sstevel@tonic-gate * #PASSREQ=* -> PermitEmptyPasswords=no 1667c478bd9Sstevel@tonic-gate * 1677c478bd9Sstevel@tonic-gate * TIMEOUT=<secs> -> LoginGraceTime=<secs> 1687c478bd9Sstevel@tonic-gate * #TIMEOUT=<secs> -> LoginGraceTime=300 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate static 1717c478bd9Sstevel@tonic-gate void 1727c478bd9Sstevel@tonic-gate deflt_fill_default_server_options(ServerOptions *options) 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate int flags; 1757c478bd9Sstevel@tonic-gate char *ptr; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate if (defopen(_PATH_DEFAULT_LOGIN)) 1787c478bd9Sstevel@tonic-gate return; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* Ignore case */ 1817c478bd9Sstevel@tonic-gate flags = defcntl(DC_GETFLAGS, 0); 1827c478bd9Sstevel@tonic-gate TURNOFF(flags, DC_CASE); 1837c478bd9Sstevel@tonic-gate (void) defcntl(DC_SETFLAGS, flags); 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if (options->permit_root_login == PERMIT_NOT_SET && 1867c478bd9Sstevel@tonic-gate (ptr = defread("CONSOLE=")) != NULL) 1877c478bd9Sstevel@tonic-gate options->permit_root_login = PERMIT_NO_PASSWD; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate if (options->permit_empty_passwd == -1 && 1907c478bd9Sstevel@tonic-gate (ptr = defread("PASSREQ=")) != NULL) { 1917c478bd9Sstevel@tonic-gate if (strcasecmp("YES", ptr) == 0) 1927c478bd9Sstevel@tonic-gate options->permit_empty_passwd = 0; 1937c478bd9Sstevel@tonic-gate else if (strcasecmp("NO", ptr) == 0) 1947c478bd9Sstevel@tonic-gate options->permit_empty_passwd = 1; 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries == -1 && 1987c478bd9Sstevel@tonic-gate (ptr = defread("RETRIES=")) != NULL) { 1997c478bd9Sstevel@tonic-gate options->max_init_auth_tries = atoi(ptr); 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries_log == -1 && 2037c478bd9Sstevel@tonic-gate (ptr = defread("SYSLOG_FAILED_LOGINS=")) != NULL) { 2047c478bd9Sstevel@tonic-gate options->max_init_auth_tries_log = atoi(ptr); 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate if (options->login_grace_time == -1) { 2087c478bd9Sstevel@tonic-gate if ((ptr = defread("TIMEOUT=")) != NULL) 2097c478bd9Sstevel@tonic-gate options->login_grace_time = (unsigned)atoi(ptr); 2107c478bd9Sstevel@tonic-gate else 2117c478bd9Sstevel@tonic-gate options->login_grace_time = 300; 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate (void) defopen((char *)NULL); 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */ 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate void 2197c478bd9Sstevel@tonic-gate fill_default_server_options(ServerOptions *options) 2207c478bd9Sstevel@tonic-gate { 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN 2237c478bd9Sstevel@tonic-gate deflt_fill_default_server_options(options); 2247c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */ 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* Portable-specific options */ 2277c478bd9Sstevel@tonic-gate if (options->pam_authentication_via_kbd_int == -1) 2287c478bd9Sstevel@tonic-gate options->pam_authentication_via_kbd_int = 0; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* Standard Options */ 2317c478bd9Sstevel@tonic-gate if (options->protocol == SSH_PROTO_UNKNOWN) 2327c478bd9Sstevel@tonic-gate options->protocol = SSH_PROTO_1|SSH_PROTO_2; 2337c478bd9Sstevel@tonic-gate if (options->num_host_key_files == 0) { 2347c478bd9Sstevel@tonic-gate /* fill default hostkeys for protocols */ 2357c478bd9Sstevel@tonic-gate if (options->protocol & SSH_PROTO_1) 2367c478bd9Sstevel@tonic-gate options->host_key_files[options->num_host_key_files++] = 2377c478bd9Sstevel@tonic-gate _PATH_HOST_KEY_FILE; 2387c478bd9Sstevel@tonic-gate #ifndef GSSAPI 2397c478bd9Sstevel@tonic-gate /* With GSS keyex we can run v2 w/ no host keys */ 2407c478bd9Sstevel@tonic-gate if (options->protocol & SSH_PROTO_2) { 2417c478bd9Sstevel@tonic-gate options->host_key_files[options->num_host_key_files++] = 2427c478bd9Sstevel@tonic-gate _PATH_HOST_RSA_KEY_FILE; 2437c478bd9Sstevel@tonic-gate options->host_key_files[options->num_host_key_files++] = 2447c478bd9Sstevel@tonic-gate _PATH_HOST_DSA_KEY_FILE; 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate #endif /* GSSAPI */ 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate if (options->num_ports == 0) 2497c478bd9Sstevel@tonic-gate options->ports[options->num_ports++] = SSH_DEFAULT_PORT; 2507c478bd9Sstevel@tonic-gate if (options->listen_addrs == NULL) 2517c478bd9Sstevel@tonic-gate add_listen_addr(options, NULL, 0); 2527c478bd9Sstevel@tonic-gate if (options->pid_file == NULL) 2537c478bd9Sstevel@tonic-gate options->pid_file = _PATH_SSH_DAEMON_PID_FILE; 2547c478bd9Sstevel@tonic-gate if (options->server_key_bits == -1) 2557c478bd9Sstevel@tonic-gate options->server_key_bits = 768; 2567c478bd9Sstevel@tonic-gate if (options->login_grace_time == -1) 2577c478bd9Sstevel@tonic-gate options->login_grace_time = 120; 2587c478bd9Sstevel@tonic-gate if (options->key_regeneration_time == -1) 2597c478bd9Sstevel@tonic-gate options->key_regeneration_time = 3600; 2607c478bd9Sstevel@tonic-gate if (options->permit_root_login == PERMIT_NOT_SET) 2617c478bd9Sstevel@tonic-gate options->permit_root_login = PERMIT_YES; 2627c478bd9Sstevel@tonic-gate if (options->ignore_rhosts == -1) 2637c478bd9Sstevel@tonic-gate options->ignore_rhosts = 1; 2647c478bd9Sstevel@tonic-gate if (options->ignore_user_known_hosts == -1) 2657c478bd9Sstevel@tonic-gate options->ignore_user_known_hosts = 0; 2667c478bd9Sstevel@tonic-gate if (options->print_motd == -1) 2677c478bd9Sstevel@tonic-gate options->print_motd = 1; 2687c478bd9Sstevel@tonic-gate if (options->print_lastlog == -1) 2697c478bd9Sstevel@tonic-gate options->print_lastlog = 1; 2707c478bd9Sstevel@tonic-gate if (options->x11_forwarding == -1) 2717c478bd9Sstevel@tonic-gate options->x11_forwarding = 1; 2727c478bd9Sstevel@tonic-gate if (options->x11_display_offset == -1) 2737c478bd9Sstevel@tonic-gate options->x11_display_offset = 10; 2747c478bd9Sstevel@tonic-gate if (options->x11_use_localhost == -1) 2757c478bd9Sstevel@tonic-gate options->x11_use_localhost = 1; 2767c478bd9Sstevel@tonic-gate if (options->xauth_location == NULL) 2777c478bd9Sstevel@tonic-gate options->xauth_location = _PATH_XAUTH; 2787c478bd9Sstevel@tonic-gate if (options->strict_modes == -1) 2797c478bd9Sstevel@tonic-gate options->strict_modes = 1; 2807c478bd9Sstevel@tonic-gate if (options->keepalives == -1) 2817c478bd9Sstevel@tonic-gate options->keepalives = 1; 2827c478bd9Sstevel@tonic-gate if (options->log_facility == SYSLOG_FACILITY_NOT_SET) 2837c478bd9Sstevel@tonic-gate options->log_facility = SYSLOG_FACILITY_AUTH; 2847c478bd9Sstevel@tonic-gate if (options->log_level == SYSLOG_LEVEL_NOT_SET) 2857c478bd9Sstevel@tonic-gate options->log_level = SYSLOG_LEVEL_INFO; 2867c478bd9Sstevel@tonic-gate if (options->rhosts_authentication == -1) 2877c478bd9Sstevel@tonic-gate options->rhosts_authentication = 0; 2887c478bd9Sstevel@tonic-gate if (options->rhosts_rsa_authentication == -1) 2897c478bd9Sstevel@tonic-gate options->rhosts_rsa_authentication = 0; 2907c478bd9Sstevel@tonic-gate if (options->hostbased_authentication == -1) 2917c478bd9Sstevel@tonic-gate options->hostbased_authentication = 0; 2927c478bd9Sstevel@tonic-gate if (options->hostbased_uses_name_from_packet_only == -1) 2937c478bd9Sstevel@tonic-gate options->hostbased_uses_name_from_packet_only = 0; 2947c478bd9Sstevel@tonic-gate if (options->rsa_authentication == -1) 2957c478bd9Sstevel@tonic-gate options->rsa_authentication = 1; 2967c478bd9Sstevel@tonic-gate if (options->pubkey_authentication == -1) 2977c478bd9Sstevel@tonic-gate options->pubkey_authentication = 1; 2987c478bd9Sstevel@tonic-gate #ifdef GSSAPI 2997c478bd9Sstevel@tonic-gate if (options->gss_authentication == -1) 3007c478bd9Sstevel@tonic-gate options->gss_authentication = 1; 3017c478bd9Sstevel@tonic-gate if (options->gss_keyex == -1) 3027c478bd9Sstevel@tonic-gate options->gss_keyex = 1; 3037c478bd9Sstevel@tonic-gate if (options->gss_store_creds == -1) 3047c478bd9Sstevel@tonic-gate options->gss_store_creds = 1; 3057c478bd9Sstevel@tonic-gate if (options->gss_use_session_ccache == -1) 3067c478bd9Sstevel@tonic-gate options->gss_use_session_ccache = 1; 3077c478bd9Sstevel@tonic-gate if (options->gss_cleanup_creds == -1) 3087c478bd9Sstevel@tonic-gate options->gss_cleanup_creds = 1; 3097c478bd9Sstevel@tonic-gate #endif 3107c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 3117c478bd9Sstevel@tonic-gate if (options->kerberos_authentication == -1) 3127c478bd9Sstevel@tonic-gate options->kerberos_authentication = 0; 3137c478bd9Sstevel@tonic-gate if (options->kerberos_or_local_passwd == -1) 3147c478bd9Sstevel@tonic-gate options->kerberos_or_local_passwd = 1; 3157c478bd9Sstevel@tonic-gate if (options->kerberos_ticket_cleanup == -1) 3167c478bd9Sstevel@tonic-gate options->kerberos_ticket_cleanup = 1; 3177c478bd9Sstevel@tonic-gate #endif 3187c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 3197c478bd9Sstevel@tonic-gate if (options->kerberos_tgt_passing == -1) 3207c478bd9Sstevel@tonic-gate options->kerberos_tgt_passing = 0; 3217c478bd9Sstevel@tonic-gate #endif 3227c478bd9Sstevel@tonic-gate #ifdef AFS 3237c478bd9Sstevel@tonic-gate if (options->afs_token_passing == -1) 3247c478bd9Sstevel@tonic-gate options->afs_token_passing = 0; 3257c478bd9Sstevel@tonic-gate #endif 3267c478bd9Sstevel@tonic-gate if (options->password_authentication == -1) 3277c478bd9Sstevel@tonic-gate options->password_authentication = 1; 3287c478bd9Sstevel@tonic-gate if (options->kbd_interactive_authentication == -1) 3297c478bd9Sstevel@tonic-gate options->kbd_interactive_authentication = 0; 3307c478bd9Sstevel@tonic-gate if (options->challenge_response_authentication == -1) 3317c478bd9Sstevel@tonic-gate options->challenge_response_authentication = 1; 3327c478bd9Sstevel@tonic-gate if (options->permit_empty_passwd == -1) 3337c478bd9Sstevel@tonic-gate options->permit_empty_passwd = 0; 3347c478bd9Sstevel@tonic-gate if (options->permit_user_env == -1) 3357c478bd9Sstevel@tonic-gate options->permit_user_env = 0; 3367c478bd9Sstevel@tonic-gate if (options->use_login == -1) 3377c478bd9Sstevel@tonic-gate options->use_login = 0; 3387c478bd9Sstevel@tonic-gate if (options->compression == -1) 3397c478bd9Sstevel@tonic-gate options->compression = 1; 3407c478bd9Sstevel@tonic-gate if (options->allow_tcp_forwarding == -1) 3417c478bd9Sstevel@tonic-gate options->allow_tcp_forwarding = 1; 3427c478bd9Sstevel@tonic-gate if (options->gateway_ports == -1) 3437c478bd9Sstevel@tonic-gate options->gateway_ports = 0; 3447c478bd9Sstevel@tonic-gate if (options->max_startups == -1) 3457c478bd9Sstevel@tonic-gate options->max_startups = 10; 3467c478bd9Sstevel@tonic-gate if (options->max_startups_rate == -1) 3477c478bd9Sstevel@tonic-gate options->max_startups_rate = 100; /* 100% */ 3487c478bd9Sstevel@tonic-gate if (options->max_startups_begin == -1) 3497c478bd9Sstevel@tonic-gate options->max_startups_begin = options->max_startups; 3507c478bd9Sstevel@tonic-gate if (options->verify_reverse_mapping == -1) 3517c478bd9Sstevel@tonic-gate options->verify_reverse_mapping = 0; 3527c478bd9Sstevel@tonic-gate if (options->client_alive_interval == -1) 3537c478bd9Sstevel@tonic-gate options->client_alive_interval = 0; 3547c478bd9Sstevel@tonic-gate if (options->client_alive_count_max == -1) 3557c478bd9Sstevel@tonic-gate options->client_alive_count_max = 3; 3567c478bd9Sstevel@tonic-gate if (options->authorized_keys_file2 == NULL) { 3577c478bd9Sstevel@tonic-gate /* authorized_keys_file2 falls back to authorized_keys_file */ 3587c478bd9Sstevel@tonic-gate if (options->authorized_keys_file != NULL) 3597c478bd9Sstevel@tonic-gate options->authorized_keys_file2 = options->authorized_keys_file; 3607c478bd9Sstevel@tonic-gate else 3617c478bd9Sstevel@tonic-gate options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2; 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate if (options->authorized_keys_file == NULL) 3647c478bd9Sstevel@tonic-gate options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS; 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate if (options->max_auth_tries == -1) 3677c478bd9Sstevel@tonic-gate options->max_auth_tries = AUTH_FAIL_MAX; 3687c478bd9Sstevel@tonic-gate if (options->max_auth_tries_log == -1) 3697c478bd9Sstevel@tonic-gate options->max_auth_tries_log = options->max_auth_tries / 2; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries == -1) 3727c478bd9Sstevel@tonic-gate options->max_init_auth_tries = AUTH_FAIL_MAX; 3737c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries_log == -1) 3747c478bd9Sstevel@tonic-gate options->max_init_auth_tries_log = options->max_init_auth_tries / 2; 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate if (options->lookup_client_hostnames == -1) 3777c478bd9Sstevel@tonic-gate options->lookup_client_hostnames = 1; 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* Keyword tokens. */ 3817c478bd9Sstevel@tonic-gate typedef enum { 3827c478bd9Sstevel@tonic-gate sBadOption, /* == unknown option */ 3837c478bd9Sstevel@tonic-gate /* Portable-specific options */ 3847c478bd9Sstevel@tonic-gate sPAMAuthenticationViaKbdInt, 3857c478bd9Sstevel@tonic-gate /* Standard Options */ 3867c478bd9Sstevel@tonic-gate sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime, 3877c478bd9Sstevel@tonic-gate sPermitRootLogin, sLogFacility, sLogLevel, 3887c478bd9Sstevel@tonic-gate sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication, 3897c478bd9Sstevel@tonic-gate #ifdef GSSAPI 3907c478bd9Sstevel@tonic-gate sGssAuthentication, sGssKeyEx, sGssStoreDelegCreds, 3917c478bd9Sstevel@tonic-gate sGssUseSessionCredCache, sGssCleanupCreds, 3927c478bd9Sstevel@tonic-gate #endif /* GSSAPI */ 3937c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 3947c478bd9Sstevel@tonic-gate sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup, 3957c478bd9Sstevel@tonic-gate #endif 3967c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 3977c478bd9Sstevel@tonic-gate sKerberosTgtPassing, 3987c478bd9Sstevel@tonic-gate #endif 3997c478bd9Sstevel@tonic-gate #ifdef AFS 4007c478bd9Sstevel@tonic-gate sAFSTokenPassing, 4017c478bd9Sstevel@tonic-gate #endif 4027c478bd9Sstevel@tonic-gate sChallengeResponseAuthentication, 4037c478bd9Sstevel@tonic-gate sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress, 4047c478bd9Sstevel@tonic-gate sPrintMotd, sPrintLastLog, sIgnoreRhosts, 4057c478bd9Sstevel@tonic-gate sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost, 4067c478bd9Sstevel@tonic-gate sStrictModes, sEmptyPasswd, sKeepAlives, 4077c478bd9Sstevel@tonic-gate sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression, 4087c478bd9Sstevel@tonic-gate sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups, 4097c478bd9Sstevel@tonic-gate sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile, 4107c478bd9Sstevel@tonic-gate sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups, 4117c478bd9Sstevel@tonic-gate sBanner, sVerifyReverseMapping, sHostbasedAuthentication, 4127c478bd9Sstevel@tonic-gate sHostbasedUsesNameFromPacketOnly, sClientAliveInterval, 4137c478bd9Sstevel@tonic-gate sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2, 4147c478bd9Sstevel@tonic-gate sMaxAuthTries, sMaxAuthTriesLog, sUsePrivilegeSeparation, 4157c478bd9Sstevel@tonic-gate sLookupClientHostnames, 4167c478bd9Sstevel@tonic-gate sDeprecated 4177c478bd9Sstevel@tonic-gate } ServerOpCodes; 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate /* Textual representation of the tokens. */ 4207c478bd9Sstevel@tonic-gate static struct { 4217c478bd9Sstevel@tonic-gate const char *name; 4227c478bd9Sstevel@tonic-gate ServerOpCodes opcode; 4237c478bd9Sstevel@tonic-gate } keywords[] = { 4247c478bd9Sstevel@tonic-gate /* Portable-specific options */ 4257c478bd9Sstevel@tonic-gate { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt }, 4267c478bd9Sstevel@tonic-gate /* Standard Options */ 4277c478bd9Sstevel@tonic-gate { "port", sPort }, 4287c478bd9Sstevel@tonic-gate { "hostkey", sHostKeyFile }, 4297c478bd9Sstevel@tonic-gate { "hostdsakey", sHostKeyFile }, /* alias */ 4307c478bd9Sstevel@tonic-gate { "pidfile", sPidFile }, 4317c478bd9Sstevel@tonic-gate { "serverkeybits", sServerKeyBits }, 4327c478bd9Sstevel@tonic-gate { "logingracetime", sLoginGraceTime }, 4337c478bd9Sstevel@tonic-gate { "keyregenerationinterval", sKeyRegenerationTime }, 4347c478bd9Sstevel@tonic-gate { "permitrootlogin", sPermitRootLogin }, 4357c478bd9Sstevel@tonic-gate { "syslogfacility", sLogFacility }, 4367c478bd9Sstevel@tonic-gate { "loglevel", sLogLevel }, 4377c478bd9Sstevel@tonic-gate { "rhostsauthentication", sRhostsAuthentication }, 4387c478bd9Sstevel@tonic-gate { "rhostsrsaauthentication", sRhostsRSAAuthentication }, 4397c478bd9Sstevel@tonic-gate { "hostbasedauthentication", sHostbasedAuthentication }, 4407c478bd9Sstevel@tonic-gate { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly }, 4417c478bd9Sstevel@tonic-gate { "rsaauthentication", sRSAAuthentication }, 4427c478bd9Sstevel@tonic-gate { "pubkeyauthentication", sPubkeyAuthentication }, 4437c478bd9Sstevel@tonic-gate { "dsaauthentication", sPubkeyAuthentication }, /* alias */ 4447c478bd9Sstevel@tonic-gate #ifdef GSSAPI 4457c478bd9Sstevel@tonic-gate { "gssapiauthentication", sGssAuthentication }, 4467c478bd9Sstevel@tonic-gate { "gssapikeyexchange", sGssKeyEx }, 4477c478bd9Sstevel@tonic-gate { "gssapistoredelegatedcredentials", sGssStoreDelegCreds }, 4487c478bd9Sstevel@tonic-gate { "gssauthentication", sGssAuthentication }, /* alias */ 4497c478bd9Sstevel@tonic-gate { "gsskeyex", sGssKeyEx }, /* alias */ 4507c478bd9Sstevel@tonic-gate { "gssstoredelegcreds", sGssStoreDelegCreds }, /* alias */ 4517c478bd9Sstevel@tonic-gate #ifndef SUNW_GSSAPI 4527c478bd9Sstevel@tonic-gate { "gssusesessionccache", sGssUseSessionCredCache }, 4537c478bd9Sstevel@tonic-gate { "gssusesessioncredcache", sGssUseSessionCredCache }, 4547c478bd9Sstevel@tonic-gate { "gsscleanupcreds", sGssCleanupCreds }, 4557c478bd9Sstevel@tonic-gate #endif /* SUNW_GSSAPI */ 4567c478bd9Sstevel@tonic-gate #endif 4577c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 4587c478bd9Sstevel@tonic-gate { "kerberosauthentication", sKerberosAuthentication }, 4597c478bd9Sstevel@tonic-gate { "kerberosorlocalpasswd", sKerberosOrLocalPasswd }, 4607c478bd9Sstevel@tonic-gate { "kerberosticketcleanup", sKerberosTicketCleanup }, 4617c478bd9Sstevel@tonic-gate #endif 4627c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 4637c478bd9Sstevel@tonic-gate { "kerberostgtpassing", sKerberosTgtPassing }, 4647c478bd9Sstevel@tonic-gate #endif 4657c478bd9Sstevel@tonic-gate #ifdef AFS 4667c478bd9Sstevel@tonic-gate { "afstokenpassing", sAFSTokenPassing }, 4677c478bd9Sstevel@tonic-gate #endif 4687c478bd9Sstevel@tonic-gate { "passwordauthentication", sPasswordAuthentication }, 4697c478bd9Sstevel@tonic-gate { "kbdinteractiveauthentication", sKbdInteractiveAuthentication }, 4707c478bd9Sstevel@tonic-gate { "challengeresponseauthentication", sChallengeResponseAuthentication }, 4717c478bd9Sstevel@tonic-gate { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */ 4727c478bd9Sstevel@tonic-gate { "checkmail", sDeprecated }, 4737c478bd9Sstevel@tonic-gate { "listenaddress", sListenAddress }, 4747c478bd9Sstevel@tonic-gate { "printmotd", sPrintMotd }, 4757c478bd9Sstevel@tonic-gate { "printlastlog", sPrintLastLog }, 4767c478bd9Sstevel@tonic-gate { "ignorerhosts", sIgnoreRhosts }, 4777c478bd9Sstevel@tonic-gate { "ignoreuserknownhosts", sIgnoreUserKnownHosts }, 4787c478bd9Sstevel@tonic-gate { "x11forwarding", sX11Forwarding }, 4797c478bd9Sstevel@tonic-gate { "x11displayoffset", sX11DisplayOffset }, 4807c478bd9Sstevel@tonic-gate { "x11uselocalhost", sX11UseLocalhost }, 4817c478bd9Sstevel@tonic-gate { "xauthlocation", sXAuthLocation }, 4827c478bd9Sstevel@tonic-gate { "strictmodes", sStrictModes }, 4837c478bd9Sstevel@tonic-gate { "permitemptypasswords", sEmptyPasswd }, 4847c478bd9Sstevel@tonic-gate { "permituserenvironment", sPermitUserEnvironment }, 4857c478bd9Sstevel@tonic-gate { "uselogin", sUseLogin }, 4867c478bd9Sstevel@tonic-gate { "compression", sCompression }, 4877c478bd9Sstevel@tonic-gate { "keepalive", sKeepAlives }, 4887c478bd9Sstevel@tonic-gate { "allowtcpforwarding", sAllowTcpForwarding }, 4897c478bd9Sstevel@tonic-gate { "allowusers", sAllowUsers }, 4907c478bd9Sstevel@tonic-gate { "denyusers", sDenyUsers }, 4917c478bd9Sstevel@tonic-gate { "allowgroups", sAllowGroups }, 4927c478bd9Sstevel@tonic-gate { "denygroups", sDenyGroups }, 4937c478bd9Sstevel@tonic-gate { "ciphers", sCiphers }, 4947c478bd9Sstevel@tonic-gate { "macs", sMacs }, 4957c478bd9Sstevel@tonic-gate { "protocol", sProtocol }, 4967c478bd9Sstevel@tonic-gate { "gatewayports", sGatewayPorts }, 4977c478bd9Sstevel@tonic-gate { "subsystem", sSubsystem }, 4987c478bd9Sstevel@tonic-gate { "maxstartups", sMaxStartups }, 4997c478bd9Sstevel@tonic-gate { "banner", sBanner }, 5007c478bd9Sstevel@tonic-gate { "verifyreversemapping", sVerifyReverseMapping }, 5017c478bd9Sstevel@tonic-gate { "reversemappingcheck", sVerifyReverseMapping }, 5027c478bd9Sstevel@tonic-gate { "clientaliveinterval", sClientAliveInterval }, 5037c478bd9Sstevel@tonic-gate { "clientalivecountmax", sClientAliveCountMax }, 5047c478bd9Sstevel@tonic-gate { "authorizedkeysfile", sAuthorizedKeysFile }, 5057c478bd9Sstevel@tonic-gate { "authorizedkeysfile2", sAuthorizedKeysFile2 }, 5067c478bd9Sstevel@tonic-gate { "maxauthtries", sMaxAuthTries }, 5077c478bd9Sstevel@tonic-gate { "maxauthtrieslog", sMaxAuthTriesLog }, 5087c478bd9Sstevel@tonic-gate { "useprivilegeseparation", sUsePrivilegeSeparation}, 5097c478bd9Sstevel@tonic-gate { "lookupclienthostnames", sLookupClientHostnames}, 5107c478bd9Sstevel@tonic-gate { NULL, sBadOption } 5117c478bd9Sstevel@tonic-gate }; 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate /* 5147c478bd9Sstevel@tonic-gate * Returns the number of the token pointed to by cp or sBadOption. 5157c478bd9Sstevel@tonic-gate */ 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate static ServerOpCodes 5187c478bd9Sstevel@tonic-gate parse_token(const char *cp, const char *filename, 5197c478bd9Sstevel@tonic-gate int linenum) 5207c478bd9Sstevel@tonic-gate { 5217c478bd9Sstevel@tonic-gate u_int i; 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate for (i = 0; keywords[i].name; i++) 5247c478bd9Sstevel@tonic-gate if (strcasecmp(cp, keywords[i].name) == 0) 5257c478bd9Sstevel@tonic-gate return keywords[i].opcode; 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate error("%s: line %d: Bad configuration option: %s", 5287c478bd9Sstevel@tonic-gate filename, linenum, cp); 5297c478bd9Sstevel@tonic-gate return sBadOption; 5307c478bd9Sstevel@tonic-gate } 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate static void 5337c478bd9Sstevel@tonic-gate add_listen_addr(ServerOptions *options, char *addr, u_short port) 5347c478bd9Sstevel@tonic-gate { 5357c478bd9Sstevel@tonic-gate int i; 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate if (options->num_ports == 0) 5387c478bd9Sstevel@tonic-gate options->ports[options->num_ports++] = SSH_DEFAULT_PORT; 5397c478bd9Sstevel@tonic-gate if (port == 0) 5407c478bd9Sstevel@tonic-gate for (i = 0; i < options->num_ports; i++) 5417c478bd9Sstevel@tonic-gate add_one_listen_addr(options, addr, options->ports[i]); 5427c478bd9Sstevel@tonic-gate else 5437c478bd9Sstevel@tonic-gate add_one_listen_addr(options, addr, port); 5447c478bd9Sstevel@tonic-gate } 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate static void 5477c478bd9Sstevel@tonic-gate add_one_listen_addr(ServerOptions *options, char *addr, u_short port) 5487c478bd9Sstevel@tonic-gate { 5497c478bd9Sstevel@tonic-gate struct addrinfo hints, *ai, *aitop; 5507c478bd9Sstevel@tonic-gate char strport[NI_MAXSERV]; 5517c478bd9Sstevel@tonic-gate int gaierr; 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate (void) memset(&hints, 0, sizeof(hints)); 5547c478bd9Sstevel@tonic-gate hints.ai_family = IPv4or6; 5557c478bd9Sstevel@tonic-gate hints.ai_socktype = SOCK_STREAM; 5567c478bd9Sstevel@tonic-gate hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; 5577c478bd9Sstevel@tonic-gate (void) snprintf(strport, sizeof strport, "%u", port); 5587c478bd9Sstevel@tonic-gate if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0) 5597c478bd9Sstevel@tonic-gate fatal("bad addr or host: %s (%s)", 5607c478bd9Sstevel@tonic-gate addr ? addr : "<NULL>", 5617c478bd9Sstevel@tonic-gate gai_strerror(gaierr)); 5627c478bd9Sstevel@tonic-gate for (ai = aitop; ai->ai_next; ai = ai->ai_next) 5637c478bd9Sstevel@tonic-gate ; 5647c478bd9Sstevel@tonic-gate ai->ai_next = options->listen_addrs; 5657c478bd9Sstevel@tonic-gate options->listen_addrs = aitop; 5667c478bd9Sstevel@tonic-gate } 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate int 5697c478bd9Sstevel@tonic-gate process_server_config_line(ServerOptions *options, char *line, 5707c478bd9Sstevel@tonic-gate const char *filename, int linenum) 5717c478bd9Sstevel@tonic-gate { 5727c478bd9Sstevel@tonic-gate char *cp, **charptr, *arg, *p; 5737c478bd9Sstevel@tonic-gate int *intptr, value, i, n; 5747c478bd9Sstevel@tonic-gate ServerOpCodes opcode; 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate cp = line; 5777c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 5787c478bd9Sstevel@tonic-gate /* Ignore leading whitespace */ 5797c478bd9Sstevel@tonic-gate if (*arg == '\0') 5807c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 5817c478bd9Sstevel@tonic-gate if (!arg || !*arg || *arg == '#') 5827c478bd9Sstevel@tonic-gate return 0; 5837c478bd9Sstevel@tonic-gate intptr = NULL; 5847c478bd9Sstevel@tonic-gate charptr = NULL; 5857c478bd9Sstevel@tonic-gate opcode = parse_token(arg, filename, linenum); 5867c478bd9Sstevel@tonic-gate switch (opcode) { 5877c478bd9Sstevel@tonic-gate /* Portable-specific options */ 5887c478bd9Sstevel@tonic-gate case sPAMAuthenticationViaKbdInt: 5897c478bd9Sstevel@tonic-gate intptr = &options->pam_authentication_via_kbd_int; 5907c478bd9Sstevel@tonic-gate goto parse_flag; 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate /* Standard Options */ 5937c478bd9Sstevel@tonic-gate case sBadOption: 5947c478bd9Sstevel@tonic-gate return -1; 5957c478bd9Sstevel@tonic-gate case sPort: 5967c478bd9Sstevel@tonic-gate /* ignore ports from configfile if cmdline specifies ports */ 5977c478bd9Sstevel@tonic-gate if (options->ports_from_cmdline) 5987c478bd9Sstevel@tonic-gate return 0; 5997c478bd9Sstevel@tonic-gate if (options->listen_addrs != NULL) 6007c478bd9Sstevel@tonic-gate fatal("%s line %d: ports must be specified before " 6017c478bd9Sstevel@tonic-gate "ListenAddress.", filename, linenum); 6027c478bd9Sstevel@tonic-gate if (options->num_ports >= MAX_PORTS) 6037c478bd9Sstevel@tonic-gate fatal("%s line %d: too many ports.", 6047c478bd9Sstevel@tonic-gate filename, linenum); 6057c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 6067c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 6077c478bd9Sstevel@tonic-gate fatal("%s line %d: missing port number.", 6087c478bd9Sstevel@tonic-gate filename, linenum); 6097c478bd9Sstevel@tonic-gate options->ports[options->num_ports++] = a2port(arg); 6107c478bd9Sstevel@tonic-gate if (options->ports[options->num_ports-1] == 0) 6117c478bd9Sstevel@tonic-gate fatal("%s line %d: Badly formatted port number.", 6127c478bd9Sstevel@tonic-gate filename, linenum); 6137c478bd9Sstevel@tonic-gate break; 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate case sServerKeyBits: 6167c478bd9Sstevel@tonic-gate intptr = &options->server_key_bits; 6177c478bd9Sstevel@tonic-gate parse_int: 6187c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 6197c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 6207c478bd9Sstevel@tonic-gate fatal("%s line %d: missing integer value.", 6217c478bd9Sstevel@tonic-gate filename, linenum); 6227c478bd9Sstevel@tonic-gate value = atoi(arg); 6237c478bd9Sstevel@tonic-gate if (*intptr == -1) 6247c478bd9Sstevel@tonic-gate *intptr = value; 6257c478bd9Sstevel@tonic-gate break; 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate case sLoginGraceTime: 6287c478bd9Sstevel@tonic-gate intptr = &options->login_grace_time; 6297c478bd9Sstevel@tonic-gate parse_time: 6307c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 6317c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 6327c478bd9Sstevel@tonic-gate fatal("%s line %d: missing time value.", 6337c478bd9Sstevel@tonic-gate filename, linenum); 6347c478bd9Sstevel@tonic-gate if ((value = convtime(arg)) == -1) 6357c478bd9Sstevel@tonic-gate fatal("%s line %d: invalid time value.", 6367c478bd9Sstevel@tonic-gate filename, linenum); 6377c478bd9Sstevel@tonic-gate if (*intptr == -1) 6387c478bd9Sstevel@tonic-gate *intptr = value; 6397c478bd9Sstevel@tonic-gate break; 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate case sKeyRegenerationTime: 6427c478bd9Sstevel@tonic-gate intptr = &options->key_regeneration_time; 6437c478bd9Sstevel@tonic-gate goto parse_time; 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate case sListenAddress: 6467c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 6477c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0) 6487c478bd9Sstevel@tonic-gate fatal("%s line %d: missing inet addr.", 6497c478bd9Sstevel@tonic-gate filename, linenum); 6507c478bd9Sstevel@tonic-gate if (*arg == '[') { 6517c478bd9Sstevel@tonic-gate if ((p = strchr(arg, ']')) == NULL) 6527c478bd9Sstevel@tonic-gate fatal("%s line %d: bad ipv6 inet addr usage.", 6537c478bd9Sstevel@tonic-gate filename, linenum); 6547c478bd9Sstevel@tonic-gate arg++; 6557c478bd9Sstevel@tonic-gate (void) memmove(p, p+1, strlen(p+1)+1); 6567c478bd9Sstevel@tonic-gate } else if (((p = strchr(arg, ':')) == NULL) || 6577c478bd9Sstevel@tonic-gate (strchr(p+1, ':') != NULL)) { 6587c478bd9Sstevel@tonic-gate add_listen_addr(options, arg, 0); 6597c478bd9Sstevel@tonic-gate break; 6607c478bd9Sstevel@tonic-gate } 6617c478bd9Sstevel@tonic-gate if (*p == ':') { 6627c478bd9Sstevel@tonic-gate u_short port; 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate p++; 6657c478bd9Sstevel@tonic-gate if (*p == '\0') 6667c478bd9Sstevel@tonic-gate fatal("%s line %d: bad inet addr:port usage.", 6677c478bd9Sstevel@tonic-gate filename, linenum); 6687c478bd9Sstevel@tonic-gate else { 6697c478bd9Sstevel@tonic-gate *(p-1) = '\0'; 6707c478bd9Sstevel@tonic-gate if ((port = a2port(p)) == 0) 6717c478bd9Sstevel@tonic-gate fatal("%s line %d: bad port number.", 6727c478bd9Sstevel@tonic-gate filename, linenum); 6737c478bd9Sstevel@tonic-gate add_listen_addr(options, arg, port); 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate } else if (*p == '\0') 6767c478bd9Sstevel@tonic-gate add_listen_addr(options, arg, 0); 6777c478bd9Sstevel@tonic-gate else 6787c478bd9Sstevel@tonic-gate fatal("%s line %d: bad inet addr usage.", 6797c478bd9Sstevel@tonic-gate filename, linenum); 6807c478bd9Sstevel@tonic-gate break; 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate case sHostKeyFile: 6837c478bd9Sstevel@tonic-gate intptr = &options->num_host_key_files; 6847c478bd9Sstevel@tonic-gate if (*intptr >= MAX_HOSTKEYS) 6857c478bd9Sstevel@tonic-gate fatal("%s line %d: too many host keys specified (max %d).", 6867c478bd9Sstevel@tonic-gate filename, linenum, MAX_HOSTKEYS); 6877c478bd9Sstevel@tonic-gate charptr = &options->host_key_files[*intptr]; 6887c478bd9Sstevel@tonic-gate parse_filename: 6897c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 6907c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 6917c478bd9Sstevel@tonic-gate fatal("%s line %d: missing file name.", 6927c478bd9Sstevel@tonic-gate filename, linenum); 6937c478bd9Sstevel@tonic-gate if (*charptr == NULL) { 6947c478bd9Sstevel@tonic-gate *charptr = tilde_expand_filename(arg, getuid()); 6957c478bd9Sstevel@tonic-gate /* increase optional counter */ 6967c478bd9Sstevel@tonic-gate if (intptr != NULL) 6977c478bd9Sstevel@tonic-gate *intptr = *intptr + 1; 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate break; 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate case sPidFile: 7027c478bd9Sstevel@tonic-gate charptr = &options->pid_file; 7037c478bd9Sstevel@tonic-gate goto parse_filename; 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate case sPermitRootLogin: 7067c478bd9Sstevel@tonic-gate intptr = &options->permit_root_login; 7077c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 7087c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 7097c478bd9Sstevel@tonic-gate fatal("%s line %d: missing yes/" 7107c478bd9Sstevel@tonic-gate "without-password/forced-commands-only/no " 7117c478bd9Sstevel@tonic-gate "argument.", filename, linenum); 7127c478bd9Sstevel@tonic-gate value = 0; /* silence compiler */ 7137c478bd9Sstevel@tonic-gate if (strcmp(arg, "without-password") == 0) 7147c478bd9Sstevel@tonic-gate value = PERMIT_NO_PASSWD; 7157c478bd9Sstevel@tonic-gate else if (strcmp(arg, "forced-commands-only") == 0) 7167c478bd9Sstevel@tonic-gate value = PERMIT_FORCED_ONLY; 7177c478bd9Sstevel@tonic-gate else if (strcmp(arg, "yes") == 0) 7187c478bd9Sstevel@tonic-gate value = PERMIT_YES; 7197c478bd9Sstevel@tonic-gate else if (strcmp(arg, "no") == 0) 7207c478bd9Sstevel@tonic-gate value = PERMIT_NO; 7217c478bd9Sstevel@tonic-gate else 7227c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad yes/" 7237c478bd9Sstevel@tonic-gate "without-password/forced-commands-only/no " 7247c478bd9Sstevel@tonic-gate "argument: %s", filename, linenum, arg); 7257c478bd9Sstevel@tonic-gate if (*intptr == -1) 7267c478bd9Sstevel@tonic-gate *intptr = value; 7277c478bd9Sstevel@tonic-gate break; 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate case sIgnoreRhosts: 7307c478bd9Sstevel@tonic-gate intptr = &options->ignore_rhosts; 7317c478bd9Sstevel@tonic-gate parse_flag: 7327c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 7337c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 7347c478bd9Sstevel@tonic-gate fatal("%s line %d: missing yes/no argument.", 7357c478bd9Sstevel@tonic-gate filename, linenum); 7367c478bd9Sstevel@tonic-gate value = 0; /* silence compiler */ 7377c478bd9Sstevel@tonic-gate if (strcmp(arg, "yes") == 0) 7387c478bd9Sstevel@tonic-gate value = 1; 7397c478bd9Sstevel@tonic-gate else if (strcmp(arg, "no") == 0) 7407c478bd9Sstevel@tonic-gate value = 0; 7417c478bd9Sstevel@tonic-gate else 7427c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad yes/no argument: %s", 7437c478bd9Sstevel@tonic-gate filename, linenum, arg); 7447c478bd9Sstevel@tonic-gate if (*intptr == -1) 7457c478bd9Sstevel@tonic-gate *intptr = value; 7467c478bd9Sstevel@tonic-gate break; 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate case sIgnoreUserKnownHosts: 7497c478bd9Sstevel@tonic-gate intptr = &options->ignore_user_known_hosts; 7507c478bd9Sstevel@tonic-gate goto parse_flag; 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate case sRhostsAuthentication: 7537c478bd9Sstevel@tonic-gate intptr = &options->rhosts_authentication; 7547c478bd9Sstevel@tonic-gate goto parse_flag; 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate case sRhostsRSAAuthentication: 7577c478bd9Sstevel@tonic-gate intptr = &options->rhosts_rsa_authentication; 7587c478bd9Sstevel@tonic-gate goto parse_flag; 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate case sHostbasedAuthentication: 7617c478bd9Sstevel@tonic-gate intptr = &options->hostbased_authentication; 7627c478bd9Sstevel@tonic-gate goto parse_flag; 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate case sHostbasedUsesNameFromPacketOnly: 7657c478bd9Sstevel@tonic-gate intptr = &options->hostbased_uses_name_from_packet_only; 7667c478bd9Sstevel@tonic-gate goto parse_flag; 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate case sRSAAuthentication: 7697c478bd9Sstevel@tonic-gate intptr = &options->rsa_authentication; 7707c478bd9Sstevel@tonic-gate goto parse_flag; 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate case sPubkeyAuthentication: 7737c478bd9Sstevel@tonic-gate intptr = &options->pubkey_authentication; 7747c478bd9Sstevel@tonic-gate goto parse_flag; 7757c478bd9Sstevel@tonic-gate #ifdef GSSAPI 7767c478bd9Sstevel@tonic-gate case sGssAuthentication: 7777c478bd9Sstevel@tonic-gate intptr = &options->gss_authentication; 7787c478bd9Sstevel@tonic-gate goto parse_flag; 7797c478bd9Sstevel@tonic-gate case sGssKeyEx: 7807c478bd9Sstevel@tonic-gate intptr = &options->gss_keyex; 7817c478bd9Sstevel@tonic-gate goto parse_flag; 7827c478bd9Sstevel@tonic-gate case sGssStoreDelegCreds: 7837c478bd9Sstevel@tonic-gate intptr = &options->gss_keyex; 7847c478bd9Sstevel@tonic-gate goto parse_flag; 7857c478bd9Sstevel@tonic-gate #ifndef SUNW_GSSAPI 7867c478bd9Sstevel@tonic-gate case sGssUseSessionCredCache: 7877c478bd9Sstevel@tonic-gate intptr = &options->gss_use_session_ccache; 7887c478bd9Sstevel@tonic-gate goto parse_flag; 7897c478bd9Sstevel@tonic-gate case sGssCleanupCreds: 7907c478bd9Sstevel@tonic-gate intptr = &options->gss_cleanup_creds; 7917c478bd9Sstevel@tonic-gate goto parse_flag; 7927c478bd9Sstevel@tonic-gate #endif /* SUNW_GSSAPI */ 7937c478bd9Sstevel@tonic-gate #endif /* GSSAPI */ 7947c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 7957c478bd9Sstevel@tonic-gate case sKerberosAuthentication: 7967c478bd9Sstevel@tonic-gate intptr = &options->kerberos_authentication; 7977c478bd9Sstevel@tonic-gate goto parse_flag; 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate case sKerberosOrLocalPasswd: 8007c478bd9Sstevel@tonic-gate intptr = &options->kerberos_or_local_passwd; 8017c478bd9Sstevel@tonic-gate goto parse_flag; 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate case sKerberosTicketCleanup: 8047c478bd9Sstevel@tonic-gate intptr = &options->kerberos_ticket_cleanup; 8057c478bd9Sstevel@tonic-gate goto parse_flag; 8067c478bd9Sstevel@tonic-gate #endif 8077c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 8087c478bd9Sstevel@tonic-gate case sKerberosTgtPassing: 8097c478bd9Sstevel@tonic-gate intptr = &options->kerberos_tgt_passing; 8107c478bd9Sstevel@tonic-gate goto parse_flag; 8117c478bd9Sstevel@tonic-gate #endif 8127c478bd9Sstevel@tonic-gate #ifdef AFS 8137c478bd9Sstevel@tonic-gate case sAFSTokenPassing: 8147c478bd9Sstevel@tonic-gate intptr = &options->afs_token_passing; 8157c478bd9Sstevel@tonic-gate goto parse_flag; 8167c478bd9Sstevel@tonic-gate #endif 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate case sPasswordAuthentication: 8197c478bd9Sstevel@tonic-gate intptr = &options->password_authentication; 8207c478bd9Sstevel@tonic-gate goto parse_flag; 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate case sKbdInteractiveAuthentication: 8237c478bd9Sstevel@tonic-gate intptr = &options->kbd_interactive_authentication; 8247c478bd9Sstevel@tonic-gate goto parse_flag; 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate case sChallengeResponseAuthentication: 8277c478bd9Sstevel@tonic-gate intptr = &options->challenge_response_authentication; 8287c478bd9Sstevel@tonic-gate goto parse_flag; 8297c478bd9Sstevel@tonic-gate 8307c478bd9Sstevel@tonic-gate case sPrintMotd: 8317c478bd9Sstevel@tonic-gate intptr = &options->print_motd; 8327c478bd9Sstevel@tonic-gate goto parse_flag; 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate case sPrintLastLog: 8357c478bd9Sstevel@tonic-gate intptr = &options->print_lastlog; 8367c478bd9Sstevel@tonic-gate goto parse_flag; 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate case sX11Forwarding: 8397c478bd9Sstevel@tonic-gate intptr = &options->x11_forwarding; 8407c478bd9Sstevel@tonic-gate goto parse_flag; 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate case sX11DisplayOffset: 8437c478bd9Sstevel@tonic-gate intptr = &options->x11_display_offset; 8447c478bd9Sstevel@tonic-gate goto parse_int; 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate case sX11UseLocalhost: 8477c478bd9Sstevel@tonic-gate intptr = &options->x11_use_localhost; 8487c478bd9Sstevel@tonic-gate goto parse_flag; 8497c478bd9Sstevel@tonic-gate 8507c478bd9Sstevel@tonic-gate case sXAuthLocation: 8517c478bd9Sstevel@tonic-gate charptr = &options->xauth_location; 8527c478bd9Sstevel@tonic-gate goto parse_filename; 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate case sStrictModes: 8557c478bd9Sstevel@tonic-gate intptr = &options->strict_modes; 8567c478bd9Sstevel@tonic-gate goto parse_flag; 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate case sKeepAlives: 8597c478bd9Sstevel@tonic-gate intptr = &options->keepalives; 8607c478bd9Sstevel@tonic-gate goto parse_flag; 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate case sEmptyPasswd: 8637c478bd9Sstevel@tonic-gate intptr = &options->permit_empty_passwd; 8647c478bd9Sstevel@tonic-gate goto parse_flag; 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate case sPermitUserEnvironment: 8677c478bd9Sstevel@tonic-gate intptr = &options->permit_user_env; 8687c478bd9Sstevel@tonic-gate goto parse_flag; 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate case sUseLogin: 8717c478bd9Sstevel@tonic-gate intptr = &options->use_login; 8727c478bd9Sstevel@tonic-gate goto parse_flag; 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate case sCompression: 8757c478bd9Sstevel@tonic-gate intptr = &options->compression; 8767c478bd9Sstevel@tonic-gate goto parse_flag; 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate case sGatewayPorts: 8799b03ea0fSjp161948 arg = strdelim(&cp); 8809b03ea0fSjp161948 if (get_yes_no_flag(&options->gateway_ports, arg, filename, 8819b03ea0fSjp161948 linenum, 1) == 1) 8829b03ea0fSjp161948 break; 8839b03ea0fSjp161948 8849b03ea0fSjp161948 if (strcmp(arg, "clientspecified") == 0) 8859b03ea0fSjp161948 options->gateway_ports = 2; 8869b03ea0fSjp161948 else 8879b03ea0fSjp161948 fatal("%.200s line %d: Bad yes/no/clientspecified " 8889b03ea0fSjp161948 "argument.", filename, linenum); 8899b03ea0fSjp161948 break; 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate case sVerifyReverseMapping: 8927c478bd9Sstevel@tonic-gate intptr = &options->verify_reverse_mapping; 8937c478bd9Sstevel@tonic-gate goto parse_flag; 8947c478bd9Sstevel@tonic-gate 8957c478bd9Sstevel@tonic-gate case sLogFacility: 8967c478bd9Sstevel@tonic-gate intptr = (int *) &options->log_facility; 8977c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 8987c478bd9Sstevel@tonic-gate value = log_facility_number(arg); 8997c478bd9Sstevel@tonic-gate if (value == SYSLOG_FACILITY_NOT_SET) 9007c478bd9Sstevel@tonic-gate fatal("%.200s line %d: unsupported log facility '%s'", 9017c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 9027c478bd9Sstevel@tonic-gate if (*intptr == -1) 9037c478bd9Sstevel@tonic-gate *intptr = (SyslogFacility) value; 9047c478bd9Sstevel@tonic-gate break; 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate case sLogLevel: 9077c478bd9Sstevel@tonic-gate intptr = (int *) &options->log_level; 9087c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 9097c478bd9Sstevel@tonic-gate value = log_level_number(arg); 9107c478bd9Sstevel@tonic-gate if (value == SYSLOG_LEVEL_NOT_SET) 9117c478bd9Sstevel@tonic-gate fatal("%.200s line %d: unsupported log level '%s'", 9127c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 9137c478bd9Sstevel@tonic-gate if (*intptr == -1) 9147c478bd9Sstevel@tonic-gate *intptr = (LogLevel) value; 9157c478bd9Sstevel@tonic-gate break; 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate case sAllowTcpForwarding: 9187c478bd9Sstevel@tonic-gate intptr = &options->allow_tcp_forwarding; 9197c478bd9Sstevel@tonic-gate goto parse_flag; 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate case sUsePrivilegeSeparation: 922*9a8058b5Sjp161948 log("%s line %d: ignoring UsePrivilegeSeparation option value." 923*9a8058b5Sjp161948 " This option is always on.", filename, linenum); 924*9a8058b5Sjp161948 while (arg) 925*9a8058b5Sjp161948 arg = strdelim(&cp); 926*9a8058b5Sjp161948 break; 9277c478bd9Sstevel@tonic-gate 9287c478bd9Sstevel@tonic-gate case sAllowUsers: 9297c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 9307c478bd9Sstevel@tonic-gate if (options->num_allow_users >= MAX_ALLOW_USERS) 9317c478bd9Sstevel@tonic-gate fatal("%s line %d: too many allow users.", 9327c478bd9Sstevel@tonic-gate filename, linenum); 9337c478bd9Sstevel@tonic-gate options->allow_users[options->num_allow_users++] = 9347c478bd9Sstevel@tonic-gate xstrdup(arg); 9357c478bd9Sstevel@tonic-gate } 9367c478bd9Sstevel@tonic-gate break; 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate case sDenyUsers: 9397c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 9407c478bd9Sstevel@tonic-gate if (options->num_deny_users >= MAX_DENY_USERS) 9417c478bd9Sstevel@tonic-gate fatal( "%s line %d: too many deny users.", 9427c478bd9Sstevel@tonic-gate filename, linenum); 9437c478bd9Sstevel@tonic-gate options->deny_users[options->num_deny_users++] = 9447c478bd9Sstevel@tonic-gate xstrdup(arg); 9457c478bd9Sstevel@tonic-gate } 9467c478bd9Sstevel@tonic-gate break; 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate case sAllowGroups: 9497c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 9507c478bd9Sstevel@tonic-gate if (options->num_allow_groups >= MAX_ALLOW_GROUPS) 9517c478bd9Sstevel@tonic-gate fatal("%s line %d: too many allow groups.", 9527c478bd9Sstevel@tonic-gate filename, linenum); 9537c478bd9Sstevel@tonic-gate options->allow_groups[options->num_allow_groups++] = 9547c478bd9Sstevel@tonic-gate xstrdup(arg); 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate break; 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate case sDenyGroups: 9597c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 9607c478bd9Sstevel@tonic-gate if (options->num_deny_groups >= MAX_DENY_GROUPS) 9617c478bd9Sstevel@tonic-gate fatal("%s line %d: too many deny groups.", 9627c478bd9Sstevel@tonic-gate filename, linenum); 9637c478bd9Sstevel@tonic-gate options->deny_groups[options->num_deny_groups++] = xstrdup(arg); 9647c478bd9Sstevel@tonic-gate } 9657c478bd9Sstevel@tonic-gate break; 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate case sCiphers: 9687c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 9697c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 9707c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing argument.", filename, linenum); 9717c478bd9Sstevel@tonic-gate if (!ciphers_valid(arg)) 9727c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad SSH2 cipher spec '%s'.", 9737c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 9747c478bd9Sstevel@tonic-gate if (options->ciphers == NULL) 9757c478bd9Sstevel@tonic-gate options->ciphers = xstrdup(arg); 9767c478bd9Sstevel@tonic-gate break; 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate case sMacs: 9797c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 9807c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 9817c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing argument.", filename, linenum); 9827c478bd9Sstevel@tonic-gate if (!mac_valid(arg)) 9837c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad SSH2 mac spec '%s'.", 9847c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 9857c478bd9Sstevel@tonic-gate if (options->macs == NULL) 9867c478bd9Sstevel@tonic-gate options->macs = xstrdup(arg); 9877c478bd9Sstevel@tonic-gate break; 9887c478bd9Sstevel@tonic-gate 9897c478bd9Sstevel@tonic-gate case sProtocol: 9907c478bd9Sstevel@tonic-gate intptr = &options->protocol; 9917c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 9927c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 9937c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing argument.", filename, linenum); 9947c478bd9Sstevel@tonic-gate value = proto_spec(arg); 9957c478bd9Sstevel@tonic-gate if (value == SSH_PROTO_UNKNOWN) 9967c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad protocol spec '%s'.", 9977c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 9987c478bd9Sstevel@tonic-gate if (*intptr == SSH_PROTO_UNKNOWN) 9997c478bd9Sstevel@tonic-gate *intptr = value; 10007c478bd9Sstevel@tonic-gate break; 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate case sSubsystem: 10037c478bd9Sstevel@tonic-gate if (options->num_subsystems >= MAX_SUBSYSTEMS) { 10047c478bd9Sstevel@tonic-gate fatal("%s line %d: too many subsystems defined.", 10057c478bd9Sstevel@tonic-gate filename, linenum); 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 10087c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 10097c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing subsystem name.", 10107c478bd9Sstevel@tonic-gate filename, linenum); 10117c478bd9Sstevel@tonic-gate for (i = 0; i < options->num_subsystems; i++) 10127c478bd9Sstevel@tonic-gate if (strcmp(arg, options->subsystem_name[i]) == 0) 10137c478bd9Sstevel@tonic-gate fatal("%s line %d: Subsystem '%s' already defined.", 10147c478bd9Sstevel@tonic-gate filename, linenum, arg); 10157c478bd9Sstevel@tonic-gate options->subsystem_name[options->num_subsystems] = xstrdup(arg); 10167c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 10177c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 10187c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing subsystem command.", 10197c478bd9Sstevel@tonic-gate filename, linenum); 10207c478bd9Sstevel@tonic-gate options->subsystem_command[options->num_subsystems] = xstrdup(arg); 10217c478bd9Sstevel@tonic-gate options->num_subsystems++; 10227c478bd9Sstevel@tonic-gate break; 10237c478bd9Sstevel@tonic-gate 10247c478bd9Sstevel@tonic-gate case sMaxStartups: 10257c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 10267c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 10277c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing MaxStartups spec.", 10287c478bd9Sstevel@tonic-gate filename, linenum); 10297c478bd9Sstevel@tonic-gate if ((n = sscanf(arg, "%d:%d:%d", 10307c478bd9Sstevel@tonic-gate &options->max_startups_begin, 10317c478bd9Sstevel@tonic-gate &options->max_startups_rate, 10327c478bd9Sstevel@tonic-gate &options->max_startups)) == 3) { 10337c478bd9Sstevel@tonic-gate if (options->max_startups_begin > 10347c478bd9Sstevel@tonic-gate options->max_startups || 10357c478bd9Sstevel@tonic-gate options->max_startups_rate > 100 || 10367c478bd9Sstevel@tonic-gate options->max_startups_rate < 1) 10377c478bd9Sstevel@tonic-gate fatal("%s line %d: Illegal MaxStartups spec.", 10387c478bd9Sstevel@tonic-gate filename, linenum); 10397c478bd9Sstevel@tonic-gate } else if (n != 1) 10407c478bd9Sstevel@tonic-gate fatal("%s line %d: Illegal MaxStartups spec.", 10417c478bd9Sstevel@tonic-gate filename, linenum); 10427c478bd9Sstevel@tonic-gate else 10437c478bd9Sstevel@tonic-gate options->max_startups = options->max_startups_begin; 10447c478bd9Sstevel@tonic-gate break; 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate case sBanner: 10477c478bd9Sstevel@tonic-gate charptr = &options->banner; 10487c478bd9Sstevel@tonic-gate goto parse_filename; 10497c478bd9Sstevel@tonic-gate /* 10507c478bd9Sstevel@tonic-gate * These options can contain %X options expanded at 10517c478bd9Sstevel@tonic-gate * connect time, so that you can specify paths like: 10527c478bd9Sstevel@tonic-gate * 10537c478bd9Sstevel@tonic-gate * AuthorizedKeysFile /etc/ssh_keys/%u 10547c478bd9Sstevel@tonic-gate */ 10557c478bd9Sstevel@tonic-gate case sAuthorizedKeysFile: 10567c478bd9Sstevel@tonic-gate case sAuthorizedKeysFile2: 10577c478bd9Sstevel@tonic-gate charptr = (opcode == sAuthorizedKeysFile ) ? 10587c478bd9Sstevel@tonic-gate &options->authorized_keys_file : 10597c478bd9Sstevel@tonic-gate &options->authorized_keys_file2; 10607c478bd9Sstevel@tonic-gate goto parse_filename; 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate case sClientAliveInterval: 10637c478bd9Sstevel@tonic-gate intptr = &options->client_alive_interval; 10647c478bd9Sstevel@tonic-gate goto parse_time; 10657c478bd9Sstevel@tonic-gate 10667c478bd9Sstevel@tonic-gate case sClientAliveCountMax: 10677c478bd9Sstevel@tonic-gate intptr = &options->client_alive_count_max; 10687c478bd9Sstevel@tonic-gate goto parse_int; 10697c478bd9Sstevel@tonic-gate 10707c478bd9Sstevel@tonic-gate case sMaxAuthTries: 10717c478bd9Sstevel@tonic-gate intptr = &options->max_auth_tries; 10727c478bd9Sstevel@tonic-gate goto parse_int; 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate case sMaxAuthTriesLog: 10757c478bd9Sstevel@tonic-gate intptr = &options->max_auth_tries_log; 10767c478bd9Sstevel@tonic-gate goto parse_int; 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate case sLookupClientHostnames: 10797c478bd9Sstevel@tonic-gate intptr = &options->lookup_client_hostnames; 10807c478bd9Sstevel@tonic-gate goto parse_flag; 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate case sDeprecated: 10837c478bd9Sstevel@tonic-gate log("%s line %d: Deprecated option %s", 10847c478bd9Sstevel@tonic-gate filename, linenum, arg); 10857c478bd9Sstevel@tonic-gate while (arg) 10867c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 10877c478bd9Sstevel@tonic-gate break; 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate default: 10907c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing handler for opcode %s (%d)", 10917c478bd9Sstevel@tonic-gate filename, linenum, arg, opcode); 10927c478bd9Sstevel@tonic-gate } 10937c478bd9Sstevel@tonic-gate if ((arg = strdelim(&cp)) != NULL && *arg != '\0') 10947c478bd9Sstevel@tonic-gate fatal("%s line %d: garbage at end of line; \"%.200s\".", 10957c478bd9Sstevel@tonic-gate filename, linenum, arg); 10967c478bd9Sstevel@tonic-gate return 0; 10977c478bd9Sstevel@tonic-gate } 10987c478bd9Sstevel@tonic-gate 10997c478bd9Sstevel@tonic-gate /* Reads the server configuration file. */ 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate void 11027c478bd9Sstevel@tonic-gate read_server_config(ServerOptions *options, const char *filename) 11037c478bd9Sstevel@tonic-gate { 11047c478bd9Sstevel@tonic-gate int linenum, bad_options = 0; 11057c478bd9Sstevel@tonic-gate char line[1024]; 11067c478bd9Sstevel@tonic-gate FILE *f; 11077c478bd9Sstevel@tonic-gate 11087c478bd9Sstevel@tonic-gate f = fopen(filename, "r"); 11097c478bd9Sstevel@tonic-gate if (!f) { 11107c478bd9Sstevel@tonic-gate perror(filename); 11117c478bd9Sstevel@tonic-gate exit(1); 11127c478bd9Sstevel@tonic-gate } 11137c478bd9Sstevel@tonic-gate linenum = 0; 11147c478bd9Sstevel@tonic-gate while (fgets(line, sizeof(line), f)) { 11157c478bd9Sstevel@tonic-gate /* Update line number counter. */ 11167c478bd9Sstevel@tonic-gate linenum++; 11177c478bd9Sstevel@tonic-gate if (process_server_config_line(options, line, filename, linenum) != 0) 11187c478bd9Sstevel@tonic-gate bad_options++; 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate (void) fclose(f); 11217c478bd9Sstevel@tonic-gate if (bad_options > 0) 11227c478bd9Sstevel@tonic-gate fatal("%s: terminating, %d bad configuration options", 11237c478bd9Sstevel@tonic-gate filename, bad_options); 11247c478bd9Sstevel@tonic-gate } 1125