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