blob: eb32db0fa7ee79d567c5fdead920eb7d585e0c46 [file] [log] [blame]
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001/* $OpenBSD: servconf.c,v 1.271 2015/05/22 03:50:02 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002/*
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10005 *
Damien Millere4340be2000-09-16 13:29:08 +11006 * As far as I am concerned, the code I have written for this software
7 * can be used freely for any purpose. Any derived versions of this
8 * software must be clearly marked as such, and if the derived work is
9 * incompatible with the protocol description in the RFC file, it must be
10 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110011 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100012
13#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
Damien Millere3b60b52006-07-10 21:08:03 +100015#include <sys/types.h>
16#include <sys/socket.h>
17
Damien Miller0dac6fb2010-11-20 15:19:38 +110018#include <netinet/in.h>
19#include <netinet/in_systm.h>
20#include <netinet/ip.h>
21
Darren Tucker5f96f3b2013-05-16 20:29:28 +100022#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100023#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100024#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100025#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100026#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100027#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100028#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100029#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000030#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100031#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100032#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100033#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100034#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100035#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100036
Damien Millerb84886b2008-05-19 15:05:07 +100037#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100041#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100042#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100043#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100044#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000045#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100047#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000048#include "kex.h"
49#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100050#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100051#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100052#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100053#include "canohost.h"
54#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110055#include "hostfile.h"
56#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000057#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000058#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000059
Damien Miller3dc71ad2009-01-28 16:31:22 +110060static void add_listen_addr(ServerOptions *, char *, int);
61static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110062
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000063/* Use of privilege separation or not */
64extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100065extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000066
Damien Millerd4a8b7e1999-10-27 13:42:43 +100067/* Initializes the server options to their default values. */
68
Damien Miller4af51302000-04-16 11:18:38 +100069void
Damien Miller95def091999-11-25 00:26:21 +110070initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100071{
Damien Miller95def091999-11-25 00:26:21 +110072 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110073
74 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100075 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110076
77 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110078 options->num_ports = 0;
79 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000080 options->queued_listen_addrs = NULL;
81 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110082 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110083 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110084 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110085 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100086 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100087 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110088 options->server_key_bits = -1;
89 options->login_grace_time = -1;
90 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000091 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110092 options->ignore_rhosts = -1;
93 options->ignore_user_known_hosts = -1;
94 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000095 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110096 options->x11_forwarding = -1;
97 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110098 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110099 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000100 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000101 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100103 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100104 options->log_facility = SYSLOG_FACILITY_NOT_SET;
105 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000107 options->hostbased_authentication = -1;
108 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000109 options->hostbased_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100110 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100111 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000112 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100113 options->kerberos_authentication = -1;
114 options->kerberos_or_local_passwd = -1;
115 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100116 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000117 options->gss_authentication=-1;
118 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000119 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100120 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100121 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000122 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100123 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000124 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100125 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000126 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000127 options->rekey_limit = -1;
128 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100129 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000130 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000131 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100132 options->num_allow_users = 0;
133 options->num_deny_users = 0;
134 options->num_allow_groups = 0;
135 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000136 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000137 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000138 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000139 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller7acefbb2014-07-18 14:11:24 +1000140 options->fwd_opts.gateway_ports = -1;
141 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
142 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000143 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000144 options->max_startups_begin = -1;
145 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000146 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000147 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000148 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000149 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000150 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000151 options->client_alive_interval = -1;
152 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000153 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000154 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100155 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000156 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000157 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100158 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100159 options->authorized_keys_command = NULL;
160 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100161 options->revoked_keys_file = NULL;
162 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000163 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000164 options->authorized_principals_command = NULL;
165 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100166 options->ip_qos_interactive = -1;
167 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000168 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000169 options->fingerprint_hash = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000170}
171
djm@openbsd.org161cf412014-12-22 07:55:51 +0000172/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
173static int
174option_clear_or_none(const char *o)
175{
176 return o == NULL || strcasecmp(o, "none") == 0;
177}
178
Damien Miller4af51302000-04-16 11:18:38 +1000179void
Damien Miller95def091999-11-25 00:26:21 +1100180fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000181{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000182 int i;
183
Damien Miller726273e2001-11-12 11:40:11 +1100184 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000185 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000186 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100187
188 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100189 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100190 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100191 if (options->num_host_key_files == 0) {
192 /* fill default hostkeys for protocols */
193 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100194 options->host_key_files[options->num_host_key_files++] =
195 _PATH_HOST_KEY_FILE;
196 if (options->protocol & SSH_PROTO_2) {
197 options->host_key_files[options->num_host_key_files++] =
198 _PATH_HOST_RSA_KEY_FILE;
199 options->host_key_files[options->num_host_key_files++] =
200 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100201#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000202 options->host_key_files[options->num_host_key_files++] =
203 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100204#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100205 options->host_key_files[options->num_host_key_files++] =
206 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100207 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100208 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100209 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100210 if (options->num_ports == 0)
211 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000212 if (options->address_family == -1)
213 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100214 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000215 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000216 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000217 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100218 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000219 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000221 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->key_regeneration_time == -1)
223 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000224 if (options->permit_root_login == PERMIT_NOT_SET)
djm@openbsd.org88a7c592015-04-27 21:42:48 +0000225 options->permit_root_login = PERMIT_NO;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100227 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->ignore_user_known_hosts == -1)
229 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->print_motd == -1)
231 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000232 if (options->print_lastlog == -1)
233 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100235 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100237 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100238 if (options->x11_use_localhost == -1)
239 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000240 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000241 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100242 if (options->permit_tty == -1)
243 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000244 if (options->permit_user_rc == -1)
245 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->strict_modes == -1)
247 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100248 if (options->tcp_keep_alive == -1)
249 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100250 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100251 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100252 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000253 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100254 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100255 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000256 if (options->hostbased_authentication == -1)
257 options->hostbased_authentication = 0;
258 if (options->hostbased_uses_name_from_packet_only == -1)
259 options->hostbased_uses_name_from_packet_only = 0;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000260 if (options->hostbased_key_types == NULL)
261 options->hostbased_key_types = xstrdup("*");
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->rsa_authentication == -1)
263 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100264 if (options->pubkey_authentication == -1)
265 options->pubkey_authentication = 1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000266 if (options->pubkey_key_types == NULL)
267 options->pubkey_key_types = xstrdup("*");
Damien Miller95def091999-11-25 00:26:21 +1100268 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000269 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100270 if (options->kerberos_or_local_passwd == -1)
271 options->kerberos_or_local_passwd = 1;
272 if (options->kerberos_ticket_cleanup == -1)
273 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100274 if (options->kerberos_get_afs_token == -1)
275 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000276 if (options->gss_authentication == -1)
277 options->gss_authentication = 0;
278 if (options->gss_cleanup_creds == -1)
279 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000280 if (options->gss_strict_acceptor == -1)
281 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100282 if (options->password_authentication == -1)
283 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100284 if (options->kbd_interactive_authentication == -1)
285 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000286 if (options->challenge_response_authentication == -1)
287 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100288 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100289 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000290 if (options->permit_user_env == -1)
291 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100292 if (options->use_login == -1)
293 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000294 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000295 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000296 if (options->rekey_limit == -1)
297 options->rekey_limit = 0;
298 if (options->rekey_interval == -1)
299 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100300 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100301 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000302 if (options->allow_streamlocal_forwarding == -1)
303 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000304 if (options->allow_agent_forwarding == -1)
305 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000306 if (options->fwd_opts.gateway_ports == -1)
307 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000308 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100309 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000310 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100311 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000312 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100313 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000314 if (options->max_authtries == -1)
315 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000316 if (options->max_sessions == -1)
317 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000318 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000319 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000320 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100321 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000322 if (options->client_alive_count_max == -1)
323 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000324 if (options->num_authkeys_files == 0) {
325 options->authorized_keys_files[options->num_authkeys_files++] =
326 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
327 options->authorized_keys_files[options->num_authkeys_files++] =
328 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
329 }
Damien Millerd27b9472005-12-13 19:29:02 +1100330 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100331 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100332 if (options->ip_qos_interactive == -1)
333 options->ip_qos_interactive = IPTOS_LOWDELAY;
334 if (options->ip_qos_bulk == -1)
335 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000336 if (options->version_addendum == NULL)
337 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000338 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
339 options->fwd_opts.streamlocal_bind_mask = 0177;
340 if (options->fwd_opts.streamlocal_bind_unlink == -1)
341 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000342 if (options->fingerprint_hash == -1)
343 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
Ben Lindstromfb62a692002-06-06 19:47:11 +0000344 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000345 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000346 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000347
djm@openbsd.org161cf412014-12-22 07:55:51 +0000348#define CLEAR_ON_NONE(v) \
349 do { \
350 if (option_clear_or_none(v)) { \
351 free(v); \
352 v = NULL; \
353 } \
354 } while(0)
355 CLEAR_ON_NONE(options->pid_file);
356 CLEAR_ON_NONE(options->xauth_location);
357 CLEAR_ON_NONE(options->banner);
358 CLEAR_ON_NONE(options->trusted_user_ca_keys);
359 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000360 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000361 for (i = 0; i < options->num_host_key_files; i++)
362 CLEAR_ON_NONE(options->host_key_files[i]);
363 for (i = 0; i < options->num_host_cert_files; i++)
364 CLEAR_ON_NONE(options->host_cert_files[i]);
365#undef CLEAR_ON_NONE
366
Tim Rice40017b02002-07-14 13:36:49 -0700367#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000368 if (use_privsep && options->compression == 1) {
369 error("This platform does not support both privilege "
370 "separation and compression");
371 error("Compression disabled");
372 options->compression = 0;
373 }
374#endif
375
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000376}
377
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000378/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100379typedef enum {
380 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100381 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000382 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100383 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000384 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
385 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000386 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100387 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100388 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000389 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100390 sPasswordAuthentication, sKbdInteractiveAuthentication,
391 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000392 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100393 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100394 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000395 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000396 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000397 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000398 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
399 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000400 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000401 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
402 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000403 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
404 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100405 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100406 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100407 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000408 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000409 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000410 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100411 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000412 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000413 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000414 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000415 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000416} ServerOpCodes;
417
Darren Tucker45150472006-07-12 22:34:17 +1000418#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
419#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
420#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
421
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100423static struct {
424 const char *name;
425 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000426 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100427} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100428 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000429#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000430 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000431#else
Darren Tucker45150472006-07-12 22:34:17 +1000432 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000433#endif
Darren Tucker45150472006-07-12 22:34:17 +1000434 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100435 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000436 { "port", sPort, SSHCFG_GLOBAL },
437 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
438 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000439 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000440 { "pidfile", sPidFile, SSHCFG_GLOBAL },
441 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
442 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
443 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100444 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000445 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
446 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
447 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100448 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
449 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000450 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000451 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100452 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
453 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000454 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000455 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000456#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100457 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000458 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
459 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100460#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000461 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000462#else
Darren Tucker45150472006-07-12 22:34:17 +1000463 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100464#endif
465#else
Darren Tucker1629c072007-02-19 22:25:37 +1100466 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000467 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
468 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
469 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000470#endif
Darren Tucker45150472006-07-12 22:34:17 +1000471 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
472 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000473#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100474 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000475 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000476 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000477#else
Darren Tucker1629c072007-02-19 22:25:37 +1100478 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000479 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000480 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000481#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100482 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
483 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100484 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000485 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
486 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
487 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
488 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
489 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
490 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
491 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
492 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000493 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
494 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
495 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000496 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
497 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100498 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000499 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
500 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
501 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000502 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000503 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
504 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
505 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000506 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000507 { "allowusers", sAllowUsers, SSHCFG_ALL },
508 { "denyusers", sDenyUsers, SSHCFG_ALL },
509 { "allowgroups", sAllowGroups, SSHCFG_ALL },
510 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "ciphers", sCiphers, SSHCFG_GLOBAL },
512 { "macs", sMacs, SSHCFG_GLOBAL },
513 { "protocol", sProtocol, SSHCFG_GLOBAL },
514 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
515 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
516 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000517 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000518 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100519 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000520 { "usedns", sUseDNS, SSHCFG_GLOBAL },
521 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
522 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
523 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
524 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000525 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000526 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000527 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000528 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000529 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100530 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000531 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000532 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000533 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000534 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100535 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100536 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100537 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
538 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000539 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000540 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100541 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100542 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
543 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000544 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
545 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000546 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100547 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000548 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
549 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
550 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000551 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000552 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000553};
554
Darren Tuckere7140f22008-06-10 23:01:51 +1000555static struct {
556 int val;
557 char *text;
558} tunmode_desc[] = {
559 { SSH_TUNMODE_NO, "no" },
560 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
561 { SSH_TUNMODE_ETHERNET, "ethernet" },
562 { SSH_TUNMODE_YES, "yes" },
563 { -1, NULL }
564};
565
Damien Miller5428f641999-11-25 11:54:57 +1100566/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000567 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100568 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000569
Damien Miller4af51302000-04-16 11:18:38 +1000570static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100571parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000572 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000573{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000574 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000575
Damien Miller95def091999-11-25 00:26:21 +1100576 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000577 if (strcasecmp(cp, keywords[i].name) == 0) {
578 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100579 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000580 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000582 error("%s: line %d: Bad configuration option: %s",
583 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100584 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000585}
586
Darren Tucker88b6fb22010-01-13 22:44:29 +1100587char *
588derelativise_path(const char *path)
589{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000590 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100591
djm@openbsd.org161cf412014-12-22 07:55:51 +0000592 if (strcasecmp(path, "none") == 0)
593 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100594 expanded = tilde_expand_filename(path, getuid());
595 if (*expanded == '/')
596 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100597 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100598 fatal("%s: getcwd: %s", __func__, strerror(errno));
599 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000600 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100601 return ret;
602}
603
Ben Lindstrombba81212001-06-25 05:01:22 +0000604static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100605add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100606{
Damien Millereccb9de2005-06-17 12:59:34 +1000607 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100608
Ben Lindstrom19066a12001-04-12 23:39:26 +0000609 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000610 for (i = 0; i < options->num_ports; i++)
611 add_one_listen_addr(options, addr, options->ports[i]);
612 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000613 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000614}
615
Ben Lindstrombba81212001-06-25 05:01:22 +0000616static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100617add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000618{
619 struct addrinfo hints, *ai, *aitop;
620 char strport[NI_MAXSERV];
621 int gaierr;
622
623 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100624 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000625 hints.ai_socktype = SOCK_STREAM;
626 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100627 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000628 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
629 fatal("bad addr or host: %s (%s)",
630 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100631 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000632 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
633 ;
634 ai->ai_next = options->listen_addrs;
635 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100636}
637
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000638/*
639 * Queue a ListenAddress to be processed once we have all of the Ports
640 * and AddressFamily options.
641 */
642static void
643queue_listen_addr(ServerOptions *options, char *addr, int port)
644{
645 options->queued_listen_addrs = xreallocarray(
646 options->queued_listen_addrs, options->num_queued_listens + 1,
647 sizeof(addr));
648 options->queued_listen_ports = xreallocarray(
649 options->queued_listen_ports, options->num_queued_listens + 1,
650 sizeof(port));
651 options->queued_listen_addrs[options->num_queued_listens] =
652 xstrdup(addr);
653 options->queued_listen_ports[options->num_queued_listens] = port;
654 options->num_queued_listens++;
655}
656
657/*
658 * Process queued (text) ListenAddress entries.
659 */
660static void
661process_queued_listen_addrs(ServerOptions *options)
662{
663 u_int i;
664
665 if (options->num_ports == 0)
666 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
667 if (options->address_family == -1)
668 options->address_family = AF_UNSPEC;
669
670 for (i = 0; i < options->num_queued_listens; i++) {
671 add_listen_addr(options, options->queued_listen_addrs[i],
672 options->queued_listen_ports[i]);
673 free(options->queued_listen_addrs[i]);
674 options->queued_listen_addrs[i] = NULL;
675 }
676 free(options->queued_listen_addrs);
677 options->queued_listen_addrs = NULL;
678 free(options->queued_listen_ports);
679 options->queued_listen_ports = NULL;
680 options->num_queued_listens = 0;
681}
682
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000683struct connection_info *
684get_connection_info(int populate, int use_dns)
685{
686 static struct connection_info ci;
687
688 if (!populate)
689 return &ci;
690 ci.host = get_canonical_hostname(use_dns);
691 ci.address = get_remote_ipaddr();
692 ci.laddress = get_local_ipaddr(packet_get_connection_in());
693 ci.lport = get_local_port();
694 return &ci;
695}
696
Darren Tucker45150472006-07-12 22:34:17 +1000697/*
698 * The strategy for the Match blocks is that the config file is parsed twice.
699 *
700 * The first time is at startup. activep is initialized to 1 and the
701 * directives in the global context are processed and acted on. Hitting a
702 * Match directive unsets activep and the directives inside the block are
703 * checked for syntax only.
704 *
705 * The second time is after a connection has been established but before
706 * authentication. activep is initialized to 2 and global config directives
707 * are ignored since they have already been processed. If the criteria in a
708 * Match block is met, activep is set and the subsequent directives
709 * processed and actioned until EOF or another Match block unsets it. Any
710 * options set are copied into the main server config.
711 *
712 * Potential additions/improvements:
713 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
714 *
715 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
716 * Match Address 192.168.0.*
717 * Tag trusted
718 * Match Group wheel
719 * Tag trusted
720 * Match Tag trusted
721 * AllowTcpForwarding yes
722 * GatewayPorts clientspecified
723 * [...]
724 *
725 * - Add a PermittedChannelRequests directive
726 * Match Group shell
727 * PermittedChannelRequests session,forwarded-tcpip
728 */
729
730static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000731match_cfg_line_group(const char *grps, int line, const char *user)
732{
733 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000734 struct passwd *pw;
735
Damien Miller565ca3f2006-08-19 00:23:15 +1000736 if (user == NULL)
737 goto out;
738
739 if ((pw = getpwnam(user)) == NULL) {
740 debug("Can't match group at line %d because user %.100s does "
741 "not exist", line, user);
742 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
743 debug("Can't Match group because user %.100s not in any group "
744 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000745 } else if (ga_match_pattern_list(grps) != 1) {
746 debug("user %.100s does not match group list %.100s at line %d",
747 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000748 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000749 debug("user %.100s matched group list %.100s at line %d", user,
750 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000751 result = 1;
752 }
753out:
754 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000755 return result;
756}
757
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000758/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000759 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100760 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000761 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000762 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000763static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000764match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000765{
Damien Millercf31f382013-10-24 21:02:56 +1100766 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000767 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000768
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000769 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000770 debug3("checking syntax for 'Match %s'", cp);
771 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000772 debug3("checking match for '%s' user %s host %s addr %s "
773 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
774 ci->host ? ci->host : "(null)",
775 ci->address ? ci->address : "(null)",
776 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000777
778 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100779 attributes++;
780 if (strcasecmp(attrib, "all") == 0) {
781 if (attributes != 1 ||
782 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
783 error("'all' cannot be combined with other "
784 "Match attributes");
785 return -1;
786 }
787 *condition = cp;
788 return 1;
789 }
Darren Tucker45150472006-07-12 22:34:17 +1000790 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
791 error("Missing Match criteria for %s", attrib);
792 return -1;
793 }
Darren Tucker45150472006-07-12 22:34:17 +1000794 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000795 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000796 result = 0;
797 continue;
798 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000799 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000800 result = 0;
801 else
802 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000803 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000804 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000805 if (ci == NULL || ci->user == NULL) {
806 result = 0;
807 continue;
808 }
809 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000810 case -1:
811 return -1;
812 case 0:
813 result = 0;
814 }
Darren Tucker45150472006-07-12 22:34:17 +1000815 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000816 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000817 result = 0;
818 continue;
819 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000820 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000821 result = 0;
822 else
823 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000824 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000825 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000826 if (ci == NULL || ci->address == NULL) {
827 result = 0;
828 continue;
829 }
830 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000831 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000832 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000833 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000834 break;
835 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000836 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000837 result = 0;
838 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000839 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000840 return -1;
841 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000842 } else if (strcasecmp(attrib, "localaddress") == 0){
843 if (ci == NULL || ci->laddress == NULL) {
844 result = 0;
845 continue;
846 }
847 switch (addr_match_list(ci->laddress, arg)) {
848 case 1:
849 debug("connection from %.100s matched "
850 "'LocalAddress %.100s' at line %d",
851 ci->laddress, arg, line);
852 break;
853 case 0:
854 case -1:
855 result = 0;
856 break;
857 case -2:
858 return -1;
859 }
860 } else if (strcasecmp(attrib, "localport") == 0) {
861 if ((port = a2port(arg)) == -1) {
862 error("Invalid LocalPort '%s' on Match line",
863 arg);
864 return -1;
865 }
866 if (ci == NULL || ci->lport == 0) {
867 result = 0;
868 continue;
869 }
870 /* TODO support port lists */
871 if (port == ci->lport)
872 debug("connection from %.100s matched "
873 "'LocalPort %d' at line %d",
874 ci->laddress, port, line);
875 else
876 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000877 } else {
878 error("Unsupported Match attribute %s", attrib);
879 return -1;
880 }
881 }
Damien Millercf31f382013-10-24 21:02:56 +1100882 if (attributes == 0) {
883 error("One or more attributes required for Match");
884 return -1;
885 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000886 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000887 debug3("match %sfound", result ? "" : "not ");
888 *condition = cp;
889 return result;
890}
891
Damien Millere2754432006-07-24 14:06:47 +1000892#define WHITESPACE " \t\r\n"
893
Damien Miller33322122011-06-20 14:43:11 +1000894/* Multistate option parsing */
895struct multistate {
896 char *key;
897 int value;
898};
899static const struct multistate multistate_addressfamily[] = {
900 { "inet", AF_INET },
901 { "inet6", AF_INET6 },
902 { "any", AF_UNSPEC },
903 { NULL, -1 }
904};
905static const struct multistate multistate_permitrootlogin[] = {
906 { "without-password", PERMIT_NO_PASSWD },
907 { "forced-commands-only", PERMIT_FORCED_ONLY },
908 { "yes", PERMIT_YES },
909 { "no", PERMIT_NO },
910 { NULL, -1 }
911};
912static const struct multistate multistate_compression[] = {
913 { "delayed", COMP_DELAYED },
914 { "yes", COMP_ZLIB },
915 { "no", COMP_NONE },
916 { NULL, -1 }
917};
918static const struct multistate multistate_gatewayports[] = {
919 { "clientspecified", 2 },
920 { "yes", 1 },
921 { "no", 0 },
922 { NULL, -1 }
923};
Damien Miller69ff1df2011-06-23 08:30:03 +1000924static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000925 { "yes", PRIVSEP_NOSANDBOX },
926 { "sandbox", PRIVSEP_ON },
927 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000928 { "no", PRIVSEP_OFF },
929 { NULL, -1 }
930};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100931static const struct multistate multistate_tcpfwd[] = {
932 { "yes", FORWARD_ALLOW },
933 { "all", FORWARD_ALLOW },
934 { "no", FORWARD_DENY },
935 { "remote", FORWARD_REMOTE },
936 { "local", FORWARD_LOCAL },
937 { NULL, -1 }
938};
Damien Miller33322122011-06-20 14:43:11 +1000939
Ben Lindstromade03f62001-12-06 18:22:17 +0000940int
941process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000942 const char *filename, int linenum, int *activep,
943 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000944{
Darren Tucker09c0f032013-05-16 20:48:57 +1000945 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000946 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100947 SyslogFacility *log_facility_ptr;
948 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000949 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000950 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000951 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000952 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000953 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000954
955 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100956 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100957 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000958 /* Ignore leading whitespace */
959 if (*arg == '\0')
960 arg = strdelim(&cp);
961 if (!arg || !*arg || *arg == '#')
962 return 0;
963 intptr = NULL;
964 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000965 opcode = parse_token(arg, filename, linenum, &flags);
966
967 if (activep == NULL) { /* We are processing a command line directive */
968 cmdline = 1;
969 activep = &cmdline;
970 }
971 if (*activep && opcode != sMatch)
972 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
973 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000974 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000975 fatal("%s line %d: Directive '%s' is not allowed "
976 "within a Match block", filename, linenum, arg);
977 } else { /* this is a directive we have already processed */
978 while (arg)
979 arg = strdelim(&cp);
980 return 0;
981 }
982 }
983
Ben Lindstromade03f62001-12-06 18:22:17 +0000984 switch (opcode) {
985 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000986 case sUsePAM:
987 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000988 goto parse_flag;
989
990 /* Standard Options */
991 case sBadOption:
992 return -1;
993 case sPort:
994 /* ignore ports from configfile if cmdline specifies ports */
995 if (options->ports_from_cmdline)
996 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000997 if (options->num_ports >= MAX_PORTS)
998 fatal("%s line %d: too many ports.",
999 filename, linenum);
1000 arg = strdelim(&cp);
1001 if (!arg || *arg == '\0')
1002 fatal("%s line %d: missing port number.",
1003 filename, linenum);
1004 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001005 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001006 fatal("%s line %d: Badly formatted port number.",
1007 filename, linenum);
1008 break;
1009
1010 case sServerKeyBits:
1011 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001012 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001013 arg = strdelim(&cp);
1014 if (!arg || *arg == '\0')
1015 fatal("%s line %d: missing integer value.",
1016 filename, linenum);
1017 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001018 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001019 *intptr = value;
1020 break;
1021
1022 case sLoginGraceTime:
1023 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001024 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001025 arg = strdelim(&cp);
1026 if (!arg || *arg == '\0')
1027 fatal("%s line %d: missing time value.",
1028 filename, linenum);
1029 if ((value = convtime(arg)) == -1)
1030 fatal("%s line %d: invalid time value.",
1031 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001032 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001033 *intptr = value;
1034 break;
1035
1036 case sKeyRegenerationTime:
1037 intptr = &options->key_regeneration_time;
1038 goto parse_time;
1039
1040 case sListenAddress:
1041 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001042 if (arg == NULL || *arg == '\0')
1043 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001045 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1046 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1047 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001048 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001049 break;
1050 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001051 p = hpdelim(&arg);
1052 if (p == NULL)
1053 fatal("%s line %d: bad address:port usage",
1054 filename, linenum);
1055 p = cleanhostname(p);
1056 if (arg == NULL)
1057 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001058 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001059 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001060
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001061 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001062
Ben Lindstromade03f62001-12-06 18:22:17 +00001063 break;
1064
Darren Tucker0f383232005-01-20 10:57:56 +11001065 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001066 intptr = &options->address_family;
1067 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001068 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001069 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001070 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001071 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001072 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001073 value = -1;
1074 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1075 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1076 value = multistate_ptr[i].value;
1077 break;
1078 }
1079 }
1080 if (value == -1)
1081 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001082 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001083 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001084 *intptr = value;
1085 break;
1086
Ben Lindstromade03f62001-12-06 18:22:17 +00001087 case sHostKeyFile:
1088 intptr = &options->num_host_key_files;
1089 if (*intptr >= MAX_HOSTKEYS)
1090 fatal("%s line %d: too many host keys specified (max %d).",
1091 filename, linenum, MAX_HOSTKEYS);
1092 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001093 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001094 arg = strdelim(&cp);
1095 if (!arg || *arg == '\0')
1096 fatal("%s line %d: missing file name.",
1097 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001098 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001099 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001100 /* increase optional counter */
1101 if (intptr != NULL)
1102 *intptr = *intptr + 1;
1103 }
1104 break;
1105
Damien Miller85b45e02013-07-20 13:21:52 +10001106 case sHostKeyAgent:
1107 charptr = &options->host_key_agent;
1108 arg = strdelim(&cp);
1109 if (!arg || *arg == '\0')
1110 fatal("%s line %d: missing socket name.",
1111 filename, linenum);
1112 if (*activep && *charptr == NULL)
1113 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1114 xstrdup(arg) : derelativise_path(arg);
1115 break;
1116
Damien Miller0a80ca12010-02-27 07:55:05 +11001117 case sHostCertificate:
1118 intptr = &options->num_host_cert_files;
1119 if (*intptr >= MAX_HOSTKEYS)
1120 fatal("%s line %d: too many host certificates "
1121 "specified (max %d).", filename, linenum,
1122 MAX_HOSTCERTS);
1123 charptr = &options->host_cert_files[*intptr];
1124 goto parse_filename;
1125 break;
1126
Ben Lindstromade03f62001-12-06 18:22:17 +00001127 case sPidFile:
1128 charptr = &options->pid_file;
1129 goto parse_filename;
1130
1131 case sPermitRootLogin:
1132 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001133 multistate_ptr = multistate_permitrootlogin;
1134 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001135
1136 case sIgnoreRhosts:
1137 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001138 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001139 arg = strdelim(&cp);
1140 if (!arg || *arg == '\0')
1141 fatal("%s line %d: missing yes/no argument.",
1142 filename, linenum);
1143 value = 0; /* silence compiler */
1144 if (strcmp(arg, "yes") == 0)
1145 value = 1;
1146 else if (strcmp(arg, "no") == 0)
1147 value = 0;
1148 else
1149 fatal("%s line %d: Bad yes/no argument: %s",
1150 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001151 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001152 *intptr = value;
1153 break;
1154
1155 case sIgnoreUserKnownHosts:
1156 intptr = &options->ignore_user_known_hosts;
1157 goto parse_flag;
1158
Ben Lindstromade03f62001-12-06 18:22:17 +00001159 case sRhostsRSAAuthentication:
1160 intptr = &options->rhosts_rsa_authentication;
1161 goto parse_flag;
1162
1163 case sHostbasedAuthentication:
1164 intptr = &options->hostbased_authentication;
1165 goto parse_flag;
1166
1167 case sHostbasedUsesNameFromPacketOnly:
1168 intptr = &options->hostbased_uses_name_from_packet_only;
1169 goto parse_flag;
1170
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001171 case sHostbasedAcceptedKeyTypes:
1172 charptr = &options->hostbased_key_types;
1173 parse_keytypes:
1174 arg = strdelim(&cp);
1175 if (!arg || *arg == '\0')
1176 fatal("%s line %d: Missing argument.",
1177 filename, linenum);
1178 if (!sshkey_names_valid2(arg, 1))
1179 fatal("%s line %d: Bad key types '%s'.",
1180 filename, linenum, arg ? arg : "<NONE>");
1181 if (*activep && *charptr == NULL)
1182 *charptr = xstrdup(arg);
1183 break;
1184
Ben Lindstromade03f62001-12-06 18:22:17 +00001185 case sRSAAuthentication:
1186 intptr = &options->rsa_authentication;
1187 goto parse_flag;
1188
1189 case sPubkeyAuthentication:
1190 intptr = &options->pubkey_authentication;
1191 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001192
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001193 case sPubkeyAcceptedKeyTypes:
1194 charptr = &options->pubkey_key_types;
1195 goto parse_keytypes;
1196
Ben Lindstromade03f62001-12-06 18:22:17 +00001197 case sKerberosAuthentication:
1198 intptr = &options->kerberos_authentication;
1199 goto parse_flag;
1200
1201 case sKerberosOrLocalPasswd:
1202 intptr = &options->kerberos_or_local_passwd;
1203 goto parse_flag;
1204
1205 case sKerberosTicketCleanup:
1206 intptr = &options->kerberos_ticket_cleanup;
1207 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001208
Darren Tucker22ef5082003-12-31 11:37:34 +11001209 case sKerberosGetAFSToken:
1210 intptr = &options->kerberos_get_afs_token;
1211 goto parse_flag;
1212
Darren Tucker0efd1552003-08-26 11:49:55 +10001213 case sGssAuthentication:
1214 intptr = &options->gss_authentication;
1215 goto parse_flag;
1216
1217 case sGssCleanupCreds:
1218 intptr = &options->gss_cleanup_creds;
1219 goto parse_flag;
1220
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001221 case sGssStrictAcceptor:
1222 intptr = &options->gss_strict_acceptor;
1223 goto parse_flag;
1224
Ben Lindstromade03f62001-12-06 18:22:17 +00001225 case sPasswordAuthentication:
1226 intptr = &options->password_authentication;
1227 goto parse_flag;
1228
1229 case sKbdInteractiveAuthentication:
1230 intptr = &options->kbd_interactive_authentication;
1231 goto parse_flag;
1232
1233 case sChallengeResponseAuthentication:
1234 intptr = &options->challenge_response_authentication;
1235 goto parse_flag;
1236
1237 case sPrintMotd:
1238 intptr = &options->print_motd;
1239 goto parse_flag;
1240
1241 case sPrintLastLog:
1242 intptr = &options->print_lastlog;
1243 goto parse_flag;
1244
1245 case sX11Forwarding:
1246 intptr = &options->x11_forwarding;
1247 goto parse_flag;
1248
1249 case sX11DisplayOffset:
1250 intptr = &options->x11_display_offset;
1251 goto parse_int;
1252
Damien Miller95c249f2002-02-05 12:11:34 +11001253 case sX11UseLocalhost:
1254 intptr = &options->x11_use_localhost;
1255 goto parse_flag;
1256
Ben Lindstromade03f62001-12-06 18:22:17 +00001257 case sXAuthLocation:
1258 charptr = &options->xauth_location;
1259 goto parse_filename;
1260
Damien Miller5ff30c62013-10-30 22:21:50 +11001261 case sPermitTTY:
1262 intptr = &options->permit_tty;
1263 goto parse_flag;
1264
Damien Miller72e6b5c2014-07-04 09:00:04 +10001265 case sPermitUserRC:
1266 intptr = &options->permit_user_rc;
1267 goto parse_flag;
1268
Ben Lindstromade03f62001-12-06 18:22:17 +00001269 case sStrictModes:
1270 intptr = &options->strict_modes;
1271 goto parse_flag;
1272
Damien Miller12c150e2003-12-17 16:31:10 +11001273 case sTCPKeepAlive:
1274 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001275 goto parse_flag;
1276
1277 case sEmptyPasswd:
1278 intptr = &options->permit_empty_passwd;
1279 goto parse_flag;
1280
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001281 case sPermitUserEnvironment:
1282 intptr = &options->permit_user_env;
1283 goto parse_flag;
1284
Ben Lindstromade03f62001-12-06 18:22:17 +00001285 case sUseLogin:
1286 intptr = &options->use_login;
1287 goto parse_flag;
1288
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001289 case sCompression:
1290 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001291 multistate_ptr = multistate_compression;
1292 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001293
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001294 case sRekeyLimit:
1295 arg = strdelim(&cp);
1296 if (!arg || *arg == '\0')
1297 fatal("%.200s line %d: Missing argument.", filename,
1298 linenum);
1299 if (strcmp(arg, "default") == 0) {
1300 val64 = 0;
1301 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001302 if (scan_scaled(arg, &val64) == -1)
1303 fatal("%.200s line %d: Bad number '%s': %s",
1304 filename, linenum, arg, strerror(errno));
1305 /* check for too-large or too-small limits */
1306 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001307 fatal("%.200s line %d: RekeyLimit too large",
1308 filename, linenum);
1309 if (val64 != 0 && val64 < 16)
1310 fatal("%.200s line %d: RekeyLimit too small",
1311 filename, linenum);
1312 }
1313 if (*activep && options->rekey_limit == -1)
1314 options->rekey_limit = (u_int32_t)val64;
1315 if (cp != NULL) { /* optional rekey interval present */
1316 if (strcmp(cp, "none") == 0) {
1317 (void)strdelim(&cp); /* discard */
1318 break;
1319 }
1320 intptr = &options->rekey_interval;
1321 goto parse_time;
1322 }
1323 break;
1324
Ben Lindstromade03f62001-12-06 18:22:17 +00001325 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001326 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001327 multistate_ptr = multistate_gatewayports;
1328 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001329
Damien Miller3a961dc2003-06-03 10:25:48 +10001330 case sUseDNS:
1331 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001332 goto parse_flag;
1333
1334 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001335 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001336 arg = strdelim(&cp);
1337 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001338 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001339 fatal("%.200s line %d: unsupported log facility '%s'",
1340 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001341 if (*log_facility_ptr == -1)
1342 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001343 break;
1344
1345 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001346 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001347 arg = strdelim(&cp);
1348 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001349 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001350 fatal("%.200s line %d: unsupported log level '%s'",
1351 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001352 if (*log_level_ptr == -1)
1353 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001354 break;
1355
1356 case sAllowTcpForwarding:
1357 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001358 multistate_ptr = multistate_tcpfwd;
1359 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001360
Damien Miller7acefbb2014-07-18 14:11:24 +10001361 case sAllowStreamLocalForwarding:
1362 intptr = &options->allow_streamlocal_forwarding;
1363 multistate_ptr = multistate_tcpfwd;
1364 goto parse_multistate;
1365
Damien Miller4f755cd2008-05-19 14:57:41 +10001366 case sAllowAgentForwarding:
1367 intptr = &options->allow_agent_forwarding;
1368 goto parse_flag;
1369
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001370 case sUsePrivilegeSeparation:
1371 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001372 multistate_ptr = multistate_privsep;
1373 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001374
Ben Lindstromade03f62001-12-06 18:22:17 +00001375 case sAllowUsers:
1376 while ((arg = strdelim(&cp)) && *arg != '\0') {
1377 if (options->num_allow_users >= MAX_ALLOW_USERS)
1378 fatal("%s line %d: too many allow users.",
1379 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001380 if (!*activep)
1381 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001382 options->allow_users[options->num_allow_users++] =
1383 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001384 }
1385 break;
1386
1387 case sDenyUsers:
1388 while ((arg = strdelim(&cp)) && *arg != '\0') {
1389 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001390 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001391 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001392 if (!*activep)
1393 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001394 options->deny_users[options->num_deny_users++] =
1395 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001396 }
1397 break;
1398
1399 case sAllowGroups:
1400 while ((arg = strdelim(&cp)) && *arg != '\0') {
1401 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1402 fatal("%s line %d: too many allow groups.",
1403 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001404 if (!*activep)
1405 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001406 options->allow_groups[options->num_allow_groups++] =
1407 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001408 }
1409 break;
1410
1411 case sDenyGroups:
1412 while ((arg = strdelim(&cp)) && *arg != '\0') {
1413 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1414 fatal("%s line %d: too many deny groups.",
1415 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001416 if (!*activep)
1417 continue;
1418 options->deny_groups[options->num_deny_groups++] =
1419 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001420 }
1421 break;
1422
1423 case sCiphers:
1424 arg = strdelim(&cp);
1425 if (!arg || *arg == '\0')
1426 fatal("%s line %d: Missing argument.", filename, linenum);
1427 if (!ciphers_valid(arg))
1428 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1429 filename, linenum, arg ? arg : "<NONE>");
1430 if (options->ciphers == NULL)
1431 options->ciphers = xstrdup(arg);
1432 break;
1433
1434 case sMacs:
1435 arg = strdelim(&cp);
1436 if (!arg || *arg == '\0')
1437 fatal("%s line %d: Missing argument.", filename, linenum);
1438 if (!mac_valid(arg))
1439 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1440 filename, linenum, arg ? arg : "<NONE>");
1441 if (options->macs == NULL)
1442 options->macs = xstrdup(arg);
1443 break;
1444
Damien Millerd5f62bf2010-09-24 22:11:14 +10001445 case sKexAlgorithms:
1446 arg = strdelim(&cp);
1447 if (!arg || *arg == '\0')
1448 fatal("%s line %d: Missing argument.",
1449 filename, linenum);
1450 if (!kex_names_valid(arg))
1451 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1452 filename, linenum, arg ? arg : "<NONE>");
1453 if (options->kex_algorithms == NULL)
1454 options->kex_algorithms = xstrdup(arg);
1455 break;
1456
Ben Lindstromade03f62001-12-06 18:22:17 +00001457 case sProtocol:
1458 intptr = &options->protocol;
1459 arg = strdelim(&cp);
1460 if (!arg || *arg == '\0')
1461 fatal("%s line %d: Missing argument.", filename, linenum);
1462 value = proto_spec(arg);
1463 if (value == SSH_PROTO_UNKNOWN)
1464 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001465 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001466 if (*intptr == SSH_PROTO_UNKNOWN)
1467 *intptr = value;
1468 break;
1469
1470 case sSubsystem:
1471 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1472 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001473 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001474 }
1475 arg = strdelim(&cp);
1476 if (!arg || *arg == '\0')
1477 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001478 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001479 if (!*activep) {
1480 arg = strdelim(&cp);
1481 break;
1482 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001483 for (i = 0; i < options->num_subsystems; i++)
1484 if (strcmp(arg, options->subsystem_name[i]) == 0)
1485 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001486 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001487 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1488 arg = strdelim(&cp);
1489 if (!arg || *arg == '\0')
1490 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001491 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001492 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001493
1494 /* Collect arguments (separate to executable) */
1495 p = xstrdup(arg);
1496 len = strlen(p) + 1;
1497 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1498 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001499 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001500 strlcat(p, " ", len);
1501 strlcat(p, arg, len);
1502 }
1503 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001504 options->num_subsystems++;
1505 break;
1506
1507 case sMaxStartups:
1508 arg = strdelim(&cp);
1509 if (!arg || *arg == '\0')
1510 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001511 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001512 if ((n = sscanf(arg, "%d:%d:%d",
1513 &options->max_startups_begin,
1514 &options->max_startups_rate,
1515 &options->max_startups)) == 3) {
1516 if (options->max_startups_begin >
1517 options->max_startups ||
1518 options->max_startups_rate > 100 ||
1519 options->max_startups_rate < 1)
1520 fatal("%s line %d: Illegal MaxStartups spec.",
1521 filename, linenum);
1522 } else if (n != 1)
1523 fatal("%s line %d: Illegal MaxStartups spec.",
1524 filename, linenum);
1525 else
1526 options->max_startups = options->max_startups_begin;
1527 break;
1528
Darren Tucker89413db2004-05-24 10:36:23 +10001529 case sMaxAuthTries:
1530 intptr = &options->max_authtries;
1531 goto parse_int;
1532
Damien Miller7207f642008-05-19 15:34:50 +10001533 case sMaxSessions:
1534 intptr = &options->max_sessions;
1535 goto parse_int;
1536
Ben Lindstromade03f62001-12-06 18:22:17 +00001537 case sBanner:
1538 charptr = &options->banner;
1539 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001540
Ben Lindstromade03f62001-12-06 18:22:17 +00001541 /*
1542 * These options can contain %X options expanded at
1543 * connect time, so that you can specify paths like:
1544 *
1545 * AuthorizedKeysFile /etc/ssh_keys/%u
1546 */
1547 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001548 if (*activep && options->num_authkeys_files == 0) {
1549 while ((arg = strdelim(&cp)) && *arg != '\0') {
1550 if (options->num_authkeys_files >=
1551 MAX_AUTHKEYS_FILES)
1552 fatal("%s line %d: "
1553 "too many authorized keys files.",
1554 filename, linenum);
1555 options->authorized_keys_files[
1556 options->num_authkeys_files++] =
1557 tilde_expand_filename(arg, getuid());
1558 }
1559 }
1560 return 0;
1561
Damien Miller30da3442010-05-10 11:58:03 +10001562 case sAuthorizedPrincipalsFile:
1563 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001564 arg = strdelim(&cp);
1565 if (!arg || *arg == '\0')
1566 fatal("%s line %d: missing file name.",
1567 filename, linenum);
1568 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001569 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001570 /* increase optional counter */
1571 if (intptr != NULL)
1572 *intptr = *intptr + 1;
1573 }
1574 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001575
1576 case sClientAliveInterval:
1577 intptr = &options->client_alive_interval;
1578 goto parse_time;
1579
1580 case sClientAliveCountMax:
1581 intptr = &options->client_alive_count_max;
1582 goto parse_int;
1583
Darren Tucker46bc0752004-05-02 22:11:30 +10001584 case sAcceptEnv:
1585 while ((arg = strdelim(&cp)) && *arg != '\0') {
1586 if (strchr(arg, '=') != NULL)
1587 fatal("%s line %d: Invalid environment name.",
1588 filename, linenum);
1589 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1590 fatal("%s line %d: too many allow env.",
1591 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001592 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001593 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001594 options->accept_env[options->num_accept_env++] =
1595 xstrdup(arg);
1596 }
1597 break;
1598
Damien Millerd27b9472005-12-13 19:29:02 +11001599 case sPermitTunnel:
1600 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001601 arg = strdelim(&cp);
1602 if (!arg || *arg == '\0')
1603 fatal("%s line %d: Missing yes/point-to-point/"
1604 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001605 value = -1;
1606 for (i = 0; tunmode_desc[i].val != -1; i++)
1607 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1608 value = tunmode_desc[i].val;
1609 break;
1610 }
1611 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001612 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1613 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001614 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001615 *intptr = value;
1616 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001617
Darren Tucker45150472006-07-12 22:34:17 +10001618 case sMatch:
1619 if (cmdline)
1620 fatal("Match directive not supported as a command-line "
1621 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001622 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001623 if (value < 0)
1624 fatal("%s line %d: Bad Match condition", filename,
1625 linenum);
1626 *activep = value;
1627 break;
1628
Damien Miller9b439df2006-07-24 14:04:00 +10001629 case sPermitOpen:
1630 arg = strdelim(&cp);
1631 if (!arg || *arg == '\0')
1632 fatal("%s line %d: missing PermitOpen specification",
1633 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001634 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001635 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001636 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001637 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001638 options->num_permitted_opens = 0;
1639 }
Damien Miller9b439df2006-07-24 14:04:00 +10001640 break;
1641 }
Damien Millerc6081482012-04-22 11:18:53 +10001642 if (strcmp(arg, "none") == 0) {
1643 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001644 options->num_permitted_opens = 1;
1645 channel_disable_adm_local_opens();
1646 }
1647 break;
1648 }
Damien Millera29b95e2007-01-05 16:28:36 +11001649 if (*activep && n == -1)
1650 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001651 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1652 p = hpdelim(&arg);
1653 if (p == NULL)
1654 fatal("%s line %d: missing host in PermitOpen",
1655 filename, linenum);
1656 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001657 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001658 fatal("%s line %d: bad port number in "
1659 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001660 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001661 options->num_permitted_opens =
1662 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001663 }
Damien Miller9b439df2006-07-24 14:04:00 +10001664 break;
1665
Damien Millere2754432006-07-24 14:06:47 +10001666 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001667 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001668 fatal("%.200s line %d: Missing argument.", filename,
1669 linenum);
1670 len = strspn(cp, WHITESPACE);
1671 if (*activep && options->adm_forced_command == NULL)
1672 options->adm_forced_command = xstrdup(cp + len);
1673 return 0;
1674
Damien Millerd8cb1f12008-02-10 22:40:12 +11001675 case sChrootDirectory:
1676 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001677
1678 arg = strdelim(&cp);
1679 if (!arg || *arg == '\0')
1680 fatal("%s line %d: missing file name.",
1681 filename, linenum);
1682 if (*activep && *charptr == NULL)
1683 *charptr = xstrdup(arg);
1684 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001685
Damien Miller1aed65e2010-03-04 21:53:35 +11001686 case sTrustedUserCAKeys:
1687 charptr = &options->trusted_user_ca_keys;
1688 goto parse_filename;
1689
1690 case sRevokedKeys:
1691 charptr = &options->revoked_keys_file;
1692 goto parse_filename;
1693
Damien Miller0dac6fb2010-11-20 15:19:38 +11001694 case sIPQoS:
1695 arg = strdelim(&cp);
1696 if ((value = parse_ipqos(arg)) == -1)
1697 fatal("%s line %d: Bad IPQoS value: %s",
1698 filename, linenum, arg);
1699 arg = strdelim(&cp);
1700 if (arg == NULL)
1701 value2 = value;
1702 else if ((value2 = parse_ipqos(arg)) == -1)
1703 fatal("%s line %d: Bad IPQoS value: %s",
1704 filename, linenum, arg);
1705 if (*activep) {
1706 options->ip_qos_interactive = value;
1707 options->ip_qos_bulk = value2;
1708 }
1709 break;
1710
Damien Miller23528812012-04-22 11:24:43 +10001711 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001712 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001713 fatal("%.200s line %d: Missing argument.", filename,
1714 linenum);
1715 len = strspn(cp, WHITESPACE);
1716 if (*activep && options->version_addendum == NULL) {
1717 if (strcasecmp(cp + len, "none") == 0)
1718 options->version_addendum = xstrdup("");
1719 else if (strchr(cp + len, '\r') != NULL)
1720 fatal("%.200s line %d: Invalid argument",
1721 filename, linenum);
1722 else
1723 options->version_addendum = xstrdup(cp + len);
1724 }
1725 return 0;
1726
Damien Miller09d3e122012-10-31 08:58:58 +11001727 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001728 if (cp == NULL)
1729 fatal("%.200s line %d: Missing argument.", filename,
1730 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001731 len = strspn(cp, WHITESPACE);
1732 if (*activep && options->authorized_keys_command == NULL) {
1733 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1734 fatal("%.200s line %d: AuthorizedKeysCommand "
1735 "must be an absolute path",
1736 filename, linenum);
1737 options->authorized_keys_command = xstrdup(cp + len);
1738 }
1739 return 0;
1740
1741 case sAuthorizedKeysCommandUser:
1742 charptr = &options->authorized_keys_command_user;
1743
1744 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001745 if (!arg || *arg == '\0')
1746 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1747 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001748 if (*activep && *charptr == NULL)
1749 *charptr = xstrdup(arg);
1750 break;
1751
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001752 case sAuthorizedPrincipalsCommand:
1753 if (cp == NULL)
1754 fatal("%.200s line %d: Missing argument.", filename,
1755 linenum);
1756 len = strspn(cp, WHITESPACE);
1757 if (*activep &&
1758 options->authorized_principals_command == NULL) {
1759 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1760 fatal("%.200s line %d: "
1761 "AuthorizedPrincipalsCommand must be "
1762 "an absolute path", filename, linenum);
1763 options->authorized_principals_command =
1764 xstrdup(cp + len);
1765 }
1766 return 0;
1767
1768 case sAuthorizedPrincipalsCommandUser:
1769 charptr = &options->authorized_principals_command_user;
1770
1771 arg = strdelim(&cp);
1772 if (!arg || *arg == '\0')
1773 fatal("%s line %d: missing "
1774 "AuthorizedPrincipalsCommandUser argument.",
1775 filename, linenum);
1776 if (*activep && *charptr == NULL)
1777 *charptr = xstrdup(arg);
1778 break;
1779
Damien Millera6e3f012012-11-04 23:21:40 +11001780 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001781 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001782 while ((arg = strdelim(&cp)) && *arg != '\0') {
1783 if (options->num_auth_methods >=
1784 MAX_AUTH_METHODS)
1785 fatal("%s line %d: "
1786 "too many authentication methods.",
1787 filename, linenum);
1788 if (auth2_methods_valid(arg, 0) != 0)
1789 fatal("%s line %d: invalid "
1790 "authentication method list.",
1791 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001792 if (!*activep)
1793 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001794 options->auth_methods[
1795 options->num_auth_methods++] = xstrdup(arg);
1796 }
1797 }
1798 return 0;
1799
Damien Miller7acefbb2014-07-18 14:11:24 +10001800 case sStreamLocalBindMask:
1801 arg = strdelim(&cp);
1802 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001803 fatal("%s line %d: missing StreamLocalBindMask "
1804 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001805 /* Parse mode in octal format */
1806 value = strtol(arg, &p, 8);
1807 if (arg == p || value < 0 || value > 0777)
1808 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001809 if (*activep)
1810 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001811 break;
1812
1813 case sStreamLocalBindUnlink:
1814 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1815 goto parse_flag;
1816
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001817 case sFingerprintHash:
1818 arg = strdelim(&cp);
1819 if (!arg || *arg == '\0')
1820 fatal("%.200s line %d: Missing argument.",
1821 filename, linenum);
1822 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1823 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1824 filename, linenum, arg);
1825 if (*activep)
1826 options->fingerprint_hash = value;
1827 break;
1828
Ben Lindstromade03f62001-12-06 18:22:17 +00001829 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001830 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001831 filename, linenum, arg);
1832 while (arg)
1833 arg = strdelim(&cp);
1834 break;
1835
Damien Millerf9b3feb2003-05-16 11:38:32 +10001836 case sUnsupported:
1837 logit("%s line %d: Unsupported option %s",
1838 filename, linenum, arg);
1839 while (arg)
1840 arg = strdelim(&cp);
1841 break;
1842
Ben Lindstromade03f62001-12-06 18:22:17 +00001843 default:
1844 fatal("%s line %d: Missing handler for opcode %s (%d)",
1845 filename, linenum, arg, opcode);
1846 }
1847 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1848 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1849 filename, linenum, arg);
1850 return 0;
1851}
1852
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001853/* Reads the server configuration file. */
1854
Damien Miller4af51302000-04-16 11:18:38 +10001855void
Darren Tucker645ab752004-06-25 13:33:20 +10001856load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001857{
Damien Miller46cb75a2012-07-31 12:22:37 +10001858 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001859 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001860 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001861
Darren Tucker645ab752004-06-25 13:33:20 +10001862 debug2("%s: filename %s", __func__, filename);
1863 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001864 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001865 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001866 }
Darren Tucker645ab752004-06-25 13:33:20 +10001867 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001868 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001869 lineno++;
1870 if (strlen(line) == sizeof(line) - 1)
1871 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001872 /*
1873 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001874 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001875 * line numbers later for error messages
1876 */
1877 if ((cp = strchr(line, '#')) != NULL)
1878 memcpy(cp, "\n", 2);
1879 cp = line + strspn(line, " \t\r");
1880
1881 buffer_append(conf, cp, strlen(cp));
1882 }
1883 buffer_append(conf, "\0", 1);
1884 fclose(f);
1885 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1886}
1887
1888void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001889parse_server_match_config(ServerOptions *options,
1890 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001891{
Darren Tucker45150472006-07-12 22:34:17 +10001892 ServerOptions mo;
1893
1894 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001895 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001896 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001897}
1898
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001899int parse_server_match_testspec(struct connection_info *ci, char *spec)
1900{
1901 char *p;
1902
1903 while ((p = strsep(&spec, ",")) && *p != '\0') {
1904 if (strncmp(p, "addr=", 5) == 0) {
1905 ci->address = xstrdup(p + 5);
1906 } else if (strncmp(p, "host=", 5) == 0) {
1907 ci->host = xstrdup(p + 5);
1908 } else if (strncmp(p, "user=", 5) == 0) {
1909 ci->user = xstrdup(p + 5);
1910 } else if (strncmp(p, "laddr=", 6) == 0) {
1911 ci->laddress = xstrdup(p + 6);
1912 } else if (strncmp(p, "lport=", 6) == 0) {
1913 ci->lport = a2port(p + 6);
1914 if (ci->lport == -1) {
1915 fprintf(stderr, "Invalid port '%s' in test mode"
1916 " specification %s\n", p+6, p);
1917 return -1;
1918 }
1919 } else {
1920 fprintf(stderr, "Invalid test mode specification %s\n",
1921 p);
1922 return -1;
1923 }
1924 }
1925 return 0;
1926}
1927
1928/*
1929 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1930 * empty spec.
1931 */
1932int server_match_spec_complete(struct connection_info *ci)
1933{
1934 if (ci->user && ci->host && ci->address)
1935 return 1; /* complete */
1936 if (!ci->user && !ci->host && !ci->address)
1937 return -1; /* empty */
1938 return 0; /* partial */
1939}
1940
Darren Tucker1629c072007-02-19 22:25:37 +11001941/*
1942 * Copy any supported values that are set.
1943 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001944 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001945 * array values that are not used pre-authentication, because any that we
1946 * do use must be explictly sent in mm_getpwnamallow().
1947 */
Darren Tucker45150472006-07-12 22:34:17 +10001948void
Darren Tucker1629c072007-02-19 22:25:37 +11001949copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001950{
Damien Miller534b2cc2013-12-05 14:07:27 +11001951#define M_CP_INTOPT(n) do {\
1952 if (src->n != -1) \
1953 dst->n = src->n; \
1954} while (0)
1955
Darren Tucker1629c072007-02-19 22:25:37 +11001956 M_CP_INTOPT(password_authentication);
1957 M_CP_INTOPT(gss_authentication);
1958 M_CP_INTOPT(rsa_authentication);
1959 M_CP_INTOPT(pubkey_authentication);
1960 M_CP_INTOPT(kerberos_authentication);
1961 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001962 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001963 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001964 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001965 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001966
1967 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001968 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001969 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001970 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001971 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001972 M_CP_INTOPT(x11_display_offset);
1973 M_CP_INTOPT(x11_forwarding);
1974 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001975 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001976 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001977 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001978 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001979 M_CP_INTOPT(ip_qos_interactive);
1980 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001981 M_CP_INTOPT(rekey_limit);
1982 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001983
Damien Miller534b2cc2013-12-05 14:07:27 +11001984 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1985#define M_CP_STROPT(n) do {\
1986 if (src->n != NULL && dst->n != src->n) { \
1987 free(dst->n); \
1988 dst->n = src->n; \
1989 } \
1990} while(0)
1991#define M_CP_STRARRAYOPT(n, num_n) do {\
1992 if (src->num_n != 0) { \
1993 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1994 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1995 } \
1996} while(0)
1997
Damien Millerf2e407e2011-05-20 19:04:14 +10001998 /* See comment in servconf.h */
1999 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002000
Damien Millerc2411902011-05-20 19:03:49 +10002001 /*
2002 * The only things that should be below this point are string options
2003 * which are only used after authentication.
2004 */
Damien Miller5d74e582011-05-20 19:03:31 +10002005 if (preauth)
2006 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002007
Damien Miller5d74e582011-05-20 19:03:31 +10002008 M_CP_STROPT(adm_forced_command);
2009 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10002010}
2011
Darren Tucker1629c072007-02-19 22:25:37 +11002012#undef M_CP_INTOPT
2013#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002014#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002015
Darren Tucker45150472006-07-12 22:34:17 +10002016void
2017parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002018 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002019{
2020 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002021 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002022
2023 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2024
Darren Tucker9fbac712004-08-12 22:41:44 +10002025 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002026 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002027 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002028 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002029 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002030 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002031 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002032 }
Darren Tuckera627d422013-06-02 07:31:17 +10002033 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002034 if (bad_options > 0)
2035 fatal("%s: terminating, %d bad configuration options",
2036 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002037 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002038}
Darren Tuckere7140f22008-06-10 23:01:51 +10002039
2040static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002041fmt_multistate_int(int val, const struct multistate *m)
2042{
2043 u_int i;
2044
2045 for (i = 0; m[i].key != NULL; i++) {
2046 if (m[i].value == val)
2047 return m[i].key;
2048 }
2049 return "UNKNOWN";
2050}
2051
2052static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002053fmt_intarg(ServerOpCodes code, int val)
2054{
Damien Miller82c55872011-06-23 08:20:30 +10002055 if (val == -1)
2056 return "unset";
2057 switch (code) {
2058 case sAddressFamily:
2059 return fmt_multistate_int(val, multistate_addressfamily);
2060 case sPermitRootLogin:
2061 return fmt_multistate_int(val, multistate_permitrootlogin);
2062 case sGatewayPorts:
2063 return fmt_multistate_int(val, multistate_gatewayports);
2064 case sCompression:
2065 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002066 case sUsePrivilegeSeparation:
2067 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002068 case sAllowTcpForwarding:
2069 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002070 case sAllowStreamLocalForwarding:
2071 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002072 case sFingerprintHash:
2073 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002074 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002075 switch (val) {
2076 case SSH_PROTO_1:
2077 return "1";
2078 case SSH_PROTO_2:
2079 return "2";
2080 case (SSH_PROTO_1|SSH_PROTO_2):
2081 return "2,1";
2082 default:
2083 return "UNKNOWN";
2084 }
Damien Miller82c55872011-06-23 08:20:30 +10002085 default:
2086 switch (val) {
2087 case 0:
2088 return "no";
2089 case 1:
2090 return "yes";
2091 default:
2092 return "UNKNOWN";
2093 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002094 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002095}
2096
2097static const char *
2098lookup_opcode_name(ServerOpCodes code)
2099{
2100 u_int i;
2101
2102 for (i = 0; keywords[i].name != NULL; i++)
2103 if (keywords[i].opcode == code)
2104 return(keywords[i].name);
2105 return "UNKNOWN";
2106}
2107
2108static void
2109dump_cfg_int(ServerOpCodes code, int val)
2110{
2111 printf("%s %d\n", lookup_opcode_name(code), val);
2112}
2113
2114static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002115dump_cfg_oct(ServerOpCodes code, int val)
2116{
2117 printf("%s 0%o\n", lookup_opcode_name(code), val);
2118}
2119
2120static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002121dump_cfg_fmtint(ServerOpCodes code, int val)
2122{
2123 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2124}
2125
2126static void
2127dump_cfg_string(ServerOpCodes code, const char *val)
2128{
2129 if (val == NULL)
2130 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002131 printf("%s %s\n", lookup_opcode_name(code),
2132 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002133}
2134
2135static void
2136dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2137{
2138 u_int i;
2139
2140 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002141 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2142}
2143
2144static void
2145dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2146{
2147 u_int i;
2148
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002149 if (count <= 0)
2150 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002151 printf("%s", lookup_opcode_name(code));
2152 for (i = 0; i < count; i++)
2153 printf(" %s", vals[i]);
2154 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002155}
2156
2157void
2158dump_config(ServerOptions *o)
2159{
2160 u_int i;
2161 int ret;
2162 struct addrinfo *ai;
2163 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002164 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002165
2166 /* these are usually at the top of the config */
2167 for (i = 0; i < o->num_ports; i++)
2168 printf("port %d\n", o->ports[i]);
2169 dump_cfg_fmtint(sProtocol, o->protocol);
2170 dump_cfg_fmtint(sAddressFamily, o->address_family);
2171
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002172 /*
2173 * ListenAddress must be after Port. add_one_listen_addr pushes
2174 * addresses onto a stack, so to maintain ordering we need to
2175 * print these in reverse order.
2176 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002177 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2178 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2179 sizeof(addr), port, sizeof(port),
2180 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2181 error("getnameinfo failed: %.100s",
2182 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2183 strerror(errno));
2184 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002185 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002186 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002187 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2188 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002189 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002190 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2191 addr, port, laddr2);
2192 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002193 }
2194 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002195 printf("%s", laddr1);
2196 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002197
2198 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002199#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002200 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002201#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002202 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2203 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2204 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2205 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2206 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002207 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002208 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2209 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002210 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002211
2212 /* formatted integer arguments */
2213 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2214 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2215 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2216 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2217 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2218 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2219 o->hostbased_uses_name_from_packet_only);
2220 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2221 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002222#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002223 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2224 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2225 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002226# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002227 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002228# endif
2229#endif
2230#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002231 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2232 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002233#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002234 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2235 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2236 o->kbd_interactive_authentication);
2237 dump_cfg_fmtint(sChallengeResponseAuthentication,
2238 o->challenge_response_authentication);
2239 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2240 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2241 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2242 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002243 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002244 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002245 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2246 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2247 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2248 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2249 dump_cfg_fmtint(sUseLogin, o->use_login);
2250 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002251 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002252 dump_cfg_fmtint(sUseDNS, o->use_dns);
2253 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002254 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002255 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002256 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002257 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002258
2259 /* string arguments */
2260 dump_cfg_string(sPidFile, o->pid_file);
2261 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002262 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2263 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002264 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002265 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002266 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002267 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2268 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002269 dump_cfg_string(sAuthorizedPrincipalsFile,
2270 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002271 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2272 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002273 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2274 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002275 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2276 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002277 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002278 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002279 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002280 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2281 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
2282 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2283 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002284
2285 /* string arguments requiring a lookup */
2286 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2287 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2288
2289 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002290 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2291 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002292 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2293 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002294 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002295 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002296 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2297 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2298 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2299 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2300 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002301 dump_cfg_strarray_oneline(sAuthenticationMethods,
2302 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002303
2304 /* other arguments */
2305 for (i = 0; i < o->num_subsystems; i++)
2306 printf("subsystem %s %s\n", o->subsystem_name[i],
2307 o->subsystem_args[i]);
2308
2309 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2310 o->max_startups_rate, o->max_startups);
2311
2312 for (i = 0; tunmode_desc[i].val != -1; i++)
2313 if (tunmode_desc[i].val == o->permit_tun) {
2314 s = tunmode_desc[i].text;
2315 break;
2316 }
2317 dump_cfg_string(sPermitTunnel, s);
2318
Damien Miller91475862011-05-05 14:14:34 +10002319 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2320 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002321
Damien Millera6d6c1f2013-08-21 02:40:01 +10002322 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2323 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002324
Darren Tuckere7140f22008-06-10 23:01:51 +10002325 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002326}