xref: /titanic_50/usr/src/cmd/ssh/sshd/servconf.c (revision bdb005b59455f11dc7f68cad9b1ec5b07de11e5d)
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 /*
12*bdb005b5SDarren J Moffat  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include "includes.h"
167c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: servconf.c,v 1.115 2002/09/04 18:52:42 stevesk Exp $");
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN
197c478bd9Sstevel@tonic-gate #include <deflt.h>
207c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate #if defined(KRB4)
237c478bd9Sstevel@tonic-gate #include <krb.h>
247c478bd9Sstevel@tonic-gate #endif
257c478bd9Sstevel@tonic-gate #if defined(KRB5)
267c478bd9Sstevel@tonic-gate #ifdef HEIMDAL
277c478bd9Sstevel@tonic-gate #include <krb.h>
287c478bd9Sstevel@tonic-gate #else
297c478bd9Sstevel@tonic-gate /* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V
307c478bd9Sstevel@tonic-gate  * keytab */
317c478bd9Sstevel@tonic-gate #define KEYFILE "/etc/krb5.keytab"
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate #ifdef AFS
357c478bd9Sstevel@tonic-gate #include <kafs.h>
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include "ssh.h"
397c478bd9Sstevel@tonic-gate #include "log.h"
40b07b2f5cSHuie-Ying Lee #include "buffer.h"
417c478bd9Sstevel@tonic-gate #include "servconf.h"
427c478bd9Sstevel@tonic-gate #include "xmalloc.h"
437c478bd9Sstevel@tonic-gate #include "compat.h"
447c478bd9Sstevel@tonic-gate #include "pathnames.h"
457c478bd9Sstevel@tonic-gate #include "tildexpand.h"
467c478bd9Sstevel@tonic-gate #include "misc.h"
477c478bd9Sstevel@tonic-gate #include "cipher.h"
487c478bd9Sstevel@tonic-gate #include "kex.h"
497c478bd9Sstevel@tonic-gate #include "mac.h"
507c478bd9Sstevel@tonic-gate #include "auth.h"
51b07b2f5cSHuie-Ying Lee #include "match.h"
52b07b2f5cSHuie-Ying Lee #include "groupaccess.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 
57b07b2f5cSHuie-Ying Lee extern Buffer cfg;
58b07b2f5cSHuie-Ying Lee 
597c478bd9Sstevel@tonic-gate /* AF_UNSPEC or AF_INET or AF_INET6 */
607c478bd9Sstevel@tonic-gate extern int IPv4or6;
617c478bd9Sstevel@tonic-gate 
626f8d59d8SJan Pechanec /*
636f8d59d8SJan Pechanec  * Initializes the server options to their initial (unset) values. Some of those
646f8d59d8SJan Pechanec  * that stay unset after the command line options and configuration files are
656f8d59d8SJan Pechanec  * read are set to their default values in fill_default_server_options().
666f8d59d8SJan Pechanec  */
677c478bd9Sstevel@tonic-gate void
687c478bd9Sstevel@tonic-gate initialize_server_options(ServerOptions *options)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	(void) memset(options, 0, sizeof(*options));
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	/* Portable-specific options */
737c478bd9Sstevel@tonic-gate 	options->pam_authentication_via_kbd_int = -1;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	/* Standard Options */
767c478bd9Sstevel@tonic-gate 	options->num_ports = 0;
777c478bd9Sstevel@tonic-gate 	options->ports_from_cmdline = 0;
787c478bd9Sstevel@tonic-gate 	options->listen_addrs = NULL;
797c478bd9Sstevel@tonic-gate 	options->num_host_key_files = 0;
807c478bd9Sstevel@tonic-gate 	options->pid_file = NULL;
817c478bd9Sstevel@tonic-gate 	options->server_key_bits = -1;
827c478bd9Sstevel@tonic-gate 	options->login_grace_time = -1;
837c478bd9Sstevel@tonic-gate 	options->key_regeneration_time = -1;
847c478bd9Sstevel@tonic-gate 	options->permit_root_login = PERMIT_NOT_SET;
857c478bd9Sstevel@tonic-gate 	options->ignore_rhosts = -1;
867c478bd9Sstevel@tonic-gate 	options->ignore_user_known_hosts = -1;
877c478bd9Sstevel@tonic-gate 	options->print_motd = -1;
887c478bd9Sstevel@tonic-gate 	options->print_lastlog = -1;
897c478bd9Sstevel@tonic-gate 	options->x11_forwarding = -1;
907c478bd9Sstevel@tonic-gate 	options->x11_display_offset = -1;
917c478bd9Sstevel@tonic-gate 	options->x11_use_localhost = -1;
927c478bd9Sstevel@tonic-gate 	options->xauth_location = NULL;
937c478bd9Sstevel@tonic-gate 	options->strict_modes = -1;
947c478bd9Sstevel@tonic-gate 	options->keepalives = -1;
957c478bd9Sstevel@tonic-gate 	options->log_facility = SYSLOG_FACILITY_NOT_SET;
967c478bd9Sstevel@tonic-gate 	options->log_level = SYSLOG_LEVEL_NOT_SET;
977c478bd9Sstevel@tonic-gate 	options->rhosts_authentication = -1;
987c478bd9Sstevel@tonic-gate 	options->rhosts_rsa_authentication = -1;
997c478bd9Sstevel@tonic-gate 	options->hostbased_authentication = -1;
1007c478bd9Sstevel@tonic-gate 	options->hostbased_uses_name_from_packet_only = -1;
1017c478bd9Sstevel@tonic-gate 	options->rsa_authentication = -1;
1027c478bd9Sstevel@tonic-gate 	options->pubkey_authentication = -1;
1037c478bd9Sstevel@tonic-gate #ifdef GSSAPI
1047c478bd9Sstevel@tonic-gate 	options->gss_authentication = -1;
1057c478bd9Sstevel@tonic-gate 	options->gss_keyex = -1;
1067c478bd9Sstevel@tonic-gate 	options->gss_store_creds = -1;
1077c478bd9Sstevel@tonic-gate 	options->gss_use_session_ccache = -1;
1087c478bd9Sstevel@tonic-gate 	options->gss_cleanup_creds = -1;
1097c478bd9Sstevel@tonic-gate #endif
1107c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
1117c478bd9Sstevel@tonic-gate 	options->kerberos_authentication = -1;
1127c478bd9Sstevel@tonic-gate 	options->kerberos_or_local_passwd = -1;
1137c478bd9Sstevel@tonic-gate 	options->kerberos_ticket_cleanup = -1;
1147c478bd9Sstevel@tonic-gate #endif
1157c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
1167c478bd9Sstevel@tonic-gate 	options->kerberos_tgt_passing = -1;
1177c478bd9Sstevel@tonic-gate #endif
1187c478bd9Sstevel@tonic-gate #ifdef AFS
1197c478bd9Sstevel@tonic-gate 	options->afs_token_passing = -1;
1207c478bd9Sstevel@tonic-gate #endif
1217c478bd9Sstevel@tonic-gate 	options->password_authentication = -1;
1227c478bd9Sstevel@tonic-gate 	options->kbd_interactive_authentication = -1;
1237c478bd9Sstevel@tonic-gate 	options->challenge_response_authentication = -1;
1247c478bd9Sstevel@tonic-gate 	options->permit_empty_passwd = -1;
1257c478bd9Sstevel@tonic-gate 	options->permit_user_env = -1;
1267c478bd9Sstevel@tonic-gate 	options->compression = -1;
1277c478bd9Sstevel@tonic-gate 	options->allow_tcp_forwarding = -1;
1287c478bd9Sstevel@tonic-gate 	options->num_allow_users = 0;
1297c478bd9Sstevel@tonic-gate 	options->num_deny_users = 0;
1307c478bd9Sstevel@tonic-gate 	options->num_allow_groups = 0;
1317c478bd9Sstevel@tonic-gate 	options->num_deny_groups = 0;
1327c478bd9Sstevel@tonic-gate 	options->ciphers = NULL;
1337c478bd9Sstevel@tonic-gate 	options->macs = NULL;
1347c478bd9Sstevel@tonic-gate 	options->protocol = SSH_PROTO_UNKNOWN;
1357c478bd9Sstevel@tonic-gate 	options->gateway_ports = -1;
1367c478bd9Sstevel@tonic-gate 	options->num_subsystems = 0;
1377c478bd9Sstevel@tonic-gate 	options->max_startups_begin = -1;
1387c478bd9Sstevel@tonic-gate 	options->max_startups_rate = -1;
1397c478bd9Sstevel@tonic-gate 	options->max_startups = -1;
1407c478bd9Sstevel@tonic-gate 	options->banner = NULL;
1417c478bd9Sstevel@tonic-gate 	options->verify_reverse_mapping = -1;
1427c478bd9Sstevel@tonic-gate 	options->client_alive_interval = -1;
1437c478bd9Sstevel@tonic-gate 	options->client_alive_count_max = -1;
1447c478bd9Sstevel@tonic-gate 	options->authorized_keys_file = NULL;
1457c478bd9Sstevel@tonic-gate 	options->authorized_keys_file2 = NULL;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	options->max_auth_tries = -1;
1487c478bd9Sstevel@tonic-gate 	options->max_auth_tries_log = -1;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	options->max_init_auth_tries = -1;
1517c478bd9Sstevel@tonic-gate 	options->max_init_auth_tries_log = -1;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	options->lookup_client_hostnames = -1;
154cd7d5fafSJan Pechanec 	options->use_openssl_engine = -1;
1556f8d59d8SJan Pechanec 	options->chroot_directory = NULL;
156d8a94255SErik Trauschke 	options->pre_userauth_hook = NULL;
157*bdb005b5SDarren J Moffat 	options->pam_service_name = NULL;
158*bdb005b5SDarren J Moffat 	options->pam_service_prefix = NULL;
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * Reads /etc/default/login and defaults several ServerOptions:
1647c478bd9Sstevel@tonic-gate  *
1657c478bd9Sstevel@tonic-gate  * PermitRootLogin
1667c478bd9Sstevel@tonic-gate  * PermitEmptyPasswords
1677c478bd9Sstevel@tonic-gate  * LoginGraceTime
1687c478bd9Sstevel@tonic-gate  *
1697c478bd9Sstevel@tonic-gate  * CONSOLE=*      -> PermitRootLogin=without-password
1707c478bd9Sstevel@tonic-gate  * #CONSOLE=*     -> PermitRootLogin=yes
1717c478bd9Sstevel@tonic-gate  *
1727c478bd9Sstevel@tonic-gate  * PASSREQ=YES    -> PermitEmptyPasswords=no
1737c478bd9Sstevel@tonic-gate  * PASSREQ=NO     -> PermitEmptyPasswords=yes
1747c478bd9Sstevel@tonic-gate  * #PASSREQ=*     -> PermitEmptyPasswords=no
1757c478bd9Sstevel@tonic-gate  *
1767c478bd9Sstevel@tonic-gate  * TIMEOUT=<secs> -> LoginGraceTime=<secs>
1777c478bd9Sstevel@tonic-gate  * #TIMEOUT=<secs> -> LoginGraceTime=300
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate static
1807c478bd9Sstevel@tonic-gate void
1817c478bd9Sstevel@tonic-gate deflt_fill_default_server_options(ServerOptions *options)
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate 	int	flags;
1847c478bd9Sstevel@tonic-gate 	char	*ptr;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	if (defopen(_PATH_DEFAULT_LOGIN))
1877c478bd9Sstevel@tonic-gate 		return;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	/* Ignore case */
1907c478bd9Sstevel@tonic-gate 	flags = defcntl(DC_GETFLAGS, 0);
1917c478bd9Sstevel@tonic-gate 	TURNOFF(flags, DC_CASE);
1927c478bd9Sstevel@tonic-gate 	(void) defcntl(DC_SETFLAGS, flags);
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	if (options->permit_root_login == PERMIT_NOT_SET &&
1957c478bd9Sstevel@tonic-gate 	    (ptr = defread("CONSOLE=")) != NULL)
1967c478bd9Sstevel@tonic-gate 		options->permit_root_login = PERMIT_NO_PASSWD;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if (options->permit_empty_passwd == -1 &&
1997c478bd9Sstevel@tonic-gate 	    (ptr = defread("PASSREQ=")) != NULL) {
2007c478bd9Sstevel@tonic-gate 		if (strcasecmp("YES", ptr) == 0)
2017c478bd9Sstevel@tonic-gate 			options->permit_empty_passwd = 0;
2027c478bd9Sstevel@tonic-gate 		else if (strcasecmp("NO", ptr) == 0)
2037c478bd9Sstevel@tonic-gate 			options->permit_empty_passwd = 1;
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	if (options->max_init_auth_tries == -1 &&
2077c478bd9Sstevel@tonic-gate 	    (ptr = defread("RETRIES=")) != NULL) {
2087c478bd9Sstevel@tonic-gate 		options->max_init_auth_tries = atoi(ptr);
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	if (options->max_init_auth_tries_log == -1 &&
2127c478bd9Sstevel@tonic-gate 	    (ptr = defread("SYSLOG_FAILED_LOGINS=")) != NULL) {
2137c478bd9Sstevel@tonic-gate 		options->max_init_auth_tries_log = atoi(ptr);
2147c478bd9Sstevel@tonic-gate 	}
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	if (options->login_grace_time == -1) {
2177c478bd9Sstevel@tonic-gate 		if ((ptr = defread("TIMEOUT=")) != NULL)
2187c478bd9Sstevel@tonic-gate 			options->login_grace_time = (unsigned)atoi(ptr);
2197c478bd9Sstevel@tonic-gate 		else
2207c478bd9Sstevel@tonic-gate 			options->login_grace_time = 300;
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	(void) defopen((char *)NULL);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate void
2287c478bd9Sstevel@tonic-gate fill_default_server_options(ServerOptions *options)
2297c478bd9Sstevel@tonic-gate {
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate #ifdef HAVE_DEFOPEN
2327c478bd9Sstevel@tonic-gate 	deflt_fill_default_server_options(options);
2337c478bd9Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	/* Portable-specific options */
2367c478bd9Sstevel@tonic-gate 	if (options->pam_authentication_via_kbd_int == -1)
2377c478bd9Sstevel@tonic-gate 		options->pam_authentication_via_kbd_int = 0;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	/* Standard Options */
2407c478bd9Sstevel@tonic-gate 	if (options->protocol == SSH_PROTO_UNKNOWN)
2417c478bd9Sstevel@tonic-gate 		options->protocol = SSH_PROTO_1|SSH_PROTO_2;
2427c478bd9Sstevel@tonic-gate 	if (options->num_host_key_files == 0) {
2437c478bd9Sstevel@tonic-gate 		/* fill default hostkeys for protocols */
2447c478bd9Sstevel@tonic-gate 		if (options->protocol & SSH_PROTO_1)
2457c478bd9Sstevel@tonic-gate 			options->host_key_files[options->num_host_key_files++] =
2467c478bd9Sstevel@tonic-gate 			    _PATH_HOST_KEY_FILE;
2477c478bd9Sstevel@tonic-gate #ifndef GSSAPI
2487c478bd9Sstevel@tonic-gate 		/* With GSS keyex we can run v2 w/ no host keys */
2497c478bd9Sstevel@tonic-gate 		if (options->protocol & SSH_PROTO_2) {
2507c478bd9Sstevel@tonic-gate 			options->host_key_files[options->num_host_key_files++] =
2517c478bd9Sstevel@tonic-gate 			    _PATH_HOST_RSA_KEY_FILE;
2527c478bd9Sstevel@tonic-gate 			options->host_key_files[options->num_host_key_files++] =
2537c478bd9Sstevel@tonic-gate 			    _PATH_HOST_DSA_KEY_FILE;
2547c478bd9Sstevel@tonic-gate 		}
2557c478bd9Sstevel@tonic-gate #endif /* GSSAPI */
2567c478bd9Sstevel@tonic-gate 	}
2577c478bd9Sstevel@tonic-gate 	if (options->num_ports == 0)
2587c478bd9Sstevel@tonic-gate 		options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
2597c478bd9Sstevel@tonic-gate 	if (options->listen_addrs == NULL)
2607c478bd9Sstevel@tonic-gate 		add_listen_addr(options, NULL, 0);
2617c478bd9Sstevel@tonic-gate 	if (options->pid_file == NULL)
2627c478bd9Sstevel@tonic-gate 		options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
2637c478bd9Sstevel@tonic-gate 	if (options->server_key_bits == -1)
2647c478bd9Sstevel@tonic-gate 		options->server_key_bits = 768;
2657c478bd9Sstevel@tonic-gate 	if (options->login_grace_time == -1)
2667c478bd9Sstevel@tonic-gate 		options->login_grace_time = 120;
2677c478bd9Sstevel@tonic-gate 	if (options->key_regeneration_time == -1)
2687c478bd9Sstevel@tonic-gate 		options->key_regeneration_time = 3600;
2697c478bd9Sstevel@tonic-gate 	if (options->permit_root_login == PERMIT_NOT_SET)
2707c478bd9Sstevel@tonic-gate 		options->permit_root_login = PERMIT_YES;
2717c478bd9Sstevel@tonic-gate 	if (options->ignore_rhosts == -1)
2727c478bd9Sstevel@tonic-gate 		options->ignore_rhosts = 1;
2737c478bd9Sstevel@tonic-gate 	if (options->ignore_user_known_hosts == -1)
2747c478bd9Sstevel@tonic-gate 		options->ignore_user_known_hosts = 0;
2757c478bd9Sstevel@tonic-gate 	if (options->print_motd == -1)
2767c478bd9Sstevel@tonic-gate 		options->print_motd = 1;
2777c478bd9Sstevel@tonic-gate 	if (options->print_lastlog == -1)
2787c478bd9Sstevel@tonic-gate 		options->print_lastlog = 1;
2797c478bd9Sstevel@tonic-gate 	if (options->x11_forwarding == -1)
2807c478bd9Sstevel@tonic-gate 		options->x11_forwarding = 1;
2817c478bd9Sstevel@tonic-gate 	if (options->x11_display_offset == -1)
2827c478bd9Sstevel@tonic-gate 		options->x11_display_offset = 10;
2837c478bd9Sstevel@tonic-gate 	if (options->x11_use_localhost == -1)
2847c478bd9Sstevel@tonic-gate 		options->x11_use_localhost = 1;
2857c478bd9Sstevel@tonic-gate 	if (options->xauth_location == NULL)
2867c478bd9Sstevel@tonic-gate 		options->xauth_location = _PATH_XAUTH;
2877c478bd9Sstevel@tonic-gate 	if (options->strict_modes == -1)
2887c478bd9Sstevel@tonic-gate 		options->strict_modes = 1;
2897c478bd9Sstevel@tonic-gate 	if (options->keepalives == -1)
2907c478bd9Sstevel@tonic-gate 		options->keepalives = 1;
2917c478bd9Sstevel@tonic-gate 	if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2927c478bd9Sstevel@tonic-gate 		options->log_facility = SYSLOG_FACILITY_AUTH;
2937c478bd9Sstevel@tonic-gate 	if (options->log_level == SYSLOG_LEVEL_NOT_SET)
2947c478bd9Sstevel@tonic-gate 		options->log_level = SYSLOG_LEVEL_INFO;
2957c478bd9Sstevel@tonic-gate 	if (options->rhosts_authentication == -1)
2967c478bd9Sstevel@tonic-gate 		options->rhosts_authentication = 0;
2977c478bd9Sstevel@tonic-gate 	if (options->rhosts_rsa_authentication == -1)
2987c478bd9Sstevel@tonic-gate 		options->rhosts_rsa_authentication = 0;
2997c478bd9Sstevel@tonic-gate 	if (options->hostbased_authentication == -1)
3007c478bd9Sstevel@tonic-gate 		options->hostbased_authentication = 0;
3017c478bd9Sstevel@tonic-gate 	if (options->hostbased_uses_name_from_packet_only == -1)
3027c478bd9Sstevel@tonic-gate 		options->hostbased_uses_name_from_packet_only = 0;
3037c478bd9Sstevel@tonic-gate 	if (options->rsa_authentication == -1)
3047c478bd9Sstevel@tonic-gate 		options->rsa_authentication = 1;
3057c478bd9Sstevel@tonic-gate 	if (options->pubkey_authentication == -1)
3067c478bd9Sstevel@tonic-gate 		options->pubkey_authentication = 1;
3077c478bd9Sstevel@tonic-gate #ifdef GSSAPI
3087c478bd9Sstevel@tonic-gate 	if (options->gss_authentication == -1)
3097c478bd9Sstevel@tonic-gate 		options->gss_authentication = 1;
3107c478bd9Sstevel@tonic-gate 	if (options->gss_keyex == -1)
3117c478bd9Sstevel@tonic-gate 		options->gss_keyex = 1;
3127c478bd9Sstevel@tonic-gate 	if (options->gss_store_creds == -1)
3137c478bd9Sstevel@tonic-gate 		options->gss_store_creds = 1;
3147c478bd9Sstevel@tonic-gate 	if (options->gss_use_session_ccache == -1)
3157c478bd9Sstevel@tonic-gate 		options->gss_use_session_ccache = 1;
3167c478bd9Sstevel@tonic-gate 	if (options->gss_cleanup_creds == -1)
3177c478bd9Sstevel@tonic-gate 		options->gss_cleanup_creds = 1;
3187c478bd9Sstevel@tonic-gate #endif
3197c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
3207c478bd9Sstevel@tonic-gate 	if (options->kerberos_authentication == -1)
3217c478bd9Sstevel@tonic-gate 		options->kerberos_authentication = 0;
3227c478bd9Sstevel@tonic-gate 	if (options->kerberos_or_local_passwd == -1)
3237c478bd9Sstevel@tonic-gate 		options->kerberos_or_local_passwd = 1;
3247c478bd9Sstevel@tonic-gate 	if (options->kerberos_ticket_cleanup == -1)
3257c478bd9Sstevel@tonic-gate 		options->kerberos_ticket_cleanup = 1;
3267c478bd9Sstevel@tonic-gate #endif
3277c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
3287c478bd9Sstevel@tonic-gate 	if (options->kerberos_tgt_passing == -1)
3297c478bd9Sstevel@tonic-gate 		options->kerberos_tgt_passing = 0;
3307c478bd9Sstevel@tonic-gate #endif
3317c478bd9Sstevel@tonic-gate #ifdef AFS
3327c478bd9Sstevel@tonic-gate 	if (options->afs_token_passing == -1)
3337c478bd9Sstevel@tonic-gate 		options->afs_token_passing = 0;
3347c478bd9Sstevel@tonic-gate #endif
3357c478bd9Sstevel@tonic-gate 	if (options->password_authentication == -1)
3367c478bd9Sstevel@tonic-gate 		options->password_authentication = 1;
3377c478bd9Sstevel@tonic-gate 	if (options->kbd_interactive_authentication == -1)
3387c478bd9Sstevel@tonic-gate 		options->kbd_interactive_authentication = 0;
3397c478bd9Sstevel@tonic-gate 	if (options->challenge_response_authentication == -1)
3407c478bd9Sstevel@tonic-gate 		options->challenge_response_authentication = 1;
3417c478bd9Sstevel@tonic-gate 	if (options->permit_empty_passwd == -1)
3427c478bd9Sstevel@tonic-gate 		options->permit_empty_passwd = 0;
3437c478bd9Sstevel@tonic-gate 	if (options->permit_user_env == -1)
3447c478bd9Sstevel@tonic-gate 		options->permit_user_env = 0;
3457c478bd9Sstevel@tonic-gate 	if (options->compression == -1)
3467c478bd9Sstevel@tonic-gate 		options->compression = 1;
3477c478bd9Sstevel@tonic-gate 	if (options->allow_tcp_forwarding == -1)
3487c478bd9Sstevel@tonic-gate 		options->allow_tcp_forwarding = 1;
3497c478bd9Sstevel@tonic-gate 	if (options->gateway_ports == -1)
3507c478bd9Sstevel@tonic-gate 		options->gateway_ports = 0;
3517c478bd9Sstevel@tonic-gate 	if (options->max_startups == -1)
3527c478bd9Sstevel@tonic-gate 		options->max_startups = 10;
3537c478bd9Sstevel@tonic-gate 	if (options->max_startups_rate == -1)
3547c478bd9Sstevel@tonic-gate 		options->max_startups_rate = 100;		/* 100% */
3557c478bd9Sstevel@tonic-gate 	if (options->max_startups_begin == -1)
3567c478bd9Sstevel@tonic-gate 		options->max_startups_begin = options->max_startups;
3577c478bd9Sstevel@tonic-gate 	if (options->verify_reverse_mapping == -1)
3587c478bd9Sstevel@tonic-gate 		options->verify_reverse_mapping = 0;
3597c478bd9Sstevel@tonic-gate 	if (options->client_alive_interval == -1)
3607c478bd9Sstevel@tonic-gate 		options->client_alive_interval = 0;
3617c478bd9Sstevel@tonic-gate 	if (options->client_alive_count_max == -1)
3627c478bd9Sstevel@tonic-gate 		options->client_alive_count_max = 3;
3637c478bd9Sstevel@tonic-gate 	if (options->authorized_keys_file2 == NULL) {
3647c478bd9Sstevel@tonic-gate 		/* authorized_keys_file2 falls back to authorized_keys_file */
3657c478bd9Sstevel@tonic-gate 		if (options->authorized_keys_file != NULL)
3667c478bd9Sstevel@tonic-gate 			options->authorized_keys_file2 = options->authorized_keys_file;
3677c478bd9Sstevel@tonic-gate 		else
3687c478bd9Sstevel@tonic-gate 			options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
3697c478bd9Sstevel@tonic-gate 	}
3707c478bd9Sstevel@tonic-gate 	if (options->authorized_keys_file == NULL)
3717c478bd9Sstevel@tonic-gate 		options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	if (options->max_auth_tries == -1)
3747c478bd9Sstevel@tonic-gate 		options->max_auth_tries = AUTH_FAIL_MAX;
3757c478bd9Sstevel@tonic-gate 	if (options->max_auth_tries_log == -1)
3767c478bd9Sstevel@tonic-gate 		options->max_auth_tries_log = options->max_auth_tries / 2;
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	if (options->max_init_auth_tries == -1)
3797c478bd9Sstevel@tonic-gate 		options->max_init_auth_tries = AUTH_FAIL_MAX;
3807c478bd9Sstevel@tonic-gate 	if (options->max_init_auth_tries_log == -1)
3817c478bd9Sstevel@tonic-gate 		options->max_init_auth_tries_log = options->max_init_auth_tries / 2;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	if (options->lookup_client_hostnames == -1)
3847c478bd9Sstevel@tonic-gate 		options->lookup_client_hostnames = 1;
385cd7d5fafSJan Pechanec 	if (options->use_openssl_engine == -1)
386cd7d5fafSJan Pechanec 		options->use_openssl_engine = 1;
387*bdb005b5SDarren J Moffat 	if (options->pam_service_prefix == NULL)
388*bdb005b5SDarren J Moffat 		options->pam_service_prefix = _SSH_PAM_SERVICE_PREFIX;
389*bdb005b5SDarren J Moffat 	if (options->pam_service_name == NULL)
390*bdb005b5SDarren J Moffat 		options->pam_service_name = NULL;
3917c478bd9Sstevel@tonic-gate }
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate /* Keyword tokens. */
3947c478bd9Sstevel@tonic-gate typedef enum {
3957c478bd9Sstevel@tonic-gate 	sBadOption,		/* == unknown option */
3967c478bd9Sstevel@tonic-gate 	/* Portable-specific options */
3977c478bd9Sstevel@tonic-gate 	sPAMAuthenticationViaKbdInt,
3987c478bd9Sstevel@tonic-gate 	/* Standard Options */
3997c478bd9Sstevel@tonic-gate 	sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
4007c478bd9Sstevel@tonic-gate 	sPermitRootLogin, sLogFacility, sLogLevel,
4017c478bd9Sstevel@tonic-gate 	sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
4027c478bd9Sstevel@tonic-gate #ifdef GSSAPI
4037c478bd9Sstevel@tonic-gate 	sGssAuthentication, sGssKeyEx, sGssStoreDelegCreds,
4047c478bd9Sstevel@tonic-gate 	sGssUseSessionCredCache, sGssCleanupCreds,
4057c478bd9Sstevel@tonic-gate #endif /* GSSAPI */
4067c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
4077c478bd9Sstevel@tonic-gate 	sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
4087c478bd9Sstevel@tonic-gate #endif
4097c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
4107c478bd9Sstevel@tonic-gate 	sKerberosTgtPassing,
4117c478bd9Sstevel@tonic-gate #endif
4127c478bd9Sstevel@tonic-gate #ifdef AFS
4137c478bd9Sstevel@tonic-gate 	sAFSTokenPassing,
4147c478bd9Sstevel@tonic-gate #endif
4157c478bd9Sstevel@tonic-gate 	sChallengeResponseAuthentication,
4167c478bd9Sstevel@tonic-gate 	sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
4177c478bd9Sstevel@tonic-gate 	sPrintMotd, sPrintLastLog, sIgnoreRhosts,
4187c478bd9Sstevel@tonic-gate 	sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
4197c478bd9Sstevel@tonic-gate 	sStrictModes, sEmptyPasswd, sKeepAlives,
4207c478bd9Sstevel@tonic-gate 	sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
4217c478bd9Sstevel@tonic-gate 	sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
4227c478bd9Sstevel@tonic-gate 	sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
4237c478bd9Sstevel@tonic-gate 	sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
4247c478bd9Sstevel@tonic-gate 	sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
4257c478bd9Sstevel@tonic-gate 	sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
4267c478bd9Sstevel@tonic-gate 	sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
4277c478bd9Sstevel@tonic-gate 	sMaxAuthTries, sMaxAuthTriesLog, sUsePrivilegeSeparation,
4286f8d59d8SJan Pechanec 	sLookupClientHostnames, sUseOpenSSLEngine, sChrootDirectory,
429*bdb005b5SDarren J Moffat 	sPreUserauthHook, sMatch, sPAMServicePrefix, sPAMServiceName,
4307c478bd9Sstevel@tonic-gate 	sDeprecated
4317c478bd9Sstevel@tonic-gate } ServerOpCodes;
4327c478bd9Sstevel@tonic-gate 
433b07b2f5cSHuie-Ying Lee #define SSHCFG_GLOBAL	0x01	/* allowed in main section of sshd_config */
434b07b2f5cSHuie-Ying Lee #define SSHCFG_MATCH	0x02	/* allowed inside a Match section */
435b07b2f5cSHuie-Ying Lee #define SSHCFG_ALL	(SSHCFG_GLOBAL|SSHCFG_MATCH)
436b07b2f5cSHuie-Ying Lee 
4377c478bd9Sstevel@tonic-gate /* Textual representation of the tokens. */
4387c478bd9Sstevel@tonic-gate static struct {
4397c478bd9Sstevel@tonic-gate 	const char *name;
4407c478bd9Sstevel@tonic-gate 	ServerOpCodes opcode;
441b07b2f5cSHuie-Ying Lee 	u_int flags;
4427c478bd9Sstevel@tonic-gate } keywords[] = {
4437c478bd9Sstevel@tonic-gate 	/* Portable-specific options */
444b07b2f5cSHuie-Ying Lee 	{ "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt, SSHCFG_GLOBAL },
4457c478bd9Sstevel@tonic-gate 	/* Standard Options */
446b07b2f5cSHuie-Ying Lee 	{ "port", sPort, SSHCFG_GLOBAL },
447b07b2f5cSHuie-Ying Lee 	{ "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
448b07b2f5cSHuie-Ying Lee 	{ "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL },			/* alias */
449b07b2f5cSHuie-Ying Lee 	{ "pidfile", sPidFile, SSHCFG_GLOBAL },
450b07b2f5cSHuie-Ying Lee 	{ "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
451b07b2f5cSHuie-Ying Lee 	{ "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
452b07b2f5cSHuie-Ying Lee 	{ "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
453b07b2f5cSHuie-Ying Lee 	{ "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
454b07b2f5cSHuie-Ying Lee 	{ "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
455b07b2f5cSHuie-Ying Lee 	{ "loglevel", sLogLevel, SSHCFG_GLOBAL },
456b07b2f5cSHuie-Ying Lee 	{ "rhostsauthentication", sRhostsAuthentication, SSHCFG_GLOBAL },
457b07b2f5cSHuie-Ying Lee 	{ "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
458b07b2f5cSHuie-Ying Lee 	{ "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
4597c478bd9Sstevel@tonic-gate 	{ "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
460b07b2f5cSHuie-Ying Lee 	{ "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
461b07b2f5cSHuie-Ying Lee 	{ "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
462b07b2f5cSHuie-Ying Lee 	{ "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL },	/* alias */
4637c478bd9Sstevel@tonic-gate #ifdef GSSAPI
464b07b2f5cSHuie-Ying Lee 	{ "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
465b07b2f5cSHuie-Ying Lee 	{ "gssapikeyexchange", sGssKeyEx,   SSHCFG_GLOBAL },
466b07b2f5cSHuie-Ying Lee 	{ "gssapistoredelegatedcredentials", sGssStoreDelegCreds, SSHCFG_GLOBAL },
467b07b2f5cSHuie-Ying Lee 	{ "gssauthentication", sGssAuthentication, SSHCFG_GLOBAL },	/* alias */
468b07b2f5cSHuie-Ying Lee 	{ "gsskeyex", sGssKeyEx, SSHCFG_GLOBAL },	/* alias */
469b07b2f5cSHuie-Ying Lee 	{ "gssstoredelegcreds", sGssStoreDelegCreds, SSHCFG_GLOBAL },	/* alias */
4707c478bd9Sstevel@tonic-gate #ifndef SUNW_GSSAPI
471b07b2f5cSHuie-Ying Lee 	{ "gssusesessionccache", sGssUseSessionCredCache, SSHCFG_GLOBAL },
472b07b2f5cSHuie-Ying Lee 	{ "gssusesessioncredcache", sGssUseSessionCredCache, SSHCFG_GLOBAL },
473b07b2f5cSHuie-Ying Lee 	{ "gsscleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL },
4747c478bd9Sstevel@tonic-gate #endif /* SUNW_GSSAPI */
4757c478bd9Sstevel@tonic-gate #endif
4767c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
477b07b2f5cSHuie-Ying Lee 	{ "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
478b07b2f5cSHuie-Ying Lee 	{ "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
479b07b2f5cSHuie-Ying Lee 	{ "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
4807c478bd9Sstevel@tonic-gate #endif
4817c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
482b07b2f5cSHuie-Ying Lee 	{ "kerberostgtpassing", sKerberosTgtPassing, SSHCFG_GLOBAL },
4837c478bd9Sstevel@tonic-gate #endif
4847c478bd9Sstevel@tonic-gate #ifdef AFS
485b07b2f5cSHuie-Ying Lee 	{ "afstokenpassing", sAFSTokenPassing, SSHCFG_GLOBAL },
4867c478bd9Sstevel@tonic-gate #endif
487b07b2f5cSHuie-Ying Lee 	{ "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
488b07b2f5cSHuie-Ying Lee 	{ "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
489b07b2f5cSHuie-Ying Lee 	{ "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
490b07b2f5cSHuie-Ying Lee 	{ "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
491b07b2f5cSHuie-Ying Lee 	{ "checkmail", sDeprecated, SSHCFG_GLOBAL },
492b07b2f5cSHuie-Ying Lee 	{ "listenaddress", sListenAddress, SSHCFG_GLOBAL },
493b07b2f5cSHuie-Ying Lee 	{ "printmotd", sPrintMotd, SSHCFG_GLOBAL },
494b07b2f5cSHuie-Ying Lee 	{ "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
495b07b2f5cSHuie-Ying Lee 	{ "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
496b07b2f5cSHuie-Ying Lee 	{ "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
497b07b2f5cSHuie-Ying Lee 	{ "x11forwarding", sX11Forwarding, SSHCFG_ALL },
498b07b2f5cSHuie-Ying Lee 	{ "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
499b07b2f5cSHuie-Ying Lee 	{ "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
500b07b2f5cSHuie-Ying Lee 	{ "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
501b07b2f5cSHuie-Ying Lee 	{ "strictmodes", sStrictModes, SSHCFG_GLOBAL },
502b07b2f5cSHuie-Ying Lee 	{ "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
503b07b2f5cSHuie-Ying Lee 	{ "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
504b07b2f5cSHuie-Ying Lee 	{ "uselogin", sUseLogin, SSHCFG_GLOBAL },
505b07b2f5cSHuie-Ying Lee 	{ "compression", sCompression, SSHCFG_GLOBAL },
506b07b2f5cSHuie-Ying Lee 	{ "keepalive", sKeepAlives, SSHCFG_GLOBAL },
507b07b2f5cSHuie-Ying Lee 	{ "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
508b07b2f5cSHuie-Ying Lee 	{ "allowusers", sAllowUsers, SSHCFG_GLOBAL },
509b07b2f5cSHuie-Ying Lee 	{ "denyusers", sDenyUsers, SSHCFG_GLOBAL },
510b07b2f5cSHuie-Ying Lee 	{ "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
511b07b2f5cSHuie-Ying Lee 	{ "denygroups", sDenyGroups, SSHCFG_GLOBAL },
512b07b2f5cSHuie-Ying Lee 	{ "ciphers", sCiphers, SSHCFG_GLOBAL },
513b07b2f5cSHuie-Ying Lee 	{ "macs", sMacs, SSHCFG_GLOBAL},
514b07b2f5cSHuie-Ying Lee 	{ "protocol", sProtocol,SSHCFG_GLOBAL },
515b07b2f5cSHuie-Ying Lee 	{ "gatewayports", sGatewayPorts, SSHCFG_ALL },
516b07b2f5cSHuie-Ying Lee 	{ "subsystem", sSubsystem, SSHCFG_GLOBAL},
517b07b2f5cSHuie-Ying Lee 	{ "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
518b07b2f5cSHuie-Ying Lee 	{ "banner", sBanner, SSHCFG_ALL },
519b07b2f5cSHuie-Ying Lee 	{ "verifyreversemapping", sVerifyReverseMapping, SSHCFG_GLOBAL },
520b07b2f5cSHuie-Ying Lee 	{ "reversemappingcheck", sVerifyReverseMapping,SSHCFG_GLOBAL },
521b07b2f5cSHuie-Ying Lee 	{ "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
522b07b2f5cSHuie-Ying Lee 	{ "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
523b07b2f5cSHuie-Ying Lee 	{ "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
524b07b2f5cSHuie-Ying Lee 	{ "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
525b07b2f5cSHuie-Ying Lee 	{ "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
526b07b2f5cSHuie-Ying Lee 	{ "maxauthtrieslog", sMaxAuthTriesLog, SSHCFG_GLOBAL },
527b07b2f5cSHuie-Ying Lee 	{ "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL },
528b07b2f5cSHuie-Ying Lee 	{ "lookupclienthostnames", sLookupClientHostnames, SSHCFG_GLOBAL },
529b07b2f5cSHuie-Ying Lee 	{ "useopensslengine", sUseOpenSSLEngine, SSHCFG_GLOBAL },
530b07b2f5cSHuie-Ying Lee 	{ "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
531d8a94255SErik Trauschke 	{ "preuserauthhook", sPreUserauthHook, SSHCFG_ALL},
532b07b2f5cSHuie-Ying Lee 	{ "match", sMatch, SSHCFG_ALL },
533*bdb005b5SDarren J Moffat 	{ "pamserviceprefix", sPAMServicePrefix, SSHCFG_GLOBAL },
534*bdb005b5SDarren J Moffat 	{ "pamservicename", sPAMServiceName, SSHCFG_GLOBAL },
535b07b2f5cSHuie-Ying Lee 
536b07b2f5cSHuie-Ying Lee 	{ NULL, sBadOption, 0 }
5377c478bd9Sstevel@tonic-gate };
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate /*
5407c478bd9Sstevel@tonic-gate  * Returns the number of the token pointed to by cp or sBadOption.
5417c478bd9Sstevel@tonic-gate  */
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate static ServerOpCodes
5447c478bd9Sstevel@tonic-gate parse_token(const char *cp, const char *filename,
545b07b2f5cSHuie-Ying Lee 	    int linenum, u_int *flags)
5467c478bd9Sstevel@tonic-gate {
5477c478bd9Sstevel@tonic-gate 	u_int i;
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	for (i = 0; keywords[i].name; i++)
550b07b2f5cSHuie-Ying Lee 		if (strcasecmp(cp, keywords[i].name) == 0) {
551b07b2f5cSHuie-Ying Lee 			*flags = keywords[i].flags;
5527c478bd9Sstevel@tonic-gate 			return keywords[i].opcode;
553b07b2f5cSHuie-Ying Lee 		}
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	error("%s: line %d: Bad configuration option: %s",
5567c478bd9Sstevel@tonic-gate 	    filename, linenum, cp);
5577c478bd9Sstevel@tonic-gate 	return sBadOption;
5587c478bd9Sstevel@tonic-gate }
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate static void
5617c478bd9Sstevel@tonic-gate add_listen_addr(ServerOptions *options, char *addr, u_short port)
5627c478bd9Sstevel@tonic-gate {
5637c478bd9Sstevel@tonic-gate 	int i;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	if (options->num_ports == 0)
5667c478bd9Sstevel@tonic-gate 		options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
5677c478bd9Sstevel@tonic-gate 	if (port == 0)
5687c478bd9Sstevel@tonic-gate 		for (i = 0; i < options->num_ports; i++)
5697c478bd9Sstevel@tonic-gate 			add_one_listen_addr(options, addr, options->ports[i]);
5707c478bd9Sstevel@tonic-gate 	else
5717c478bd9Sstevel@tonic-gate 		add_one_listen_addr(options, addr, port);
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate static void
5757c478bd9Sstevel@tonic-gate add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
5767c478bd9Sstevel@tonic-gate {
5777c478bd9Sstevel@tonic-gate 	struct addrinfo hints, *ai, *aitop;
5787c478bd9Sstevel@tonic-gate 	char strport[NI_MAXSERV];
5797c478bd9Sstevel@tonic-gate 	int gaierr;
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	(void) memset(&hints, 0, sizeof(hints));
5827c478bd9Sstevel@tonic-gate 	hints.ai_family = IPv4or6;
5837c478bd9Sstevel@tonic-gate 	hints.ai_socktype = SOCK_STREAM;
5847c478bd9Sstevel@tonic-gate 	hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
5857c478bd9Sstevel@tonic-gate 	(void) snprintf(strport, sizeof strport, "%u", port);
5867c478bd9Sstevel@tonic-gate 	if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
5877c478bd9Sstevel@tonic-gate 		fatal("bad addr or host: %s (%s)",
5887c478bd9Sstevel@tonic-gate 		    addr ? addr : "<NULL>",
5897c478bd9Sstevel@tonic-gate 		    gai_strerror(gaierr));
5907c478bd9Sstevel@tonic-gate 	for (ai = aitop; ai->ai_next; ai = ai->ai_next)
5917c478bd9Sstevel@tonic-gate 		;
5927c478bd9Sstevel@tonic-gate 	ai->ai_next = options->listen_addrs;
5937c478bd9Sstevel@tonic-gate 	options->listen_addrs = aitop;
5947c478bd9Sstevel@tonic-gate }
5957c478bd9Sstevel@tonic-gate 
596b07b2f5cSHuie-Ying Lee /*
597b07b2f5cSHuie-Ying Lee  * The strategy for the Match blocks is that the config file is parsed twice.
598b07b2f5cSHuie-Ying Lee  *
599b07b2f5cSHuie-Ying Lee  * The first time is at startup.  activep is initialized to 1 and the
600b07b2f5cSHuie-Ying Lee  * directives in the global context are processed and acted on.  Hitting a
601b07b2f5cSHuie-Ying Lee  * Match directive unsets activep and the directives inside the block are
602b07b2f5cSHuie-Ying Lee  * checked for syntax only.
603b07b2f5cSHuie-Ying Lee  *
604b07b2f5cSHuie-Ying Lee  * The second time is after a connection has been established but before
605b07b2f5cSHuie-Ying Lee  * authentication.  activep is initialized to 2 and global config directives
606b07b2f5cSHuie-Ying Lee  * are ignored since they have already been processed.  If the criteria in a
607b07b2f5cSHuie-Ying Lee  * Match block is met, activep is set and the subsequent directives
608b07b2f5cSHuie-Ying Lee  * processed and actioned until EOF or another Match block unsets it.  Any
609b07b2f5cSHuie-Ying Lee  * options set are copied into the main server config.
610b07b2f5cSHuie-Ying Lee  *
611b07b2f5cSHuie-Ying Lee  * Potential additions/improvements:
612b07b2f5cSHuie-Ying Lee  *  - Add Match support for pre-kex directives, eg Protocol, Ciphers.
613b07b2f5cSHuie-Ying Lee  *
614b07b2f5cSHuie-Ying Lee  *  - Add a Tag directive (idea from David Leonard) ala pf, eg:
615b07b2f5cSHuie-Ying Lee  *	Match Address 192.168.0.*
616b07b2f5cSHuie-Ying Lee  *		Tag trusted
617b07b2f5cSHuie-Ying Lee  *	Match Group wheel
618b07b2f5cSHuie-Ying Lee  *		Tag trusted
619b07b2f5cSHuie-Ying Lee  *	Match Tag trusted
620b07b2f5cSHuie-Ying Lee  *		AllowTcpForwarding yes
621b07b2f5cSHuie-Ying Lee  *		GatewayPorts clientspecified
622b07b2f5cSHuie-Ying Lee  *		[...]
623b07b2f5cSHuie-Ying Lee  *
624b07b2f5cSHuie-Ying Lee  *  - Add a PermittedChannelRequests directive
625b07b2f5cSHuie-Ying Lee  *	Match Group shell
626b07b2f5cSHuie-Ying Lee  *		PermittedChannelRequests session,forwarded-tcpip
627b07b2f5cSHuie-Ying Lee  */
628b07b2f5cSHuie-Ying Lee 
629b07b2f5cSHuie-Ying Lee static int
630b07b2f5cSHuie-Ying Lee match_cfg_line_group(const char *grps, int line, const char *user)
631b07b2f5cSHuie-Ying Lee {
632b07b2f5cSHuie-Ying Lee 	int result = 0;
633b07b2f5cSHuie-Ying Lee 	struct passwd *pw;
634b07b2f5cSHuie-Ying Lee 
635b07b2f5cSHuie-Ying Lee 	if (user == NULL)
636b07b2f5cSHuie-Ying Lee 		goto out;
637b07b2f5cSHuie-Ying Lee 
638b07b2f5cSHuie-Ying Lee 	if ((pw = getpwnam(user)) == NULL) {
639b07b2f5cSHuie-Ying Lee 		debug("Can't match group at line %d because user %.100s does "
640b07b2f5cSHuie-Ying Lee 		    "not exist", line, user);
641b07b2f5cSHuie-Ying Lee 	} else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
642b07b2f5cSHuie-Ying Lee 		debug("Can't Match group because user %.100s not in any group "
643b07b2f5cSHuie-Ying Lee 		    "at line %d", user, line);
644b07b2f5cSHuie-Ying Lee 	} else if (ga_match_pattern_list(grps) != 1) {
645b07b2f5cSHuie-Ying Lee 		debug("user %.100s does not match group list %.100s at line %d",
646b07b2f5cSHuie-Ying Lee 		    user, grps, line);
647b07b2f5cSHuie-Ying Lee 	} else {
648b07b2f5cSHuie-Ying Lee 		debug("user %.100s matched group list %.100s at line %d", user,
649b07b2f5cSHuie-Ying Lee 		    grps, line);
650b07b2f5cSHuie-Ying Lee 		result = 1;
651b07b2f5cSHuie-Ying Lee 	}
652b07b2f5cSHuie-Ying Lee out:
653b07b2f5cSHuie-Ying Lee 	ga_free();
654b07b2f5cSHuie-Ying Lee 	return result;
655b07b2f5cSHuie-Ying Lee }
656b07b2f5cSHuie-Ying Lee 
657b07b2f5cSHuie-Ying Lee static int
658b07b2f5cSHuie-Ying Lee match_cfg_line(char **condition, int line, const char *user, const char *host,
659b07b2f5cSHuie-Ying Lee     const char *address)
660b07b2f5cSHuie-Ying Lee {
661b07b2f5cSHuie-Ying Lee 	int result = 1;
662b07b2f5cSHuie-Ying Lee 	char *arg, *attrib, *cp = *condition;
663b07b2f5cSHuie-Ying Lee 	size_t len;
664b07b2f5cSHuie-Ying Lee 
665b07b2f5cSHuie-Ying Lee 	if (user == NULL)
666b07b2f5cSHuie-Ying Lee 		debug3("checking syntax for 'Match %s'", cp);
667b07b2f5cSHuie-Ying Lee 	else
668b07b2f5cSHuie-Ying Lee 		debug3("checking match for '%s' user %s host %s addr %s", cp,
669b07b2f5cSHuie-Ying Lee 		    user ? user : "(null)", host ? host : "(null)",
670b07b2f5cSHuie-Ying Lee 		    address ? address : "(null)");
671b07b2f5cSHuie-Ying Lee 
67256e7e6c6SHuie-Ying Lee 	while ((attrib = strdelim(&cp)) != NULL && *attrib != '\0') {
673b07b2f5cSHuie-Ying Lee 		if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
674b07b2f5cSHuie-Ying Lee 			error("Missing Match criteria for %s", attrib);
675b07b2f5cSHuie-Ying Lee 			return -1;
676b07b2f5cSHuie-Ying Lee 		}
677b07b2f5cSHuie-Ying Lee 		len = strlen(arg);
678b07b2f5cSHuie-Ying Lee 		if (strcasecmp(attrib, "user") == 0) {
679b07b2f5cSHuie-Ying Lee 			if (!user) {
680b07b2f5cSHuie-Ying Lee 				result = 0;
681b07b2f5cSHuie-Ying Lee 				continue;
682b07b2f5cSHuie-Ying Lee 			}
683b07b2f5cSHuie-Ying Lee 			if (match_pattern_list(user, arg, len, 0) != 1)
684b07b2f5cSHuie-Ying Lee 				result = 0;
685b07b2f5cSHuie-Ying Lee 			else
686b07b2f5cSHuie-Ying Lee 				debug("user %.100s matched 'User %.100s' at "
687b07b2f5cSHuie-Ying Lee 				    "line %d", user, arg, line);
688b07b2f5cSHuie-Ying Lee 		} else if (strcasecmp(attrib, "group") == 0) {
689b07b2f5cSHuie-Ying Lee 			switch (match_cfg_line_group(arg, line, user)) {
690b07b2f5cSHuie-Ying Lee 			case -1:
691b07b2f5cSHuie-Ying Lee 				return -1;
692b07b2f5cSHuie-Ying Lee 			case 0:
693b07b2f5cSHuie-Ying Lee 				result = 0;
694b07b2f5cSHuie-Ying Lee 			}
695b07b2f5cSHuie-Ying Lee 		} else if (strcasecmp(attrib, "host") == 0) {
696b07b2f5cSHuie-Ying Lee 			if (!host) {
697b07b2f5cSHuie-Ying Lee 				result = 0;
698b07b2f5cSHuie-Ying Lee 				continue;
699b07b2f5cSHuie-Ying Lee 			}
700b07b2f5cSHuie-Ying Lee 			if (match_hostname(host, arg, len) != 1)
701b07b2f5cSHuie-Ying Lee 				result = 0;
702b07b2f5cSHuie-Ying Lee 			else
703b07b2f5cSHuie-Ying Lee 				debug("connection from %.100s matched 'Host "
704b07b2f5cSHuie-Ying Lee 				    "%.100s' at line %d", host, arg, line);
705b07b2f5cSHuie-Ying Lee 		} else if (strcasecmp(attrib, "address") == 0) {
706b07b2f5cSHuie-Ying Lee 			switch (addr_match_list(address, arg)) {
707b07b2f5cSHuie-Ying Lee 			case 1:
708b07b2f5cSHuie-Ying Lee 				debug("connection from %.100s matched 'Address "
709b07b2f5cSHuie-Ying Lee 				    "%.100s' at line %d", address, arg, line);
710b07b2f5cSHuie-Ying Lee 				break;
711b07b2f5cSHuie-Ying Lee 			case 0:
712b07b2f5cSHuie-Ying Lee 			case -1:
713b07b2f5cSHuie-Ying Lee 				result = 0;
714b07b2f5cSHuie-Ying Lee 				break;
715b07b2f5cSHuie-Ying Lee 			case -2:
716b07b2f5cSHuie-Ying Lee 				return -1;
717b07b2f5cSHuie-Ying Lee 			}
718b07b2f5cSHuie-Ying Lee 		} else {
719b07b2f5cSHuie-Ying Lee 			error("Unsupported Match attribute %s", attrib);
720b07b2f5cSHuie-Ying Lee 			return -1;
721b07b2f5cSHuie-Ying Lee 		}
722b07b2f5cSHuie-Ying Lee 	}
723b07b2f5cSHuie-Ying Lee 	if (user != NULL)
724b07b2f5cSHuie-Ying Lee 		debug3("match %sfound", result ? "" : "not ");
725b07b2f5cSHuie-Ying Lee 	*condition = cp;
726b07b2f5cSHuie-Ying Lee 	return result;
727b07b2f5cSHuie-Ying Lee }
728b07b2f5cSHuie-Ying Lee 
729b07b2f5cSHuie-Ying Lee #define WHITESPACE " \t\r\n"
730b07b2f5cSHuie-Ying Lee 
7317c478bd9Sstevel@tonic-gate int
7327c478bd9Sstevel@tonic-gate process_server_config_line(ServerOptions *options, char *line,
733b07b2f5cSHuie-Ying Lee     const char *filename, int linenum, int *activep, const char *user,
734b07b2f5cSHuie-Ying Lee     const char *host, const char *address)
7357c478bd9Sstevel@tonic-gate {
7367c478bd9Sstevel@tonic-gate 	char *cp, **charptr, *arg, *p;
737b07b2f5cSHuie-Ying Lee 	int cmdline = 0, *intptr, value, n;
7387c478bd9Sstevel@tonic-gate 	ServerOpCodes opcode;
739b07b2f5cSHuie-Ying Lee 	u_int i, flags = 0;
7406f8d59d8SJan Pechanec 	size_t len;
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 	cp = line;
7437c478bd9Sstevel@tonic-gate 	arg = strdelim(&cp);
7447c478bd9Sstevel@tonic-gate 	/* Ignore leading whitespace */
7457c478bd9Sstevel@tonic-gate 	if (*arg == '\0')
7467c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
7477c478bd9Sstevel@tonic-gate 	if (!arg || !*arg || *arg == '#')
7487c478bd9Sstevel@tonic-gate 		return 0;
7497c478bd9Sstevel@tonic-gate 	intptr = NULL;
7507c478bd9Sstevel@tonic-gate 	charptr = NULL;
751b07b2f5cSHuie-Ying Lee 	opcode = parse_token(arg, filename, linenum, &flags);
752b07b2f5cSHuie-Ying Lee 
753b07b2f5cSHuie-Ying Lee 	if (activep == NULL) { /* We are processing a command line directive */
754b07b2f5cSHuie-Ying Lee 		cmdline = 1;
755b07b2f5cSHuie-Ying Lee 		activep = &cmdline;
756b07b2f5cSHuie-Ying Lee 	}
757b07b2f5cSHuie-Ying Lee 	if (*activep && opcode != sMatch)
758b07b2f5cSHuie-Ying Lee 		debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
759b07b2f5cSHuie-Ying Lee 	if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
760b07b2f5cSHuie-Ying Lee 		if (user == NULL) {
761b07b2f5cSHuie-Ying Lee 			fatal("%s line %d: Directive '%s' is not allowed "
762b07b2f5cSHuie-Ying Lee 			    "within a Match block", filename, linenum, arg);
763b07b2f5cSHuie-Ying Lee 		} else { /* this is a directive we have already processed */
764b07b2f5cSHuie-Ying Lee 			while (arg)
765b07b2f5cSHuie-Ying Lee 				arg = strdelim(&cp);
766b07b2f5cSHuie-Ying Lee 			return 0;
767b07b2f5cSHuie-Ying Lee 		}
768b07b2f5cSHuie-Ying Lee 	}
769b07b2f5cSHuie-Ying Lee 
7707c478bd9Sstevel@tonic-gate 	switch (opcode) {
7717c478bd9Sstevel@tonic-gate 	/* Portable-specific options */
7727c478bd9Sstevel@tonic-gate 	case sPAMAuthenticationViaKbdInt:
7737c478bd9Sstevel@tonic-gate 		intptr = &options->pam_authentication_via_kbd_int;
7747c478bd9Sstevel@tonic-gate 		goto parse_flag;
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 	/* Standard Options */
7777c478bd9Sstevel@tonic-gate 	case sBadOption:
7787c478bd9Sstevel@tonic-gate 		return -1;
7797c478bd9Sstevel@tonic-gate 	case sPort:
7807c478bd9Sstevel@tonic-gate 		/* ignore ports from configfile if cmdline specifies ports */
7817c478bd9Sstevel@tonic-gate 		if (options->ports_from_cmdline)
7827c478bd9Sstevel@tonic-gate 			return 0;
7837c478bd9Sstevel@tonic-gate 		if (options->listen_addrs != NULL)
7847c478bd9Sstevel@tonic-gate 			fatal("%s line %d: ports must be specified before "
7857c478bd9Sstevel@tonic-gate 			    "ListenAddress.", filename, linenum);
7867c478bd9Sstevel@tonic-gate 		if (options->num_ports >= MAX_PORTS)
7877c478bd9Sstevel@tonic-gate 			fatal("%s line %d: too many ports.",
7887c478bd9Sstevel@tonic-gate 			    filename, linenum);
7897c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
7907c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
7917c478bd9Sstevel@tonic-gate 			fatal("%s line %d: missing port number.",
7927c478bd9Sstevel@tonic-gate 			    filename, linenum);
7937c478bd9Sstevel@tonic-gate 		options->ports[options->num_ports++] = a2port(arg);
7947c478bd9Sstevel@tonic-gate 		if (options->ports[options->num_ports-1] == 0)
7957c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Badly formatted port number.",
7967c478bd9Sstevel@tonic-gate 			    filename, linenum);
7977c478bd9Sstevel@tonic-gate 		break;
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate 	case sServerKeyBits:
8007c478bd9Sstevel@tonic-gate 		intptr = &options->server_key_bits;
8017c478bd9Sstevel@tonic-gate parse_int:
8027c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
8037c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
8047c478bd9Sstevel@tonic-gate 			fatal("%s line %d: missing integer value.",
8057c478bd9Sstevel@tonic-gate 			    filename, linenum);
8067c478bd9Sstevel@tonic-gate 		value = atoi(arg);
807b07b2f5cSHuie-Ying Lee 		if (*activep && *intptr == -1)
8087c478bd9Sstevel@tonic-gate 			*intptr = value;
8097c478bd9Sstevel@tonic-gate 		break;
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 	case sLoginGraceTime:
8127c478bd9Sstevel@tonic-gate 		intptr = &options->login_grace_time;
8137c478bd9Sstevel@tonic-gate parse_time:
8147c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
8157c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
8167c478bd9Sstevel@tonic-gate 			fatal("%s line %d: missing time value.",
8177c478bd9Sstevel@tonic-gate 			    filename, linenum);
8187c478bd9Sstevel@tonic-gate 		if ((value = convtime(arg)) == -1)
8197c478bd9Sstevel@tonic-gate 			fatal("%s line %d: invalid time value.",
8207c478bd9Sstevel@tonic-gate 			    filename, linenum);
8217c478bd9Sstevel@tonic-gate 		if (*intptr == -1)
8227c478bd9Sstevel@tonic-gate 			*intptr = value;
8237c478bd9Sstevel@tonic-gate 		break;
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 	case sKeyRegenerationTime:
8267c478bd9Sstevel@tonic-gate 		intptr = &options->key_regeneration_time;
8277c478bd9Sstevel@tonic-gate 		goto parse_time;
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 	case sListenAddress:
8307c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
8317c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
8327c478bd9Sstevel@tonic-gate 			fatal("%s line %d: missing inet addr.",
8337c478bd9Sstevel@tonic-gate 			    filename, linenum);
8347c478bd9Sstevel@tonic-gate 		if (*arg == '[') {
8357c478bd9Sstevel@tonic-gate 			if ((p = strchr(arg, ']')) == NULL)
8367c478bd9Sstevel@tonic-gate 				fatal("%s line %d: bad ipv6 inet addr usage.",
8377c478bd9Sstevel@tonic-gate 				    filename, linenum);
8387c478bd9Sstevel@tonic-gate 			arg++;
8397c478bd9Sstevel@tonic-gate 			(void) memmove(p, p+1, strlen(p+1)+1);
8407c478bd9Sstevel@tonic-gate 		} else if (((p = strchr(arg, ':')) == NULL) ||
8417c478bd9Sstevel@tonic-gate 			    (strchr(p+1, ':') != NULL)) {
8427c478bd9Sstevel@tonic-gate 			add_listen_addr(options, arg, 0);
8437c478bd9Sstevel@tonic-gate 			break;
8447c478bd9Sstevel@tonic-gate 		}
8457c478bd9Sstevel@tonic-gate 		if (*p == ':') {
8467c478bd9Sstevel@tonic-gate 			u_short port;
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate 			p++;
8497c478bd9Sstevel@tonic-gate 			if (*p == '\0')
8507c478bd9Sstevel@tonic-gate 				fatal("%s line %d: bad inet addr:port usage.",
8517c478bd9Sstevel@tonic-gate 				    filename, linenum);
8527c478bd9Sstevel@tonic-gate 			else {
8537c478bd9Sstevel@tonic-gate 				*(p-1) = '\0';
8547c478bd9Sstevel@tonic-gate 				if ((port = a2port(p)) == 0)
8557c478bd9Sstevel@tonic-gate 					fatal("%s line %d: bad port number.",
8567c478bd9Sstevel@tonic-gate 					    filename, linenum);
8577c478bd9Sstevel@tonic-gate 				add_listen_addr(options, arg, port);
8587c478bd9Sstevel@tonic-gate 			}
8597c478bd9Sstevel@tonic-gate 		} else if (*p == '\0')
8607c478bd9Sstevel@tonic-gate 			add_listen_addr(options, arg, 0);
8617c478bd9Sstevel@tonic-gate 		else
8627c478bd9Sstevel@tonic-gate 			fatal("%s line %d: bad inet addr usage.",
8637c478bd9Sstevel@tonic-gate 			    filename, linenum);
8647c478bd9Sstevel@tonic-gate 		break;
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate 	case sHostKeyFile:
8677c478bd9Sstevel@tonic-gate 		intptr = &options->num_host_key_files;
8687c478bd9Sstevel@tonic-gate 		if (*intptr >= MAX_HOSTKEYS)
8697c478bd9Sstevel@tonic-gate 			fatal("%s line %d: too many host keys specified (max %d).",
8707c478bd9Sstevel@tonic-gate 			    filename, linenum, MAX_HOSTKEYS);
8717c478bd9Sstevel@tonic-gate 		charptr = &options->host_key_files[*intptr];
8727c478bd9Sstevel@tonic-gate parse_filename:
8737c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
8747c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
8757c478bd9Sstevel@tonic-gate 			fatal("%s line %d: missing file name.",
8767c478bd9Sstevel@tonic-gate 			    filename, linenum);
877b07b2f5cSHuie-Ying Lee 		if (*activep && *charptr == NULL) {
8787c478bd9Sstevel@tonic-gate 			*charptr = tilde_expand_filename(arg, getuid());
8797c478bd9Sstevel@tonic-gate 			/* increase optional counter */
8807c478bd9Sstevel@tonic-gate 			if (intptr != NULL)
8817c478bd9Sstevel@tonic-gate 				*intptr = *intptr + 1;
8827c478bd9Sstevel@tonic-gate 		}
8837c478bd9Sstevel@tonic-gate 		break;
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 	case sPidFile:
8867c478bd9Sstevel@tonic-gate 		charptr = &options->pid_file;
8877c478bd9Sstevel@tonic-gate 		goto parse_filename;
8887c478bd9Sstevel@tonic-gate 
8897c478bd9Sstevel@tonic-gate 	case sPermitRootLogin:
8907c478bd9Sstevel@tonic-gate 		intptr = &options->permit_root_login;
8917c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
8927c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
8937c478bd9Sstevel@tonic-gate 			fatal("%s line %d: missing yes/"
8947c478bd9Sstevel@tonic-gate 			    "without-password/forced-commands-only/no "
8957c478bd9Sstevel@tonic-gate 			    "argument.", filename, linenum);
8967c478bd9Sstevel@tonic-gate 		value = 0;	/* silence compiler */
8977c478bd9Sstevel@tonic-gate 		if (strcmp(arg, "without-password") == 0)
8987c478bd9Sstevel@tonic-gate 			value = PERMIT_NO_PASSWD;
8997c478bd9Sstevel@tonic-gate 		else if (strcmp(arg, "forced-commands-only") == 0)
9007c478bd9Sstevel@tonic-gate 			value = PERMIT_FORCED_ONLY;
9017c478bd9Sstevel@tonic-gate 		else if (strcmp(arg, "yes") == 0)
9027c478bd9Sstevel@tonic-gate 			value = PERMIT_YES;
9037c478bd9Sstevel@tonic-gate 		else if (strcmp(arg, "no") == 0)
9047c478bd9Sstevel@tonic-gate 			value = PERMIT_NO;
9057c478bd9Sstevel@tonic-gate 		else
9067c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Bad yes/"
9077c478bd9Sstevel@tonic-gate 			    "without-password/forced-commands-only/no "
9087c478bd9Sstevel@tonic-gate 			    "argument: %s", filename, linenum, arg);
909b07b2f5cSHuie-Ying Lee 		if (*activep && *intptr == -1)
9107c478bd9Sstevel@tonic-gate 			*intptr = value;
9117c478bd9Sstevel@tonic-gate 		break;
9127c478bd9Sstevel@tonic-gate 
9137c478bd9Sstevel@tonic-gate 	case sIgnoreRhosts:
9147c478bd9Sstevel@tonic-gate 		intptr = &options->ignore_rhosts;
9157c478bd9Sstevel@tonic-gate parse_flag:
9167c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
9177c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
9187c478bd9Sstevel@tonic-gate 			fatal("%s line %d: missing yes/no argument.",
9197c478bd9Sstevel@tonic-gate 			    filename, linenum);
9207c478bd9Sstevel@tonic-gate 		value = 0;	/* silence compiler */
9217c478bd9Sstevel@tonic-gate 		if (strcmp(arg, "yes") == 0)
9227c478bd9Sstevel@tonic-gate 			value = 1;
9237c478bd9Sstevel@tonic-gate 		else if (strcmp(arg, "no") == 0)
9247c478bd9Sstevel@tonic-gate 			value = 0;
9257c478bd9Sstevel@tonic-gate 		else
9267c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Bad yes/no argument: %s",
9277c478bd9Sstevel@tonic-gate 				filename, linenum, arg);
928b07b2f5cSHuie-Ying Lee 		if (*activep && *intptr == -1)
9297c478bd9Sstevel@tonic-gate 			*intptr = value;
9307c478bd9Sstevel@tonic-gate 		break;
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	case sIgnoreUserKnownHosts:
9337c478bd9Sstevel@tonic-gate 		intptr = &options->ignore_user_known_hosts;
9347c478bd9Sstevel@tonic-gate 		goto parse_flag;
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate 	case sRhostsAuthentication:
9377c478bd9Sstevel@tonic-gate 		intptr = &options->rhosts_authentication;
9387c478bd9Sstevel@tonic-gate 		goto parse_flag;
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	case sRhostsRSAAuthentication:
9417c478bd9Sstevel@tonic-gate 		intptr = &options->rhosts_rsa_authentication;
9427c478bd9Sstevel@tonic-gate 		goto parse_flag;
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate 	case sHostbasedAuthentication:
9457c478bd9Sstevel@tonic-gate 		intptr = &options->hostbased_authentication;
9467c478bd9Sstevel@tonic-gate 		goto parse_flag;
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate 	case sHostbasedUsesNameFromPacketOnly:
9497c478bd9Sstevel@tonic-gate 		intptr = &options->hostbased_uses_name_from_packet_only;
9507c478bd9Sstevel@tonic-gate 		goto parse_flag;
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate 	case sRSAAuthentication:
9537c478bd9Sstevel@tonic-gate 		intptr = &options->rsa_authentication;
9547c478bd9Sstevel@tonic-gate 		goto parse_flag;
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate 	case sPubkeyAuthentication:
9577c478bd9Sstevel@tonic-gate 		intptr = &options->pubkey_authentication;
9587c478bd9Sstevel@tonic-gate 		goto parse_flag;
9597c478bd9Sstevel@tonic-gate #ifdef GSSAPI
9607c478bd9Sstevel@tonic-gate 	case sGssAuthentication:
9617c478bd9Sstevel@tonic-gate 		intptr = &options->gss_authentication;
9627c478bd9Sstevel@tonic-gate 		goto parse_flag;
9637c478bd9Sstevel@tonic-gate 	case sGssKeyEx:
9647c478bd9Sstevel@tonic-gate 		intptr = &options->gss_keyex;
9657c478bd9Sstevel@tonic-gate 		goto parse_flag;
9667c478bd9Sstevel@tonic-gate 	case sGssStoreDelegCreds:
9677c478bd9Sstevel@tonic-gate 		intptr = &options->gss_keyex;
9687c478bd9Sstevel@tonic-gate 		goto parse_flag;
9697c478bd9Sstevel@tonic-gate #ifndef SUNW_GSSAPI
9707c478bd9Sstevel@tonic-gate 	case sGssUseSessionCredCache:
9717c478bd9Sstevel@tonic-gate 		intptr = &options->gss_use_session_ccache;
9727c478bd9Sstevel@tonic-gate 		goto parse_flag;
9737c478bd9Sstevel@tonic-gate 	case sGssCleanupCreds:
9747c478bd9Sstevel@tonic-gate 		intptr = &options->gss_cleanup_creds;
9757c478bd9Sstevel@tonic-gate 		goto parse_flag;
9767c478bd9Sstevel@tonic-gate #endif /* SUNW_GSSAPI */
9777c478bd9Sstevel@tonic-gate #endif /* GSSAPI */
9787c478bd9Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
9797c478bd9Sstevel@tonic-gate 	case sKerberosAuthentication:
9807c478bd9Sstevel@tonic-gate 		intptr = &options->kerberos_authentication;
9817c478bd9Sstevel@tonic-gate 		goto parse_flag;
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	case sKerberosOrLocalPasswd:
9847c478bd9Sstevel@tonic-gate 		intptr = &options->kerberos_or_local_passwd;
9857c478bd9Sstevel@tonic-gate 		goto parse_flag;
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate 	case sKerberosTicketCleanup:
9887c478bd9Sstevel@tonic-gate 		intptr = &options->kerberos_ticket_cleanup;
9897c478bd9Sstevel@tonic-gate 		goto parse_flag;
9907c478bd9Sstevel@tonic-gate #endif
9917c478bd9Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
9927c478bd9Sstevel@tonic-gate 	case sKerberosTgtPassing:
9937c478bd9Sstevel@tonic-gate 		intptr = &options->kerberos_tgt_passing;
9947c478bd9Sstevel@tonic-gate 		goto parse_flag;
9957c478bd9Sstevel@tonic-gate #endif
9967c478bd9Sstevel@tonic-gate #ifdef AFS
9977c478bd9Sstevel@tonic-gate 	case sAFSTokenPassing:
9987c478bd9Sstevel@tonic-gate 		intptr = &options->afs_token_passing;
9997c478bd9Sstevel@tonic-gate 		goto parse_flag;
10007c478bd9Sstevel@tonic-gate #endif
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate 	case sPasswordAuthentication:
10037c478bd9Sstevel@tonic-gate 		intptr = &options->password_authentication;
10047c478bd9Sstevel@tonic-gate 		goto parse_flag;
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate 	case sKbdInteractiveAuthentication:
10077c478bd9Sstevel@tonic-gate 		intptr = &options->kbd_interactive_authentication;
10087c478bd9Sstevel@tonic-gate 		goto parse_flag;
10097c478bd9Sstevel@tonic-gate 
10107c478bd9Sstevel@tonic-gate 	case sChallengeResponseAuthentication:
10117c478bd9Sstevel@tonic-gate 		intptr = &options->challenge_response_authentication;
10127c478bd9Sstevel@tonic-gate 		goto parse_flag;
10137c478bd9Sstevel@tonic-gate 
10147c478bd9Sstevel@tonic-gate 	case sPrintMotd:
10157c478bd9Sstevel@tonic-gate 		intptr = &options->print_motd;
10167c478bd9Sstevel@tonic-gate 		goto parse_flag;
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 	case sPrintLastLog:
10197c478bd9Sstevel@tonic-gate 		intptr = &options->print_lastlog;
10207c478bd9Sstevel@tonic-gate 		goto parse_flag;
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 	case sX11Forwarding:
10237c478bd9Sstevel@tonic-gate 		intptr = &options->x11_forwarding;
10247c478bd9Sstevel@tonic-gate 		goto parse_flag;
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 	case sX11DisplayOffset:
10277c478bd9Sstevel@tonic-gate 		intptr = &options->x11_display_offset;
10287c478bd9Sstevel@tonic-gate 		goto parse_int;
10297c478bd9Sstevel@tonic-gate 
10307c478bd9Sstevel@tonic-gate 	case sX11UseLocalhost:
10317c478bd9Sstevel@tonic-gate 		intptr = &options->x11_use_localhost;
10327c478bd9Sstevel@tonic-gate 		goto parse_flag;
10337c478bd9Sstevel@tonic-gate 
10347c478bd9Sstevel@tonic-gate 	case sXAuthLocation:
10357c478bd9Sstevel@tonic-gate 		charptr = &options->xauth_location;
10367c478bd9Sstevel@tonic-gate 		goto parse_filename;
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 	case sStrictModes:
10397c478bd9Sstevel@tonic-gate 		intptr = &options->strict_modes;
10407c478bd9Sstevel@tonic-gate 		goto parse_flag;
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 	case sKeepAlives:
10437c478bd9Sstevel@tonic-gate 		intptr = &options->keepalives;
10447c478bd9Sstevel@tonic-gate 		goto parse_flag;
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 	case sEmptyPasswd:
10477c478bd9Sstevel@tonic-gate 		intptr = &options->permit_empty_passwd;
10487c478bd9Sstevel@tonic-gate 		goto parse_flag;
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate 	case sPermitUserEnvironment:
10517c478bd9Sstevel@tonic-gate 		intptr = &options->permit_user_env;
10527c478bd9Sstevel@tonic-gate 		goto parse_flag;
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 	case sUseLogin:
1055b9aa66a7SJan Pechanec 		log("%s line %d: ignoring UseLogin option value."
1056b9aa66a7SJan Pechanec 		    " This option is always off.", filename, linenum);
1057b9aa66a7SJan Pechanec 		while (arg)
1058b9aa66a7SJan Pechanec 			arg = strdelim(&cp);
1059b9aa66a7SJan Pechanec 		break;
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 	case sCompression:
10627c478bd9Sstevel@tonic-gate 		intptr = &options->compression;
10637c478bd9Sstevel@tonic-gate 		goto parse_flag;
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 	case sGatewayPorts:
1066b07b2f5cSHuie-Ying Lee 		intptr = &options->gateway_ports;
10679b03ea0fSjp161948 		arg = strdelim(&cp);
1068b07b2f5cSHuie-Ying Lee 		if (!arg || *arg == '\0')
1069b07b2f5cSHuie-Ying Lee 			fatal("%s line %d: missing yes/no/clientspecified "
10709b03ea0fSjp161948 			    "argument.", filename, linenum);
1071b07b2f5cSHuie-Ying Lee 		value = 0;	/* silence compiler */
1072b07b2f5cSHuie-Ying Lee 		if (strcmp(arg, "clientspecified") == 0)
1073b07b2f5cSHuie-Ying Lee 			value = 2;
1074b07b2f5cSHuie-Ying Lee 		else if (strcmp(arg, "yes") == 0)
1075b07b2f5cSHuie-Ying Lee 			value = 1;
1076b07b2f5cSHuie-Ying Lee 		else if (strcmp(arg, "no") == 0)
1077b07b2f5cSHuie-Ying Lee 			value = 0;
1078b07b2f5cSHuie-Ying Lee 		else
1079b07b2f5cSHuie-Ying Lee 			fatal("%s line %d: Bad yes/no/clientspecified "
1080b07b2f5cSHuie-Ying Lee 			    "argument: %s", filename, linenum, arg);
1081b07b2f5cSHuie-Ying Lee 		if (*activep && *intptr == -1)
1082b07b2f5cSHuie-Ying Lee 			*intptr = value;
10839b03ea0fSjp161948 		break;
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 	case sVerifyReverseMapping:
10867c478bd9Sstevel@tonic-gate 		intptr = &options->verify_reverse_mapping;
10877c478bd9Sstevel@tonic-gate 		goto parse_flag;
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate 	case sLogFacility:
10907c478bd9Sstevel@tonic-gate 		intptr = (int *) &options->log_facility;
10917c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
10927c478bd9Sstevel@tonic-gate 		value = log_facility_number(arg);
10937c478bd9Sstevel@tonic-gate 		if (value == SYSLOG_FACILITY_NOT_SET)
10947c478bd9Sstevel@tonic-gate 			fatal("%.200s line %d: unsupported log facility '%s'",
10957c478bd9Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
10967c478bd9Sstevel@tonic-gate 		if (*intptr == -1)
10977c478bd9Sstevel@tonic-gate 			*intptr = (SyslogFacility) value;
10987c478bd9Sstevel@tonic-gate 		break;
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate 	case sLogLevel:
11017c478bd9Sstevel@tonic-gate 		intptr = (int *) &options->log_level;
11027c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
11037c478bd9Sstevel@tonic-gate 		value = log_level_number(arg);
11047c478bd9Sstevel@tonic-gate 		if (value == SYSLOG_LEVEL_NOT_SET)
11057c478bd9Sstevel@tonic-gate 			fatal("%.200s line %d: unsupported log level '%s'",
11067c478bd9Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
11077c478bd9Sstevel@tonic-gate 		if (*intptr == -1)
11087c478bd9Sstevel@tonic-gate 			*intptr = (LogLevel) value;
11097c478bd9Sstevel@tonic-gate 		break;
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate 	case sAllowTcpForwarding:
11127c478bd9Sstevel@tonic-gate 		intptr = &options->allow_tcp_forwarding;
11137c478bd9Sstevel@tonic-gate 		goto parse_flag;
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate 	case sUsePrivilegeSeparation:
11169a8058b5Sjp161948 		log("%s line %d: ignoring UsePrivilegeSeparation option value."
11179a8058b5Sjp161948 		    " This option is always on.", filename, linenum);
11189a8058b5Sjp161948 		while (arg)
11199a8058b5Sjp161948 			arg = strdelim(&cp);
11209a8058b5Sjp161948 		break;
11217c478bd9Sstevel@tonic-gate 
11227c478bd9Sstevel@tonic-gate 	case sAllowUsers:
11237c478bd9Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
11247c478bd9Sstevel@tonic-gate 			if (options->num_allow_users >= MAX_ALLOW_USERS)
11257c478bd9Sstevel@tonic-gate 				fatal("%s line %d: too many allow users.",
11267c478bd9Sstevel@tonic-gate 				    filename, linenum);
11277c478bd9Sstevel@tonic-gate 			options->allow_users[options->num_allow_users++] =
11287c478bd9Sstevel@tonic-gate 			    xstrdup(arg);
11297c478bd9Sstevel@tonic-gate 		}
11307c478bd9Sstevel@tonic-gate 		break;
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate 	case sDenyUsers:
11337c478bd9Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
11347c478bd9Sstevel@tonic-gate 			if (options->num_deny_users >= MAX_DENY_USERS)
11357c478bd9Sstevel@tonic-gate 				fatal( "%s line %d: too many deny users.",
11367c478bd9Sstevel@tonic-gate 				    filename, linenum);
11377c478bd9Sstevel@tonic-gate 			options->deny_users[options->num_deny_users++] =
11387c478bd9Sstevel@tonic-gate 			    xstrdup(arg);
11397c478bd9Sstevel@tonic-gate 		}
11407c478bd9Sstevel@tonic-gate 		break;
11417c478bd9Sstevel@tonic-gate 
11427c478bd9Sstevel@tonic-gate 	case sAllowGroups:
11437c478bd9Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
11447c478bd9Sstevel@tonic-gate 			if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
11457c478bd9Sstevel@tonic-gate 				fatal("%s line %d: too many allow groups.",
11467c478bd9Sstevel@tonic-gate 				    filename, linenum);
11477c478bd9Sstevel@tonic-gate 			options->allow_groups[options->num_allow_groups++] =
11487c478bd9Sstevel@tonic-gate 			    xstrdup(arg);
11497c478bd9Sstevel@tonic-gate 		}
11507c478bd9Sstevel@tonic-gate 		break;
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate 	case sDenyGroups:
11537c478bd9Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
11547c478bd9Sstevel@tonic-gate 			if (options->num_deny_groups >= MAX_DENY_GROUPS)
11557c478bd9Sstevel@tonic-gate 				fatal("%s line %d: too many deny groups.",
11567c478bd9Sstevel@tonic-gate 				    filename, linenum);
11577c478bd9Sstevel@tonic-gate 			options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
11587c478bd9Sstevel@tonic-gate 		}
11597c478bd9Sstevel@tonic-gate 		break;
11607c478bd9Sstevel@tonic-gate 
11617c478bd9Sstevel@tonic-gate 	case sCiphers:
11627c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
11637c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
11647c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Missing argument.", filename, linenum);
11657c478bd9Sstevel@tonic-gate 		if (!ciphers_valid(arg))
11667c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
11677c478bd9Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
11687c478bd9Sstevel@tonic-gate 		if (options->ciphers == NULL)
11697c478bd9Sstevel@tonic-gate 			options->ciphers = xstrdup(arg);
11707c478bd9Sstevel@tonic-gate 		break;
11717c478bd9Sstevel@tonic-gate 
11727c478bd9Sstevel@tonic-gate 	case sMacs:
11737c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
11747c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
11757c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Missing argument.", filename, linenum);
11767c478bd9Sstevel@tonic-gate 		if (!mac_valid(arg))
11777c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Bad SSH2 mac spec '%s'.",
11787c478bd9Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
11797c478bd9Sstevel@tonic-gate 		if (options->macs == NULL)
11807c478bd9Sstevel@tonic-gate 			options->macs = xstrdup(arg);
11817c478bd9Sstevel@tonic-gate 		break;
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 	case sProtocol:
11847c478bd9Sstevel@tonic-gate 		intptr = &options->protocol;
11857c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
11867c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
11877c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Missing argument.", filename, linenum);
11887c478bd9Sstevel@tonic-gate 		value = proto_spec(arg);
11897c478bd9Sstevel@tonic-gate 		if (value == SSH_PROTO_UNKNOWN)
11907c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Bad protocol spec '%s'.",
11917c478bd9Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
11927c478bd9Sstevel@tonic-gate 		if (*intptr == SSH_PROTO_UNKNOWN)
11937c478bd9Sstevel@tonic-gate 			*intptr = value;
11947c478bd9Sstevel@tonic-gate 		break;
11957c478bd9Sstevel@tonic-gate 
11967c478bd9Sstevel@tonic-gate 	case sSubsystem:
11977c478bd9Sstevel@tonic-gate 		if (options->num_subsystems >= MAX_SUBSYSTEMS) {
11987c478bd9Sstevel@tonic-gate 			fatal("%s line %d: too many subsystems defined.",
11997c478bd9Sstevel@tonic-gate 			    filename, linenum);
12007c478bd9Sstevel@tonic-gate 		}
12017c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
12027c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
12037c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Missing subsystem name.",
12047c478bd9Sstevel@tonic-gate 			    filename, linenum);
1205b07b2f5cSHuie-Ying Lee 		if (!*activep) {
1206b07b2f5cSHuie-Ying Lee 			arg = strdelim(&cp);
1207b07b2f5cSHuie-Ying Lee 			break;
1208b07b2f5cSHuie-Ying Lee 		}
12097c478bd9Sstevel@tonic-gate 		for (i = 0; i < options->num_subsystems; i++)
12107c478bd9Sstevel@tonic-gate 			if (strcmp(arg, options->subsystem_name[i]) == 0)
12117c478bd9Sstevel@tonic-gate 				fatal("%s line %d: Subsystem '%s' already defined.",
12127c478bd9Sstevel@tonic-gate 				    filename, linenum, arg);
12137c478bd9Sstevel@tonic-gate 		options->subsystem_name[options->num_subsystems] = xstrdup(arg);
12147c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
12157c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
12167c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Missing subsystem command.",
12177c478bd9Sstevel@tonic-gate 			    filename, linenum);
12187c478bd9Sstevel@tonic-gate 		options->subsystem_command[options->num_subsystems] = xstrdup(arg);
12196f8d59d8SJan Pechanec 
12206f8d59d8SJan Pechanec 		/*
12216f8d59d8SJan Pechanec 		 * Collect arguments (separate to executable), including the
12226f8d59d8SJan Pechanec 		 * name of the executable, in a way that is easier to parse
12236f8d59d8SJan Pechanec 		 * later.
12246f8d59d8SJan Pechanec 		 */
12256f8d59d8SJan Pechanec 		p = xstrdup(arg);
12266f8d59d8SJan Pechanec 		len = strlen(p) + 1;
12276f8d59d8SJan Pechanec 		while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
12286f8d59d8SJan Pechanec 			len += 1 + strlen(arg);
12296f8d59d8SJan Pechanec 			p = xrealloc(p, len);
12306f8d59d8SJan Pechanec 			strlcat(p, " ", len);
12316f8d59d8SJan Pechanec 			strlcat(p, arg, len);
12326f8d59d8SJan Pechanec 		}
12336f8d59d8SJan Pechanec 		options->subsystem_args[options->num_subsystems] = p;
12347c478bd9Sstevel@tonic-gate 		options->num_subsystems++;
12357c478bd9Sstevel@tonic-gate 		break;
12367c478bd9Sstevel@tonic-gate 
12377c478bd9Sstevel@tonic-gate 	case sMaxStartups:
12387c478bd9Sstevel@tonic-gate 		arg = strdelim(&cp);
12397c478bd9Sstevel@tonic-gate 		if (!arg || *arg == '\0')
12407c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Missing MaxStartups spec.",
12417c478bd9Sstevel@tonic-gate 			    filename, linenum);
12427c478bd9Sstevel@tonic-gate 		if ((n = sscanf(arg, "%d:%d:%d",
12437c478bd9Sstevel@tonic-gate 		    &options->max_startups_begin,
12447c478bd9Sstevel@tonic-gate 		    &options->max_startups_rate,
12457c478bd9Sstevel@tonic-gate 		    &options->max_startups)) == 3) {
12467c478bd9Sstevel@tonic-gate 			if (options->max_startups_begin >
12477c478bd9Sstevel@tonic-gate 			    options->max_startups ||
12487c478bd9Sstevel@tonic-gate 			    options->max_startups_rate > 100 ||
12497c478bd9Sstevel@tonic-gate 			    options->max_startups_rate < 1)
12507c478bd9Sstevel@tonic-gate 				fatal("%s line %d: Illegal MaxStartups spec.",
12517c478bd9Sstevel@tonic-gate 				    filename, linenum);
12527c478bd9Sstevel@tonic-gate 		} else if (n != 1)
12537c478bd9Sstevel@tonic-gate 			fatal("%s line %d: Illegal MaxStartups spec.",
12547c478bd9Sstevel@tonic-gate 			    filename, linenum);
12557c478bd9Sstevel@tonic-gate 		else
12567c478bd9Sstevel@tonic-gate 			options->max_startups = options->max_startups_begin;
12577c478bd9Sstevel@tonic-gate 		break;
12587c478bd9Sstevel@tonic-gate 
12597c478bd9Sstevel@tonic-gate 	case sBanner:
12607c478bd9Sstevel@tonic-gate 		charptr = &options->banner;
12617c478bd9Sstevel@tonic-gate 		goto parse_filename;
12627c478bd9Sstevel@tonic-gate 	/*
12637c478bd9Sstevel@tonic-gate 	 * These options can contain %X options expanded at
12647c478bd9Sstevel@tonic-gate 	 * connect time, so that you can specify paths like:
12657c478bd9Sstevel@tonic-gate 	 *
12667c478bd9Sstevel@tonic-gate 	 * AuthorizedKeysFile	/etc/ssh_keys/%u
12677c478bd9Sstevel@tonic-gate 	 */
12687c478bd9Sstevel@tonic-gate 	case sAuthorizedKeysFile:
12697c478bd9Sstevel@tonic-gate 	case sAuthorizedKeysFile2:
12707c478bd9Sstevel@tonic-gate 		charptr = (opcode == sAuthorizedKeysFile) ?
12717c478bd9Sstevel@tonic-gate 		    &options->authorized_keys_file :
12727c478bd9Sstevel@tonic-gate 		    &options->authorized_keys_file2;
12737c478bd9Sstevel@tonic-gate 		goto parse_filename;
12747c478bd9Sstevel@tonic-gate 
12757c478bd9Sstevel@tonic-gate 	case sClientAliveInterval:
12767c478bd9Sstevel@tonic-gate 		intptr = &options->client_alive_interval;
12777c478bd9Sstevel@tonic-gate 		goto parse_time;
12787c478bd9Sstevel@tonic-gate 
12797c478bd9Sstevel@tonic-gate 	case sClientAliveCountMax:
12807c478bd9Sstevel@tonic-gate 		intptr = &options->client_alive_count_max;
12817c478bd9Sstevel@tonic-gate 		goto parse_int;
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	case sMaxAuthTries:
12847c478bd9Sstevel@tonic-gate 		intptr = &options->max_auth_tries;
12857c478bd9Sstevel@tonic-gate 		goto parse_int;
12867c478bd9Sstevel@tonic-gate 
12877c478bd9Sstevel@tonic-gate 	case sMaxAuthTriesLog:
12887c478bd9Sstevel@tonic-gate 		intptr = &options->max_auth_tries_log;
12897c478bd9Sstevel@tonic-gate 		goto parse_int;
12907c478bd9Sstevel@tonic-gate 
12917c478bd9Sstevel@tonic-gate 	case sLookupClientHostnames:
12927c478bd9Sstevel@tonic-gate 		intptr = &options->lookup_client_hostnames;
12937c478bd9Sstevel@tonic-gate 		goto parse_flag;
12946f8d59d8SJan Pechanec 
1295cd7d5fafSJan Pechanec 	case sUseOpenSSLEngine:
1296cd7d5fafSJan Pechanec 		intptr = &options->use_openssl_engine;
1297cd7d5fafSJan Pechanec 		goto parse_flag;
12987c478bd9Sstevel@tonic-gate 
12996f8d59d8SJan Pechanec 	case sChrootDirectory:
13006f8d59d8SJan Pechanec 		charptr = &options->chroot_directory;
13016f8d59d8SJan Pechanec 
13026f8d59d8SJan Pechanec 		arg = strdelim(&cp);
13036f8d59d8SJan Pechanec 		if (arg == NULL || *arg == '\0')
13046f8d59d8SJan Pechanec 			fatal("%s line %d: missing directory name for "
13056f8d59d8SJan Pechanec 			    "ChrootDirectory.", filename, linenum);
1306b07b2f5cSHuie-Ying Lee 		if (*activep && *charptr == NULL)
13076f8d59d8SJan Pechanec 			*charptr = xstrdup(arg);
13086f8d59d8SJan Pechanec 		break;
13096f8d59d8SJan Pechanec 
1310d8a94255SErik Trauschke 	case sPreUserauthHook:
1311d8a94255SErik Trauschke 		charptr = &options->pre_userauth_hook;
1312d8a94255SErik Trauschke 		goto parse_filename;
1313d8a94255SErik Trauschke 
1314b07b2f5cSHuie-Ying Lee 	case sMatch:
1315b07b2f5cSHuie-Ying Lee 		if (cmdline)
1316b07b2f5cSHuie-Ying Lee 			fatal("Match directive not supported as a command-line "
1317b07b2f5cSHuie-Ying Lee 			   "option");
1318b07b2f5cSHuie-Ying Lee 		value = match_cfg_line(&cp, linenum, user, host, address);
1319b07b2f5cSHuie-Ying Lee 		if (value < 0)
1320b07b2f5cSHuie-Ying Lee 			fatal("%s line %d: Bad Match condition", filename,
1321b07b2f5cSHuie-Ying Lee 			    linenum);
1322b07b2f5cSHuie-Ying Lee 		*activep = value;
1323b07b2f5cSHuie-Ying Lee 		break;
1324b07b2f5cSHuie-Ying Lee 
13257c478bd9Sstevel@tonic-gate 	case sDeprecated:
13267c478bd9Sstevel@tonic-gate 		log("%s line %d: Deprecated option %s",
13277c478bd9Sstevel@tonic-gate 		    filename, linenum, arg);
13287c478bd9Sstevel@tonic-gate 		while (arg)
13297c478bd9Sstevel@tonic-gate 		    arg = strdelim(&cp);
13307c478bd9Sstevel@tonic-gate 		break;
13317c478bd9Sstevel@tonic-gate 
1332*bdb005b5SDarren J Moffat 	case sPAMServicePrefix:
1333*bdb005b5SDarren J Moffat 		arg = strdelim(&cp);
1334*bdb005b5SDarren J Moffat 		if (!arg || *arg == '\0')
1335*bdb005b5SDarren J Moffat 			fatal("%s line %d: Missing argument.",
1336*bdb005b5SDarren J Moffat 			    filename, linenum);
1337*bdb005b5SDarren J Moffat 		if (options->pam_service_name != NULL)
1338*bdb005b5SDarren J Moffat 			fatal("%s line %d: PAMServiceName and PAMServicePrefix "
1339*bdb005b5SDarren J Moffat 			    "are mutually exclusive.", filename, linenum);
1340*bdb005b5SDarren J Moffat 		if (options->pam_service_prefix == NULL)
1341*bdb005b5SDarren J Moffat 			options->pam_service_prefix = xstrdup(arg);
1342*bdb005b5SDarren J Moffat 		break;
1343*bdb005b5SDarren J Moffat 
1344*bdb005b5SDarren J Moffat 	case sPAMServiceName:
1345*bdb005b5SDarren J Moffat 		arg = strdelim(&cp);
1346*bdb005b5SDarren J Moffat 		if (!arg || *arg == '\0')
1347*bdb005b5SDarren J Moffat 			fatal("%s line %d: Missing argument.",
1348*bdb005b5SDarren J Moffat 			    filename, linenum);
1349*bdb005b5SDarren J Moffat 		if (options->pam_service_prefix != NULL)
1350*bdb005b5SDarren J Moffat 			fatal("%s line %d: PAMServiceName and PAMServicePrefix "
1351*bdb005b5SDarren J Moffat 			    "are mutually exclusive.", filename, linenum);
1352*bdb005b5SDarren J Moffat 		if (options->pam_service_name == NULL)
1353*bdb005b5SDarren J Moffat 			options->pam_service_name = xstrdup(arg);
1354*bdb005b5SDarren J Moffat 		break;
1355*bdb005b5SDarren J Moffat 
13567c478bd9Sstevel@tonic-gate 	default:
13577c478bd9Sstevel@tonic-gate 		fatal("%s line %d: Missing handler for opcode %s (%d)",
13587c478bd9Sstevel@tonic-gate 		    filename, linenum, arg, opcode);
13597c478bd9Sstevel@tonic-gate 	}
13607c478bd9Sstevel@tonic-gate 	if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
13617c478bd9Sstevel@tonic-gate 		fatal("%s line %d: garbage at end of line; \"%.200s\".",
13627c478bd9Sstevel@tonic-gate 		    filename, linenum, arg);
13637c478bd9Sstevel@tonic-gate 	return 0;
13647c478bd9Sstevel@tonic-gate }
13657c478bd9Sstevel@tonic-gate 
1366b07b2f5cSHuie-Ying Lee 
13677c478bd9Sstevel@tonic-gate /* Reads the server configuration file. */
13687c478bd9Sstevel@tonic-gate 
13697c478bd9Sstevel@tonic-gate void
1370b07b2f5cSHuie-Ying Lee load_server_config(const char *filename, Buffer *conf)
13717c478bd9Sstevel@tonic-gate {
1372b07b2f5cSHuie-Ying Lee 	char line[1024], *cp;
13737c478bd9Sstevel@tonic-gate 	FILE *f;
13747c478bd9Sstevel@tonic-gate 
1375b07b2f5cSHuie-Ying Lee 	debug2("%s: filename %s", __func__, filename);
1376b07b2f5cSHuie-Ying Lee 	if ((f = fopen(filename, "r")) == NULL) {
13777c478bd9Sstevel@tonic-gate 		perror(filename);
13787c478bd9Sstevel@tonic-gate 		exit(1);
13797c478bd9Sstevel@tonic-gate 	}
1380b07b2f5cSHuie-Ying Lee 	buffer_clear(conf);
13817c478bd9Sstevel@tonic-gate 	while (fgets(line, sizeof(line), f)) {
1382b07b2f5cSHuie-Ying Lee 		/*
1383b07b2f5cSHuie-Ying Lee 		 * Trim out comments and strip whitespace
1384b07b2f5cSHuie-Ying Lee 		 * NB - preserve newlines, they are needed to reproduce
1385b07b2f5cSHuie-Ying Lee 		 * line numbers later for error messages
1386b07b2f5cSHuie-Ying Lee 		 */
1387b07b2f5cSHuie-Ying Lee 		if ((cp = strchr(line, '#')) != NULL)
1388b07b2f5cSHuie-Ying Lee 			memcpy(cp, "\n", 2);
1389b07b2f5cSHuie-Ying Lee 		cp = line + strspn(line, " \t\r");
1390b07b2f5cSHuie-Ying Lee 
1391b07b2f5cSHuie-Ying Lee 		buffer_append(conf, cp, strlen(cp));
1392b07b2f5cSHuie-Ying Lee 	}
1393b07b2f5cSHuie-Ying Lee 	buffer_append(conf, "\0", 1);
1394b07b2f5cSHuie-Ying Lee 	fclose(f);
1395b07b2f5cSHuie-Ying Lee 	debug2("%s: done config len = %d", __func__, buffer_len(conf));
1396b07b2f5cSHuie-Ying Lee }
1397b07b2f5cSHuie-Ying Lee 
1398b07b2f5cSHuie-Ying Lee void
1399b07b2f5cSHuie-Ying Lee parse_server_match_config(ServerOptions *options, const char *user,
1400b07b2f5cSHuie-Ying Lee     const char *host, const char *address)
1401b07b2f5cSHuie-Ying Lee {
1402b07b2f5cSHuie-Ying Lee 	ServerOptions mo;
1403b07b2f5cSHuie-Ying Lee 
1404b07b2f5cSHuie-Ying Lee 	initialize_server_options(&mo);
1405b07b2f5cSHuie-Ying Lee 	parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
1406b07b2f5cSHuie-Ying Lee 	copy_set_server_options(options, &mo, 0);
1407b07b2f5cSHuie-Ying Lee }
1408b07b2f5cSHuie-Ying Lee 
1409b07b2f5cSHuie-Ying Lee 
1410b07b2f5cSHuie-Ying Lee 
1411b07b2f5cSHuie-Ying Lee /* Helper macros */
1412b07b2f5cSHuie-Ying Lee #define M_CP_INTOPT(n) do {\
1413b07b2f5cSHuie-Ying Lee 	if (src->n != -1) \
1414b07b2f5cSHuie-Ying Lee 		dst->n = src->n; \
1415b07b2f5cSHuie-Ying Lee } while (0)
1416b07b2f5cSHuie-Ying Lee #define M_CP_STROPT(n) do {\
1417b07b2f5cSHuie-Ying Lee 	if (src->n != NULL) { \
1418b07b2f5cSHuie-Ying Lee 		if (dst->n != NULL) \
1419b07b2f5cSHuie-Ying Lee 			xfree(dst->n); \
1420b07b2f5cSHuie-Ying Lee 		dst->n = src->n; \
1421b07b2f5cSHuie-Ying Lee 	} \
1422b07b2f5cSHuie-Ying Lee } while(0)
1423b07b2f5cSHuie-Ying Lee 
1424b07b2f5cSHuie-Ying Lee /*
1425b07b2f5cSHuie-Ying Lee  * Copy any supported values that are set.
1426b07b2f5cSHuie-Ying Lee  *
1427b07b2f5cSHuie-Ying Lee  * If the preauth flag is set, we do not bother copying the the string or
1428b07b2f5cSHuie-Ying Lee  * array values that are not used pre-authentication, because any that we
1429b07b2f5cSHuie-Ying Lee  * do use must be explictly sent in mm_getpwnamallow().
1430b07b2f5cSHuie-Ying Lee  */
1431b07b2f5cSHuie-Ying Lee void
1432b07b2f5cSHuie-Ying Lee copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1433b07b2f5cSHuie-Ying Lee {
1434b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(password_authentication);
1435b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(gss_authentication);
1436b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(rsa_authentication);
1437b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(pubkey_authentication);
1438b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(hostbased_authentication);
1439b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(kbd_interactive_authentication);
1440b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(permit_root_login);
1441b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(permit_empty_passwd);
1442b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(allow_tcp_forwarding);
1443b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(gateway_ports);
1444b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(x11_display_offset);
1445b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(x11_forwarding);
1446b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(x11_use_localhost);
1447b07b2f5cSHuie-Ying Lee 	M_CP_INTOPT(max_auth_tries);
1448b07b2f5cSHuie-Ying Lee 	M_CP_STROPT(banner);
1449b07b2f5cSHuie-Ying Lee 
1450b07b2f5cSHuie-Ying Lee 	if (preauth)
1451b07b2f5cSHuie-Ying Lee 		return;
1452b07b2f5cSHuie-Ying Lee 	M_CP_STROPT(chroot_directory);
1453b07b2f5cSHuie-Ying Lee }
1454b07b2f5cSHuie-Ying Lee 
1455b07b2f5cSHuie-Ying Lee #undef M_CP_INTOPT
1456b07b2f5cSHuie-Ying Lee #undef M_CP_STROPT
1457b07b2f5cSHuie-Ying Lee 
1458b07b2f5cSHuie-Ying Lee void
1459b07b2f5cSHuie-Ying Lee parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1460b07b2f5cSHuie-Ying Lee     const char *user, const char *host, const char *address)
1461b07b2f5cSHuie-Ying Lee {
1462b07b2f5cSHuie-Ying Lee 	int active, linenum, bad_options = 0;
1463b07b2f5cSHuie-Ying Lee 	char *cp, *obuf, *cbuf;
1464b07b2f5cSHuie-Ying Lee 
1465b07b2f5cSHuie-Ying Lee 	debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1466b07b2f5cSHuie-Ying Lee 
1467b07b2f5cSHuie-Ying Lee 	obuf = cbuf = xstrdup(buffer_ptr(conf));
1468b07b2f5cSHuie-Ying Lee 	active = user ? 0 : 1;
1469b07b2f5cSHuie-Ying Lee 	linenum = 1;
1470b07b2f5cSHuie-Ying Lee 	while ((cp = strsep(&cbuf, "\n")) != NULL) {
1471b07b2f5cSHuie-Ying Lee 		if (process_server_config_line(options, cp, filename,
1472b07b2f5cSHuie-Ying Lee 		    linenum++, &active, user, host, address) != 0)
14737c478bd9Sstevel@tonic-gate 			bad_options++;
14747c478bd9Sstevel@tonic-gate 	}
1475b07b2f5cSHuie-Ying Lee 	xfree(obuf);
14767c478bd9Sstevel@tonic-gate 	if (bad_options > 0)
14777c478bd9Sstevel@tonic-gate 		fatal("%s: terminating, %d bad configuration options",
14787c478bd9Sstevel@tonic-gate 		    filename, bad_options);
14797c478bd9Sstevel@tonic-gate }
14806f8d59d8SJan Pechanec 
1481b07b2f5cSHuie-Ying Lee 
14826f8d59d8SJan Pechanec /*
14836f8d59d8SJan Pechanec  * Note that "none" is a special path having the same affect on sshd
14846f8d59d8SJan Pechanec  * configuration as not specifying ChrootDirectory at all.
14856f8d59d8SJan Pechanec  */
14866f8d59d8SJan Pechanec int
14876f8d59d8SJan Pechanec chroot_requested(char *chroot_directory)
14886f8d59d8SJan Pechanec {
14896f8d59d8SJan Pechanec 	return (chroot_directory != NULL &&
14906f8d59d8SJan Pechanec 	    strcasecmp(chroot_directory, "none") != 0);
14916f8d59d8SJan Pechanec }
1492