xref: /onnv-gate/usr/src/cmd/ssh/sshd/servconf.c (revision 5562:0f12179b71ab)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
30Sstevel@tonic-gate  *                    All rights reserved
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
60Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
70Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
80Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
90Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
100Sstevel@tonic-gate  */
110Sstevel@tonic-gate /*
125334Sjp161948  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
130Sstevel@tonic-gate  * Use is subject to license terms.
140Sstevel@tonic-gate  */
150Sstevel@tonic-gate 
160Sstevel@tonic-gate #include "includes.h"
170Sstevel@tonic-gate RCSID("$OpenBSD: servconf.c,v 1.115 2002/09/04 18:52:42 stevesk Exp $");
180Sstevel@tonic-gate 
190Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
200Sstevel@tonic-gate 
210Sstevel@tonic-gate #ifdef HAVE_DEFOPEN
220Sstevel@tonic-gate #include <deflt.h>
230Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #if defined(KRB4)
260Sstevel@tonic-gate #include <krb.h>
270Sstevel@tonic-gate #endif
280Sstevel@tonic-gate #if defined(KRB5)
290Sstevel@tonic-gate #ifdef HEIMDAL
300Sstevel@tonic-gate #include <krb.h>
310Sstevel@tonic-gate #else
320Sstevel@tonic-gate /* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V
330Sstevel@tonic-gate  * keytab */
340Sstevel@tonic-gate #define KEYFILE "/etc/krb5.keytab"
350Sstevel@tonic-gate #endif
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate #ifdef AFS
380Sstevel@tonic-gate #include <kafs.h>
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include "ssh.h"
420Sstevel@tonic-gate #include "log.h"
430Sstevel@tonic-gate #include "servconf.h"
440Sstevel@tonic-gate #include "xmalloc.h"
450Sstevel@tonic-gate #include "compat.h"
460Sstevel@tonic-gate #include "pathnames.h"
470Sstevel@tonic-gate #include "tildexpand.h"
480Sstevel@tonic-gate #include "misc.h"
490Sstevel@tonic-gate #include "cipher.h"
500Sstevel@tonic-gate #include "kex.h"
510Sstevel@tonic-gate #include "mac.h"
520Sstevel@tonic-gate #include "auth.h"
530Sstevel@tonic-gate 
540Sstevel@tonic-gate static void add_listen_addr(ServerOptions *, char *, u_short);
550Sstevel@tonic-gate static void add_one_listen_addr(ServerOptions *, char *, u_short);
560Sstevel@tonic-gate 
570Sstevel@tonic-gate /* AF_UNSPEC or AF_INET or AF_INET6 */
580Sstevel@tonic-gate extern int IPv4or6;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /* Initializes the server options to their default values. */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate void
630Sstevel@tonic-gate initialize_server_options(ServerOptions *options)
640Sstevel@tonic-gate {
650Sstevel@tonic-gate 	(void) memset(options, 0, sizeof(*options));
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	/* Portable-specific options */
680Sstevel@tonic-gate 	options->pam_authentication_via_kbd_int = -1;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	/* Standard Options */
710Sstevel@tonic-gate 	options->num_ports = 0;
720Sstevel@tonic-gate 	options->ports_from_cmdline = 0;
730Sstevel@tonic-gate 	options->listen_addrs = NULL;
740Sstevel@tonic-gate 	options->num_host_key_files = 0;
750Sstevel@tonic-gate 	options->pid_file = NULL;
760Sstevel@tonic-gate 	options->server_key_bits = -1;
770Sstevel@tonic-gate 	options->login_grace_time = -1;
780Sstevel@tonic-gate 	options->key_regeneration_time = -1;
790Sstevel@tonic-gate 	options->permit_root_login = PERMIT_NOT_SET;
800Sstevel@tonic-gate 	options->ignore_rhosts = -1;
810Sstevel@tonic-gate 	options->ignore_user_known_hosts = -1;
820Sstevel@tonic-gate 	options->print_motd = -1;
830Sstevel@tonic-gate 	options->print_lastlog = -1;
840Sstevel@tonic-gate 	options->x11_forwarding = -1;
850Sstevel@tonic-gate 	options->x11_display_offset = -1;
860Sstevel@tonic-gate 	options->x11_use_localhost = -1;
870Sstevel@tonic-gate 	options->xauth_location = NULL;
880Sstevel@tonic-gate 	options->strict_modes = -1;
890Sstevel@tonic-gate 	options->keepalives = -1;
900Sstevel@tonic-gate 	options->log_facility = SYSLOG_FACILITY_NOT_SET;
910Sstevel@tonic-gate 	options->log_level = SYSLOG_LEVEL_NOT_SET;
920Sstevel@tonic-gate 	options->rhosts_authentication = -1;
930Sstevel@tonic-gate 	options->rhosts_rsa_authentication = -1;
940Sstevel@tonic-gate 	options->hostbased_authentication = -1;
950Sstevel@tonic-gate 	options->hostbased_uses_name_from_packet_only = -1;
960Sstevel@tonic-gate 	options->rsa_authentication = -1;
970Sstevel@tonic-gate 	options->pubkey_authentication = -1;
980Sstevel@tonic-gate #ifdef GSSAPI
990Sstevel@tonic-gate 	options->gss_authentication = -1;
1000Sstevel@tonic-gate 	options->gss_keyex = -1;
1010Sstevel@tonic-gate 	options->gss_store_creds = -1;
1020Sstevel@tonic-gate 	options->gss_use_session_ccache = -1;
1030Sstevel@tonic-gate 	options->gss_cleanup_creds = -1;
1040Sstevel@tonic-gate #endif
1050Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
1060Sstevel@tonic-gate 	options->kerberos_authentication = -1;
1070Sstevel@tonic-gate 	options->kerberos_or_local_passwd = -1;
1080Sstevel@tonic-gate 	options->kerberos_ticket_cleanup = -1;
1090Sstevel@tonic-gate #endif
1100Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
1110Sstevel@tonic-gate 	options->kerberos_tgt_passing = -1;
1120Sstevel@tonic-gate #endif
1130Sstevel@tonic-gate #ifdef AFS
1140Sstevel@tonic-gate 	options->afs_token_passing = -1;
1150Sstevel@tonic-gate #endif
1160Sstevel@tonic-gate 	options->password_authentication = -1;
1170Sstevel@tonic-gate 	options->kbd_interactive_authentication = -1;
1180Sstevel@tonic-gate 	options->challenge_response_authentication = -1;
1190Sstevel@tonic-gate 	options->permit_empty_passwd = -1;
1200Sstevel@tonic-gate 	options->permit_user_env = -1;
1210Sstevel@tonic-gate 	options->use_login = -1;
1220Sstevel@tonic-gate 	options->compression = -1;
1230Sstevel@tonic-gate 	options->allow_tcp_forwarding = -1;
1240Sstevel@tonic-gate 	options->num_allow_users = 0;
1250Sstevel@tonic-gate 	options->num_deny_users = 0;
1260Sstevel@tonic-gate 	options->num_allow_groups = 0;
1270Sstevel@tonic-gate 	options->num_deny_groups = 0;
1280Sstevel@tonic-gate 	options->ciphers = NULL;
1290Sstevel@tonic-gate 	options->macs = NULL;
1300Sstevel@tonic-gate 	options->protocol = SSH_PROTO_UNKNOWN;
1310Sstevel@tonic-gate 	options->gateway_ports = -1;
1320Sstevel@tonic-gate 	options->num_subsystems = 0;
1330Sstevel@tonic-gate 	options->max_startups_begin = -1;
1340Sstevel@tonic-gate 	options->max_startups_rate = -1;
1350Sstevel@tonic-gate 	options->max_startups = -1;
1360Sstevel@tonic-gate 	options->banner = NULL;
1370Sstevel@tonic-gate 	options->verify_reverse_mapping = -1;
1380Sstevel@tonic-gate 	options->client_alive_interval = -1;
1390Sstevel@tonic-gate 	options->client_alive_count_max = -1;
1400Sstevel@tonic-gate 	options->authorized_keys_file = NULL;
1410Sstevel@tonic-gate 	options->authorized_keys_file2 = NULL;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	options->max_auth_tries = -1;
1440Sstevel@tonic-gate 	options->max_auth_tries_log = -1;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	options->max_init_auth_tries = -1;
1470Sstevel@tonic-gate 	options->max_init_auth_tries_log = -1;
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	options->lookup_client_hostnames = -1;
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #ifdef HAVE_DEFOPEN
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * Reads /etc/default/login and defaults several ServerOptions:
1550Sstevel@tonic-gate  *
1560Sstevel@tonic-gate  * PermitRootLogin
1570Sstevel@tonic-gate  * PermitEmptyPasswords
1580Sstevel@tonic-gate  * LoginGraceTime
1590Sstevel@tonic-gate  *
1600Sstevel@tonic-gate  * CONSOLE=*      -> PermitRootLogin=without-password
1610Sstevel@tonic-gate  * #CONSOLE=*     -> PermitRootLogin=yes
1620Sstevel@tonic-gate  *
1630Sstevel@tonic-gate  * PASSREQ=YES    -> PermitEmptyPasswords=no
1640Sstevel@tonic-gate  * PASSREQ=NO     -> PermitEmptyPasswords=yes
1650Sstevel@tonic-gate  * #PASSREQ=*     -> PermitEmptyPasswords=no
1660Sstevel@tonic-gate  *
1670Sstevel@tonic-gate  * TIMEOUT=<secs> -> LoginGraceTime=<secs>
1680Sstevel@tonic-gate  * #TIMEOUT=<secs> -> LoginGraceTime=300
1690Sstevel@tonic-gate  */
1700Sstevel@tonic-gate static
1710Sstevel@tonic-gate void
1720Sstevel@tonic-gate deflt_fill_default_server_options(ServerOptions *options)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate 	int	flags;
1750Sstevel@tonic-gate 	char	*ptr;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	if (defopen(_PATH_DEFAULT_LOGIN))
1780Sstevel@tonic-gate 		return;
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	/* Ignore case */
1810Sstevel@tonic-gate 	flags = defcntl(DC_GETFLAGS, 0);
1820Sstevel@tonic-gate 	TURNOFF(flags, DC_CASE);
1830Sstevel@tonic-gate 	(void) defcntl(DC_SETFLAGS, flags);
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	if (options->permit_root_login == PERMIT_NOT_SET &&
1860Sstevel@tonic-gate 	    (ptr = defread("CONSOLE=")) != NULL)
1870Sstevel@tonic-gate 		options->permit_root_login = PERMIT_NO_PASSWD;
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	if (options->permit_empty_passwd == -1 &&
1900Sstevel@tonic-gate 	    (ptr = defread("PASSREQ=")) != NULL) {
1910Sstevel@tonic-gate 		if (strcasecmp("YES", ptr) == 0)
1920Sstevel@tonic-gate 			options->permit_empty_passwd = 0;
1930Sstevel@tonic-gate 		else if (strcasecmp("NO", ptr) == 0)
1940Sstevel@tonic-gate 			options->permit_empty_passwd = 1;
1950Sstevel@tonic-gate 	}
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	if (options->max_init_auth_tries == -1 &&
1980Sstevel@tonic-gate 	    (ptr = defread("RETRIES=")) != NULL) {
1990Sstevel@tonic-gate 		options->max_init_auth_tries = atoi(ptr);
2000Sstevel@tonic-gate 	}
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	if (options->max_init_auth_tries_log == -1 &&
2030Sstevel@tonic-gate 	    (ptr = defread("SYSLOG_FAILED_LOGINS=")) != NULL) {
2040Sstevel@tonic-gate 		options->max_init_auth_tries_log = atoi(ptr);
2050Sstevel@tonic-gate 	}
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate 	if (options->login_grace_time == -1) {
2080Sstevel@tonic-gate 		if ((ptr = defread("TIMEOUT=")) != NULL)
2090Sstevel@tonic-gate 			options->login_grace_time = (unsigned)atoi(ptr);
2100Sstevel@tonic-gate 		else
2110Sstevel@tonic-gate 			options->login_grace_time = 300;
2120Sstevel@tonic-gate 	}
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	(void) defopen((char *)NULL);
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate void
2190Sstevel@tonic-gate fill_default_server_options(ServerOptions *options)
2200Sstevel@tonic-gate {
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate #ifdef HAVE_DEFOPEN
2230Sstevel@tonic-gate 	deflt_fill_default_server_options(options);
2240Sstevel@tonic-gate #endif /* HAVE_DEFOPEN */
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	/* Portable-specific options */
2270Sstevel@tonic-gate 	if (options->pam_authentication_via_kbd_int == -1)
2280Sstevel@tonic-gate 		options->pam_authentication_via_kbd_int = 0;
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 	/* Standard Options */
2310Sstevel@tonic-gate 	if (options->protocol == SSH_PROTO_UNKNOWN)
2320Sstevel@tonic-gate 		options->protocol = SSH_PROTO_1|SSH_PROTO_2;
2330Sstevel@tonic-gate 	if (options->num_host_key_files == 0) {
2340Sstevel@tonic-gate 		/* fill default hostkeys for protocols */
2350Sstevel@tonic-gate 		if (options->protocol & SSH_PROTO_1)
2360Sstevel@tonic-gate 			options->host_key_files[options->num_host_key_files++] =
2370Sstevel@tonic-gate 			    _PATH_HOST_KEY_FILE;
2380Sstevel@tonic-gate #ifndef GSSAPI
2390Sstevel@tonic-gate 		/* With GSS keyex we can run v2 w/ no host keys */
2400Sstevel@tonic-gate 		if (options->protocol & SSH_PROTO_2) {
2410Sstevel@tonic-gate 			options->host_key_files[options->num_host_key_files++] =
2420Sstevel@tonic-gate 			    _PATH_HOST_RSA_KEY_FILE;
2430Sstevel@tonic-gate 			options->host_key_files[options->num_host_key_files++] =
2440Sstevel@tonic-gate 			    _PATH_HOST_DSA_KEY_FILE;
2450Sstevel@tonic-gate 		}
2460Sstevel@tonic-gate #endif /* GSSAPI */
2470Sstevel@tonic-gate 	}
2480Sstevel@tonic-gate 	if (options->num_ports == 0)
2490Sstevel@tonic-gate 		options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
2500Sstevel@tonic-gate 	if (options->listen_addrs == NULL)
2510Sstevel@tonic-gate 		add_listen_addr(options, NULL, 0);
2520Sstevel@tonic-gate 	if (options->pid_file == NULL)
2530Sstevel@tonic-gate 		options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
2540Sstevel@tonic-gate 	if (options->server_key_bits == -1)
2550Sstevel@tonic-gate 		options->server_key_bits = 768;
2560Sstevel@tonic-gate 	if (options->login_grace_time == -1)
2570Sstevel@tonic-gate 		options->login_grace_time = 120;
2580Sstevel@tonic-gate 	if (options->key_regeneration_time == -1)
2590Sstevel@tonic-gate 		options->key_regeneration_time = 3600;
2600Sstevel@tonic-gate 	if (options->permit_root_login == PERMIT_NOT_SET)
2610Sstevel@tonic-gate 		options->permit_root_login = PERMIT_YES;
2620Sstevel@tonic-gate 	if (options->ignore_rhosts == -1)
2630Sstevel@tonic-gate 		options->ignore_rhosts = 1;
2640Sstevel@tonic-gate 	if (options->ignore_user_known_hosts == -1)
2650Sstevel@tonic-gate 		options->ignore_user_known_hosts = 0;
2660Sstevel@tonic-gate 	if (options->print_motd == -1)
2670Sstevel@tonic-gate 		options->print_motd = 1;
2680Sstevel@tonic-gate 	if (options->print_lastlog == -1)
2690Sstevel@tonic-gate 		options->print_lastlog = 1;
2700Sstevel@tonic-gate 	if (options->x11_forwarding == -1)
2710Sstevel@tonic-gate 		options->x11_forwarding = 1;
2720Sstevel@tonic-gate 	if (options->x11_display_offset == -1)
2730Sstevel@tonic-gate 		options->x11_display_offset = 10;
2740Sstevel@tonic-gate 	if (options->x11_use_localhost == -1)
2750Sstevel@tonic-gate 		options->x11_use_localhost = 1;
2760Sstevel@tonic-gate 	if (options->xauth_location == NULL)
2770Sstevel@tonic-gate 		options->xauth_location = _PATH_XAUTH;
2780Sstevel@tonic-gate 	if (options->strict_modes == -1)
2790Sstevel@tonic-gate 		options->strict_modes = 1;
2800Sstevel@tonic-gate 	if (options->keepalives == -1)
2810Sstevel@tonic-gate 		options->keepalives = 1;
2820Sstevel@tonic-gate 	if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2830Sstevel@tonic-gate 		options->log_facility = SYSLOG_FACILITY_AUTH;
2840Sstevel@tonic-gate 	if (options->log_level == SYSLOG_LEVEL_NOT_SET)
2850Sstevel@tonic-gate 		options->log_level = SYSLOG_LEVEL_INFO;
2860Sstevel@tonic-gate 	if (options->rhosts_authentication == -1)
2870Sstevel@tonic-gate 		options->rhosts_authentication = 0;
2880Sstevel@tonic-gate 	if (options->rhosts_rsa_authentication == -1)
2890Sstevel@tonic-gate 		options->rhosts_rsa_authentication = 0;
2900Sstevel@tonic-gate 	if (options->hostbased_authentication == -1)
2910Sstevel@tonic-gate 		options->hostbased_authentication = 0;
2920Sstevel@tonic-gate 	if (options->hostbased_uses_name_from_packet_only == -1)
2930Sstevel@tonic-gate 		options->hostbased_uses_name_from_packet_only = 0;
2940Sstevel@tonic-gate 	if (options->rsa_authentication == -1)
2950Sstevel@tonic-gate 		options->rsa_authentication = 1;
2960Sstevel@tonic-gate 	if (options->pubkey_authentication == -1)
2970Sstevel@tonic-gate 		options->pubkey_authentication = 1;
2980Sstevel@tonic-gate #ifdef GSSAPI
2990Sstevel@tonic-gate 	if (options->gss_authentication == -1)
3000Sstevel@tonic-gate 		options->gss_authentication = 1;
3010Sstevel@tonic-gate 	if (options->gss_keyex == -1)
3020Sstevel@tonic-gate 		options->gss_keyex = 1;
3030Sstevel@tonic-gate 	if (options->gss_store_creds == -1)
3040Sstevel@tonic-gate 		options->gss_store_creds = 1;
3050Sstevel@tonic-gate 	if (options->gss_use_session_ccache == -1)
3060Sstevel@tonic-gate 		options->gss_use_session_ccache = 1;
3070Sstevel@tonic-gate 	if (options->gss_cleanup_creds == -1)
3080Sstevel@tonic-gate 		options->gss_cleanup_creds = 1;
3090Sstevel@tonic-gate #endif
3100Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
3110Sstevel@tonic-gate 	if (options->kerberos_authentication == -1)
3120Sstevel@tonic-gate 		options->kerberos_authentication = 0;
3130Sstevel@tonic-gate 	if (options->kerberos_or_local_passwd == -1)
3140Sstevel@tonic-gate 		options->kerberos_or_local_passwd = 1;
3150Sstevel@tonic-gate 	if (options->kerberos_ticket_cleanup == -1)
3160Sstevel@tonic-gate 		options->kerberos_ticket_cleanup = 1;
3170Sstevel@tonic-gate #endif
3180Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
3190Sstevel@tonic-gate 	if (options->kerberos_tgt_passing == -1)
3200Sstevel@tonic-gate 		options->kerberos_tgt_passing = 0;
3210Sstevel@tonic-gate #endif
3220Sstevel@tonic-gate #ifdef AFS
3230Sstevel@tonic-gate 	if (options->afs_token_passing == -1)
3240Sstevel@tonic-gate 		options->afs_token_passing = 0;
3250Sstevel@tonic-gate #endif
3260Sstevel@tonic-gate 	if (options->password_authentication == -1)
3270Sstevel@tonic-gate 		options->password_authentication = 1;
3280Sstevel@tonic-gate 	if (options->kbd_interactive_authentication == -1)
3290Sstevel@tonic-gate 		options->kbd_interactive_authentication = 0;
3300Sstevel@tonic-gate 	if (options->challenge_response_authentication == -1)
3310Sstevel@tonic-gate 		options->challenge_response_authentication = 1;
3320Sstevel@tonic-gate 	if (options->permit_empty_passwd == -1)
3330Sstevel@tonic-gate 		options->permit_empty_passwd = 0;
3340Sstevel@tonic-gate 	if (options->permit_user_env == -1)
3350Sstevel@tonic-gate 		options->permit_user_env = 0;
3360Sstevel@tonic-gate 	if (options->use_login == -1)
3370Sstevel@tonic-gate 		options->use_login = 0;
3380Sstevel@tonic-gate 	if (options->compression == -1)
3390Sstevel@tonic-gate 		options->compression = 1;
3400Sstevel@tonic-gate 	if (options->allow_tcp_forwarding == -1)
3410Sstevel@tonic-gate 		options->allow_tcp_forwarding = 1;
3420Sstevel@tonic-gate 	if (options->gateway_ports == -1)
3430Sstevel@tonic-gate 		options->gateway_ports = 0;
3440Sstevel@tonic-gate 	if (options->max_startups == -1)
3450Sstevel@tonic-gate 		options->max_startups = 10;
3460Sstevel@tonic-gate 	if (options->max_startups_rate == -1)
3470Sstevel@tonic-gate 		options->max_startups_rate = 100;		/* 100% */
3480Sstevel@tonic-gate 	if (options->max_startups_begin == -1)
3490Sstevel@tonic-gate 		options->max_startups_begin = options->max_startups;
3500Sstevel@tonic-gate 	if (options->verify_reverse_mapping == -1)
3510Sstevel@tonic-gate 		options->verify_reverse_mapping = 0;
3520Sstevel@tonic-gate 	if (options->client_alive_interval == -1)
3530Sstevel@tonic-gate 		options->client_alive_interval = 0;
3540Sstevel@tonic-gate 	if (options->client_alive_count_max == -1)
3550Sstevel@tonic-gate 		options->client_alive_count_max = 3;
3560Sstevel@tonic-gate 	if (options->authorized_keys_file2 == NULL) {
3570Sstevel@tonic-gate 		/* authorized_keys_file2 falls back to authorized_keys_file */
3580Sstevel@tonic-gate 		if (options->authorized_keys_file != NULL)
3590Sstevel@tonic-gate 			options->authorized_keys_file2 = options->authorized_keys_file;
3600Sstevel@tonic-gate 		else
3610Sstevel@tonic-gate 			options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
3620Sstevel@tonic-gate 	}
3630Sstevel@tonic-gate 	if (options->authorized_keys_file == NULL)
3640Sstevel@tonic-gate 		options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	if (options->max_auth_tries == -1)
3670Sstevel@tonic-gate 		options->max_auth_tries = AUTH_FAIL_MAX;
3680Sstevel@tonic-gate 	if (options->max_auth_tries_log == -1)
3690Sstevel@tonic-gate 		options->max_auth_tries_log = options->max_auth_tries / 2;
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	if (options->max_init_auth_tries == -1)
3720Sstevel@tonic-gate 		options->max_init_auth_tries = AUTH_FAIL_MAX;
3730Sstevel@tonic-gate 	if (options->max_init_auth_tries_log == -1)
3740Sstevel@tonic-gate 		options->max_init_auth_tries_log = options->max_init_auth_tries / 2;
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 	if (options->lookup_client_hostnames == -1)
3770Sstevel@tonic-gate 		options->lookup_client_hostnames = 1;
3780Sstevel@tonic-gate }
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate /* Keyword tokens. */
3810Sstevel@tonic-gate typedef enum {
3820Sstevel@tonic-gate 	sBadOption,		/* == unknown option */
3830Sstevel@tonic-gate 	/* Portable-specific options */
3840Sstevel@tonic-gate 	sPAMAuthenticationViaKbdInt,
3850Sstevel@tonic-gate 	/* Standard Options */
3860Sstevel@tonic-gate 	sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
3870Sstevel@tonic-gate 	sPermitRootLogin, sLogFacility, sLogLevel,
3880Sstevel@tonic-gate 	sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
3890Sstevel@tonic-gate #ifdef GSSAPI
3900Sstevel@tonic-gate 	sGssAuthentication, sGssKeyEx, sGssStoreDelegCreds,
3910Sstevel@tonic-gate 	sGssUseSessionCredCache, sGssCleanupCreds,
3920Sstevel@tonic-gate #endif /* GSSAPI */
3930Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
3940Sstevel@tonic-gate 	sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
3950Sstevel@tonic-gate #endif
3960Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
3970Sstevel@tonic-gate 	sKerberosTgtPassing,
3980Sstevel@tonic-gate #endif
3990Sstevel@tonic-gate #ifdef AFS
4000Sstevel@tonic-gate 	sAFSTokenPassing,
4010Sstevel@tonic-gate #endif
4020Sstevel@tonic-gate 	sChallengeResponseAuthentication,
4030Sstevel@tonic-gate 	sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
4040Sstevel@tonic-gate 	sPrintMotd, sPrintLastLog, sIgnoreRhosts,
4050Sstevel@tonic-gate 	sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
4060Sstevel@tonic-gate 	sStrictModes, sEmptyPasswd, sKeepAlives,
4070Sstevel@tonic-gate 	sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
4080Sstevel@tonic-gate 	sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
4090Sstevel@tonic-gate 	sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
4100Sstevel@tonic-gate 	sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
4110Sstevel@tonic-gate 	sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
4120Sstevel@tonic-gate 	sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
4130Sstevel@tonic-gate 	sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
4140Sstevel@tonic-gate 	sMaxAuthTries, sMaxAuthTriesLog, sUsePrivilegeSeparation,
4150Sstevel@tonic-gate 	sLookupClientHostnames,
4160Sstevel@tonic-gate 	sDeprecated
4170Sstevel@tonic-gate } ServerOpCodes;
4180Sstevel@tonic-gate 
4190Sstevel@tonic-gate /* Textual representation of the tokens. */
4200Sstevel@tonic-gate static struct {
4210Sstevel@tonic-gate 	const char *name;
4220Sstevel@tonic-gate 	ServerOpCodes opcode;
4230Sstevel@tonic-gate } keywords[] = {
4240Sstevel@tonic-gate 	/* Portable-specific options */
4250Sstevel@tonic-gate 	{ "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
4260Sstevel@tonic-gate 	/* Standard Options */
4270Sstevel@tonic-gate 	{ "port", sPort },
4280Sstevel@tonic-gate 	{ "hostkey", sHostKeyFile },
4290Sstevel@tonic-gate 	{ "hostdsakey", sHostKeyFile },					/* alias */
4300Sstevel@tonic-gate 	{ "pidfile", sPidFile },
4310Sstevel@tonic-gate 	{ "serverkeybits", sServerKeyBits },
4320Sstevel@tonic-gate 	{ "logingracetime", sLoginGraceTime },
4330Sstevel@tonic-gate 	{ "keyregenerationinterval", sKeyRegenerationTime },
4340Sstevel@tonic-gate 	{ "permitrootlogin", sPermitRootLogin },
4350Sstevel@tonic-gate 	{ "syslogfacility", sLogFacility },
4360Sstevel@tonic-gate 	{ "loglevel", sLogLevel },
4370Sstevel@tonic-gate 	{ "rhostsauthentication", sRhostsAuthentication },
4380Sstevel@tonic-gate 	{ "rhostsrsaauthentication", sRhostsRSAAuthentication },
4390Sstevel@tonic-gate 	{ "hostbasedauthentication", sHostbasedAuthentication },
4400Sstevel@tonic-gate 	{ "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
4410Sstevel@tonic-gate 	{ "rsaauthentication", sRSAAuthentication },
4420Sstevel@tonic-gate 	{ "pubkeyauthentication", sPubkeyAuthentication },
4430Sstevel@tonic-gate 	{ "dsaauthentication", sPubkeyAuthentication },			/* alias */
4440Sstevel@tonic-gate #ifdef GSSAPI
4450Sstevel@tonic-gate 	{ "gssapiauthentication", sGssAuthentication },
4460Sstevel@tonic-gate 	{ "gssapikeyexchange", sGssKeyEx },
4470Sstevel@tonic-gate 	{ "gssapistoredelegatedcredentials", sGssStoreDelegCreds },
4480Sstevel@tonic-gate 	{ "gssauthentication", sGssAuthentication },			/* alias */
4490Sstevel@tonic-gate 	{ "gsskeyex", sGssKeyEx },					/* alias */
4500Sstevel@tonic-gate 	{ "gssstoredelegcreds", sGssStoreDelegCreds },			/* alias */
4510Sstevel@tonic-gate #ifndef SUNW_GSSAPI
4520Sstevel@tonic-gate 	{ "gssusesessionccache", sGssUseSessionCredCache },
4530Sstevel@tonic-gate 	{ "gssusesessioncredcache", sGssUseSessionCredCache },
4540Sstevel@tonic-gate 	{ "gsscleanupcreds", sGssCleanupCreds },
4550Sstevel@tonic-gate #endif /* SUNW_GSSAPI */
4560Sstevel@tonic-gate #endif
4570Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
4580Sstevel@tonic-gate 	{ "kerberosauthentication", sKerberosAuthentication },
4590Sstevel@tonic-gate 	{ "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
4600Sstevel@tonic-gate 	{ "kerberosticketcleanup", sKerberosTicketCleanup },
4610Sstevel@tonic-gate #endif
4620Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
4630Sstevel@tonic-gate 	{ "kerberostgtpassing", sKerberosTgtPassing },
4640Sstevel@tonic-gate #endif
4650Sstevel@tonic-gate #ifdef AFS
4660Sstevel@tonic-gate 	{ "afstokenpassing", sAFSTokenPassing },
4670Sstevel@tonic-gate #endif
4680Sstevel@tonic-gate 	{ "passwordauthentication", sPasswordAuthentication },
4690Sstevel@tonic-gate 	{ "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
4700Sstevel@tonic-gate 	{ "challengeresponseauthentication", sChallengeResponseAuthentication },
4710Sstevel@tonic-gate 	{ "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
4720Sstevel@tonic-gate 	{ "checkmail", sDeprecated },
4730Sstevel@tonic-gate 	{ "listenaddress", sListenAddress },
4740Sstevel@tonic-gate 	{ "printmotd", sPrintMotd },
4750Sstevel@tonic-gate 	{ "printlastlog", sPrintLastLog },
4760Sstevel@tonic-gate 	{ "ignorerhosts", sIgnoreRhosts },
4770Sstevel@tonic-gate 	{ "ignoreuserknownhosts", sIgnoreUserKnownHosts },
4780Sstevel@tonic-gate 	{ "x11forwarding", sX11Forwarding },
4790Sstevel@tonic-gate 	{ "x11displayoffset", sX11DisplayOffset },
4800Sstevel@tonic-gate 	{ "x11uselocalhost", sX11UseLocalhost },
4810Sstevel@tonic-gate 	{ "xauthlocation", sXAuthLocation },
4820Sstevel@tonic-gate 	{ "strictmodes", sStrictModes },
4830Sstevel@tonic-gate 	{ "permitemptypasswords", sEmptyPasswd },
4840Sstevel@tonic-gate 	{ "permituserenvironment", sPermitUserEnvironment },
4850Sstevel@tonic-gate 	{ "uselogin", sUseLogin },
4860Sstevel@tonic-gate 	{ "compression", sCompression },
4870Sstevel@tonic-gate 	{ "keepalive", sKeepAlives },
4880Sstevel@tonic-gate 	{ "allowtcpforwarding", sAllowTcpForwarding },
4890Sstevel@tonic-gate 	{ "allowusers", sAllowUsers },
4900Sstevel@tonic-gate 	{ "denyusers", sDenyUsers },
4910Sstevel@tonic-gate 	{ "allowgroups", sAllowGroups },
4920Sstevel@tonic-gate 	{ "denygroups", sDenyGroups },
4930Sstevel@tonic-gate 	{ "ciphers", sCiphers },
4940Sstevel@tonic-gate 	{ "macs", sMacs },
4950Sstevel@tonic-gate 	{ "protocol", sProtocol },
4960Sstevel@tonic-gate 	{ "gatewayports", sGatewayPorts },
4970Sstevel@tonic-gate 	{ "subsystem", sSubsystem },
4980Sstevel@tonic-gate 	{ "maxstartups", sMaxStartups },
4990Sstevel@tonic-gate 	{ "banner", sBanner },
5000Sstevel@tonic-gate 	{ "verifyreversemapping", sVerifyReverseMapping },
5010Sstevel@tonic-gate 	{ "reversemappingcheck", sVerifyReverseMapping },
5020Sstevel@tonic-gate 	{ "clientaliveinterval", sClientAliveInterval },
5030Sstevel@tonic-gate 	{ "clientalivecountmax", sClientAliveCountMax },
5040Sstevel@tonic-gate 	{ "authorizedkeysfile", sAuthorizedKeysFile },
5050Sstevel@tonic-gate 	{ "authorizedkeysfile2", sAuthorizedKeysFile2 },
5060Sstevel@tonic-gate 	{ "maxauthtries", sMaxAuthTries },
5070Sstevel@tonic-gate 	{ "maxauthtrieslog", sMaxAuthTriesLog },
5080Sstevel@tonic-gate 	{ "useprivilegeseparation", sUsePrivilegeSeparation},
5090Sstevel@tonic-gate 	{ "lookupclienthostnames", sLookupClientHostnames},
5100Sstevel@tonic-gate 	{ NULL, sBadOption }
5110Sstevel@tonic-gate };
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate /*
5140Sstevel@tonic-gate  * Returns the number of the token pointed to by cp or sBadOption.
5150Sstevel@tonic-gate  */
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate static ServerOpCodes
5180Sstevel@tonic-gate parse_token(const char *cp, const char *filename,
5190Sstevel@tonic-gate 	    int linenum)
5200Sstevel@tonic-gate {
5210Sstevel@tonic-gate 	u_int i;
5220Sstevel@tonic-gate 
5230Sstevel@tonic-gate 	for (i = 0; keywords[i].name; i++)
5240Sstevel@tonic-gate 		if (strcasecmp(cp, keywords[i].name) == 0)
5250Sstevel@tonic-gate 			return keywords[i].opcode;
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 	error("%s: line %d: Bad configuration option: %s",
5280Sstevel@tonic-gate 	    filename, linenum, cp);
5290Sstevel@tonic-gate 	return sBadOption;
5300Sstevel@tonic-gate }
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate static void
5330Sstevel@tonic-gate add_listen_addr(ServerOptions *options, char *addr, u_short port)
5340Sstevel@tonic-gate {
5350Sstevel@tonic-gate 	int i;
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 	if (options->num_ports == 0)
5380Sstevel@tonic-gate 		options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
5390Sstevel@tonic-gate 	if (port == 0)
5400Sstevel@tonic-gate 		for (i = 0; i < options->num_ports; i++)
5410Sstevel@tonic-gate 			add_one_listen_addr(options, addr, options->ports[i]);
5420Sstevel@tonic-gate 	else
5430Sstevel@tonic-gate 		add_one_listen_addr(options, addr, port);
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate static void
5470Sstevel@tonic-gate add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
5480Sstevel@tonic-gate {
5490Sstevel@tonic-gate 	struct addrinfo hints, *ai, *aitop;
5500Sstevel@tonic-gate 	char strport[NI_MAXSERV];
5510Sstevel@tonic-gate 	int gaierr;
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate 	(void) memset(&hints, 0, sizeof(hints));
5540Sstevel@tonic-gate 	hints.ai_family = IPv4or6;
5550Sstevel@tonic-gate 	hints.ai_socktype = SOCK_STREAM;
5560Sstevel@tonic-gate 	hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
5570Sstevel@tonic-gate 	(void) snprintf(strport, sizeof strport, "%u", port);
5580Sstevel@tonic-gate 	if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
5590Sstevel@tonic-gate 		fatal("bad addr or host: %s (%s)",
5600Sstevel@tonic-gate 		    addr ? addr : "<NULL>",
5610Sstevel@tonic-gate 		    gai_strerror(gaierr));
5620Sstevel@tonic-gate 	for (ai = aitop; ai->ai_next; ai = ai->ai_next)
5630Sstevel@tonic-gate 		;
5640Sstevel@tonic-gate 	ai->ai_next = options->listen_addrs;
5650Sstevel@tonic-gate 	options->listen_addrs = aitop;
5660Sstevel@tonic-gate }
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate int
5690Sstevel@tonic-gate process_server_config_line(ServerOptions *options, char *line,
5700Sstevel@tonic-gate     const char *filename, int linenum)
5710Sstevel@tonic-gate {
5720Sstevel@tonic-gate 	char *cp, **charptr, *arg, *p;
5730Sstevel@tonic-gate 	int *intptr, value, i, n;
5740Sstevel@tonic-gate 	ServerOpCodes opcode;
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate 	cp = line;
5770Sstevel@tonic-gate 	arg = strdelim(&cp);
5780Sstevel@tonic-gate 	/* Ignore leading whitespace */
5790Sstevel@tonic-gate 	if (*arg == '\0')
5800Sstevel@tonic-gate 		arg = strdelim(&cp);
5810Sstevel@tonic-gate 	if (!arg || !*arg || *arg == '#')
5820Sstevel@tonic-gate 		return 0;
5830Sstevel@tonic-gate 	intptr = NULL;
5840Sstevel@tonic-gate 	charptr = NULL;
5850Sstevel@tonic-gate 	opcode = parse_token(arg, filename, linenum);
5860Sstevel@tonic-gate 	switch (opcode) {
5870Sstevel@tonic-gate 	/* Portable-specific options */
5880Sstevel@tonic-gate 	case sPAMAuthenticationViaKbdInt:
5890Sstevel@tonic-gate 		intptr = &options->pam_authentication_via_kbd_int;
5900Sstevel@tonic-gate 		goto parse_flag;
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate 	/* Standard Options */
5930Sstevel@tonic-gate 	case sBadOption:
5940Sstevel@tonic-gate 		return -1;
5950Sstevel@tonic-gate 	case sPort:
5960Sstevel@tonic-gate 		/* ignore ports from configfile if cmdline specifies ports */
5970Sstevel@tonic-gate 		if (options->ports_from_cmdline)
5980Sstevel@tonic-gate 			return 0;
5990Sstevel@tonic-gate 		if (options->listen_addrs != NULL)
6000Sstevel@tonic-gate 			fatal("%s line %d: ports must be specified before "
6010Sstevel@tonic-gate 			    "ListenAddress.", filename, linenum);
6020Sstevel@tonic-gate 		if (options->num_ports >= MAX_PORTS)
6030Sstevel@tonic-gate 			fatal("%s line %d: too many ports.",
6040Sstevel@tonic-gate 			    filename, linenum);
6050Sstevel@tonic-gate 		arg = strdelim(&cp);
6060Sstevel@tonic-gate 		if (!arg || *arg == '\0')
6070Sstevel@tonic-gate 			fatal("%s line %d: missing port number.",
6080Sstevel@tonic-gate 			    filename, linenum);
6090Sstevel@tonic-gate 		options->ports[options->num_ports++] = a2port(arg);
6100Sstevel@tonic-gate 		if (options->ports[options->num_ports-1] == 0)
6110Sstevel@tonic-gate 			fatal("%s line %d: Badly formatted port number.",
6120Sstevel@tonic-gate 			    filename, linenum);
6130Sstevel@tonic-gate 		break;
6140Sstevel@tonic-gate 
6150Sstevel@tonic-gate 	case sServerKeyBits:
6160Sstevel@tonic-gate 		intptr = &options->server_key_bits;
6170Sstevel@tonic-gate parse_int:
6180Sstevel@tonic-gate 		arg = strdelim(&cp);
6190Sstevel@tonic-gate 		if (!arg || *arg == '\0')
6200Sstevel@tonic-gate 			fatal("%s line %d: missing integer value.",
6210Sstevel@tonic-gate 			    filename, linenum);
6220Sstevel@tonic-gate 		value = atoi(arg);
6230Sstevel@tonic-gate 		if (*intptr == -1)
6240Sstevel@tonic-gate 			*intptr = value;
6250Sstevel@tonic-gate 		break;
6260Sstevel@tonic-gate 
6270Sstevel@tonic-gate 	case sLoginGraceTime:
6280Sstevel@tonic-gate 		intptr = &options->login_grace_time;
6290Sstevel@tonic-gate parse_time:
6300Sstevel@tonic-gate 		arg = strdelim(&cp);
6310Sstevel@tonic-gate 		if (!arg || *arg == '\0')
6320Sstevel@tonic-gate 			fatal("%s line %d: missing time value.",
6330Sstevel@tonic-gate 			    filename, linenum);
6340Sstevel@tonic-gate 		if ((value = convtime(arg)) == -1)
6350Sstevel@tonic-gate 			fatal("%s line %d: invalid time value.",
6360Sstevel@tonic-gate 			    filename, linenum);
6370Sstevel@tonic-gate 		if (*intptr == -1)
6380Sstevel@tonic-gate 			*intptr = value;
6390Sstevel@tonic-gate 		break;
6400Sstevel@tonic-gate 
6410Sstevel@tonic-gate 	case sKeyRegenerationTime:
6420Sstevel@tonic-gate 		intptr = &options->key_regeneration_time;
6430Sstevel@tonic-gate 		goto parse_time;
6440Sstevel@tonic-gate 
6450Sstevel@tonic-gate 	case sListenAddress:
6460Sstevel@tonic-gate 		arg = strdelim(&cp);
6470Sstevel@tonic-gate 		if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
6480Sstevel@tonic-gate 			fatal("%s line %d: missing inet addr.",
6490Sstevel@tonic-gate 			    filename, linenum);
6500Sstevel@tonic-gate 		if (*arg == '[') {
6510Sstevel@tonic-gate 			if ((p = strchr(arg, ']')) == NULL)
6520Sstevel@tonic-gate 				fatal("%s line %d: bad ipv6 inet addr usage.",
6530Sstevel@tonic-gate 				    filename, linenum);
6540Sstevel@tonic-gate 			arg++;
6550Sstevel@tonic-gate 			(void) memmove(p, p+1, strlen(p+1)+1);
6560Sstevel@tonic-gate 		} else if (((p = strchr(arg, ':')) == NULL) ||
6570Sstevel@tonic-gate 			    (strchr(p+1, ':') != NULL)) {
6580Sstevel@tonic-gate 			add_listen_addr(options, arg, 0);
6590Sstevel@tonic-gate 			break;
6600Sstevel@tonic-gate 		}
6610Sstevel@tonic-gate 		if (*p == ':') {
6620Sstevel@tonic-gate 			u_short port;
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate 			p++;
6650Sstevel@tonic-gate 			if (*p == '\0')
6660Sstevel@tonic-gate 				fatal("%s line %d: bad inet addr:port usage.",
6670Sstevel@tonic-gate 				    filename, linenum);
6680Sstevel@tonic-gate 			else {
6690Sstevel@tonic-gate 				*(p-1) = '\0';
6700Sstevel@tonic-gate 				if ((port = a2port(p)) == 0)
6710Sstevel@tonic-gate 					fatal("%s line %d: bad port number.",
6720Sstevel@tonic-gate 					    filename, linenum);
6730Sstevel@tonic-gate 				add_listen_addr(options, arg, port);
6740Sstevel@tonic-gate 			}
6750Sstevel@tonic-gate 		} else if (*p == '\0')
6760Sstevel@tonic-gate 			add_listen_addr(options, arg, 0);
6770Sstevel@tonic-gate 		else
6780Sstevel@tonic-gate 			fatal("%s line %d: bad inet addr usage.",
6790Sstevel@tonic-gate 			    filename, linenum);
6800Sstevel@tonic-gate 		break;
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate 	case sHostKeyFile:
6830Sstevel@tonic-gate 		intptr = &options->num_host_key_files;
6840Sstevel@tonic-gate 		if (*intptr >= MAX_HOSTKEYS)
6850Sstevel@tonic-gate 			fatal("%s line %d: too many host keys specified (max %d).",
6860Sstevel@tonic-gate 			    filename, linenum, MAX_HOSTKEYS);
6870Sstevel@tonic-gate 		charptr = &options->host_key_files[*intptr];
6880Sstevel@tonic-gate parse_filename:
6890Sstevel@tonic-gate 		arg = strdelim(&cp);
6900Sstevel@tonic-gate 		if (!arg || *arg == '\0')
6910Sstevel@tonic-gate 			fatal("%s line %d: missing file name.",
6920Sstevel@tonic-gate 			    filename, linenum);
6930Sstevel@tonic-gate 		if (*charptr == NULL) {
6940Sstevel@tonic-gate 			*charptr = tilde_expand_filename(arg, getuid());
6950Sstevel@tonic-gate 			/* increase optional counter */
6960Sstevel@tonic-gate 			if (intptr != NULL)
6970Sstevel@tonic-gate 				*intptr = *intptr + 1;
6980Sstevel@tonic-gate 		}
6990Sstevel@tonic-gate 		break;
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate 	case sPidFile:
7020Sstevel@tonic-gate 		charptr = &options->pid_file;
7030Sstevel@tonic-gate 		goto parse_filename;
7040Sstevel@tonic-gate 
7050Sstevel@tonic-gate 	case sPermitRootLogin:
7060Sstevel@tonic-gate 		intptr = &options->permit_root_login;
7070Sstevel@tonic-gate 		arg = strdelim(&cp);
7080Sstevel@tonic-gate 		if (!arg || *arg == '\0')
7090Sstevel@tonic-gate 			fatal("%s line %d: missing yes/"
7100Sstevel@tonic-gate 			    "without-password/forced-commands-only/no "
7110Sstevel@tonic-gate 			    "argument.", filename, linenum);
7120Sstevel@tonic-gate 		value = 0;	/* silence compiler */
7130Sstevel@tonic-gate 		if (strcmp(arg, "without-password") == 0)
7140Sstevel@tonic-gate 			value = PERMIT_NO_PASSWD;
7150Sstevel@tonic-gate 		else if (strcmp(arg, "forced-commands-only") == 0)
7160Sstevel@tonic-gate 			value = PERMIT_FORCED_ONLY;
7170Sstevel@tonic-gate 		else if (strcmp(arg, "yes") == 0)
7180Sstevel@tonic-gate 			value = PERMIT_YES;
7190Sstevel@tonic-gate 		else if (strcmp(arg, "no") == 0)
7200Sstevel@tonic-gate 			value = PERMIT_NO;
7210Sstevel@tonic-gate 		else
7220Sstevel@tonic-gate 			fatal("%s line %d: Bad yes/"
7230Sstevel@tonic-gate 			    "without-password/forced-commands-only/no "
7240Sstevel@tonic-gate 			    "argument: %s", filename, linenum, arg);
7250Sstevel@tonic-gate 		if (*intptr == -1)
7260Sstevel@tonic-gate 			*intptr = value;
7270Sstevel@tonic-gate 		break;
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate 	case sIgnoreRhosts:
7300Sstevel@tonic-gate 		intptr = &options->ignore_rhosts;
7310Sstevel@tonic-gate parse_flag:
7320Sstevel@tonic-gate 		arg = strdelim(&cp);
7330Sstevel@tonic-gate 		if (!arg || *arg == '\0')
7340Sstevel@tonic-gate 			fatal("%s line %d: missing yes/no argument.",
7350Sstevel@tonic-gate 			    filename, linenum);
7360Sstevel@tonic-gate 		value = 0;	/* silence compiler */
7370Sstevel@tonic-gate 		if (strcmp(arg, "yes") == 0)
7380Sstevel@tonic-gate 			value = 1;
7390Sstevel@tonic-gate 		else if (strcmp(arg, "no") == 0)
7400Sstevel@tonic-gate 			value = 0;
7410Sstevel@tonic-gate 		else
7420Sstevel@tonic-gate 			fatal("%s line %d: Bad yes/no argument: %s",
7430Sstevel@tonic-gate 				filename, linenum, arg);
7440Sstevel@tonic-gate 		if (*intptr == -1)
7450Sstevel@tonic-gate 			*intptr = value;
7460Sstevel@tonic-gate 		break;
7470Sstevel@tonic-gate 
7480Sstevel@tonic-gate 	case sIgnoreUserKnownHosts:
7490Sstevel@tonic-gate 		intptr = &options->ignore_user_known_hosts;
7500Sstevel@tonic-gate 		goto parse_flag;
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate 	case sRhostsAuthentication:
7530Sstevel@tonic-gate 		intptr = &options->rhosts_authentication;
7540Sstevel@tonic-gate 		goto parse_flag;
7550Sstevel@tonic-gate 
7560Sstevel@tonic-gate 	case sRhostsRSAAuthentication:
7570Sstevel@tonic-gate 		intptr = &options->rhosts_rsa_authentication;
7580Sstevel@tonic-gate 		goto parse_flag;
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate 	case sHostbasedAuthentication:
7610Sstevel@tonic-gate 		intptr = &options->hostbased_authentication;
7620Sstevel@tonic-gate 		goto parse_flag;
7630Sstevel@tonic-gate 
7640Sstevel@tonic-gate 	case sHostbasedUsesNameFromPacketOnly:
7650Sstevel@tonic-gate 		intptr = &options->hostbased_uses_name_from_packet_only;
7660Sstevel@tonic-gate 		goto parse_flag;
7670Sstevel@tonic-gate 
7680Sstevel@tonic-gate 	case sRSAAuthentication:
7690Sstevel@tonic-gate 		intptr = &options->rsa_authentication;
7700Sstevel@tonic-gate 		goto parse_flag;
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate 	case sPubkeyAuthentication:
7730Sstevel@tonic-gate 		intptr = &options->pubkey_authentication;
7740Sstevel@tonic-gate 		goto parse_flag;
7750Sstevel@tonic-gate #ifdef GSSAPI
7760Sstevel@tonic-gate 	case sGssAuthentication:
7770Sstevel@tonic-gate 		intptr = &options->gss_authentication;
7780Sstevel@tonic-gate 		goto parse_flag;
7790Sstevel@tonic-gate 	case sGssKeyEx:
7800Sstevel@tonic-gate 		intptr = &options->gss_keyex;
7810Sstevel@tonic-gate 		goto parse_flag;
7820Sstevel@tonic-gate 	case sGssStoreDelegCreds:
7830Sstevel@tonic-gate 		intptr = &options->gss_keyex;
7840Sstevel@tonic-gate 		goto parse_flag;
7850Sstevel@tonic-gate #ifndef SUNW_GSSAPI
7860Sstevel@tonic-gate 	case sGssUseSessionCredCache:
7870Sstevel@tonic-gate 		intptr = &options->gss_use_session_ccache;
7880Sstevel@tonic-gate 		goto parse_flag;
7890Sstevel@tonic-gate 	case sGssCleanupCreds:
7900Sstevel@tonic-gate 		intptr = &options->gss_cleanup_creds;
7910Sstevel@tonic-gate 		goto parse_flag;
7920Sstevel@tonic-gate #endif /* SUNW_GSSAPI */
7930Sstevel@tonic-gate #endif /* GSSAPI */
7940Sstevel@tonic-gate #if defined(KRB4) || defined(KRB5)
7950Sstevel@tonic-gate 	case sKerberosAuthentication:
7960Sstevel@tonic-gate 		intptr = &options->kerberos_authentication;
7970Sstevel@tonic-gate 		goto parse_flag;
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 	case sKerberosOrLocalPasswd:
8000Sstevel@tonic-gate 		intptr = &options->kerberos_or_local_passwd;
8010Sstevel@tonic-gate 		goto parse_flag;
8020Sstevel@tonic-gate 
8030Sstevel@tonic-gate 	case sKerberosTicketCleanup:
8040Sstevel@tonic-gate 		intptr = &options->kerberos_ticket_cleanup;
8050Sstevel@tonic-gate 		goto parse_flag;
8060Sstevel@tonic-gate #endif
8070Sstevel@tonic-gate #if defined(AFS) || defined(KRB5)
8080Sstevel@tonic-gate 	case sKerberosTgtPassing:
8090Sstevel@tonic-gate 		intptr = &options->kerberos_tgt_passing;
8100Sstevel@tonic-gate 		goto parse_flag;
8110Sstevel@tonic-gate #endif
8120Sstevel@tonic-gate #ifdef AFS
8130Sstevel@tonic-gate 	case sAFSTokenPassing:
8140Sstevel@tonic-gate 		intptr = &options->afs_token_passing;
8150Sstevel@tonic-gate 		goto parse_flag;
8160Sstevel@tonic-gate #endif
8170Sstevel@tonic-gate 
8180Sstevel@tonic-gate 	case sPasswordAuthentication:
8190Sstevel@tonic-gate 		intptr = &options->password_authentication;
8200Sstevel@tonic-gate 		goto parse_flag;
8210Sstevel@tonic-gate 
8220Sstevel@tonic-gate 	case sKbdInteractiveAuthentication:
8230Sstevel@tonic-gate 		intptr = &options->kbd_interactive_authentication;
8240Sstevel@tonic-gate 		goto parse_flag;
8250Sstevel@tonic-gate 
8260Sstevel@tonic-gate 	case sChallengeResponseAuthentication:
8270Sstevel@tonic-gate 		intptr = &options->challenge_response_authentication;
8280Sstevel@tonic-gate 		goto parse_flag;
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 	case sPrintMotd:
8310Sstevel@tonic-gate 		intptr = &options->print_motd;
8320Sstevel@tonic-gate 		goto parse_flag;
8330Sstevel@tonic-gate 
8340Sstevel@tonic-gate 	case sPrintLastLog:
8350Sstevel@tonic-gate 		intptr = &options->print_lastlog;
8360Sstevel@tonic-gate 		goto parse_flag;
8370Sstevel@tonic-gate 
8380Sstevel@tonic-gate 	case sX11Forwarding:
8390Sstevel@tonic-gate 		intptr = &options->x11_forwarding;
8400Sstevel@tonic-gate 		goto parse_flag;
8410Sstevel@tonic-gate 
8420Sstevel@tonic-gate 	case sX11DisplayOffset:
8430Sstevel@tonic-gate 		intptr = &options->x11_display_offset;
8440Sstevel@tonic-gate 		goto parse_int;
8450Sstevel@tonic-gate 
8460Sstevel@tonic-gate 	case sX11UseLocalhost:
8470Sstevel@tonic-gate 		intptr = &options->x11_use_localhost;
8480Sstevel@tonic-gate 		goto parse_flag;
8490Sstevel@tonic-gate 
8500Sstevel@tonic-gate 	case sXAuthLocation:
8510Sstevel@tonic-gate 		charptr = &options->xauth_location;
8520Sstevel@tonic-gate 		goto parse_filename;
8530Sstevel@tonic-gate 
8540Sstevel@tonic-gate 	case sStrictModes:
8550Sstevel@tonic-gate 		intptr = &options->strict_modes;
8560Sstevel@tonic-gate 		goto parse_flag;
8570Sstevel@tonic-gate 
8580Sstevel@tonic-gate 	case sKeepAlives:
8590Sstevel@tonic-gate 		intptr = &options->keepalives;
8600Sstevel@tonic-gate 		goto parse_flag;
8610Sstevel@tonic-gate 
8620Sstevel@tonic-gate 	case sEmptyPasswd:
8630Sstevel@tonic-gate 		intptr = &options->permit_empty_passwd;
8640Sstevel@tonic-gate 		goto parse_flag;
8650Sstevel@tonic-gate 
8660Sstevel@tonic-gate 	case sPermitUserEnvironment:
8670Sstevel@tonic-gate 		intptr = &options->permit_user_env;
8680Sstevel@tonic-gate 		goto parse_flag;
8690Sstevel@tonic-gate 
8700Sstevel@tonic-gate 	case sUseLogin:
8710Sstevel@tonic-gate 		intptr = &options->use_login;
8720Sstevel@tonic-gate 		goto parse_flag;
8730Sstevel@tonic-gate 
8740Sstevel@tonic-gate 	case sCompression:
8750Sstevel@tonic-gate 		intptr = &options->compression;
8760Sstevel@tonic-gate 		goto parse_flag;
8770Sstevel@tonic-gate 
8780Sstevel@tonic-gate 	case sGatewayPorts:
8795334Sjp161948 		arg = strdelim(&cp);
8805334Sjp161948 		if (get_yes_no_flag(&options->gateway_ports, arg, filename,
8815334Sjp161948 		    linenum, 1) == 1)
8825334Sjp161948 			break;
8835334Sjp161948 
8845334Sjp161948 		if (strcmp(arg, "clientspecified") == 0)
8855334Sjp161948 			options->gateway_ports = 2;
8865334Sjp161948 		else
8875334Sjp161948 			fatal("%.200s line %d: Bad yes/no/clientspecified "
8885334Sjp161948 			    "argument.", filename, linenum);
8895334Sjp161948 		break;
8900Sstevel@tonic-gate 
8910Sstevel@tonic-gate 	case sVerifyReverseMapping:
8920Sstevel@tonic-gate 		intptr = &options->verify_reverse_mapping;
8930Sstevel@tonic-gate 		goto parse_flag;
8940Sstevel@tonic-gate 
8950Sstevel@tonic-gate 	case sLogFacility:
8960Sstevel@tonic-gate 		intptr = (int *) &options->log_facility;
8970Sstevel@tonic-gate 		arg = strdelim(&cp);
8980Sstevel@tonic-gate 		value = log_facility_number(arg);
8990Sstevel@tonic-gate 		if (value == SYSLOG_FACILITY_NOT_SET)
9000Sstevel@tonic-gate 			fatal("%.200s line %d: unsupported log facility '%s'",
9010Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
9020Sstevel@tonic-gate 		if (*intptr == -1)
9030Sstevel@tonic-gate 			*intptr = (SyslogFacility) value;
9040Sstevel@tonic-gate 		break;
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate 	case sLogLevel:
9070Sstevel@tonic-gate 		intptr = (int *) &options->log_level;
9080Sstevel@tonic-gate 		arg = strdelim(&cp);
9090Sstevel@tonic-gate 		value = log_level_number(arg);
9100Sstevel@tonic-gate 		if (value == SYSLOG_LEVEL_NOT_SET)
9110Sstevel@tonic-gate 			fatal("%.200s line %d: unsupported log level '%s'",
9120Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
9130Sstevel@tonic-gate 		if (*intptr == -1)
9140Sstevel@tonic-gate 			*intptr = (LogLevel) value;
9150Sstevel@tonic-gate 		break;
9160Sstevel@tonic-gate 
9170Sstevel@tonic-gate 	case sAllowTcpForwarding:
9180Sstevel@tonic-gate 		intptr = &options->allow_tcp_forwarding;
9190Sstevel@tonic-gate 		goto parse_flag;
9200Sstevel@tonic-gate 
9210Sstevel@tonic-gate 	case sUsePrivilegeSeparation:
922*5562Sjp161948 		log("%s line %d: ignoring UsePrivilegeSeparation option value."
923*5562Sjp161948 		    " This option is always on.", filename, linenum);
924*5562Sjp161948 		while (arg)
925*5562Sjp161948 		    arg = strdelim(&cp);
926*5562Sjp161948 		break;
9270Sstevel@tonic-gate 
9280Sstevel@tonic-gate 	case sAllowUsers:
9290Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
9300Sstevel@tonic-gate 			if (options->num_allow_users >= MAX_ALLOW_USERS)
9310Sstevel@tonic-gate 				fatal("%s line %d: too many allow users.",
9320Sstevel@tonic-gate 				    filename, linenum);
9330Sstevel@tonic-gate 			options->allow_users[options->num_allow_users++] =
9340Sstevel@tonic-gate 			    xstrdup(arg);
9350Sstevel@tonic-gate 		}
9360Sstevel@tonic-gate 		break;
9370Sstevel@tonic-gate 
9380Sstevel@tonic-gate 	case sDenyUsers:
9390Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
9400Sstevel@tonic-gate 			if (options->num_deny_users >= MAX_DENY_USERS)
9410Sstevel@tonic-gate 				fatal( "%s line %d: too many deny users.",
9420Sstevel@tonic-gate 				    filename, linenum);
9430Sstevel@tonic-gate 			options->deny_users[options->num_deny_users++] =
9440Sstevel@tonic-gate 			    xstrdup(arg);
9450Sstevel@tonic-gate 		}
9460Sstevel@tonic-gate 		break;
9470Sstevel@tonic-gate 
9480Sstevel@tonic-gate 	case sAllowGroups:
9490Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
9500Sstevel@tonic-gate 			if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
9510Sstevel@tonic-gate 				fatal("%s line %d: too many allow groups.",
9520Sstevel@tonic-gate 				    filename, linenum);
9530Sstevel@tonic-gate 			options->allow_groups[options->num_allow_groups++] =
9540Sstevel@tonic-gate 			    xstrdup(arg);
9550Sstevel@tonic-gate 		}
9560Sstevel@tonic-gate 		break;
9570Sstevel@tonic-gate 
9580Sstevel@tonic-gate 	case sDenyGroups:
9590Sstevel@tonic-gate 		while (((arg = strdelim(&cp)) != NULL) && *arg != '\0') {
9600Sstevel@tonic-gate 			if (options->num_deny_groups >= MAX_DENY_GROUPS)
9610Sstevel@tonic-gate 				fatal("%s line %d: too many deny groups.",
9620Sstevel@tonic-gate 				    filename, linenum);
9630Sstevel@tonic-gate 			options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
9640Sstevel@tonic-gate 		}
9650Sstevel@tonic-gate 		break;
9660Sstevel@tonic-gate 
9670Sstevel@tonic-gate 	case sCiphers:
9680Sstevel@tonic-gate 		arg = strdelim(&cp);
9690Sstevel@tonic-gate 		if (!arg || *arg == '\0')
9700Sstevel@tonic-gate 			fatal("%s line %d: Missing argument.", filename, linenum);
9710Sstevel@tonic-gate 		if (!ciphers_valid(arg))
9720Sstevel@tonic-gate 			fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
9730Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
9740Sstevel@tonic-gate 		if (options->ciphers == NULL)
9750Sstevel@tonic-gate 			options->ciphers = xstrdup(arg);
9760Sstevel@tonic-gate 		break;
9770Sstevel@tonic-gate 
9780Sstevel@tonic-gate 	case sMacs:
9790Sstevel@tonic-gate 		arg = strdelim(&cp);
9800Sstevel@tonic-gate 		if (!arg || *arg == '\0')
9810Sstevel@tonic-gate 			fatal("%s line %d: Missing argument.", filename, linenum);
9820Sstevel@tonic-gate 		if (!mac_valid(arg))
9830Sstevel@tonic-gate 			fatal("%s line %d: Bad SSH2 mac spec '%s'.",
9840Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
9850Sstevel@tonic-gate 		if (options->macs == NULL)
9860Sstevel@tonic-gate 			options->macs = xstrdup(arg);
9870Sstevel@tonic-gate 		break;
9880Sstevel@tonic-gate 
9890Sstevel@tonic-gate 	case sProtocol:
9900Sstevel@tonic-gate 		intptr = &options->protocol;
9910Sstevel@tonic-gate 		arg = strdelim(&cp);
9920Sstevel@tonic-gate 		if (!arg || *arg == '\0')
9930Sstevel@tonic-gate 			fatal("%s line %d: Missing argument.", filename, linenum);
9940Sstevel@tonic-gate 		value = proto_spec(arg);
9950Sstevel@tonic-gate 		if (value == SSH_PROTO_UNKNOWN)
9960Sstevel@tonic-gate 			fatal("%s line %d: Bad protocol spec '%s'.",
9970Sstevel@tonic-gate 			    filename, linenum, arg ? arg : "<NONE>");
9980Sstevel@tonic-gate 		if (*intptr == SSH_PROTO_UNKNOWN)
9990Sstevel@tonic-gate 			*intptr = value;
10000Sstevel@tonic-gate 		break;
10010Sstevel@tonic-gate 
10020Sstevel@tonic-gate 	case sSubsystem:
10030Sstevel@tonic-gate 		if (options->num_subsystems >= MAX_SUBSYSTEMS) {
10040Sstevel@tonic-gate 			fatal("%s line %d: too many subsystems defined.",
10050Sstevel@tonic-gate 			    filename, linenum);
10060Sstevel@tonic-gate 		}
10070Sstevel@tonic-gate 		arg = strdelim(&cp);
10080Sstevel@tonic-gate 		if (!arg || *arg == '\0')
10090Sstevel@tonic-gate 			fatal("%s line %d: Missing subsystem name.",
10100Sstevel@tonic-gate 			    filename, linenum);
10110Sstevel@tonic-gate 		for (i = 0; i < options->num_subsystems; i++)
10120Sstevel@tonic-gate 			if (strcmp(arg, options->subsystem_name[i]) == 0)
10130Sstevel@tonic-gate 				fatal("%s line %d: Subsystem '%s' already defined.",
10140Sstevel@tonic-gate 				    filename, linenum, arg);
10150Sstevel@tonic-gate 		options->subsystem_name[options->num_subsystems] = xstrdup(arg);
10160Sstevel@tonic-gate 		arg = strdelim(&cp);
10170Sstevel@tonic-gate 		if (!arg || *arg == '\0')
10180Sstevel@tonic-gate 			fatal("%s line %d: Missing subsystem command.",
10190Sstevel@tonic-gate 			    filename, linenum);
10200Sstevel@tonic-gate 		options->subsystem_command[options->num_subsystems] = xstrdup(arg);
10210Sstevel@tonic-gate 		options->num_subsystems++;
10220Sstevel@tonic-gate 		break;
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate 	case sMaxStartups:
10250Sstevel@tonic-gate 		arg = strdelim(&cp);
10260Sstevel@tonic-gate 		if (!arg || *arg == '\0')
10270Sstevel@tonic-gate 			fatal("%s line %d: Missing MaxStartups spec.",
10280Sstevel@tonic-gate 			    filename, linenum);
10290Sstevel@tonic-gate 		if ((n = sscanf(arg, "%d:%d:%d",
10300Sstevel@tonic-gate 		    &options->max_startups_begin,
10310Sstevel@tonic-gate 		    &options->max_startups_rate,
10320Sstevel@tonic-gate 		    &options->max_startups)) == 3) {
10330Sstevel@tonic-gate 			if (options->max_startups_begin >
10340Sstevel@tonic-gate 			    options->max_startups ||
10350Sstevel@tonic-gate 			    options->max_startups_rate > 100 ||
10360Sstevel@tonic-gate 			    options->max_startups_rate < 1)
10370Sstevel@tonic-gate 				fatal("%s line %d: Illegal MaxStartups spec.",
10380Sstevel@tonic-gate 				    filename, linenum);
10390Sstevel@tonic-gate 		} else if (n != 1)
10400Sstevel@tonic-gate 			fatal("%s line %d: Illegal MaxStartups spec.",
10410Sstevel@tonic-gate 			    filename, linenum);
10420Sstevel@tonic-gate 		else
10430Sstevel@tonic-gate 			options->max_startups = options->max_startups_begin;
10440Sstevel@tonic-gate 		break;
10450Sstevel@tonic-gate 
10460Sstevel@tonic-gate 	case sBanner:
10470Sstevel@tonic-gate 		charptr = &options->banner;
10480Sstevel@tonic-gate 		goto parse_filename;
10490Sstevel@tonic-gate 	/*
10500Sstevel@tonic-gate 	 * These options can contain %X options expanded at
10510Sstevel@tonic-gate 	 * connect time, so that you can specify paths like:
10520Sstevel@tonic-gate 	 *
10530Sstevel@tonic-gate 	 * AuthorizedKeysFile	/etc/ssh_keys/%u
10540Sstevel@tonic-gate 	 */
10550Sstevel@tonic-gate 	case sAuthorizedKeysFile:
10560Sstevel@tonic-gate 	case sAuthorizedKeysFile2:
10570Sstevel@tonic-gate 		charptr = (opcode == sAuthorizedKeysFile ) ?
10580Sstevel@tonic-gate 		    &options->authorized_keys_file :
10590Sstevel@tonic-gate 		    &options->authorized_keys_file2;
10600Sstevel@tonic-gate 		goto parse_filename;
10610Sstevel@tonic-gate 
10620Sstevel@tonic-gate 	case sClientAliveInterval:
10630Sstevel@tonic-gate 		intptr = &options->client_alive_interval;
10640Sstevel@tonic-gate 		goto parse_time;
10650Sstevel@tonic-gate 
10660Sstevel@tonic-gate 	case sClientAliveCountMax:
10670Sstevel@tonic-gate 		intptr = &options->client_alive_count_max;
10680Sstevel@tonic-gate 		goto parse_int;
10690Sstevel@tonic-gate 
10700Sstevel@tonic-gate 	case sMaxAuthTries:
10710Sstevel@tonic-gate 		intptr = &options->max_auth_tries;
10720Sstevel@tonic-gate 		goto parse_int;
10730Sstevel@tonic-gate 
10740Sstevel@tonic-gate 	case sMaxAuthTriesLog:
10750Sstevel@tonic-gate 		intptr = &options->max_auth_tries_log;
10760Sstevel@tonic-gate 		goto parse_int;
10770Sstevel@tonic-gate 
10780Sstevel@tonic-gate 	case sLookupClientHostnames:
10790Sstevel@tonic-gate 		intptr = &options->lookup_client_hostnames;
10800Sstevel@tonic-gate 		goto parse_flag;
10810Sstevel@tonic-gate 
10820Sstevel@tonic-gate 	case sDeprecated:
10830Sstevel@tonic-gate 		log("%s line %d: Deprecated option %s",
10840Sstevel@tonic-gate 		    filename, linenum, arg);
10850Sstevel@tonic-gate 		while (arg)
10860Sstevel@tonic-gate 		    arg = strdelim(&cp);
10870Sstevel@tonic-gate 		break;
10880Sstevel@tonic-gate 
10890Sstevel@tonic-gate 	default:
10900Sstevel@tonic-gate 		fatal("%s line %d: Missing handler for opcode %s (%d)",
10910Sstevel@tonic-gate 		    filename, linenum, arg, opcode);
10920Sstevel@tonic-gate 	}
10930Sstevel@tonic-gate 	if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
10940Sstevel@tonic-gate 		fatal("%s line %d: garbage at end of line; \"%.200s\".",
10950Sstevel@tonic-gate 		    filename, linenum, arg);
10960Sstevel@tonic-gate 	return 0;
10970Sstevel@tonic-gate }
10980Sstevel@tonic-gate 
10990Sstevel@tonic-gate /* Reads the server configuration file. */
11000Sstevel@tonic-gate 
11010Sstevel@tonic-gate void
11020Sstevel@tonic-gate read_server_config(ServerOptions *options, const char *filename)
11030Sstevel@tonic-gate {
11040Sstevel@tonic-gate 	int linenum, bad_options = 0;
11050Sstevel@tonic-gate 	char line[1024];
11060Sstevel@tonic-gate 	FILE *f;
11070Sstevel@tonic-gate 
11080Sstevel@tonic-gate 	f = fopen(filename, "r");
11090Sstevel@tonic-gate 	if (!f) {
11100Sstevel@tonic-gate 		perror(filename);
11110Sstevel@tonic-gate 		exit(1);
11120Sstevel@tonic-gate 	}
11130Sstevel@tonic-gate 	linenum = 0;
11140Sstevel@tonic-gate 	while (fgets(line, sizeof(line), f)) {
11150Sstevel@tonic-gate 		/* Update line number counter. */
11160Sstevel@tonic-gate 		linenum++;
11170Sstevel@tonic-gate 		if (process_server_config_line(options, line, filename, linenum) != 0)
11180Sstevel@tonic-gate 			bad_options++;
11190Sstevel@tonic-gate 	}
11200Sstevel@tonic-gate 	(void) fclose(f);
11210Sstevel@tonic-gate 	if (bad_options > 0)
11220Sstevel@tonic-gate 		fatal("%s: terminating, %d bad configuration options",
11230Sstevel@tonic-gate 		    filename, bad_options);
11240Sstevel@tonic-gate }
1125