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 /* 126f8d59d8SJan Pechanec * Copyright 2009 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 #ifdef HAVE_DEFOPEN 207c478bd9Sstevel@tonic-gate #include <deflt.h> 217c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */ 227c478bd9Sstevel@tonic-gate 237c478bd9Sstevel@tonic-gate #if defined(KRB4) 247c478bd9Sstevel@tonic-gate #include <krb.h> 257c478bd9Sstevel@tonic-gate #endif 267c478bd9Sstevel@tonic-gate #if defined(KRB5) 277c478bd9Sstevel@tonic-gate #ifdef HEIMDAL 287c478bd9Sstevel@tonic-gate #include <krb.h> 297c478bd9Sstevel@tonic-gate #else 307c478bd9Sstevel@tonic-gate /* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V 317c478bd9Sstevel@tonic-gate * keytab */ 327c478bd9Sstevel@tonic-gate #define KEYFILE "/etc/krb5.keytab" 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate #ifdef AFS 367c478bd9Sstevel@tonic-gate #include <kafs.h> 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include "ssh.h" 407c478bd9Sstevel@tonic-gate #include "log.h" 41b07b2f5cSHuie-Ying Lee #include "buffer.h" 427c478bd9Sstevel@tonic-gate #include "servconf.h" 437c478bd9Sstevel@tonic-gate #include "xmalloc.h" 447c478bd9Sstevel@tonic-gate #include "compat.h" 457c478bd9Sstevel@tonic-gate #include "pathnames.h" 467c478bd9Sstevel@tonic-gate #include "tildexpand.h" 477c478bd9Sstevel@tonic-gate #include "misc.h" 487c478bd9Sstevel@tonic-gate #include "cipher.h" 497c478bd9Sstevel@tonic-gate #include "kex.h" 507c478bd9Sstevel@tonic-gate #include "mac.h" 517c478bd9Sstevel@tonic-gate #include "auth.h" 52b07b2f5cSHuie-Ying Lee #include "match.h" 53b07b2f5cSHuie-Ying Lee #include "groupaccess.h" 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate static void add_listen_addr(ServerOptions *, char *, u_short); 567c478bd9Sstevel@tonic-gate static void add_one_listen_addr(ServerOptions *, char *, u_short); 577c478bd9Sstevel@tonic-gate 58b07b2f5cSHuie-Ying Lee extern Buffer cfg; 59b07b2f5cSHuie-Ying Lee 607c478bd9Sstevel@tonic-gate /* AF_UNSPEC or AF_INET or AF_INET6 */ 617c478bd9Sstevel@tonic-gate extern int IPv4or6; 627c478bd9Sstevel@tonic-gate 636f8d59d8SJan Pechanec /* 646f8d59d8SJan Pechanec * Initializes the server options to their initial (unset) values. Some of those 656f8d59d8SJan Pechanec * that stay unset after the command line options and configuration files are 666f8d59d8SJan Pechanec * read are set to their default values in fill_default_server_options(). 676f8d59d8SJan Pechanec */ 687c478bd9Sstevel@tonic-gate void 697c478bd9Sstevel@tonic-gate initialize_server_options(ServerOptions *options) 707c478bd9Sstevel@tonic-gate { 717c478bd9Sstevel@tonic-gate (void) memset(options, 0, sizeof(*options)); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* Portable-specific options */ 747c478bd9Sstevel@tonic-gate options->pam_authentication_via_kbd_int = -1; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* Standard Options */ 777c478bd9Sstevel@tonic-gate options->num_ports = 0; 787c478bd9Sstevel@tonic-gate options->ports_from_cmdline = 0; 797c478bd9Sstevel@tonic-gate options->listen_addrs = NULL; 807c478bd9Sstevel@tonic-gate options->num_host_key_files = 0; 817c478bd9Sstevel@tonic-gate options->pid_file = NULL; 827c478bd9Sstevel@tonic-gate options->server_key_bits = -1; 837c478bd9Sstevel@tonic-gate options->login_grace_time = -1; 847c478bd9Sstevel@tonic-gate options->key_regeneration_time = -1; 857c478bd9Sstevel@tonic-gate options->permit_root_login = PERMIT_NOT_SET; 867c478bd9Sstevel@tonic-gate options->ignore_rhosts = -1; 877c478bd9Sstevel@tonic-gate options->ignore_user_known_hosts = -1; 887c478bd9Sstevel@tonic-gate options->print_motd = -1; 897c478bd9Sstevel@tonic-gate options->print_lastlog = -1; 907c478bd9Sstevel@tonic-gate options->x11_forwarding = -1; 917c478bd9Sstevel@tonic-gate options->x11_display_offset = -1; 927c478bd9Sstevel@tonic-gate options->x11_use_localhost = -1; 937c478bd9Sstevel@tonic-gate options->xauth_location = NULL; 947c478bd9Sstevel@tonic-gate options->strict_modes = -1; 957c478bd9Sstevel@tonic-gate options->keepalives = -1; 967c478bd9Sstevel@tonic-gate options->log_facility = SYSLOG_FACILITY_NOT_SET; 977c478bd9Sstevel@tonic-gate options->log_level = SYSLOG_LEVEL_NOT_SET; 987c478bd9Sstevel@tonic-gate options->rhosts_authentication = -1; 997c478bd9Sstevel@tonic-gate options->rhosts_rsa_authentication = -1; 1007c478bd9Sstevel@tonic-gate options->hostbased_authentication = -1; 1017c478bd9Sstevel@tonic-gate options->hostbased_uses_name_from_packet_only = -1; 1027c478bd9Sstevel@tonic-gate options->rsa_authentication = -1; 1037c478bd9Sstevel@tonic-gate options->pubkey_authentication = -1; 1047c478bd9Sstevel@tonic-gate #ifdef GSSAPI 1057c478bd9Sstevel@tonic-gate options->gss_authentication = -1; 1067c478bd9Sstevel@tonic-gate options->gss_keyex = -1; 1077c478bd9Sstevel@tonic-gate options->gss_store_creds = -1; 1087c478bd9Sstevel@tonic-gate options->gss_use_session_ccache = -1; 1097c478bd9Sstevel@tonic-gate options->gss_cleanup_creds = -1; 1107c478bd9Sstevel@tonic-gate #endif 1117c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 1127c478bd9Sstevel@tonic-gate options->kerberos_authentication = -1; 1137c478bd9Sstevel@tonic-gate options->kerberos_or_local_passwd = -1; 1147c478bd9Sstevel@tonic-gate options->kerberos_ticket_cleanup = -1; 1157c478bd9Sstevel@tonic-gate #endif 1167c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 1177c478bd9Sstevel@tonic-gate options->kerberos_tgt_passing = -1; 1187c478bd9Sstevel@tonic-gate #endif 1197c478bd9Sstevel@tonic-gate #ifdef AFS 1207c478bd9Sstevel@tonic-gate options->afs_token_passing = -1; 1217c478bd9Sstevel@tonic-gate #endif 1227c478bd9Sstevel@tonic-gate options->password_authentication = -1; 1237c478bd9Sstevel@tonic-gate options->kbd_interactive_authentication = -1; 1247c478bd9Sstevel@tonic-gate options->challenge_response_authentication = -1; 1257c478bd9Sstevel@tonic-gate options->permit_empty_passwd = -1; 1267c478bd9Sstevel@tonic-gate options->permit_user_env = -1; 1277c478bd9Sstevel@tonic-gate options->compression = -1; 1287c478bd9Sstevel@tonic-gate options->allow_tcp_forwarding = -1; 1297c478bd9Sstevel@tonic-gate options->num_allow_users = 0; 1307c478bd9Sstevel@tonic-gate options->num_deny_users = 0; 1317c478bd9Sstevel@tonic-gate options->num_allow_groups = 0; 1327c478bd9Sstevel@tonic-gate options->num_deny_groups = 0; 1337c478bd9Sstevel@tonic-gate options->ciphers = NULL; 1347c478bd9Sstevel@tonic-gate options->macs = NULL; 1357c478bd9Sstevel@tonic-gate options->protocol = SSH_PROTO_UNKNOWN; 1367c478bd9Sstevel@tonic-gate options->gateway_ports = -1; 1377c478bd9Sstevel@tonic-gate options->num_subsystems = 0; 1387c478bd9Sstevel@tonic-gate options->max_startups_begin = -1; 1397c478bd9Sstevel@tonic-gate options->max_startups_rate = -1; 1407c478bd9Sstevel@tonic-gate options->max_startups = -1; 1417c478bd9Sstevel@tonic-gate options->banner = NULL; 1427c478bd9Sstevel@tonic-gate options->verify_reverse_mapping = -1; 1437c478bd9Sstevel@tonic-gate options->client_alive_interval = -1; 1447c478bd9Sstevel@tonic-gate options->client_alive_count_max = -1; 1457c478bd9Sstevel@tonic-gate options->authorized_keys_file = NULL; 1467c478bd9Sstevel@tonic-gate options->authorized_keys_file2 = NULL; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate options->max_auth_tries = -1; 1497c478bd9Sstevel@tonic-gate options->max_auth_tries_log = -1; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate options->max_init_auth_tries = -1; 1527c478bd9Sstevel@tonic-gate options->max_init_auth_tries_log = -1; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate options->lookup_client_hostnames = -1; 155cd7d5fafSJan Pechanec options->use_openssl_engine = -1; 1566f8d59d8SJan Pechanec options->chroot_directory = NULL; 157*d8a94255SErik Trauschke options->pre_userauth_hook = NULL; 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN 1617c478bd9Sstevel@tonic-gate /* 1627c478bd9Sstevel@tonic-gate * Reads /etc/default/login and defaults several ServerOptions: 1637c478bd9Sstevel@tonic-gate * 1647c478bd9Sstevel@tonic-gate * PermitRootLogin 1657c478bd9Sstevel@tonic-gate * PermitEmptyPasswords 1667c478bd9Sstevel@tonic-gate * LoginGraceTime 1677c478bd9Sstevel@tonic-gate * 1687c478bd9Sstevel@tonic-gate * CONSOLE=* -> PermitRootLogin=without-password 1697c478bd9Sstevel@tonic-gate * #CONSOLE=* -> PermitRootLogin=yes 1707c478bd9Sstevel@tonic-gate * 1717c478bd9Sstevel@tonic-gate * PASSREQ=YES -> PermitEmptyPasswords=no 1727c478bd9Sstevel@tonic-gate * PASSREQ=NO -> PermitEmptyPasswords=yes 1737c478bd9Sstevel@tonic-gate * #PASSREQ=* -> PermitEmptyPasswords=no 1747c478bd9Sstevel@tonic-gate * 1757c478bd9Sstevel@tonic-gate * TIMEOUT=<secs> -> LoginGraceTime=<secs> 1767c478bd9Sstevel@tonic-gate * #TIMEOUT=<secs> -> LoginGraceTime=300 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate static 1797c478bd9Sstevel@tonic-gate void 1807c478bd9Sstevel@tonic-gate deflt_fill_default_server_options(ServerOptions *options) 1817c478bd9Sstevel@tonic-gate { 1827c478bd9Sstevel@tonic-gate int flags; 1837c478bd9Sstevel@tonic-gate char *ptr; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if (defopen(_PATH_DEFAULT_LOGIN)) 1867c478bd9Sstevel@tonic-gate return; 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* Ignore case */ 1897c478bd9Sstevel@tonic-gate flags = defcntl(DC_GETFLAGS, 0); 1907c478bd9Sstevel@tonic-gate TURNOFF(flags, DC_CASE); 1917c478bd9Sstevel@tonic-gate (void) defcntl(DC_SETFLAGS, flags); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate if (options->permit_root_login == PERMIT_NOT_SET && 1947c478bd9Sstevel@tonic-gate (ptr = defread("CONSOLE=")) != NULL) 1957c478bd9Sstevel@tonic-gate options->permit_root_login = PERMIT_NO_PASSWD; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate if (options->permit_empty_passwd == -1 && 1987c478bd9Sstevel@tonic-gate (ptr = defread("PASSREQ=")) != NULL) { 1997c478bd9Sstevel@tonic-gate if (strcasecmp("YES", ptr) == 0) 2007c478bd9Sstevel@tonic-gate options->permit_empty_passwd = 0; 2017c478bd9Sstevel@tonic-gate else if (strcasecmp("NO", ptr) == 0) 2027c478bd9Sstevel@tonic-gate options->permit_empty_passwd = 1; 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries == -1 && 2067c478bd9Sstevel@tonic-gate (ptr = defread("RETRIES=")) != NULL) { 2077c478bd9Sstevel@tonic-gate options->max_init_auth_tries = atoi(ptr); 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries_log == -1 && 2117c478bd9Sstevel@tonic-gate (ptr = defread("SYSLOG_FAILED_LOGINS=")) != NULL) { 2127c478bd9Sstevel@tonic-gate options->max_init_auth_tries_log = atoi(ptr); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate if (options->login_grace_time == -1) { 2167c478bd9Sstevel@tonic-gate if ((ptr = defread("TIMEOUT=")) != NULL) 2177c478bd9Sstevel@tonic-gate options->login_grace_time = (unsigned)atoi(ptr); 2187c478bd9Sstevel@tonic-gate else 2197c478bd9Sstevel@tonic-gate options->login_grace_time = 300; 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate (void) defopen((char *)NULL); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */ 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate void 2277c478bd9Sstevel@tonic-gate fill_default_server_options(ServerOptions *options) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN 2317c478bd9Sstevel@tonic-gate deflt_fill_default_server_options(options); 2327c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */ 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate /* Portable-specific options */ 2357c478bd9Sstevel@tonic-gate if (options->pam_authentication_via_kbd_int == -1) 2367c478bd9Sstevel@tonic-gate options->pam_authentication_via_kbd_int = 0; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* Standard Options */ 2397c478bd9Sstevel@tonic-gate if (options->protocol == SSH_PROTO_UNKNOWN) 2407c478bd9Sstevel@tonic-gate options->protocol = SSH_PROTO_1|SSH_PROTO_2; 2417c478bd9Sstevel@tonic-gate if (options->num_host_key_files == 0) { 2427c478bd9Sstevel@tonic-gate /* fill default hostkeys for protocols */ 2437c478bd9Sstevel@tonic-gate if (options->protocol & SSH_PROTO_1) 2447c478bd9Sstevel@tonic-gate options->host_key_files[options->num_host_key_files++] = 2457c478bd9Sstevel@tonic-gate _PATH_HOST_KEY_FILE; 2467c478bd9Sstevel@tonic-gate #ifndef GSSAPI 2477c478bd9Sstevel@tonic-gate /* With GSS keyex we can run v2 w/ no host keys */ 2487c478bd9Sstevel@tonic-gate if (options->protocol & SSH_PROTO_2) { 2497c478bd9Sstevel@tonic-gate options->host_key_files[options->num_host_key_files++] = 2507c478bd9Sstevel@tonic-gate _PATH_HOST_RSA_KEY_FILE; 2517c478bd9Sstevel@tonic-gate options->host_key_files[options->num_host_key_files++] = 2527c478bd9Sstevel@tonic-gate _PATH_HOST_DSA_KEY_FILE; 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate #endif /* GSSAPI */ 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate if (options->num_ports == 0) 2577c478bd9Sstevel@tonic-gate options->ports[options->num_ports++] = SSH_DEFAULT_PORT; 2587c478bd9Sstevel@tonic-gate if (options->listen_addrs == NULL) 2597c478bd9Sstevel@tonic-gate add_listen_addr(options, NULL, 0); 2607c478bd9Sstevel@tonic-gate if (options->pid_file == NULL) 2617c478bd9Sstevel@tonic-gate options->pid_file = _PATH_SSH_DAEMON_PID_FILE; 2627c478bd9Sstevel@tonic-gate if (options->server_key_bits == -1) 2637c478bd9Sstevel@tonic-gate options->server_key_bits = 768; 2647c478bd9Sstevel@tonic-gate if (options->login_grace_time == -1) 2657c478bd9Sstevel@tonic-gate options->login_grace_time = 120; 2667c478bd9Sstevel@tonic-gate if (options->key_regeneration_time == -1) 2677c478bd9Sstevel@tonic-gate options->key_regeneration_time = 3600; 2687c478bd9Sstevel@tonic-gate if (options->permit_root_login == PERMIT_NOT_SET) 2697c478bd9Sstevel@tonic-gate options->permit_root_login = PERMIT_YES; 2707c478bd9Sstevel@tonic-gate if (options->ignore_rhosts == -1) 2717c478bd9Sstevel@tonic-gate options->ignore_rhosts = 1; 2727c478bd9Sstevel@tonic-gate if (options->ignore_user_known_hosts == -1) 2737c478bd9Sstevel@tonic-gate options->ignore_user_known_hosts = 0; 2747c478bd9Sstevel@tonic-gate if (options->print_motd == -1) 2757c478bd9Sstevel@tonic-gate options->print_motd = 1; 2767c478bd9Sstevel@tonic-gate if (options->print_lastlog == -1) 2777c478bd9Sstevel@tonic-gate options->print_lastlog = 1; 2787c478bd9Sstevel@tonic-gate if (options->x11_forwarding == -1) 2797c478bd9Sstevel@tonic-gate options->x11_forwarding = 1; 2807c478bd9Sstevel@tonic-gate if (options->x11_display_offset == -1) 2817c478bd9Sstevel@tonic-gate options->x11_display_offset = 10; 2827c478bd9Sstevel@tonic-gate if (options->x11_use_localhost == -1) 2837c478bd9Sstevel@tonic-gate options->x11_use_localhost = 1; 2847c478bd9Sstevel@tonic-gate if (options->xauth_location == NULL) 2857c478bd9Sstevel@tonic-gate options->xauth_location = _PATH_XAUTH; 2867c478bd9Sstevel@tonic-gate if (options->strict_modes == -1) 2877c478bd9Sstevel@tonic-gate options->strict_modes = 1; 2887c478bd9Sstevel@tonic-gate if (options->keepalives == -1) 2897c478bd9Sstevel@tonic-gate options->keepalives = 1; 2907c478bd9Sstevel@tonic-gate if (options->log_facility == SYSLOG_FACILITY_NOT_SET) 2917c478bd9Sstevel@tonic-gate options->log_facility = SYSLOG_FACILITY_AUTH; 2927c478bd9Sstevel@tonic-gate if (options->log_level == SYSLOG_LEVEL_NOT_SET) 2937c478bd9Sstevel@tonic-gate options->log_level = SYSLOG_LEVEL_INFO; 2947c478bd9Sstevel@tonic-gate if (options->rhosts_authentication == -1) 2957c478bd9Sstevel@tonic-gate options->rhosts_authentication = 0; 2967c478bd9Sstevel@tonic-gate if (options->rhosts_rsa_authentication == -1) 2977c478bd9Sstevel@tonic-gate options->rhosts_rsa_authentication = 0; 2987c478bd9Sstevel@tonic-gate if (options->hostbased_authentication == -1) 2997c478bd9Sstevel@tonic-gate options->hostbased_authentication = 0; 3007c478bd9Sstevel@tonic-gate if (options->hostbased_uses_name_from_packet_only == -1) 3017c478bd9Sstevel@tonic-gate options->hostbased_uses_name_from_packet_only = 0; 3027c478bd9Sstevel@tonic-gate if (options->rsa_authentication == -1) 3037c478bd9Sstevel@tonic-gate options->rsa_authentication = 1; 3047c478bd9Sstevel@tonic-gate if (options->pubkey_authentication == -1) 3057c478bd9Sstevel@tonic-gate options->pubkey_authentication = 1; 3067c478bd9Sstevel@tonic-gate #ifdef GSSAPI 3077c478bd9Sstevel@tonic-gate if (options->gss_authentication == -1) 3087c478bd9Sstevel@tonic-gate options->gss_authentication = 1; 3097c478bd9Sstevel@tonic-gate if (options->gss_keyex == -1) 3107c478bd9Sstevel@tonic-gate options->gss_keyex = 1; 3117c478bd9Sstevel@tonic-gate if (options->gss_store_creds == -1) 3127c478bd9Sstevel@tonic-gate options->gss_store_creds = 1; 3137c478bd9Sstevel@tonic-gate if (options->gss_use_session_ccache == -1) 3147c478bd9Sstevel@tonic-gate options->gss_use_session_ccache = 1; 3157c478bd9Sstevel@tonic-gate if (options->gss_cleanup_creds == -1) 3167c478bd9Sstevel@tonic-gate options->gss_cleanup_creds = 1; 3177c478bd9Sstevel@tonic-gate #endif 3187c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 3197c478bd9Sstevel@tonic-gate if (options->kerberos_authentication == -1) 3207c478bd9Sstevel@tonic-gate options->kerberos_authentication = 0; 3217c478bd9Sstevel@tonic-gate if (options->kerberos_or_local_passwd == -1) 3227c478bd9Sstevel@tonic-gate options->kerberos_or_local_passwd = 1; 3237c478bd9Sstevel@tonic-gate if (options->kerberos_ticket_cleanup == -1) 3247c478bd9Sstevel@tonic-gate options->kerberos_ticket_cleanup = 1; 3257c478bd9Sstevel@tonic-gate #endif 3267c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 3277c478bd9Sstevel@tonic-gate if (options->kerberos_tgt_passing == -1) 3287c478bd9Sstevel@tonic-gate options->kerberos_tgt_passing = 0; 3297c478bd9Sstevel@tonic-gate #endif 3307c478bd9Sstevel@tonic-gate #ifdef AFS 3317c478bd9Sstevel@tonic-gate if (options->afs_token_passing == -1) 3327c478bd9Sstevel@tonic-gate options->afs_token_passing = 0; 3337c478bd9Sstevel@tonic-gate #endif 3347c478bd9Sstevel@tonic-gate if (options->password_authentication == -1) 3357c478bd9Sstevel@tonic-gate options->password_authentication = 1; 3367c478bd9Sstevel@tonic-gate if (options->kbd_interactive_authentication == -1) 3377c478bd9Sstevel@tonic-gate options->kbd_interactive_authentication = 0; 3387c478bd9Sstevel@tonic-gate if (options->challenge_response_authentication == -1) 3397c478bd9Sstevel@tonic-gate options->challenge_response_authentication = 1; 3407c478bd9Sstevel@tonic-gate if (options->permit_empty_passwd == -1) 3417c478bd9Sstevel@tonic-gate options->permit_empty_passwd = 0; 3427c478bd9Sstevel@tonic-gate if (options->permit_user_env == -1) 3437c478bd9Sstevel@tonic-gate options->permit_user_env = 0; 3447c478bd9Sstevel@tonic-gate if (options->compression == -1) 3457c478bd9Sstevel@tonic-gate options->compression = 1; 3467c478bd9Sstevel@tonic-gate if (options->allow_tcp_forwarding == -1) 3477c478bd9Sstevel@tonic-gate options->allow_tcp_forwarding = 1; 3487c478bd9Sstevel@tonic-gate if (options->gateway_ports == -1) 3497c478bd9Sstevel@tonic-gate options->gateway_ports = 0; 3507c478bd9Sstevel@tonic-gate if (options->max_startups == -1) 3517c478bd9Sstevel@tonic-gate options->max_startups = 10; 3527c478bd9Sstevel@tonic-gate if (options->max_startups_rate == -1) 3537c478bd9Sstevel@tonic-gate options->max_startups_rate = 100; /* 100% */ 3547c478bd9Sstevel@tonic-gate if (options->max_startups_begin == -1) 3557c478bd9Sstevel@tonic-gate options->max_startups_begin = options->max_startups; 3567c478bd9Sstevel@tonic-gate if (options->verify_reverse_mapping == -1) 3577c478bd9Sstevel@tonic-gate options->verify_reverse_mapping = 0; 3587c478bd9Sstevel@tonic-gate if (options->client_alive_interval == -1) 3597c478bd9Sstevel@tonic-gate options->client_alive_interval = 0; 3607c478bd9Sstevel@tonic-gate if (options->client_alive_count_max == -1) 3617c478bd9Sstevel@tonic-gate options->client_alive_count_max = 3; 3627c478bd9Sstevel@tonic-gate if (options->authorized_keys_file2 == NULL) { 3637c478bd9Sstevel@tonic-gate /* authorized_keys_file2 falls back to authorized_keys_file */ 3647c478bd9Sstevel@tonic-gate if (options->authorized_keys_file != NULL) 3657c478bd9Sstevel@tonic-gate options->authorized_keys_file2 = options->authorized_keys_file; 3667c478bd9Sstevel@tonic-gate else 3677c478bd9Sstevel@tonic-gate options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2; 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate if (options->authorized_keys_file == NULL) 3707c478bd9Sstevel@tonic-gate options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS; 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate if (options->max_auth_tries == -1) 3737c478bd9Sstevel@tonic-gate options->max_auth_tries = AUTH_FAIL_MAX; 3747c478bd9Sstevel@tonic-gate if (options->max_auth_tries_log == -1) 3757c478bd9Sstevel@tonic-gate options->max_auth_tries_log = options->max_auth_tries / 2; 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries == -1) 3787c478bd9Sstevel@tonic-gate options->max_init_auth_tries = AUTH_FAIL_MAX; 3797c478bd9Sstevel@tonic-gate if (options->max_init_auth_tries_log == -1) 3807c478bd9Sstevel@tonic-gate options->max_init_auth_tries_log = options->max_init_auth_tries / 2; 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate if (options->lookup_client_hostnames == -1) 3837c478bd9Sstevel@tonic-gate options->lookup_client_hostnames = 1; 384cd7d5fafSJan Pechanec if (options->use_openssl_engine == -1) 385cd7d5fafSJan Pechanec options->use_openssl_engine = 1; 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate /* Keyword tokens. */ 3897c478bd9Sstevel@tonic-gate typedef enum { 3907c478bd9Sstevel@tonic-gate sBadOption, /* == unknown option */ 3917c478bd9Sstevel@tonic-gate /* Portable-specific options */ 3927c478bd9Sstevel@tonic-gate sPAMAuthenticationViaKbdInt, 3937c478bd9Sstevel@tonic-gate /* Standard Options */ 3947c478bd9Sstevel@tonic-gate sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime, 3957c478bd9Sstevel@tonic-gate sPermitRootLogin, sLogFacility, sLogLevel, 3967c478bd9Sstevel@tonic-gate sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication, 3977c478bd9Sstevel@tonic-gate #ifdef GSSAPI 3987c478bd9Sstevel@tonic-gate sGssAuthentication, sGssKeyEx, sGssStoreDelegCreds, 3997c478bd9Sstevel@tonic-gate sGssUseSessionCredCache, sGssCleanupCreds, 4007c478bd9Sstevel@tonic-gate #endif /* GSSAPI */ 4017c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 4027c478bd9Sstevel@tonic-gate sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup, 4037c478bd9Sstevel@tonic-gate #endif 4047c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 4057c478bd9Sstevel@tonic-gate sKerberosTgtPassing, 4067c478bd9Sstevel@tonic-gate #endif 4077c478bd9Sstevel@tonic-gate #ifdef AFS 4087c478bd9Sstevel@tonic-gate sAFSTokenPassing, 4097c478bd9Sstevel@tonic-gate #endif 4107c478bd9Sstevel@tonic-gate sChallengeResponseAuthentication, 4117c478bd9Sstevel@tonic-gate sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress, 4127c478bd9Sstevel@tonic-gate sPrintMotd, sPrintLastLog, sIgnoreRhosts, 4137c478bd9Sstevel@tonic-gate sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost, 4147c478bd9Sstevel@tonic-gate sStrictModes, sEmptyPasswd, sKeepAlives, 4157c478bd9Sstevel@tonic-gate sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression, 4167c478bd9Sstevel@tonic-gate sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups, 4177c478bd9Sstevel@tonic-gate sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile, 4187c478bd9Sstevel@tonic-gate sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups, 4197c478bd9Sstevel@tonic-gate sBanner, sVerifyReverseMapping, sHostbasedAuthentication, 4207c478bd9Sstevel@tonic-gate sHostbasedUsesNameFromPacketOnly, sClientAliveInterval, 4217c478bd9Sstevel@tonic-gate sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2, 4227c478bd9Sstevel@tonic-gate sMaxAuthTries, sMaxAuthTriesLog, sUsePrivilegeSeparation, 4236f8d59d8SJan Pechanec sLookupClientHostnames, sUseOpenSSLEngine, sChrootDirectory, 424*d8a94255SErik Trauschke sPreUserauthHook, sMatch, 4257c478bd9Sstevel@tonic-gate sDeprecated 4267c478bd9Sstevel@tonic-gate } ServerOpCodes; 4277c478bd9Sstevel@tonic-gate 428b07b2f5cSHuie-Ying Lee #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */ 429b07b2f5cSHuie-Ying Lee #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */ 430b07b2f5cSHuie-Ying Lee #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH) 431b07b2f5cSHuie-Ying Lee 4327c478bd9Sstevel@tonic-gate /* Textual representation of the tokens. */ 4337c478bd9Sstevel@tonic-gate static struct { 4347c478bd9Sstevel@tonic-gate const char *name; 4357c478bd9Sstevel@tonic-gate ServerOpCodes opcode; 436b07b2f5cSHuie-Ying Lee u_int flags; 4377c478bd9Sstevel@tonic-gate } keywords[] = { 4387c478bd9Sstevel@tonic-gate /* Portable-specific options */ 439b07b2f5cSHuie-Ying Lee { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt, SSHCFG_GLOBAL }, 4407c478bd9Sstevel@tonic-gate /* Standard Options */ 441b07b2f5cSHuie-Ying Lee { "port", sPort, SSHCFG_GLOBAL }, 442b07b2f5cSHuie-Ying Lee { "hostkey", sHostKeyFile, SSHCFG_GLOBAL }, 443b07b2f5cSHuie-Ying Lee { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */ 444b07b2f5cSHuie-Ying Lee { "pidfile", sPidFile, SSHCFG_GLOBAL }, 445b07b2f5cSHuie-Ying Lee { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL }, 446b07b2f5cSHuie-Ying Lee { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL }, 447b07b2f5cSHuie-Ying Lee { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL }, 448b07b2f5cSHuie-Ying Lee { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL }, 449b07b2f5cSHuie-Ying Lee { "syslogfacility", sLogFacility, SSHCFG_GLOBAL }, 450b07b2f5cSHuie-Ying Lee { "loglevel", sLogLevel, SSHCFG_GLOBAL }, 451b07b2f5cSHuie-Ying Lee { "rhostsauthentication", sRhostsAuthentication, SSHCFG_GLOBAL }, 452b07b2f5cSHuie-Ying Lee { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL }, 453b07b2f5cSHuie-Ying Lee { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL }, 4547c478bd9Sstevel@tonic-gate { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly }, 455b07b2f5cSHuie-Ying Lee { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL }, 456b07b2f5cSHuie-Ying Lee { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL }, 457b07b2f5cSHuie-Ying Lee { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */ 4587c478bd9Sstevel@tonic-gate #ifdef GSSAPI 459b07b2f5cSHuie-Ying Lee { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL }, 460b07b2f5cSHuie-Ying Lee { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL }, 461b07b2f5cSHuie-Ying Lee { "gssapistoredelegatedcredentials", sGssStoreDelegCreds, SSHCFG_GLOBAL }, 462b07b2f5cSHuie-Ying Lee { "gssauthentication", sGssAuthentication, SSHCFG_GLOBAL }, /* alias */ 463b07b2f5cSHuie-Ying Lee { "gsskeyex", sGssKeyEx, SSHCFG_GLOBAL }, /* alias */ 464b07b2f5cSHuie-Ying Lee { "gssstoredelegcreds", sGssStoreDelegCreds, SSHCFG_GLOBAL }, /* alias */ 4657c478bd9Sstevel@tonic-gate #ifndef SUNW_GSSAPI 466b07b2f5cSHuie-Ying Lee { "gssusesessionccache", sGssUseSessionCredCache, SSHCFG_GLOBAL }, 467b07b2f5cSHuie-Ying Lee { "gssusesessioncredcache", sGssUseSessionCredCache, SSHCFG_GLOBAL }, 468b07b2f5cSHuie-Ying Lee { "gsscleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL }, 4697c478bd9Sstevel@tonic-gate #endif /* SUNW_GSSAPI */ 4707c478bd9Sstevel@tonic-gate #endif 4717c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 472b07b2f5cSHuie-Ying Lee { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL }, 473b07b2f5cSHuie-Ying Lee { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL }, 474b07b2f5cSHuie-Ying Lee { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL }, 4757c478bd9Sstevel@tonic-gate #endif 4767c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 477b07b2f5cSHuie-Ying Lee { "kerberostgtpassing", sKerberosTgtPassing, SSHCFG_GLOBAL }, 4787c478bd9Sstevel@tonic-gate #endif 4797c478bd9Sstevel@tonic-gate #ifdef AFS 480b07b2f5cSHuie-Ying Lee { "afstokenpassing", sAFSTokenPassing, SSHCFG_GLOBAL }, 4817c478bd9Sstevel@tonic-gate #endif 482b07b2f5cSHuie-Ying Lee { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL }, 483b07b2f5cSHuie-Ying Lee { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL }, 484b07b2f5cSHuie-Ying Lee { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, 485b07b2f5cSHuie-Ying Lee { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */ 486b07b2f5cSHuie-Ying Lee { "checkmail", sDeprecated, SSHCFG_GLOBAL }, 487b07b2f5cSHuie-Ying Lee { "listenaddress", sListenAddress, SSHCFG_GLOBAL }, 488b07b2f5cSHuie-Ying Lee { "printmotd", sPrintMotd, SSHCFG_GLOBAL }, 489b07b2f5cSHuie-Ying Lee { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL }, 490b07b2f5cSHuie-Ying Lee { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL }, 491b07b2f5cSHuie-Ying Lee { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL }, 492b07b2f5cSHuie-Ying Lee { "x11forwarding", sX11Forwarding, SSHCFG_ALL }, 493b07b2f5cSHuie-Ying Lee { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL }, 494b07b2f5cSHuie-Ying Lee { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL }, 495b07b2f5cSHuie-Ying Lee { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL }, 496b07b2f5cSHuie-Ying Lee { "strictmodes", sStrictModes, SSHCFG_GLOBAL }, 497b07b2f5cSHuie-Ying Lee { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL }, 498b07b2f5cSHuie-Ying Lee { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL }, 499b07b2f5cSHuie-Ying Lee { "uselogin", sUseLogin, SSHCFG_GLOBAL }, 500b07b2f5cSHuie-Ying Lee { "compression", sCompression, SSHCFG_GLOBAL }, 501b07b2f5cSHuie-Ying Lee { "keepalive", sKeepAlives, SSHCFG_GLOBAL }, 502b07b2f5cSHuie-Ying Lee { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL }, 503b07b2f5cSHuie-Ying Lee { "allowusers", sAllowUsers, SSHCFG_GLOBAL }, 504b07b2f5cSHuie-Ying Lee { "denyusers", sDenyUsers, SSHCFG_GLOBAL }, 505b07b2f5cSHuie-Ying Lee { "allowgroups", sAllowGroups, SSHCFG_GLOBAL }, 506b07b2f5cSHuie-Ying Lee { "denygroups", sDenyGroups, SSHCFG_GLOBAL }, 507b07b2f5cSHuie-Ying Lee { "ciphers", sCiphers, SSHCFG_GLOBAL }, 508b07b2f5cSHuie-Ying Lee { "macs", sMacs, SSHCFG_GLOBAL}, 509b07b2f5cSHuie-Ying Lee { "protocol", sProtocol,SSHCFG_GLOBAL }, 510b07b2f5cSHuie-Ying Lee { "gatewayports", sGatewayPorts, SSHCFG_ALL }, 511b07b2f5cSHuie-Ying Lee { "subsystem", sSubsystem, SSHCFG_GLOBAL}, 512b07b2f5cSHuie-Ying Lee { "maxstartups", sMaxStartups, SSHCFG_GLOBAL }, 513b07b2f5cSHuie-Ying Lee { "banner", sBanner, SSHCFG_ALL }, 514b07b2f5cSHuie-Ying Lee { "verifyreversemapping", sVerifyReverseMapping, SSHCFG_GLOBAL }, 515b07b2f5cSHuie-Ying Lee { "reversemappingcheck", sVerifyReverseMapping,SSHCFG_GLOBAL }, 516b07b2f5cSHuie-Ying Lee { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL }, 517b07b2f5cSHuie-Ying Lee { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL }, 518b07b2f5cSHuie-Ying Lee { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL }, 519b07b2f5cSHuie-Ying Lee { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL }, 520b07b2f5cSHuie-Ying Lee { "maxauthtries", sMaxAuthTries, SSHCFG_ALL }, 521b07b2f5cSHuie-Ying Lee { "maxauthtrieslog", sMaxAuthTriesLog, SSHCFG_GLOBAL }, 522b07b2f5cSHuie-Ying Lee { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL }, 523b07b2f5cSHuie-Ying Lee { "lookupclienthostnames", sLookupClientHostnames, SSHCFG_GLOBAL }, 524b07b2f5cSHuie-Ying Lee { "useopensslengine", sUseOpenSSLEngine, SSHCFG_GLOBAL }, 525b07b2f5cSHuie-Ying Lee { "chrootdirectory", sChrootDirectory, SSHCFG_ALL }, 526*d8a94255SErik Trauschke { "preuserauthhook", sPreUserauthHook, SSHCFG_ALL}, 527b07b2f5cSHuie-Ying Lee { "match", sMatch, SSHCFG_ALL }, 528b07b2f5cSHuie-Ying Lee 529b07b2f5cSHuie-Ying Lee { NULL, sBadOption, 0 } 5307c478bd9Sstevel@tonic-gate }; 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate /* 5337c478bd9Sstevel@tonic-gate * Returns the number of the token pointed to by cp or sBadOption. 5347c478bd9Sstevel@tonic-gate */ 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate static ServerOpCodes 5377c478bd9Sstevel@tonic-gate parse_token(const char *cp, const char *filename, 538b07b2f5cSHuie-Ying Lee int linenum, u_int *flags) 5397c478bd9Sstevel@tonic-gate { 5407c478bd9Sstevel@tonic-gate u_int i; 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate for (i = 0; keywords[i].name; i++) 543b07b2f5cSHuie-Ying Lee if (strcasecmp(cp, keywords[i].name) == 0) { 544b07b2f5cSHuie-Ying Lee *flags = keywords[i].flags; 5457c478bd9Sstevel@tonic-gate return keywords[i].opcode; 546b07b2f5cSHuie-Ying Lee } 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate error("%s: line %d: Bad configuration option: %s", 5497c478bd9Sstevel@tonic-gate filename, linenum, cp); 5507c478bd9Sstevel@tonic-gate return sBadOption; 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate static void 5547c478bd9Sstevel@tonic-gate add_listen_addr(ServerOptions *options, char *addr, u_short port) 5557c478bd9Sstevel@tonic-gate { 5567c478bd9Sstevel@tonic-gate int i; 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate if (options->num_ports == 0) 5597c478bd9Sstevel@tonic-gate options->ports[options->num_ports++] = SSH_DEFAULT_PORT; 5607c478bd9Sstevel@tonic-gate if (port == 0) 5617c478bd9Sstevel@tonic-gate for (i = 0; i < options->num_ports; i++) 5627c478bd9Sstevel@tonic-gate add_one_listen_addr(options, addr, options->ports[i]); 5637c478bd9Sstevel@tonic-gate else 5647c478bd9Sstevel@tonic-gate add_one_listen_addr(options, addr, port); 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate static void 5687c478bd9Sstevel@tonic-gate add_one_listen_addr(ServerOptions *options, char *addr, u_short port) 5697c478bd9Sstevel@tonic-gate { 5707c478bd9Sstevel@tonic-gate struct addrinfo hints, *ai, *aitop; 5717c478bd9Sstevel@tonic-gate char strport[NI_MAXSERV]; 5727c478bd9Sstevel@tonic-gate int gaierr; 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate (void) memset(&hints, 0, sizeof(hints)); 5757c478bd9Sstevel@tonic-gate hints.ai_family = IPv4or6; 5767c478bd9Sstevel@tonic-gate hints.ai_socktype = SOCK_STREAM; 5777c478bd9Sstevel@tonic-gate hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; 5787c478bd9Sstevel@tonic-gate (void) snprintf(strport, sizeof strport, "%u", port); 5797c478bd9Sstevel@tonic-gate if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0) 5807c478bd9Sstevel@tonic-gate fatal("bad addr or host: %s (%s)", 5817c478bd9Sstevel@tonic-gate addr ? addr : "<NULL>", 5827c478bd9Sstevel@tonic-gate gai_strerror(gaierr)); 5837c478bd9Sstevel@tonic-gate for (ai = aitop; ai->ai_next; ai = ai->ai_next) 5847c478bd9Sstevel@tonic-gate ; 5857c478bd9Sstevel@tonic-gate ai->ai_next = options->listen_addrs; 5867c478bd9Sstevel@tonic-gate options->listen_addrs = aitop; 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate 589b07b2f5cSHuie-Ying Lee /* 590b07b2f5cSHuie-Ying Lee * The strategy for the Match blocks is that the config file is parsed twice. 591b07b2f5cSHuie-Ying Lee * 592b07b2f5cSHuie-Ying Lee * The first time is at startup. activep is initialized to 1 and the 593b07b2f5cSHuie-Ying Lee * directives in the global context are processed and acted on. Hitting a 594b07b2f5cSHuie-Ying Lee * Match directive unsets activep and the directives inside the block are 595b07b2f5cSHuie-Ying Lee * checked for syntax only. 596b07b2f5cSHuie-Ying Lee * 597b07b2f5cSHuie-Ying Lee * The second time is after a connection has been established but before 598b07b2f5cSHuie-Ying Lee * authentication. activep is initialized to 2 and global config directives 599b07b2f5cSHuie-Ying Lee * are ignored since they have already been processed. If the criteria in a 600b07b2f5cSHuie-Ying Lee * Match block is met, activep is set and the subsequent directives 601b07b2f5cSHuie-Ying Lee * processed and actioned until EOF or another Match block unsets it. Any 602b07b2f5cSHuie-Ying Lee * options set are copied into the main server config. 603b07b2f5cSHuie-Ying Lee * 604b07b2f5cSHuie-Ying Lee * Potential additions/improvements: 605b07b2f5cSHuie-Ying Lee * - Add Match support for pre-kex directives, eg Protocol, Ciphers. 606b07b2f5cSHuie-Ying Lee * 607b07b2f5cSHuie-Ying Lee * - Add a Tag directive (idea from David Leonard) ala pf, eg: 608b07b2f5cSHuie-Ying Lee * Match Address 192.168.0.* 609b07b2f5cSHuie-Ying Lee * Tag trusted 610b07b2f5cSHuie-Ying Lee * Match Group wheel 611b07b2f5cSHuie-Ying Lee * Tag trusted 612b07b2f5cSHuie-Ying Lee * Match Tag trusted 613b07b2f5cSHuie-Ying Lee * AllowTcpForwarding yes 614b07b2f5cSHuie-Ying Lee * GatewayPorts clientspecified 615b07b2f5cSHuie-Ying Lee * [...] 616b07b2f5cSHuie-Ying Lee * 617b07b2f5cSHuie-Ying Lee * - Add a PermittedChannelRequests directive 618b07b2f5cSHuie-Ying Lee * Match Group shell 619b07b2f5cSHuie-Ying Lee * PermittedChannelRequests session,forwarded-tcpip 620b07b2f5cSHuie-Ying Lee */ 621b07b2f5cSHuie-Ying Lee 622b07b2f5cSHuie-Ying Lee static int 623b07b2f5cSHuie-Ying Lee match_cfg_line_group(const char *grps, int line, const char *user) 624b07b2f5cSHuie-Ying Lee { 625b07b2f5cSHuie-Ying Lee int result = 0; 626b07b2f5cSHuie-Ying Lee struct passwd *pw; 627b07b2f5cSHuie-Ying Lee 628b07b2f5cSHuie-Ying Lee if (user == NULL) 629b07b2f5cSHuie-Ying Lee goto out; 630b07b2f5cSHuie-Ying Lee 631b07b2f5cSHuie-Ying Lee if ((pw = getpwnam(user)) == NULL) { 632b07b2f5cSHuie-Ying Lee debug("Can't match group at line %d because user %.100s does " 633b07b2f5cSHuie-Ying Lee "not exist", line, user); 634b07b2f5cSHuie-Ying Lee } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) { 635b07b2f5cSHuie-Ying Lee debug("Can't Match group because user %.100s not in any group " 636b07b2f5cSHuie-Ying Lee "at line %d", user, line); 637b07b2f5cSHuie-Ying Lee } else if (ga_match_pattern_list(grps) != 1) { 638b07b2f5cSHuie-Ying Lee debug("user %.100s does not match group list %.100s at line %d", 639b07b2f5cSHuie-Ying Lee user, grps, line); 640b07b2f5cSHuie-Ying Lee } else { 641b07b2f5cSHuie-Ying Lee debug("user %.100s matched group list %.100s at line %d", user, 642b07b2f5cSHuie-Ying Lee grps, line); 643b07b2f5cSHuie-Ying Lee result = 1; 644b07b2f5cSHuie-Ying Lee } 645b07b2f5cSHuie-Ying Lee out: 646b07b2f5cSHuie-Ying Lee ga_free(); 647b07b2f5cSHuie-Ying Lee return result; 648b07b2f5cSHuie-Ying Lee } 649b07b2f5cSHuie-Ying Lee 650b07b2f5cSHuie-Ying Lee static int 651b07b2f5cSHuie-Ying Lee match_cfg_line(char **condition, int line, const char *user, const char *host, 652b07b2f5cSHuie-Ying Lee const char *address) 653b07b2f5cSHuie-Ying Lee { 654b07b2f5cSHuie-Ying Lee int result = 1; 655b07b2f5cSHuie-Ying Lee char *arg, *attrib, *cp = *condition; 656b07b2f5cSHuie-Ying Lee size_t len; 657b07b2f5cSHuie-Ying Lee 658b07b2f5cSHuie-Ying Lee if (user == NULL) 659b07b2f5cSHuie-Ying Lee debug3("checking syntax for 'Match %s'", cp); 660b07b2f5cSHuie-Ying Lee else 661b07b2f5cSHuie-Ying Lee debug3("checking match for '%s' user %s host %s addr %s", cp, 662b07b2f5cSHuie-Ying Lee user ? user : "(null)", host ? host : "(null)", 663b07b2f5cSHuie-Ying Lee address ? address : "(null)"); 664b07b2f5cSHuie-Ying Lee 66556e7e6c6SHuie-Ying Lee while ((attrib = strdelim(&cp)) != NULL && *attrib != '\0') { 666b07b2f5cSHuie-Ying Lee if ((arg = strdelim(&cp)) == NULL || *arg == '\0') { 667b07b2f5cSHuie-Ying Lee error("Missing Match criteria for %s", attrib); 668b07b2f5cSHuie-Ying Lee return -1; 669b07b2f5cSHuie-Ying Lee } 670b07b2f5cSHuie-Ying Lee len = strlen(arg); 671b07b2f5cSHuie-Ying Lee if (strcasecmp(attrib, "user") == 0) { 672b07b2f5cSHuie-Ying Lee if (!user) { 673b07b2f5cSHuie-Ying Lee result = 0; 674b07b2f5cSHuie-Ying Lee continue; 675b07b2f5cSHuie-Ying Lee } 676b07b2f5cSHuie-Ying Lee if (match_pattern_list(user, arg, len, 0) != 1) 677b07b2f5cSHuie-Ying Lee result = 0; 678b07b2f5cSHuie-Ying Lee else 679b07b2f5cSHuie-Ying Lee debug("user %.100s matched 'User %.100s' at " 680b07b2f5cSHuie-Ying Lee "line %d", user, arg, line); 681b07b2f5cSHuie-Ying Lee } else if (strcasecmp(attrib, "group") == 0) { 682b07b2f5cSHuie-Ying Lee switch (match_cfg_line_group(arg, line, user)) { 683b07b2f5cSHuie-Ying Lee case -1: 684b07b2f5cSHuie-Ying Lee return -1; 685b07b2f5cSHuie-Ying Lee case 0: 686b07b2f5cSHuie-Ying Lee result = 0; 687b07b2f5cSHuie-Ying Lee } 688b07b2f5cSHuie-Ying Lee } else if (strcasecmp(attrib, "host") == 0) { 689b07b2f5cSHuie-Ying Lee if (!host) { 690b07b2f5cSHuie-Ying Lee result = 0; 691b07b2f5cSHuie-Ying Lee continue; 692b07b2f5cSHuie-Ying Lee } 693b07b2f5cSHuie-Ying Lee if (match_hostname(host, arg, len) != 1) 694b07b2f5cSHuie-Ying Lee result = 0; 695b07b2f5cSHuie-Ying Lee else 696b07b2f5cSHuie-Ying Lee debug("connection from %.100s matched 'Host " 697b07b2f5cSHuie-Ying Lee "%.100s' at line %d", host, arg, line); 698b07b2f5cSHuie-Ying Lee } else if (strcasecmp(attrib, "address") == 0) { 699b07b2f5cSHuie-Ying Lee switch (addr_match_list(address, arg)) { 700b07b2f5cSHuie-Ying Lee case 1: 701b07b2f5cSHuie-Ying Lee debug("connection from %.100s matched 'Address " 702b07b2f5cSHuie-Ying Lee "%.100s' at line %d", address, arg, line); 703b07b2f5cSHuie-Ying Lee break; 704b07b2f5cSHuie-Ying Lee case 0: 705b07b2f5cSHuie-Ying Lee case -1: 706b07b2f5cSHuie-Ying Lee result = 0; 707b07b2f5cSHuie-Ying Lee break; 708b07b2f5cSHuie-Ying Lee case -2: 709b07b2f5cSHuie-Ying Lee return -1; 710b07b2f5cSHuie-Ying Lee } 711b07b2f5cSHuie-Ying Lee } else { 712b07b2f5cSHuie-Ying Lee error("Unsupported Match attribute %s", attrib); 713b07b2f5cSHuie-Ying Lee return -1; 714b07b2f5cSHuie-Ying Lee } 715b07b2f5cSHuie-Ying Lee } 716b07b2f5cSHuie-Ying Lee if (user != NULL) 717b07b2f5cSHuie-Ying Lee debug3("match %sfound", result ? "" : "not "); 718b07b2f5cSHuie-Ying Lee *condition = cp; 719b07b2f5cSHuie-Ying Lee return result; 720b07b2f5cSHuie-Ying Lee } 721b07b2f5cSHuie-Ying Lee 722b07b2f5cSHuie-Ying Lee #define WHITESPACE " \t\r\n" 723b07b2f5cSHuie-Ying Lee 7247c478bd9Sstevel@tonic-gate int 7257c478bd9Sstevel@tonic-gate process_server_config_line(ServerOptions *options, char *line, 726b07b2f5cSHuie-Ying Lee const char *filename, int linenum, int *activep, const char *user, 727b07b2f5cSHuie-Ying Lee const char *host, const char *address) 7287c478bd9Sstevel@tonic-gate { 7297c478bd9Sstevel@tonic-gate char *cp, **charptr, *arg, *p; 730b07b2f5cSHuie-Ying Lee int cmdline = 0, *intptr, value, n; 7317c478bd9Sstevel@tonic-gate ServerOpCodes opcode; 732b07b2f5cSHuie-Ying Lee u_int i, flags = 0; 7336f8d59d8SJan Pechanec size_t len; 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate cp = line; 7367c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 7377c478bd9Sstevel@tonic-gate /* Ignore leading whitespace */ 7387c478bd9Sstevel@tonic-gate if (*arg == '\0') 7397c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 7407c478bd9Sstevel@tonic-gate if (!arg || !*arg || *arg == '#') 7417c478bd9Sstevel@tonic-gate return 0; 7427c478bd9Sstevel@tonic-gate intptr = NULL; 7437c478bd9Sstevel@tonic-gate charptr = NULL; 744b07b2f5cSHuie-Ying Lee opcode = parse_token(arg, filename, linenum, &flags); 745b07b2f5cSHuie-Ying Lee 746b07b2f5cSHuie-Ying Lee if (activep == NULL) { /* We are processing a command line directive */ 747b07b2f5cSHuie-Ying Lee cmdline = 1; 748b07b2f5cSHuie-Ying Lee activep = &cmdline; 749b07b2f5cSHuie-Ying Lee } 750b07b2f5cSHuie-Ying Lee if (*activep && opcode != sMatch) 751b07b2f5cSHuie-Ying Lee debug3("%s:%d setting %s %s", filename, linenum, arg, cp); 752b07b2f5cSHuie-Ying Lee if (*activep == 0 && !(flags & SSHCFG_MATCH)) { 753b07b2f5cSHuie-Ying Lee if (user == NULL) { 754b07b2f5cSHuie-Ying Lee fatal("%s line %d: Directive '%s' is not allowed " 755b07b2f5cSHuie-Ying Lee "within a Match block", filename, linenum, arg); 756b07b2f5cSHuie-Ying Lee } else { /* this is a directive we have already processed */ 757b07b2f5cSHuie-Ying Lee while (arg) 758b07b2f5cSHuie-Ying Lee arg = strdelim(&cp); 759b07b2f5cSHuie-Ying Lee return 0; 760b07b2f5cSHuie-Ying Lee } 761b07b2f5cSHuie-Ying Lee } 762b07b2f5cSHuie-Ying Lee 7637c478bd9Sstevel@tonic-gate switch (opcode) { 7647c478bd9Sstevel@tonic-gate /* Portable-specific options */ 7657c478bd9Sstevel@tonic-gate case sPAMAuthenticationViaKbdInt: 7667c478bd9Sstevel@tonic-gate intptr = &options->pam_authentication_via_kbd_int; 7677c478bd9Sstevel@tonic-gate goto parse_flag; 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate /* Standard Options */ 7707c478bd9Sstevel@tonic-gate case sBadOption: 7717c478bd9Sstevel@tonic-gate return -1; 7727c478bd9Sstevel@tonic-gate case sPort: 7737c478bd9Sstevel@tonic-gate /* ignore ports from configfile if cmdline specifies ports */ 7747c478bd9Sstevel@tonic-gate if (options->ports_from_cmdline) 7757c478bd9Sstevel@tonic-gate return 0; 7767c478bd9Sstevel@tonic-gate if (options->listen_addrs != NULL) 7777c478bd9Sstevel@tonic-gate fatal("%s line %d: ports must be specified before " 7787c478bd9Sstevel@tonic-gate "ListenAddress.", filename, linenum); 7797c478bd9Sstevel@tonic-gate if (options->num_ports >= MAX_PORTS) 7807c478bd9Sstevel@tonic-gate fatal("%s line %d: too many ports.", 7817c478bd9Sstevel@tonic-gate filename, linenum); 7827c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 7837c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 7847c478bd9Sstevel@tonic-gate fatal("%s line %d: missing port number.", 7857c478bd9Sstevel@tonic-gate filename, linenum); 7867c478bd9Sstevel@tonic-gate options->ports[options->num_ports++] = a2port(arg); 7877c478bd9Sstevel@tonic-gate if (options->ports[options->num_ports-1] == 0) 7887c478bd9Sstevel@tonic-gate fatal("%s line %d: Badly formatted port number.", 7897c478bd9Sstevel@tonic-gate filename, linenum); 7907c478bd9Sstevel@tonic-gate break; 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate case sServerKeyBits: 7937c478bd9Sstevel@tonic-gate intptr = &options->server_key_bits; 7947c478bd9Sstevel@tonic-gate parse_int: 7957c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 7967c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 7977c478bd9Sstevel@tonic-gate fatal("%s line %d: missing integer value.", 7987c478bd9Sstevel@tonic-gate filename, linenum); 7997c478bd9Sstevel@tonic-gate value = atoi(arg); 800b07b2f5cSHuie-Ying Lee if (*activep && *intptr == -1) 8017c478bd9Sstevel@tonic-gate *intptr = value; 8027c478bd9Sstevel@tonic-gate break; 8037c478bd9Sstevel@tonic-gate 8047c478bd9Sstevel@tonic-gate case sLoginGraceTime: 8057c478bd9Sstevel@tonic-gate intptr = &options->login_grace_time; 8067c478bd9Sstevel@tonic-gate parse_time: 8077c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 8087c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 8097c478bd9Sstevel@tonic-gate fatal("%s line %d: missing time value.", 8107c478bd9Sstevel@tonic-gate filename, linenum); 8117c478bd9Sstevel@tonic-gate if ((value = convtime(arg)) == -1) 8127c478bd9Sstevel@tonic-gate fatal("%s line %d: invalid time value.", 8137c478bd9Sstevel@tonic-gate filename, linenum); 8147c478bd9Sstevel@tonic-gate if (*intptr == -1) 8157c478bd9Sstevel@tonic-gate *intptr = value; 8167c478bd9Sstevel@tonic-gate break; 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate case sKeyRegenerationTime: 8197c478bd9Sstevel@tonic-gate intptr = &options->key_regeneration_time; 8207c478bd9Sstevel@tonic-gate goto parse_time; 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate case sListenAddress: 8237c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 8247c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0) 8257c478bd9Sstevel@tonic-gate fatal("%s line %d: missing inet addr.", 8267c478bd9Sstevel@tonic-gate filename, linenum); 8277c478bd9Sstevel@tonic-gate if (*arg == '[') { 8287c478bd9Sstevel@tonic-gate if ((p = strchr(arg, ']')) == NULL) 8297c478bd9Sstevel@tonic-gate fatal("%s line %d: bad ipv6 inet addr usage.", 8307c478bd9Sstevel@tonic-gate filename, linenum); 8317c478bd9Sstevel@tonic-gate arg++; 8327c478bd9Sstevel@tonic-gate (void) memmove(p, p+1, strlen(p+1)+1); 8337c478bd9Sstevel@tonic-gate } else if (((p = strchr(arg, ':')) == NULL) || 8347c478bd9Sstevel@tonic-gate (strchr(p+1, ':') != NULL)) { 8357c478bd9Sstevel@tonic-gate add_listen_addr(options, arg, 0); 8367c478bd9Sstevel@tonic-gate break; 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate if (*p == ':') { 8397c478bd9Sstevel@tonic-gate u_short port; 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate p++; 8427c478bd9Sstevel@tonic-gate if (*p == '\0') 8437c478bd9Sstevel@tonic-gate fatal("%s line %d: bad inet addr:port usage.", 8447c478bd9Sstevel@tonic-gate filename, linenum); 8457c478bd9Sstevel@tonic-gate else { 8467c478bd9Sstevel@tonic-gate *(p-1) = '\0'; 8477c478bd9Sstevel@tonic-gate if ((port = a2port(p)) == 0) 8487c478bd9Sstevel@tonic-gate fatal("%s line %d: bad port number.", 8497c478bd9Sstevel@tonic-gate filename, linenum); 8507c478bd9Sstevel@tonic-gate add_listen_addr(options, arg, port); 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate } else if (*p == '\0') 8537c478bd9Sstevel@tonic-gate add_listen_addr(options, arg, 0); 8547c478bd9Sstevel@tonic-gate else 8557c478bd9Sstevel@tonic-gate fatal("%s line %d: bad inet addr usage.", 8567c478bd9Sstevel@tonic-gate filename, linenum); 8577c478bd9Sstevel@tonic-gate break; 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate case sHostKeyFile: 8607c478bd9Sstevel@tonic-gate intptr = &options->num_host_key_files; 8617c478bd9Sstevel@tonic-gate if (*intptr >= MAX_HOSTKEYS) 8627c478bd9Sstevel@tonic-gate fatal("%s line %d: too many host keys specified (max %d).", 8637c478bd9Sstevel@tonic-gate filename, linenum, MAX_HOSTKEYS); 8647c478bd9Sstevel@tonic-gate charptr = &options->host_key_files[*intptr]; 8657c478bd9Sstevel@tonic-gate parse_filename: 8667c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 8677c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 8687c478bd9Sstevel@tonic-gate fatal("%s line %d: missing file name.", 8697c478bd9Sstevel@tonic-gate filename, linenum); 870b07b2f5cSHuie-Ying Lee if (*activep && *charptr == NULL) { 8717c478bd9Sstevel@tonic-gate *charptr = tilde_expand_filename(arg, getuid()); 8727c478bd9Sstevel@tonic-gate /* increase optional counter */ 8737c478bd9Sstevel@tonic-gate if (intptr != NULL) 8747c478bd9Sstevel@tonic-gate *intptr = *intptr + 1; 8757c478bd9Sstevel@tonic-gate } 8767c478bd9Sstevel@tonic-gate break; 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate case sPidFile: 8797c478bd9Sstevel@tonic-gate charptr = &options->pid_file; 8807c478bd9Sstevel@tonic-gate goto parse_filename; 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate case sPermitRootLogin: 8837c478bd9Sstevel@tonic-gate intptr = &options->permit_root_login; 8847c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 8857c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 8867c478bd9Sstevel@tonic-gate fatal("%s line %d: missing yes/" 8877c478bd9Sstevel@tonic-gate "without-password/forced-commands-only/no " 8887c478bd9Sstevel@tonic-gate "argument.", filename, linenum); 8897c478bd9Sstevel@tonic-gate value = 0; /* silence compiler */ 8907c478bd9Sstevel@tonic-gate if (strcmp(arg, "without-password") == 0) 8917c478bd9Sstevel@tonic-gate value = PERMIT_NO_PASSWD; 8927c478bd9Sstevel@tonic-gate else if (strcmp(arg, "forced-commands-only") == 0) 8937c478bd9Sstevel@tonic-gate value = PERMIT_FORCED_ONLY; 8947c478bd9Sstevel@tonic-gate else if (strcmp(arg, "yes") == 0) 8957c478bd9Sstevel@tonic-gate value = PERMIT_YES; 8967c478bd9Sstevel@tonic-gate else if (strcmp(arg, "no") == 0) 8977c478bd9Sstevel@tonic-gate value = PERMIT_NO; 8987c478bd9Sstevel@tonic-gate else 8997c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad yes/" 9007c478bd9Sstevel@tonic-gate "without-password/forced-commands-only/no " 9017c478bd9Sstevel@tonic-gate "argument: %s", filename, linenum, arg); 902b07b2f5cSHuie-Ying Lee if (*activep && *intptr == -1) 9037c478bd9Sstevel@tonic-gate *intptr = value; 9047c478bd9Sstevel@tonic-gate break; 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate case sIgnoreRhosts: 9077c478bd9Sstevel@tonic-gate intptr = &options->ignore_rhosts; 9087c478bd9Sstevel@tonic-gate parse_flag: 9097c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 9107c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 9117c478bd9Sstevel@tonic-gate fatal("%s line %d: missing yes/no argument.", 9127c478bd9Sstevel@tonic-gate filename, linenum); 9137c478bd9Sstevel@tonic-gate value = 0; /* silence compiler */ 9147c478bd9Sstevel@tonic-gate if (strcmp(arg, "yes") == 0) 9157c478bd9Sstevel@tonic-gate value = 1; 9167c478bd9Sstevel@tonic-gate else if (strcmp(arg, "no") == 0) 9177c478bd9Sstevel@tonic-gate value = 0; 9187c478bd9Sstevel@tonic-gate else 9197c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad yes/no argument: %s", 9207c478bd9Sstevel@tonic-gate filename, linenum, arg); 921b07b2f5cSHuie-Ying Lee if (*activep && *intptr == -1) 9227c478bd9Sstevel@tonic-gate *intptr = value; 9237c478bd9Sstevel@tonic-gate break; 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate case sIgnoreUserKnownHosts: 9267c478bd9Sstevel@tonic-gate intptr = &options->ignore_user_known_hosts; 9277c478bd9Sstevel@tonic-gate goto parse_flag; 9287c478bd9Sstevel@tonic-gate 9297c478bd9Sstevel@tonic-gate case sRhostsAuthentication: 9307c478bd9Sstevel@tonic-gate intptr = &options->rhosts_authentication; 9317c478bd9Sstevel@tonic-gate goto parse_flag; 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate case sRhostsRSAAuthentication: 9347c478bd9Sstevel@tonic-gate intptr = &options->rhosts_rsa_authentication; 9357c478bd9Sstevel@tonic-gate goto parse_flag; 9367c478bd9Sstevel@tonic-gate 9377c478bd9Sstevel@tonic-gate case sHostbasedAuthentication: 9387c478bd9Sstevel@tonic-gate intptr = &options->hostbased_authentication; 9397c478bd9Sstevel@tonic-gate goto parse_flag; 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate case sHostbasedUsesNameFromPacketOnly: 9427c478bd9Sstevel@tonic-gate intptr = &options->hostbased_uses_name_from_packet_only; 9437c478bd9Sstevel@tonic-gate goto parse_flag; 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate case sRSAAuthentication: 9467c478bd9Sstevel@tonic-gate intptr = &options->rsa_authentication; 9477c478bd9Sstevel@tonic-gate goto parse_flag; 9487c478bd9Sstevel@tonic-gate 9497c478bd9Sstevel@tonic-gate case sPubkeyAuthentication: 9507c478bd9Sstevel@tonic-gate intptr = &options->pubkey_authentication; 9517c478bd9Sstevel@tonic-gate goto parse_flag; 9527c478bd9Sstevel@tonic-gate #ifdef GSSAPI 9537c478bd9Sstevel@tonic-gate case sGssAuthentication: 9547c478bd9Sstevel@tonic-gate intptr = &options->gss_authentication; 9557c478bd9Sstevel@tonic-gate goto parse_flag; 9567c478bd9Sstevel@tonic-gate case sGssKeyEx: 9577c478bd9Sstevel@tonic-gate intptr = &options->gss_keyex; 9587c478bd9Sstevel@tonic-gate goto parse_flag; 9597c478bd9Sstevel@tonic-gate case sGssStoreDelegCreds: 9607c478bd9Sstevel@tonic-gate intptr = &options->gss_keyex; 9617c478bd9Sstevel@tonic-gate goto parse_flag; 9627c478bd9Sstevel@tonic-gate #ifndef SUNW_GSSAPI 9637c478bd9Sstevel@tonic-gate case sGssUseSessionCredCache: 9647c478bd9Sstevel@tonic-gate intptr = &options->gss_use_session_ccache; 9657c478bd9Sstevel@tonic-gate goto parse_flag; 9667c478bd9Sstevel@tonic-gate case sGssCleanupCreds: 9677c478bd9Sstevel@tonic-gate intptr = &options->gss_cleanup_creds; 9687c478bd9Sstevel@tonic-gate goto parse_flag; 9697c478bd9Sstevel@tonic-gate #endif /* SUNW_GSSAPI */ 9707c478bd9Sstevel@tonic-gate #endif /* GSSAPI */ 9717c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5) 9727c478bd9Sstevel@tonic-gate case sKerberosAuthentication: 9737c478bd9Sstevel@tonic-gate intptr = &options->kerberos_authentication; 9747c478bd9Sstevel@tonic-gate goto parse_flag; 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate case sKerberosOrLocalPasswd: 9777c478bd9Sstevel@tonic-gate intptr = &options->kerberos_or_local_passwd; 9787c478bd9Sstevel@tonic-gate goto parse_flag; 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate case sKerberosTicketCleanup: 9817c478bd9Sstevel@tonic-gate intptr = &options->kerberos_ticket_cleanup; 9827c478bd9Sstevel@tonic-gate goto parse_flag; 9837c478bd9Sstevel@tonic-gate #endif 9847c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5) 9857c478bd9Sstevel@tonic-gate case sKerberosTgtPassing: 9867c478bd9Sstevel@tonic-gate intptr = &options->kerberos_tgt_passing; 9877c478bd9Sstevel@tonic-gate goto parse_flag; 9887c478bd9Sstevel@tonic-gate #endif 9897c478bd9Sstevel@tonic-gate #ifdef AFS 9907c478bd9Sstevel@tonic-gate case sAFSTokenPassing: 9917c478bd9Sstevel@tonic-gate intptr = &options->afs_token_passing; 9927c478bd9Sstevel@tonic-gate goto parse_flag; 9937c478bd9Sstevel@tonic-gate #endif 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate case sPasswordAuthentication: 9967c478bd9Sstevel@tonic-gate intptr = &options->password_authentication; 9977c478bd9Sstevel@tonic-gate goto parse_flag; 9987c478bd9Sstevel@tonic-gate 9997c478bd9Sstevel@tonic-gate case sKbdInteractiveAuthentication: 10007c478bd9Sstevel@tonic-gate intptr = &options->kbd_interactive_authentication; 10017c478bd9Sstevel@tonic-gate goto parse_flag; 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate case sChallengeResponseAuthentication: 10047c478bd9Sstevel@tonic-gate intptr = &options->challenge_response_authentication; 10057c478bd9Sstevel@tonic-gate goto parse_flag; 10067c478bd9Sstevel@tonic-gate 10077c478bd9Sstevel@tonic-gate case sPrintMotd: 10087c478bd9Sstevel@tonic-gate intptr = &options->print_motd; 10097c478bd9Sstevel@tonic-gate goto parse_flag; 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate case sPrintLastLog: 10127c478bd9Sstevel@tonic-gate intptr = &options->print_lastlog; 10137c478bd9Sstevel@tonic-gate goto parse_flag; 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate case sX11Forwarding: 10167c478bd9Sstevel@tonic-gate intptr = &options->x11_forwarding; 10177c478bd9Sstevel@tonic-gate goto parse_flag; 10187c478bd9Sstevel@tonic-gate 10197c478bd9Sstevel@tonic-gate case sX11DisplayOffset: 10207c478bd9Sstevel@tonic-gate intptr = &options->x11_display_offset; 10217c478bd9Sstevel@tonic-gate goto parse_int; 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate case sX11UseLocalhost: 10247c478bd9Sstevel@tonic-gate intptr = &options->x11_use_localhost; 10257c478bd9Sstevel@tonic-gate goto parse_flag; 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate case sXAuthLocation: 10287c478bd9Sstevel@tonic-gate charptr = &options->xauth_location; 10297c478bd9Sstevel@tonic-gate goto parse_filename; 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate case sStrictModes: 10327c478bd9Sstevel@tonic-gate intptr = &options->strict_modes; 10337c478bd9Sstevel@tonic-gate goto parse_flag; 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate case sKeepAlives: 10367c478bd9Sstevel@tonic-gate intptr = &options->keepalives; 10377c478bd9Sstevel@tonic-gate goto parse_flag; 10387c478bd9Sstevel@tonic-gate 10397c478bd9Sstevel@tonic-gate case sEmptyPasswd: 10407c478bd9Sstevel@tonic-gate intptr = &options->permit_empty_passwd; 10417c478bd9Sstevel@tonic-gate goto parse_flag; 10427c478bd9Sstevel@tonic-gate 10437c478bd9Sstevel@tonic-gate case sPermitUserEnvironment: 10447c478bd9Sstevel@tonic-gate intptr = &options->permit_user_env; 10457c478bd9Sstevel@tonic-gate goto parse_flag; 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate case sUseLogin: 1048b9aa66a7SJan Pechanec log("%s line %d: ignoring UseLogin option value." 1049b9aa66a7SJan Pechanec " This option is always off.", filename, linenum); 1050b9aa66a7SJan Pechanec while (arg) 1051b9aa66a7SJan Pechanec arg = strdelim(&cp); 1052b9aa66a7SJan Pechanec break; 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate case sCompression: 10557c478bd9Sstevel@tonic-gate intptr = &options->compression; 10567c478bd9Sstevel@tonic-gate goto parse_flag; 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate case sGatewayPorts: 1059b07b2f5cSHuie-Ying Lee intptr = &options->gateway_ports; 10609b03ea0fSjp161948 arg = strdelim(&cp); 1061b07b2f5cSHuie-Ying Lee if (!arg || *arg == '\0') 1062b07b2f5cSHuie-Ying Lee fatal("%s line %d: missing yes/no/clientspecified " 10639b03ea0fSjp161948 "argument.", filename, linenum); 1064b07b2f5cSHuie-Ying Lee value = 0; /* silence compiler */ 1065b07b2f5cSHuie-Ying Lee if (strcmp(arg, "clientspecified") == 0) 1066b07b2f5cSHuie-Ying Lee value = 2; 1067b07b2f5cSHuie-Ying Lee else if (strcmp(arg, "yes") == 0) 1068b07b2f5cSHuie-Ying Lee value = 1; 1069b07b2f5cSHuie-Ying Lee else if (strcmp(arg, "no") == 0) 1070b07b2f5cSHuie-Ying Lee value = 0; 1071b07b2f5cSHuie-Ying Lee else 1072b07b2f5cSHuie-Ying Lee fatal("%s line %d: Bad yes/no/clientspecified " 1073b07b2f5cSHuie-Ying Lee "argument: %s", filename, linenum, arg); 1074b07b2f5cSHuie-Ying Lee if (*activep && *intptr == -1) 1075b07b2f5cSHuie-Ying Lee *intptr = value; 10769b03ea0fSjp161948 break; 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate case sVerifyReverseMapping: 10797c478bd9Sstevel@tonic-gate intptr = &options->verify_reverse_mapping; 10807c478bd9Sstevel@tonic-gate goto parse_flag; 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate case sLogFacility: 10837c478bd9Sstevel@tonic-gate intptr = (int *) &options->log_facility; 10847c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 10857c478bd9Sstevel@tonic-gate value = log_facility_number(arg); 10867c478bd9Sstevel@tonic-gate if (value == SYSLOG_FACILITY_NOT_SET) 10877c478bd9Sstevel@tonic-gate fatal("%.200s line %d: unsupported log facility '%s'", 10887c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 10897c478bd9Sstevel@tonic-gate if (*intptr == -1) 10907c478bd9Sstevel@tonic-gate *intptr = (SyslogFacility) value; 10917c478bd9Sstevel@tonic-gate break; 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate case sLogLevel: 10947c478bd9Sstevel@tonic-gate intptr = (int *) &options->log_level; 10957c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 10967c478bd9Sstevel@tonic-gate value = log_level_number(arg); 10977c478bd9Sstevel@tonic-gate if (value == SYSLOG_LEVEL_NOT_SET) 10987c478bd9Sstevel@tonic-gate fatal("%.200s line %d: unsupported log level '%s'", 10997c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 11007c478bd9Sstevel@tonic-gate if (*intptr == -1) 11017c478bd9Sstevel@tonic-gate *intptr = (LogLevel) value; 11027c478bd9Sstevel@tonic-gate break; 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate case sAllowTcpForwarding: 11057c478bd9Sstevel@tonic-gate intptr = &options->allow_tcp_forwarding; 11067c478bd9Sstevel@tonic-gate goto parse_flag; 11077c478bd9Sstevel@tonic-gate 11087c478bd9Sstevel@tonic-gate case sUsePrivilegeSeparation: 11099a8058b5Sjp161948 log("%s line %d: ignoring UsePrivilegeSeparation option value." 11109a8058b5Sjp161948 " This option is always on.", filename, linenum); 11119a8058b5Sjp161948 while (arg) 11129a8058b5Sjp161948 arg = strdelim(&cp); 11139a8058b5Sjp161948 break; 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate case sAllowUsers: 11167c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 11177c478bd9Sstevel@tonic-gate if (options->num_allow_users >= MAX_ALLOW_USERS) 11187c478bd9Sstevel@tonic-gate fatal("%s line %d: too many allow users.", 11197c478bd9Sstevel@tonic-gate filename, linenum); 11207c478bd9Sstevel@tonic-gate options->allow_users[options->num_allow_users++] = 11217c478bd9Sstevel@tonic-gate xstrdup(arg); 11227c478bd9Sstevel@tonic-gate } 11237c478bd9Sstevel@tonic-gate break; 11247c478bd9Sstevel@tonic-gate 11257c478bd9Sstevel@tonic-gate case sDenyUsers: 11267c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 11277c478bd9Sstevel@tonic-gate if (options->num_deny_users >= MAX_DENY_USERS) 11287c478bd9Sstevel@tonic-gate fatal( "%s line %d: too many deny users.", 11297c478bd9Sstevel@tonic-gate filename, linenum); 11307c478bd9Sstevel@tonic-gate options->deny_users[options->num_deny_users++] = 11317c478bd9Sstevel@tonic-gate xstrdup(arg); 11327c478bd9Sstevel@tonic-gate } 11337c478bd9Sstevel@tonic-gate break; 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate case sAllowGroups: 11367c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 11377c478bd9Sstevel@tonic-gate if (options->num_allow_groups >= MAX_ALLOW_GROUPS) 11387c478bd9Sstevel@tonic-gate fatal("%s line %d: too many allow groups.", 11397c478bd9Sstevel@tonic-gate filename, linenum); 11407c478bd9Sstevel@tonic-gate options->allow_groups[options->num_allow_groups++] = 11417c478bd9Sstevel@tonic-gate xstrdup(arg); 11427c478bd9Sstevel@tonic-gate } 11437c478bd9Sstevel@tonic-gate break; 11447c478bd9Sstevel@tonic-gate 11457c478bd9Sstevel@tonic-gate case sDenyGroups: 11467c478bd9Sstevel@tonic-gate while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') { 11477c478bd9Sstevel@tonic-gate if (options->num_deny_groups >= MAX_DENY_GROUPS) 11487c478bd9Sstevel@tonic-gate fatal("%s line %d: too many deny groups.", 11497c478bd9Sstevel@tonic-gate filename, linenum); 11507c478bd9Sstevel@tonic-gate options->deny_groups[options->num_deny_groups++] = xstrdup(arg); 11517c478bd9Sstevel@tonic-gate } 11527c478bd9Sstevel@tonic-gate break; 11537c478bd9Sstevel@tonic-gate 11547c478bd9Sstevel@tonic-gate case sCiphers: 11557c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 11567c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 11577c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing argument.", filename, linenum); 11587c478bd9Sstevel@tonic-gate if (!ciphers_valid(arg)) 11597c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad SSH2 cipher spec '%s'.", 11607c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 11617c478bd9Sstevel@tonic-gate if (options->ciphers == NULL) 11627c478bd9Sstevel@tonic-gate options->ciphers = xstrdup(arg); 11637c478bd9Sstevel@tonic-gate break; 11647c478bd9Sstevel@tonic-gate 11657c478bd9Sstevel@tonic-gate case sMacs: 11667c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 11677c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 11687c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing argument.", filename, linenum); 11697c478bd9Sstevel@tonic-gate if (!mac_valid(arg)) 11707c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad SSH2 mac spec '%s'.", 11717c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 11727c478bd9Sstevel@tonic-gate if (options->macs == NULL) 11737c478bd9Sstevel@tonic-gate options->macs = xstrdup(arg); 11747c478bd9Sstevel@tonic-gate break; 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate case sProtocol: 11777c478bd9Sstevel@tonic-gate intptr = &options->protocol; 11787c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 11797c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 11807c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing argument.", filename, linenum); 11817c478bd9Sstevel@tonic-gate value = proto_spec(arg); 11827c478bd9Sstevel@tonic-gate if (value == SSH_PROTO_UNKNOWN) 11837c478bd9Sstevel@tonic-gate fatal("%s line %d: Bad protocol spec '%s'.", 11847c478bd9Sstevel@tonic-gate filename, linenum, arg ? arg : "<NONE>"); 11857c478bd9Sstevel@tonic-gate if (*intptr == SSH_PROTO_UNKNOWN) 11867c478bd9Sstevel@tonic-gate *intptr = value; 11877c478bd9Sstevel@tonic-gate break; 11887c478bd9Sstevel@tonic-gate 11897c478bd9Sstevel@tonic-gate case sSubsystem: 11907c478bd9Sstevel@tonic-gate if (options->num_subsystems >= MAX_SUBSYSTEMS) { 11917c478bd9Sstevel@tonic-gate fatal("%s line %d: too many subsystems defined.", 11927c478bd9Sstevel@tonic-gate filename, linenum); 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 11957c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 11967c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing subsystem name.", 11977c478bd9Sstevel@tonic-gate filename, linenum); 1198b07b2f5cSHuie-Ying Lee if (!*activep) { 1199b07b2f5cSHuie-Ying Lee arg = strdelim(&cp); 1200b07b2f5cSHuie-Ying Lee break; 1201b07b2f5cSHuie-Ying Lee } 12027c478bd9Sstevel@tonic-gate for (i = 0; i < options->num_subsystems; i++) 12037c478bd9Sstevel@tonic-gate if (strcmp(arg, options->subsystem_name[i]) == 0) 12047c478bd9Sstevel@tonic-gate fatal("%s line %d: Subsystem '%s' already defined.", 12057c478bd9Sstevel@tonic-gate filename, linenum, arg); 12067c478bd9Sstevel@tonic-gate options->subsystem_name[options->num_subsystems] = xstrdup(arg); 12077c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 12087c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 12097c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing subsystem command.", 12107c478bd9Sstevel@tonic-gate filename, linenum); 12117c478bd9Sstevel@tonic-gate options->subsystem_command[options->num_subsystems] = xstrdup(arg); 12126f8d59d8SJan Pechanec 12136f8d59d8SJan Pechanec /* 12146f8d59d8SJan Pechanec * Collect arguments (separate to executable), including the 12156f8d59d8SJan Pechanec * name of the executable, in a way that is easier to parse 12166f8d59d8SJan Pechanec * later. 12176f8d59d8SJan Pechanec */ 12186f8d59d8SJan Pechanec p = xstrdup(arg); 12196f8d59d8SJan Pechanec len = strlen(p) + 1; 12206f8d59d8SJan Pechanec while ((arg = strdelim(&cp)) != NULL && *arg != '\0') { 12216f8d59d8SJan Pechanec len += 1 + strlen(arg); 12226f8d59d8SJan Pechanec p = xrealloc(p, len); 12236f8d59d8SJan Pechanec strlcat(p, " ", len); 12246f8d59d8SJan Pechanec strlcat(p, arg, len); 12256f8d59d8SJan Pechanec } 12266f8d59d8SJan Pechanec options->subsystem_args[options->num_subsystems] = p; 12277c478bd9Sstevel@tonic-gate options->num_subsystems++; 12287c478bd9Sstevel@tonic-gate break; 12297c478bd9Sstevel@tonic-gate 12307c478bd9Sstevel@tonic-gate case sMaxStartups: 12317c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 12327c478bd9Sstevel@tonic-gate if (!arg || *arg == '\0') 12337c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing MaxStartups spec.", 12347c478bd9Sstevel@tonic-gate filename, linenum); 12357c478bd9Sstevel@tonic-gate if ((n = sscanf(arg, "%d:%d:%d", 12367c478bd9Sstevel@tonic-gate &options->max_startups_begin, 12377c478bd9Sstevel@tonic-gate &options->max_startups_rate, 12387c478bd9Sstevel@tonic-gate &options->max_startups)) == 3) { 12397c478bd9Sstevel@tonic-gate if (options->max_startups_begin > 12407c478bd9Sstevel@tonic-gate options->max_startups || 12417c478bd9Sstevel@tonic-gate options->max_startups_rate > 100 || 12427c478bd9Sstevel@tonic-gate options->max_startups_rate < 1) 12437c478bd9Sstevel@tonic-gate fatal("%s line %d: Illegal MaxStartups spec.", 12447c478bd9Sstevel@tonic-gate filename, linenum); 12457c478bd9Sstevel@tonic-gate } else if (n != 1) 12467c478bd9Sstevel@tonic-gate fatal("%s line %d: Illegal MaxStartups spec.", 12477c478bd9Sstevel@tonic-gate filename, linenum); 12487c478bd9Sstevel@tonic-gate else 12497c478bd9Sstevel@tonic-gate options->max_startups = options->max_startups_begin; 12507c478bd9Sstevel@tonic-gate break; 12517c478bd9Sstevel@tonic-gate 12527c478bd9Sstevel@tonic-gate case sBanner: 12537c478bd9Sstevel@tonic-gate charptr = &options->banner; 12547c478bd9Sstevel@tonic-gate goto parse_filename; 12557c478bd9Sstevel@tonic-gate /* 12567c478bd9Sstevel@tonic-gate * These options can contain %X options expanded at 12577c478bd9Sstevel@tonic-gate * connect time, so that you can specify paths like: 12587c478bd9Sstevel@tonic-gate * 12597c478bd9Sstevel@tonic-gate * AuthorizedKeysFile /etc/ssh_keys/%u 12607c478bd9Sstevel@tonic-gate */ 12617c478bd9Sstevel@tonic-gate case sAuthorizedKeysFile: 12627c478bd9Sstevel@tonic-gate case sAuthorizedKeysFile2: 12637c478bd9Sstevel@tonic-gate charptr = (opcode == sAuthorizedKeysFile) ? 12647c478bd9Sstevel@tonic-gate &options->authorized_keys_file : 12657c478bd9Sstevel@tonic-gate &options->authorized_keys_file2; 12667c478bd9Sstevel@tonic-gate goto parse_filename; 12677c478bd9Sstevel@tonic-gate 12687c478bd9Sstevel@tonic-gate case sClientAliveInterval: 12697c478bd9Sstevel@tonic-gate intptr = &options->client_alive_interval; 12707c478bd9Sstevel@tonic-gate goto parse_time; 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate case sClientAliveCountMax: 12737c478bd9Sstevel@tonic-gate intptr = &options->client_alive_count_max; 12747c478bd9Sstevel@tonic-gate goto parse_int; 12757c478bd9Sstevel@tonic-gate 12767c478bd9Sstevel@tonic-gate case sMaxAuthTries: 12777c478bd9Sstevel@tonic-gate intptr = &options->max_auth_tries; 12787c478bd9Sstevel@tonic-gate goto parse_int; 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate case sMaxAuthTriesLog: 12817c478bd9Sstevel@tonic-gate intptr = &options->max_auth_tries_log; 12827c478bd9Sstevel@tonic-gate goto parse_int; 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate case sLookupClientHostnames: 12857c478bd9Sstevel@tonic-gate intptr = &options->lookup_client_hostnames; 12867c478bd9Sstevel@tonic-gate goto parse_flag; 12876f8d59d8SJan Pechanec 1288cd7d5fafSJan Pechanec case sUseOpenSSLEngine: 1289cd7d5fafSJan Pechanec intptr = &options->use_openssl_engine; 1290cd7d5fafSJan Pechanec goto parse_flag; 12917c478bd9Sstevel@tonic-gate 12926f8d59d8SJan Pechanec case sChrootDirectory: 12936f8d59d8SJan Pechanec charptr = &options->chroot_directory; 12946f8d59d8SJan Pechanec 12956f8d59d8SJan Pechanec arg = strdelim(&cp); 12966f8d59d8SJan Pechanec if (arg == NULL || *arg == '\0') 12976f8d59d8SJan Pechanec fatal("%s line %d: missing directory name for " 12986f8d59d8SJan Pechanec "ChrootDirectory.", filename, linenum); 1299b07b2f5cSHuie-Ying Lee if (*activep && *charptr == NULL) 13006f8d59d8SJan Pechanec *charptr = xstrdup(arg); 13016f8d59d8SJan Pechanec break; 13026f8d59d8SJan Pechanec 1303*d8a94255SErik Trauschke case sPreUserauthHook: 1304*d8a94255SErik Trauschke charptr = &options->pre_userauth_hook; 1305*d8a94255SErik Trauschke goto parse_filename; 1306*d8a94255SErik Trauschke 1307b07b2f5cSHuie-Ying Lee case sMatch: 1308b07b2f5cSHuie-Ying Lee if (cmdline) 1309b07b2f5cSHuie-Ying Lee fatal("Match directive not supported as a command-line " 1310b07b2f5cSHuie-Ying Lee "option"); 1311b07b2f5cSHuie-Ying Lee value = match_cfg_line(&cp, linenum, user, host, address); 1312b07b2f5cSHuie-Ying Lee if (value < 0) 1313b07b2f5cSHuie-Ying Lee fatal("%s line %d: Bad Match condition", filename, 1314b07b2f5cSHuie-Ying Lee linenum); 1315b07b2f5cSHuie-Ying Lee *activep = value; 1316b07b2f5cSHuie-Ying Lee break; 1317b07b2f5cSHuie-Ying Lee 13187c478bd9Sstevel@tonic-gate case sDeprecated: 13197c478bd9Sstevel@tonic-gate log("%s line %d: Deprecated option %s", 13207c478bd9Sstevel@tonic-gate filename, linenum, arg); 13217c478bd9Sstevel@tonic-gate while (arg) 13227c478bd9Sstevel@tonic-gate arg = strdelim(&cp); 13237c478bd9Sstevel@tonic-gate break; 13247c478bd9Sstevel@tonic-gate 13257c478bd9Sstevel@tonic-gate default: 13267c478bd9Sstevel@tonic-gate fatal("%s line %d: Missing handler for opcode %s (%d)", 13277c478bd9Sstevel@tonic-gate filename, linenum, arg, opcode); 13287c478bd9Sstevel@tonic-gate } 13297c478bd9Sstevel@tonic-gate if ((arg = strdelim(&cp)) != NULL && *arg != '\0') 13307c478bd9Sstevel@tonic-gate fatal("%s line %d: garbage at end of line; \"%.200s\".", 13317c478bd9Sstevel@tonic-gate filename, linenum, arg); 13327c478bd9Sstevel@tonic-gate return 0; 13337c478bd9Sstevel@tonic-gate } 13347c478bd9Sstevel@tonic-gate 1335b07b2f5cSHuie-Ying Lee 13367c478bd9Sstevel@tonic-gate /* Reads the server configuration file. */ 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate void 1339b07b2f5cSHuie-Ying Lee load_server_config(const char *filename, Buffer *conf) 13407c478bd9Sstevel@tonic-gate { 1341b07b2f5cSHuie-Ying Lee char line[1024], *cp; 13427c478bd9Sstevel@tonic-gate FILE *f; 13437c478bd9Sstevel@tonic-gate 1344b07b2f5cSHuie-Ying Lee debug2("%s: filename %s", __func__, filename); 1345b07b2f5cSHuie-Ying Lee if ((f = fopen(filename, "r")) == NULL) { 13467c478bd9Sstevel@tonic-gate perror(filename); 13477c478bd9Sstevel@tonic-gate exit(1); 13487c478bd9Sstevel@tonic-gate } 1349b07b2f5cSHuie-Ying Lee buffer_clear(conf); 13507c478bd9Sstevel@tonic-gate while (fgets(line, sizeof(line), f)) { 1351b07b2f5cSHuie-Ying Lee /* 1352b07b2f5cSHuie-Ying Lee * Trim out comments and strip whitespace 1353b07b2f5cSHuie-Ying Lee * NB - preserve newlines, they are needed to reproduce 1354b07b2f5cSHuie-Ying Lee * line numbers later for error messages 1355b07b2f5cSHuie-Ying Lee */ 1356b07b2f5cSHuie-Ying Lee if ((cp = strchr(line, '#')) != NULL) 1357b07b2f5cSHuie-Ying Lee memcpy(cp, "\n", 2); 1358b07b2f5cSHuie-Ying Lee cp = line + strspn(line, " \t\r"); 1359b07b2f5cSHuie-Ying Lee 1360b07b2f5cSHuie-Ying Lee buffer_append(conf, cp, strlen(cp)); 1361b07b2f5cSHuie-Ying Lee } 1362b07b2f5cSHuie-Ying Lee buffer_append(conf, "\0", 1); 1363b07b2f5cSHuie-Ying Lee fclose(f); 1364b07b2f5cSHuie-Ying Lee debug2("%s: done config len = %d", __func__, buffer_len(conf)); 1365b07b2f5cSHuie-Ying Lee } 1366b07b2f5cSHuie-Ying Lee 1367b07b2f5cSHuie-Ying Lee void 1368b07b2f5cSHuie-Ying Lee parse_server_match_config(ServerOptions *options, const char *user, 1369b07b2f5cSHuie-Ying Lee const char *host, const char *address) 1370b07b2f5cSHuie-Ying Lee { 1371b07b2f5cSHuie-Ying Lee ServerOptions mo; 1372b07b2f5cSHuie-Ying Lee 1373b07b2f5cSHuie-Ying Lee initialize_server_options(&mo); 1374b07b2f5cSHuie-Ying Lee parse_server_config(&mo, "reprocess config", &cfg, user, host, address); 1375b07b2f5cSHuie-Ying Lee copy_set_server_options(options, &mo, 0); 1376b07b2f5cSHuie-Ying Lee } 1377b07b2f5cSHuie-Ying Lee 1378b07b2f5cSHuie-Ying Lee 1379b07b2f5cSHuie-Ying Lee 1380b07b2f5cSHuie-Ying Lee /* Helper macros */ 1381b07b2f5cSHuie-Ying Lee #define M_CP_INTOPT(n) do {\ 1382b07b2f5cSHuie-Ying Lee if (src->n != -1) \ 1383b07b2f5cSHuie-Ying Lee dst->n = src->n; \ 1384b07b2f5cSHuie-Ying Lee } while (0) 1385b07b2f5cSHuie-Ying Lee #define M_CP_STROPT(n) do {\ 1386b07b2f5cSHuie-Ying Lee if (src->n != NULL) { \ 1387b07b2f5cSHuie-Ying Lee if (dst->n != NULL) \ 1388b07b2f5cSHuie-Ying Lee xfree(dst->n); \ 1389b07b2f5cSHuie-Ying Lee dst->n = src->n; \ 1390b07b2f5cSHuie-Ying Lee } \ 1391b07b2f5cSHuie-Ying Lee } while(0) 1392b07b2f5cSHuie-Ying Lee 1393b07b2f5cSHuie-Ying Lee /* 1394b07b2f5cSHuie-Ying Lee * Copy any supported values that are set. 1395b07b2f5cSHuie-Ying Lee * 1396b07b2f5cSHuie-Ying Lee * If the preauth flag is set, we do not bother copying the the string or 1397b07b2f5cSHuie-Ying Lee * array values that are not used pre-authentication, because any that we 1398b07b2f5cSHuie-Ying Lee * do use must be explictly sent in mm_getpwnamallow(). 1399b07b2f5cSHuie-Ying Lee */ 1400b07b2f5cSHuie-Ying Lee void 1401b07b2f5cSHuie-Ying Lee copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth) 1402b07b2f5cSHuie-Ying Lee { 1403b07b2f5cSHuie-Ying Lee M_CP_INTOPT(password_authentication); 1404b07b2f5cSHuie-Ying Lee M_CP_INTOPT(gss_authentication); 1405b07b2f5cSHuie-Ying Lee M_CP_INTOPT(rsa_authentication); 1406b07b2f5cSHuie-Ying Lee M_CP_INTOPT(pubkey_authentication); 1407b07b2f5cSHuie-Ying Lee M_CP_INTOPT(hostbased_authentication); 1408b07b2f5cSHuie-Ying Lee M_CP_INTOPT(kbd_interactive_authentication); 1409b07b2f5cSHuie-Ying Lee M_CP_INTOPT(permit_root_login); 1410b07b2f5cSHuie-Ying Lee M_CP_INTOPT(permit_empty_passwd); 1411b07b2f5cSHuie-Ying Lee M_CP_INTOPT(allow_tcp_forwarding); 1412b07b2f5cSHuie-Ying Lee M_CP_INTOPT(gateway_ports); 1413b07b2f5cSHuie-Ying Lee M_CP_INTOPT(x11_display_offset); 1414b07b2f5cSHuie-Ying Lee M_CP_INTOPT(x11_forwarding); 1415b07b2f5cSHuie-Ying Lee M_CP_INTOPT(x11_use_localhost); 1416b07b2f5cSHuie-Ying Lee M_CP_INTOPT(max_auth_tries); 1417b07b2f5cSHuie-Ying Lee M_CP_STROPT(banner); 1418b07b2f5cSHuie-Ying Lee 1419b07b2f5cSHuie-Ying Lee if (preauth) 1420b07b2f5cSHuie-Ying Lee return; 1421b07b2f5cSHuie-Ying Lee M_CP_STROPT(chroot_directory); 1422b07b2f5cSHuie-Ying Lee } 1423b07b2f5cSHuie-Ying Lee 1424b07b2f5cSHuie-Ying Lee #undef M_CP_INTOPT 1425b07b2f5cSHuie-Ying Lee #undef M_CP_STROPT 1426b07b2f5cSHuie-Ying Lee 1427b07b2f5cSHuie-Ying Lee void 1428b07b2f5cSHuie-Ying Lee parse_server_config(ServerOptions *options, const char *filename, Buffer *conf, 1429b07b2f5cSHuie-Ying Lee const char *user, const char *host, const char *address) 1430b07b2f5cSHuie-Ying Lee { 1431b07b2f5cSHuie-Ying Lee int active, linenum, bad_options = 0; 1432b07b2f5cSHuie-Ying Lee char *cp, *obuf, *cbuf; 1433b07b2f5cSHuie-Ying Lee 1434b07b2f5cSHuie-Ying Lee debug2("%s: config %s len %d", __func__, filename, buffer_len(conf)); 1435b07b2f5cSHuie-Ying Lee 1436b07b2f5cSHuie-Ying Lee obuf = cbuf = xstrdup(buffer_ptr(conf)); 1437b07b2f5cSHuie-Ying Lee active = user ? 0 : 1; 1438b07b2f5cSHuie-Ying Lee linenum = 1; 1439b07b2f5cSHuie-Ying Lee while ((cp = strsep(&cbuf, "\n")) != NULL) { 1440b07b2f5cSHuie-Ying Lee if (process_server_config_line(options, cp, filename, 1441b07b2f5cSHuie-Ying Lee linenum++, &active, user, host, address) != 0) 14427c478bd9Sstevel@tonic-gate bad_options++; 14437c478bd9Sstevel@tonic-gate } 1444b07b2f5cSHuie-Ying Lee xfree(obuf); 14457c478bd9Sstevel@tonic-gate if (bad_options > 0) 14467c478bd9Sstevel@tonic-gate fatal("%s: terminating, %d bad configuration options", 14477c478bd9Sstevel@tonic-gate filename, bad_options); 14487c478bd9Sstevel@tonic-gate } 14496f8d59d8SJan Pechanec 1450b07b2f5cSHuie-Ying Lee 14516f8d59d8SJan Pechanec /* 14526f8d59d8SJan Pechanec * Note that "none" is a special path having the same affect on sshd 14536f8d59d8SJan Pechanec * configuration as not specifying ChrootDirectory at all. 14546f8d59d8SJan Pechanec */ 14556f8d59d8SJan Pechanec int 14566f8d59d8SJan Pechanec chroot_requested(char *chroot_directory) 14576f8d59d8SJan Pechanec { 14586f8d59d8SJan Pechanec return (chroot_directory != NULL && 14596f8d59d8SJan Pechanec strcasecmp(chroot_directory, "none") != 0); 14606f8d59d8SJan Pechanec } 1461