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