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