blob: 97c268e3c7a99497a874ac07c14628b796875590 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
sf@openbsd.org168b46f2018-07-09 13:37:10 +00002/* $OpenBSD: servconf.c,v 1.337 2018/07/09 13:37:10 sf Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000018#ifdef HAVE_SYS_SYSCTL_H
19#include <sys/sysctl.h>
20#endif
Damien Millere3b60b52006-07-10 21:08:03 +100021
Damien Miller0dac6fb2010-11-20 15:19:38 +110022#include <netinet/in.h>
23#include <netinet/in_systm.h>
24#include <netinet/ip.h>
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000025#ifdef HAVE_NET_ROUTE_H
26#include <net/route.h>
27#endif
Damien Miller0dac6fb2010-11-20 15:19:38 +110028
Darren Tucker5f96f3b2013-05-16 20:29:28 +100029#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100030#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100031#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100032#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100033#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100034#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100035#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100036#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000037#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100038#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100039#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100040#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100041#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100042#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100043
Damien Millerb84886b2008-05-19 15:05:07 +100044#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100045#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100049#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100050#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100051#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000052#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000053#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100054#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000055#include "kex.h"
56#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100057#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100058#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100059#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100060#include "canohost.h"
61#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110062#include "hostfile.h"
63#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000064#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000065#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000066
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000067static void add_listen_addr(ServerOptions *, const char *,
68 const char *, int);
69static void add_one_listen_addr(ServerOptions *, const char *,
70 const char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110071
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000072/* Use of privilege separation or not */
73extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100074extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000075
Damien Millerd4a8b7e1999-10-27 13:42:43 +100076/* Initializes the server options to their default values. */
77
Damien Miller4af51302000-04-16 11:18:38 +100078void
Damien Miller95def091999-11-25 00:26:21 +110079initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080{
Damien Miller95def091999-11-25 00:26:21 +110081 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110082
83 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100084 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110085
86 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110087 options->num_ports = 0;
88 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000089 options->queued_listen_addrs = NULL;
90 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110091 options->listen_addrs = NULL;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000092 options->num_listen_addrs = 0;
Darren Tucker0f383232005-01-20 10:57:56 +110093 options->address_family = -1;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +000094 options->routing_domain = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110095 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110096 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100097 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100098 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110099 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000100 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->ignore_rhosts = -1;
102 options->ignore_user_known_hosts = -1;
103 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000104 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +1100105 options->x11_forwarding = -1;
106 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +1100107 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100108 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000109 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000110 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100112 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100113 options->log_facility = SYSLOG_FACILITY_NOT_SET;
114 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000115 options->hostbased_authentication = -1;
116 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000117 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000118 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100119 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000120 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->kerberos_authentication = -1;
122 options->kerberos_or_local_passwd = -1;
123 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100124 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000125 options->gss_authentication=-1;
126 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000127 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100128 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100129 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000130 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100131 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000132 options->permit_user_env = -1;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000133 options->permit_user_env_whitelist = NULL;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000134 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000135 options->rekey_limit = -1;
136 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100137 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000138 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000139 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100140 options->num_allow_users = 0;
141 options->num_deny_users = 0;
142 options->num_allow_groups = 0;
143 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000144 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000145 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000146 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000147 options->fwd_opts.gateway_ports = -1;
148 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
149 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000150 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000151 options->max_startups_begin = -1;
152 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000153 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000154 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000155 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000156 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000157 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000158 options->client_alive_interval = -1;
159 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000160 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000161 options->num_accept_env = 0;
djm@openbsd.org28013752018-06-09 03:03:10 +0000162 options->num_setenv = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100163 options->permit_tun = -1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000164 options->permitted_opens = NULL;
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000165 options->permitted_listens = NULL;
Damien Millere2754432006-07-24 14:06:47 +1000166 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100167 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100168 options->authorized_keys_command = NULL;
169 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100170 options->revoked_keys_file = NULL;
171 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000172 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000173 options->authorized_principals_command = NULL;
174 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100175 options->ip_qos_interactive = -1;
176 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000177 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000178 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000179 options->disable_forwarding = -1;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000180 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000181}
182
djm@openbsd.org161cf412014-12-22 07:55:51 +0000183/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
184static int
185option_clear_or_none(const char *o)
186{
187 return o == NULL || strcasecmp(o, "none") == 0;
188}
189
djm@openbsd.orged085102015-10-29 08:05:01 +0000190static void
191assemble_algorithms(ServerOptions *o)
192{
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000193 char *all_cipher, *all_mac, *all_kex, *all_key;
194
195 all_cipher = cipher_alg_list(',', 0);
196 all_mac = mac_alg_list(',');
197 all_kex = kex_alg_list(',');
198 all_key = sshkey_alg_list(0, 0, 1, ',');
199 if (kex_assemble_names(&o->ciphers,
200 KEX_SERVER_ENCRYPT, all_cipher) != 0 ||
201 kex_assemble_names(&o->macs,
202 KEX_SERVER_MAC, all_mac) != 0 ||
203 kex_assemble_names(&o->kex_algorithms,
204 KEX_SERVER_KEX, all_kex) != 0 ||
205 kex_assemble_names(&o->hostkeyalgorithms,
206 KEX_DEFAULT_PK_ALG, all_key) != 0 ||
207 kex_assemble_names(&o->hostbased_key_types,
208 KEX_DEFAULT_PK_ALG, all_key) != 0 ||
209 kex_assemble_names(&o->pubkey_key_types,
210 KEX_DEFAULT_PK_ALG, all_key) != 0)
djm@openbsd.orged085102015-10-29 08:05:01 +0000211 fatal("kex_assemble_names failed");
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000212 free(all_cipher);
213 free(all_mac);
214 free(all_kex);
215 free(all_key);
djm@openbsd.orged085102015-10-29 08:05:01 +0000216}
217
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000218static void
219array_append(const char *file, const int line, const char *directive,
220 char ***array, u_int *lp, const char *s)
221{
222
223 if (*lp >= INT_MAX)
224 fatal("%s line %d: Too many %s entries", file, line, directive);
225
226 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
227 (*array)[*lp] = xstrdup(s);
228 (*lp)++;
229}
230
231void
232servconf_add_hostkey(const char *file, const int line,
233 ServerOptions *options, const char *path)
234{
235 char *apath = derelativise_path(path);
236
237 array_append(file, line, "HostKey",
238 &options->host_key_files, &options->num_host_key_files, apath);
239 free(apath);
240}
241
242void
243servconf_add_hostcert(const char *file, const int line,
244 ServerOptions *options, const char *path)
245{
246 char *apath = derelativise_path(path);
247
248 array_append(file, line, "HostCertificate",
249 &options->host_cert_files, &options->num_host_cert_files, apath);
250 free(apath);
251}
252
Damien Miller4af51302000-04-16 11:18:38 +1000253void
Damien Miller95def091999-11-25 00:26:21 +1100254fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000255{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000256 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000257
Damien Miller726273e2001-11-12 11:40:11 +1100258 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000259 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000260 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100261
262 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100263 if (options->num_host_key_files == 0) {
264 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000265 servconf_add_hostkey("[default]", 0, options,
266 _PATH_HOST_RSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100267#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000268 servconf_add_hostkey("[default]", 0, options,
269 _PATH_HOST_ECDSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100270#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000271 servconf_add_hostkey("[default]", 0, options,
272 _PATH_HOST_ED25519_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000273#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000274 servconf_add_hostkey("[default]", 0, options,
275 _PATH_HOST_XMSS_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000276#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100277 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100278 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100279 if (options->num_ports == 0)
280 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000281 if (options->address_family == -1)
282 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100283 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000284 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000285 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000286 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100287 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000288 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000289 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000290 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100291 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100292 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100293 if (options->ignore_user_known_hosts == -1)
294 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100295 if (options->print_motd == -1)
296 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000297 if (options->print_lastlog == -1)
298 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100299 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100300 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100301 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100302 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100303 if (options->x11_use_localhost == -1)
304 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000305 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000306 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100307 if (options->permit_tty == -1)
308 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000309 if (options->permit_user_rc == -1)
310 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100311 if (options->strict_modes == -1)
312 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100313 if (options->tcp_keep_alive == -1)
314 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100315 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100316 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100317 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000318 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000319 if (options->hostbased_authentication == -1)
320 options->hostbased_authentication = 0;
321 if (options->hostbased_uses_name_from_packet_only == -1)
322 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100323 if (options->pubkey_authentication == -1)
324 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100325 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000326 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100327 if (options->kerberos_or_local_passwd == -1)
328 options->kerberos_or_local_passwd = 1;
329 if (options->kerberos_ticket_cleanup == -1)
330 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100331 if (options->kerberos_get_afs_token == -1)
332 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000333 if (options->gss_authentication == -1)
334 options->gss_authentication = 0;
335 if (options->gss_cleanup_creds == -1)
336 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000337 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000338 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100339 if (options->password_authentication == -1)
340 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100341 if (options->kbd_interactive_authentication == -1)
342 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000343 if (options->challenge_response_authentication == -1)
344 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100345 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100346 options->permit_empty_passwd = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000347 if (options->permit_user_env == -1) {
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000348 options->permit_user_env = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000349 options->permit_user_env_whitelist = NULL;
350 }
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000351 if (options->compression == -1)
sf@openbsd.org168b46f2018-07-09 13:37:10 +0000352 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000353 if (options->rekey_limit == -1)
354 options->rekey_limit = 0;
355 if (options->rekey_interval == -1)
356 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100357 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100358 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000359 if (options->allow_streamlocal_forwarding == -1)
360 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000361 if (options->allow_agent_forwarding == -1)
362 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000363 if (options->fwd_opts.gateway_ports == -1)
364 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000365 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100366 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000367 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100368 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000369 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100370 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000371 if (options->max_authtries == -1)
372 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000373 if (options->max_sessions == -1)
374 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000375 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000376 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000377 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100378 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000379 if (options->client_alive_count_max == -1)
380 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000381 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000382 array_append("[default]", 0, "AuthorizedKeysFiles",
383 &options->authorized_keys_files,
384 &options->num_authkeys_files,
385 _PATH_SSH_USER_PERMITTED_KEYS);
386 array_append("[default]", 0, "AuthorizedKeysFiles",
387 &options->authorized_keys_files,
388 &options->num_authkeys_files,
389 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000390 }
Damien Millerd27b9472005-12-13 19:29:02 +1100391 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100392 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100393 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000394 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100395 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000396 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000397 if (options->version_addendum == NULL)
398 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000399 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
400 options->fwd_opts.streamlocal_bind_mask = 0177;
401 if (options->fwd_opts.streamlocal_bind_unlink == -1)
402 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000403 if (options->fingerprint_hash == -1)
404 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000405 if (options->disable_forwarding == -1)
406 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000407 if (options->expose_userauth_info == -1)
408 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000409
djm@openbsd.orged085102015-10-29 08:05:01 +0000410 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000411
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000412 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000413 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000414 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000415
djm@openbsd.org161cf412014-12-22 07:55:51 +0000416#define CLEAR_ON_NONE(v) \
417 do { \
418 if (option_clear_or_none(v)) { \
419 free(v); \
420 v = NULL; \
421 } \
422 } while(0)
423 CLEAR_ON_NONE(options->pid_file);
424 CLEAR_ON_NONE(options->xauth_location);
425 CLEAR_ON_NONE(options->banner);
426 CLEAR_ON_NONE(options->trusted_user_ca_keys);
427 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000428 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000429 CLEAR_ON_NONE(options->adm_forced_command);
430 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000431 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000432 for (i = 0; i < options->num_host_key_files; i++)
433 CLEAR_ON_NONE(options->host_key_files[i]);
434 for (i = 0; i < options->num_host_cert_files; i++)
435 CLEAR_ON_NONE(options->host_cert_files[i]);
436#undef CLEAR_ON_NONE
437
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000438 /* Similar handling for AuthenticationMethods=any */
439 if (options->num_auth_methods == 1 &&
440 strcmp(options->auth_methods[0], "any") == 0) {
441 free(options->auth_methods[0]);
442 options->auth_methods[0] = NULL;
443 options->num_auth_methods = 0;
444 }
445
Tim Rice40017b02002-07-14 13:36:49 -0700446#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000447 if (use_privsep && options->compression == 1) {
448 error("This platform does not support both privilege "
449 "separation and compression");
450 error("Compression disabled");
451 options->compression = 0;
452 }
453#endif
454
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000455}
456
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000457/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100458typedef enum {
459 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100460 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000461 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100462 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000463 sPort, sHostKeyFile, sLoginGraceTime,
464 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000465 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100466 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000467 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100468 sPasswordAuthentication, sKbdInteractiveAuthentication,
469 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000470 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100471 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100472 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000473 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000474 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000475 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000476 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
477 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000478 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000479 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000480 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000481 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000482 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000483 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000484 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100485 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100486 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000487 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000488 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000489 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100490 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000491 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000492 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000493 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000494 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000495 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000496} ServerOpCodes;
497
Darren Tucker45150472006-07-12 22:34:17 +1000498#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
499#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
500#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
501
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000502/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100503static struct {
504 const char *name;
505 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000506 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100507} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100508 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000509#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000510 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000511#else
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000513#endif
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100515 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000516 { "port", sPort, SSHCFG_GLOBAL },
517 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
518 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000519 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000520 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000521 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000523 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100524 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000526 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000527 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000528 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100529 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000530 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000531 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000532 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000533 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100534 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000535 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000536 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000537#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100538 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000539 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
540 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100541#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000542 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000543#else
Darren Tucker45150472006-07-12 22:34:17 +1000544 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100545#endif
546#else
Darren Tucker1629c072007-02-19 22:25:37 +1100547 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000548 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
549 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
550 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000551#endif
Darren Tucker45150472006-07-12 22:34:17 +1000552 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
553 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000554#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100555 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000556 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000557 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000558#else
Darren Tucker1629c072007-02-19 22:25:37 +1100559 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000560 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000561 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000562#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100563 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
564 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100565 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000566 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
567 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
568 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
569 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
570 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100571#ifdef DISABLE_LASTLOG
572 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
573#else
Darren Tucker45150472006-07-12 22:34:17 +1000574 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100575#endif
Darren Tucker45150472006-07-12 22:34:17 +1000576 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
577 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000578 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
579 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
580 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000581 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
582 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100583 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000584 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000585 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000586 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000587 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000588 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
589 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
590 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000591 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000592 { "allowusers", sAllowUsers, SSHCFG_ALL },
593 { "denyusers", sDenyUsers, SSHCFG_ALL },
594 { "allowgroups", sAllowGroups, SSHCFG_ALL },
595 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000596 { "ciphers", sCiphers, SSHCFG_GLOBAL },
597 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000598 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000599 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
600 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
601 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000602 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000603 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100604 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000605 { "usedns", sUseDNS, SSHCFG_GLOBAL },
606 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
607 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000608 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
609 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000610 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000611 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000612 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000613 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000614 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000615 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100616 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000617 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000618 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000619 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000620 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000621 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100622 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100623 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100624 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
625 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000626 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000627 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100628 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100629 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
630 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000631 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
632 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000633 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100634 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000635 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
636 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
637 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000638 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000639 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000640 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000641 { "rdomain", sRDomain, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000642 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000643};
644
Darren Tuckere7140f22008-06-10 23:01:51 +1000645static struct {
646 int val;
647 char *text;
648} tunmode_desc[] = {
649 { SSH_TUNMODE_NO, "no" },
650 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
651 { SSH_TUNMODE_ETHERNET, "ethernet" },
652 { SSH_TUNMODE_YES, "yes" },
653 { -1, NULL }
654};
655
djm@openbsd.org115063a2018-06-06 18:22:41 +0000656/* Returns an opcode name from its number */
657
658static const char *
659lookup_opcode_name(ServerOpCodes code)
660{
661 u_int i;
662
663 for (i = 0; keywords[i].name != NULL; i++)
664 if (keywords[i].opcode == code)
665 return(keywords[i].name);
666 return "UNKNOWN";
667}
668
669
Damien Miller5428f641999-11-25 11:54:57 +1100670/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000671 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100672 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000673
Damien Miller4af51302000-04-16 11:18:38 +1000674static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100675parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000676 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000677{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000678 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000679
Damien Miller95def091999-11-25 00:26:21 +1100680 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000681 if (strcasecmp(cp, keywords[i].name) == 0) {
682 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100683 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000684 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000685
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000686 error("%s: line %d: Bad configuration option: %s",
687 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100688 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000689}
690
Darren Tucker88b6fb22010-01-13 22:44:29 +1100691char *
692derelativise_path(const char *path)
693{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000694 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100695
djm@openbsd.org161cf412014-12-22 07:55:51 +0000696 if (strcasecmp(path, "none") == 0)
697 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100698 expanded = tilde_expand_filename(path, getuid());
699 if (*expanded == '/')
700 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100701 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100702 fatal("%s: getcwd: %s", __func__, strerror(errno));
703 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000704 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100705 return ret;
706}
707
Ben Lindstrombba81212001-06-25 05:01:22 +0000708static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000709add_listen_addr(ServerOptions *options, const char *addr,
710 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100711{
Damien Millereccb9de2005-06-17 12:59:34 +1000712 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100713
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000714 if (port > 0)
715 add_one_listen_addr(options, addr, rdomain, port);
716 else {
717 for (i = 0; i < options->num_ports; i++) {
718 add_one_listen_addr(options, addr, rdomain,
719 options->ports[i]);
720 }
721 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000722}
723
Ben Lindstrombba81212001-06-25 05:01:22 +0000724static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000725add_one_listen_addr(ServerOptions *options, const char *addr,
726 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000727{
728 struct addrinfo hints, *ai, *aitop;
729 char strport[NI_MAXSERV];
730 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000731 u_int i;
732
733 /* Find listen_addrs entry for this rdomain */
734 for (i = 0; i < options->num_listen_addrs; i++) {
735 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
736 break;
737 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
738 continue;
739 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
740 break;
741 }
742 if (i >= options->num_listen_addrs) {
743 /* No entry for this rdomain; allocate one */
744 if (i >= INT_MAX)
745 fatal("%s: too many listen addresses", __func__);
746 options->listen_addrs = xrecallocarray(options->listen_addrs,
747 options->num_listen_addrs, options->num_listen_addrs + 1,
748 sizeof(*options->listen_addrs));
749 i = options->num_listen_addrs++;
750 if (rdomain != NULL)
751 options->listen_addrs[i].rdomain = xstrdup(rdomain);
752 }
753 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000754
755 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100756 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000757 hints.ai_socktype = SOCK_STREAM;
758 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100759 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000760 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
761 fatal("bad addr or host: %s (%s)",
762 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100763 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000764 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
765 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000766 ai->ai_next = options->listen_addrs[i].addrs;
767 options->listen_addrs[i].addrs = aitop;
768}
769
770/* Returns nonzero if the routing domain name is valid */
771static int
772valid_rdomain(const char *name)
773{
Damien Miller43c29bb2017-10-25 13:10:59 +1100774#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100775 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100776#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000777 const char *errstr;
778 long long num;
779 struct rt_tableinfo info;
780 int mib[6];
781 size_t miblen = sizeof(mib);
782
783 if (name == NULL)
784 return 1;
785
786 num = strtonum(name, 0, 255, &errstr);
787 if (errstr != NULL)
788 return 0;
789
790 /* Check whether the table actually exists */
791 memset(mib, 0, sizeof(mib));
792 mib[0] = CTL_NET;
793 mib[1] = PF_ROUTE;
794 mib[4] = NET_RT_TABLE;
795 mib[5] = (int)num;
796 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
797 return 0;
798
799 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100800#else /* defined(__OpenBSD__) */
801 error("Routing domains are not supported on this platform");
802 return 0;
803#endif
Damien Miller34132e52000-01-14 15:45:46 +1100804}
805
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000806/*
807 * Queue a ListenAddress to be processed once we have all of the Ports
808 * and AddressFamily options.
809 */
810static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000811queue_listen_addr(ServerOptions *options, const char *addr,
812 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000813{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000814 struct queued_listenaddr *qla;
815
816 options->queued_listen_addrs = xrecallocarray(
817 options->queued_listen_addrs,
818 options->num_queued_listens, options->num_queued_listens + 1,
819 sizeof(*options->queued_listen_addrs));
820 qla = &options->queued_listen_addrs[options->num_queued_listens++];
821 qla->addr = xstrdup(addr);
822 qla->port = port;
823 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000824}
825
826/*
827 * Process queued (text) ListenAddress entries.
828 */
829static void
830process_queued_listen_addrs(ServerOptions *options)
831{
832 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000833 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000834
835 if (options->num_ports == 0)
836 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
837 if (options->address_family == -1)
838 options->address_family = AF_UNSPEC;
839
840 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000841 qla = &options->queued_listen_addrs[i];
842 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
843 free(qla->addr);
844 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000845 }
846 free(options->queued_listen_addrs);
847 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000848 options->num_queued_listens = 0;
849}
850
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000851/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000852 * Inform channels layer of permitopen options for a single forwarding
853 * direction (local/remote).
854 */
855static void
856process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
857 char **opens, u_int num_opens)
858{
859 u_int i;
860 int port;
861 char *host, *arg, *oarg;
862 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
863 const char *what = lookup_opcode_name(opcode);
864
865 channel_clear_permission(ssh, FORWARD_ADM, where);
866 if (num_opens == 0)
867 return; /* permit any */
868
869 /* handle keywords: "any" / "none" */
870 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
871 return;
872 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
873 channel_disable_admin(ssh, where);
874 return;
875 }
876 /* Otherwise treat it as a list of permitted host:port */
877 for (i = 0; i < num_opens; i++) {
878 oarg = arg = xstrdup(opens[i]);
879 host = hpdelim(&arg);
880 if (host == NULL)
881 fatal("%s: missing host in %s", __func__, what);
882 host = cleanhostname(host);
883 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
884 fatal("%s: bad port number in %s", __func__, what);
885 /* Send it to channels layer */
886 channel_add_permission(ssh, FORWARD_ADM,
887 where, host, port);
888 free(oarg);
889 }
890}
891
892/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000893 * Inform channels layer of permitopen options from configuration.
894 */
895void
896process_permitopen(struct ssh *ssh, ServerOptions *options)
897{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000898 process_permitopen_list(ssh, sPermitOpen,
899 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000900 process_permitopen_list(ssh, sPermitListen,
901 options->permitted_listens,
902 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000903}
904
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000905struct connection_info *
906get_connection_info(int populate, int use_dns)
907{
djm@openbsd.org95767262016-03-07 19:02:43 +0000908 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000909 static struct connection_info ci;
910
911 if (!populate)
912 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000913 ci.host = auth_get_canonical_hostname(ssh, use_dns);
914 ci.address = ssh_remote_ipaddr(ssh);
915 ci.laddress = ssh_local_ipaddr(ssh);
916 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000917 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000918 return &ci;
919}
920
Darren Tucker45150472006-07-12 22:34:17 +1000921/*
922 * The strategy for the Match blocks is that the config file is parsed twice.
923 *
924 * The first time is at startup. activep is initialized to 1 and the
925 * directives in the global context are processed and acted on. Hitting a
926 * Match directive unsets activep and the directives inside the block are
927 * checked for syntax only.
928 *
929 * The second time is after a connection has been established but before
930 * authentication. activep is initialized to 2 and global config directives
931 * are ignored since they have already been processed. If the criteria in a
932 * Match block is met, activep is set and the subsequent directives
933 * processed and actioned until EOF or another Match block unsets it. Any
934 * options set are copied into the main server config.
935 *
936 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000937 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000938 *
939 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
940 * Match Address 192.168.0.*
941 * Tag trusted
942 * Match Group wheel
943 * Tag trusted
944 * Match Tag trusted
945 * AllowTcpForwarding yes
946 * GatewayPorts clientspecified
947 * [...]
948 *
949 * - Add a PermittedChannelRequests directive
950 * Match Group shell
951 * PermittedChannelRequests session,forwarded-tcpip
952 */
953
954static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000955match_cfg_line_group(const char *grps, int line, const char *user)
956{
957 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000958 struct passwd *pw;
959
Damien Miller565ca3f2006-08-19 00:23:15 +1000960 if (user == NULL)
961 goto out;
962
963 if ((pw = getpwnam(user)) == NULL) {
964 debug("Can't match group at line %d because user %.100s does "
965 "not exist", line, user);
966 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
967 debug("Can't Match group because user %.100s not in any group "
968 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000969 } else if (ga_match_pattern_list(grps) != 1) {
970 debug("user %.100s does not match group list %.100s at line %d",
971 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000972 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000973 debug("user %.100s matched group list %.100s at line %d", user,
974 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000975 result = 1;
976 }
977out:
978 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000979 return result;
980}
981
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +0000982static void
983match_test_missing_fatal(const char *criteria, const char *attrib)
984{
985 fatal("'Match %s' in configuration but '%s' not in connection "
986 "test specification.", criteria, attrib);
987}
988
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000989/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000990 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100991 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000992 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000993 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000994static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000995match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000996{
Damien Millercf31f382013-10-24 21:02:56 +1100997 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000998 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000999
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001000 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001001 debug3("checking syntax for 'Match %s'", cp);
1002 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001003 debug3("checking match for '%s' user %s host %s addr %s "
1004 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
1005 ci->host ? ci->host : "(null)",
1006 ci->address ? ci->address : "(null)",
1007 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +10001008
1009 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +11001010 attributes++;
1011 if (strcasecmp(attrib, "all") == 0) {
1012 if (attributes != 1 ||
1013 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1014 error("'all' cannot be combined with other "
1015 "Match attributes");
1016 return -1;
1017 }
1018 *condition = cp;
1019 return 1;
1020 }
Darren Tucker45150472006-07-12 22:34:17 +10001021 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1022 error("Missing Match criteria for %s", attrib);
1023 return -1;
1024 }
Darren Tucker45150472006-07-12 22:34:17 +10001025 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001026 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001027 result = 0;
1028 continue;
1029 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001030 if (ci->user == NULL)
1031 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001032 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001033 result = 0;
1034 else
1035 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001036 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001037 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001038 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001039 result = 0;
1040 continue;
1041 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001042 if (ci->user == NULL)
1043 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001044 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001045 case -1:
1046 return -1;
1047 case 0:
1048 result = 0;
1049 }
Darren Tucker45150472006-07-12 22:34:17 +10001050 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001051 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001052 result = 0;
1053 continue;
1054 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001055 if (ci->host == NULL)
1056 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001057 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001058 result = 0;
1059 else
1060 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001061 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001062 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001063 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001064 result = 0;
1065 continue;
1066 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001067 if (ci->address == NULL)
1068 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001069 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001070 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001071 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001072 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001073 break;
1074 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001075 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001076 result = 0;
1077 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001078 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001079 return -1;
1080 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001081 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001082 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001083 result = 0;
1084 continue;
1085 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001086 if (ci->laddress == NULL)
1087 match_test_missing_fatal("LocalAddress",
1088 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001089 switch (addr_match_list(ci->laddress, arg)) {
1090 case 1:
1091 debug("connection from %.100s matched "
1092 "'LocalAddress %.100s' at line %d",
1093 ci->laddress, arg, line);
1094 break;
1095 case 0:
1096 case -1:
1097 result = 0;
1098 break;
1099 case -2:
1100 return -1;
1101 }
1102 } else if (strcasecmp(attrib, "localport") == 0) {
1103 if ((port = a2port(arg)) == -1) {
1104 error("Invalid LocalPort '%s' on Match line",
1105 arg);
1106 return -1;
1107 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001108 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001109 result = 0;
1110 continue;
1111 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001112 if (ci->lport == 0)
1113 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001114 /* TODO support port lists */
1115 if (port == ci->lport)
1116 debug("connection from %.100s matched "
1117 "'LocalPort %d' at line %d",
1118 ci->laddress, port, line);
1119 else
1120 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001121 } else if (strcasecmp(attrib, "rdomain") == 0) {
1122 if (ci == NULL || ci->rdomain == NULL) {
1123 result = 0;
1124 continue;
1125 }
1126 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1127 result = 0;
1128 else
1129 debug("user %.100s matched 'RDomain %.100s' at "
1130 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001131 } else {
1132 error("Unsupported Match attribute %s", attrib);
1133 return -1;
1134 }
1135 }
Damien Millercf31f382013-10-24 21:02:56 +11001136 if (attributes == 0) {
1137 error("One or more attributes required for Match");
1138 return -1;
1139 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001140 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001141 debug3("match %sfound", result ? "" : "not ");
1142 *condition = cp;
1143 return result;
1144}
1145
Damien Millere2754432006-07-24 14:06:47 +10001146#define WHITESPACE " \t\r\n"
1147
Damien Miller33322122011-06-20 14:43:11 +10001148/* Multistate option parsing */
1149struct multistate {
1150 char *key;
1151 int value;
1152};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001153static const struct multistate multistate_flag[] = {
1154 { "yes", 1 },
1155 { "no", 0 },
1156 { NULL, -1 }
1157};
Damien Miller33322122011-06-20 14:43:11 +10001158static const struct multistate multistate_addressfamily[] = {
1159 { "inet", AF_INET },
1160 { "inet6", AF_INET6 },
1161 { "any", AF_UNSPEC },
1162 { NULL, -1 }
1163};
1164static const struct multistate multistate_permitrootlogin[] = {
1165 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001166 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001167 { "forced-commands-only", PERMIT_FORCED_ONLY },
1168 { "yes", PERMIT_YES },
1169 { "no", PERMIT_NO },
1170 { NULL, -1 }
1171};
1172static const struct multistate multistate_compression[] = {
sf@openbsd.org168b46f2018-07-09 13:37:10 +00001173 { "yes", COMP_DELAYED },
1174 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001175 { "no", COMP_NONE },
1176 { NULL, -1 }
1177};
1178static const struct multistate multistate_gatewayports[] = {
1179 { "clientspecified", 2 },
1180 { "yes", 1 },
1181 { "no", 0 },
1182 { NULL, -1 }
1183};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001184static const struct multistate multistate_tcpfwd[] = {
1185 { "yes", FORWARD_ALLOW },
1186 { "all", FORWARD_ALLOW },
1187 { "no", FORWARD_DENY },
1188 { "remote", FORWARD_REMOTE },
1189 { "local", FORWARD_LOCAL },
1190 { NULL, -1 }
1191};
Damien Miller33322122011-06-20 14:43:11 +10001192
Ben Lindstromade03f62001-12-06 18:22:17 +00001193int
1194process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001195 const char *filename, int linenum, int *activep,
1196 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001197{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001198 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001199 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001200 SyslogFacility *log_facility_ptr;
1201 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001202 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001203 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001204 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001205 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001206 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001207 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001208
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001209 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1210 if ((len = strlen(line)) == 0)
1211 return 0;
1212 for (len--; len > 0; len--) {
1213 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1214 break;
1215 line[len] = '\0';
1216 }
1217
Ben Lindstromade03f62001-12-06 18:22:17 +00001218 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001219 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001220 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001221 /* Ignore leading whitespace */
1222 if (*arg == '\0')
1223 arg = strdelim(&cp);
1224 if (!arg || !*arg || *arg == '#')
1225 return 0;
1226 intptr = NULL;
1227 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001228 opcode = parse_token(arg, filename, linenum, &flags);
1229
1230 if (activep == NULL) { /* We are processing a command line directive */
1231 cmdline = 1;
1232 activep = &cmdline;
1233 }
1234 if (*activep && opcode != sMatch)
1235 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1236 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001237 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001238 fatal("%s line %d: Directive '%s' is not allowed "
1239 "within a Match block", filename, linenum, arg);
1240 } else { /* this is a directive we have already processed */
1241 while (arg)
1242 arg = strdelim(&cp);
1243 return 0;
1244 }
1245 }
1246
Ben Lindstromade03f62001-12-06 18:22:17 +00001247 switch (opcode) {
1248 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001249 case sUsePAM:
1250 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001251 goto parse_flag;
1252
1253 /* Standard Options */
1254 case sBadOption:
1255 return -1;
1256 case sPort:
1257 /* ignore ports from configfile if cmdline specifies ports */
1258 if (options->ports_from_cmdline)
1259 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001260 if (options->num_ports >= MAX_PORTS)
1261 fatal("%s line %d: too many ports.",
1262 filename, linenum);
1263 arg = strdelim(&cp);
1264 if (!arg || *arg == '\0')
1265 fatal("%s line %d: missing port number.",
1266 filename, linenum);
1267 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001268 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001269 fatal("%s line %d: Badly formatted port number.",
1270 filename, linenum);
1271 break;
1272
Ben Lindstromade03f62001-12-06 18:22:17 +00001273 case sLoginGraceTime:
1274 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001275 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001276 arg = strdelim(&cp);
1277 if (!arg || *arg == '\0')
1278 fatal("%s line %d: missing time value.",
1279 filename, linenum);
1280 if ((value = convtime(arg)) == -1)
1281 fatal("%s line %d: invalid time value.",
1282 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001283 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001284 *intptr = value;
1285 break;
1286
Ben Lindstromade03f62001-12-06 18:22:17 +00001287 case sListenAddress:
1288 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001289 if (arg == NULL || *arg == '\0')
1290 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001291 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001292 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1293 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1294 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001295 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001296 p = arg;
1297 } else {
1298 p = hpdelim(&arg);
1299 if (p == NULL)
1300 fatal("%s line %d: bad address:port usage",
1301 filename, linenum);
1302 p = cleanhostname(p);
1303 if (arg == NULL)
1304 port = 0;
1305 else if ((port = a2port(arg)) <= 0)
1306 fatal("%s line %d: bad port number",
1307 filename, linenum);
1308 }
1309 /* Optional routing table */
1310 arg2 = NULL;
1311 if ((arg = strdelim(&cp)) != NULL) {
1312 if (strcmp(arg, "rdomain") != 0 ||
1313 (arg2 = strdelim(&cp)) == NULL)
1314 fatal("%s line %d: bad ListenAddress syntax",
1315 filename, linenum);
1316 if (!valid_rdomain(arg2))
1317 fatal("%s line %d: bad routing domain",
1318 filename, linenum);
1319 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001320
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001321 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001322
Ben Lindstromade03f62001-12-06 18:22:17 +00001323 break;
1324
Darren Tucker0f383232005-01-20 10:57:56 +11001325 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001326 intptr = &options->address_family;
1327 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001328 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001329 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001330 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001331 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001332 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001333 value = -1;
1334 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1335 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1336 value = multistate_ptr[i].value;
1337 break;
1338 }
1339 }
1340 if (value == -1)
1341 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001342 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001343 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001344 *intptr = value;
1345 break;
1346
Ben Lindstromade03f62001-12-06 18:22:17 +00001347 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001348 arg = strdelim(&cp);
1349 if (!arg || *arg == '\0')
1350 fatal("%s line %d: missing file name.",
1351 filename, linenum);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001352 if (*activep)
1353 servconf_add_hostkey(filename, linenum, options, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001354 break;
1355
Damien Miller85b45e02013-07-20 13:21:52 +10001356 case sHostKeyAgent:
1357 charptr = &options->host_key_agent;
1358 arg = strdelim(&cp);
1359 if (!arg || *arg == '\0')
1360 fatal("%s line %d: missing socket name.",
1361 filename, linenum);
1362 if (*activep && *charptr == NULL)
1363 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1364 xstrdup(arg) : derelativise_path(arg);
1365 break;
1366
Damien Miller0a80ca12010-02-27 07:55:05 +11001367 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001368 arg = strdelim(&cp);
1369 if (!arg || *arg == '\0')
1370 fatal("%s line %d: missing file name.",
1371 filename, linenum);
1372 if (*activep)
1373 servconf_add_hostcert(filename, linenum, options, arg);
1374 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001375
Ben Lindstromade03f62001-12-06 18:22:17 +00001376 case sPidFile:
1377 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001378 parse_filename:
1379 arg = strdelim(&cp);
1380 if (!arg || *arg == '\0')
1381 fatal("%s line %d: missing file name.",
1382 filename, linenum);
1383 if (*activep && *charptr == NULL) {
1384 *charptr = derelativise_path(arg);
1385 /* increase optional counter */
1386 if (intptr != NULL)
1387 *intptr = *intptr + 1;
1388 }
1389 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001390
1391 case sPermitRootLogin:
1392 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001393 multistate_ptr = multistate_permitrootlogin;
1394 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001395
1396 case sIgnoreRhosts:
1397 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001398 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001399 multistate_ptr = multistate_flag;
1400 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001401
1402 case sIgnoreUserKnownHosts:
1403 intptr = &options->ignore_user_known_hosts;
1404 goto parse_flag;
1405
Ben Lindstromade03f62001-12-06 18:22:17 +00001406 case sHostbasedAuthentication:
1407 intptr = &options->hostbased_authentication;
1408 goto parse_flag;
1409
1410 case sHostbasedUsesNameFromPacketOnly:
1411 intptr = &options->hostbased_uses_name_from_packet_only;
1412 goto parse_flag;
1413
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001414 case sHostbasedAcceptedKeyTypes:
1415 charptr = &options->hostbased_key_types;
1416 parse_keytypes:
1417 arg = strdelim(&cp);
1418 if (!arg || *arg == '\0')
1419 fatal("%s line %d: Missing argument.",
1420 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001421 if (*arg != '-' &&
1422 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001423 fatal("%s line %d: Bad key types '%s'.",
1424 filename, linenum, arg ? arg : "<NONE>");
1425 if (*activep && *charptr == NULL)
1426 *charptr = xstrdup(arg);
1427 break;
1428
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001429 case sHostKeyAlgorithms:
1430 charptr = &options->hostkeyalgorithms;
1431 goto parse_keytypes;
1432
Ben Lindstromade03f62001-12-06 18:22:17 +00001433 case sPubkeyAuthentication:
1434 intptr = &options->pubkey_authentication;
1435 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001436
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001437 case sPubkeyAcceptedKeyTypes:
1438 charptr = &options->pubkey_key_types;
1439 goto parse_keytypes;
1440
Ben Lindstromade03f62001-12-06 18:22:17 +00001441 case sKerberosAuthentication:
1442 intptr = &options->kerberos_authentication;
1443 goto parse_flag;
1444
1445 case sKerberosOrLocalPasswd:
1446 intptr = &options->kerberos_or_local_passwd;
1447 goto parse_flag;
1448
1449 case sKerberosTicketCleanup:
1450 intptr = &options->kerberos_ticket_cleanup;
1451 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001452
Darren Tucker22ef5082003-12-31 11:37:34 +11001453 case sKerberosGetAFSToken:
1454 intptr = &options->kerberos_get_afs_token;
1455 goto parse_flag;
1456
Darren Tucker0efd1552003-08-26 11:49:55 +10001457 case sGssAuthentication:
1458 intptr = &options->gss_authentication;
1459 goto parse_flag;
1460
1461 case sGssCleanupCreds:
1462 intptr = &options->gss_cleanup_creds;
1463 goto parse_flag;
1464
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001465 case sGssStrictAcceptor:
1466 intptr = &options->gss_strict_acceptor;
1467 goto parse_flag;
1468
Ben Lindstromade03f62001-12-06 18:22:17 +00001469 case sPasswordAuthentication:
1470 intptr = &options->password_authentication;
1471 goto parse_flag;
1472
1473 case sKbdInteractiveAuthentication:
1474 intptr = &options->kbd_interactive_authentication;
1475 goto parse_flag;
1476
1477 case sChallengeResponseAuthentication:
1478 intptr = &options->challenge_response_authentication;
1479 goto parse_flag;
1480
1481 case sPrintMotd:
1482 intptr = &options->print_motd;
1483 goto parse_flag;
1484
1485 case sPrintLastLog:
1486 intptr = &options->print_lastlog;
1487 goto parse_flag;
1488
1489 case sX11Forwarding:
1490 intptr = &options->x11_forwarding;
1491 goto parse_flag;
1492
1493 case sX11DisplayOffset:
1494 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001495 parse_int:
1496 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001497 if ((errstr = atoi_err(arg, &value)) != NULL)
1498 fatal("%s line %d: integer value %s.",
1499 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001500 if (*activep && *intptr == -1)
1501 *intptr = value;
1502 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001503
Damien Miller95c249f2002-02-05 12:11:34 +11001504 case sX11UseLocalhost:
1505 intptr = &options->x11_use_localhost;
1506 goto parse_flag;
1507
Ben Lindstromade03f62001-12-06 18:22:17 +00001508 case sXAuthLocation:
1509 charptr = &options->xauth_location;
1510 goto parse_filename;
1511
Damien Miller5ff30c62013-10-30 22:21:50 +11001512 case sPermitTTY:
1513 intptr = &options->permit_tty;
1514 goto parse_flag;
1515
Damien Miller72e6b5c2014-07-04 09:00:04 +10001516 case sPermitUserRC:
1517 intptr = &options->permit_user_rc;
1518 goto parse_flag;
1519
Ben Lindstromade03f62001-12-06 18:22:17 +00001520 case sStrictModes:
1521 intptr = &options->strict_modes;
1522 goto parse_flag;
1523
Damien Miller12c150e2003-12-17 16:31:10 +11001524 case sTCPKeepAlive:
1525 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001526 goto parse_flag;
1527
1528 case sEmptyPasswd:
1529 intptr = &options->permit_empty_passwd;
1530 goto parse_flag;
1531
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001532 case sPermitUserEnvironment:
1533 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001534 charptr = &options->permit_user_env_whitelist;
1535 arg = strdelim(&cp);
1536 if (!arg || *arg == '\0')
1537 fatal("%s line %d: missing argument.",
1538 filename, linenum);
1539 value = 0;
1540 p = NULL;
1541 if (strcmp(arg, "yes") == 0)
1542 value = 1;
1543 else if (strcmp(arg, "no") == 0)
1544 value = 0;
1545 else {
1546 /* Pattern-list specified */
1547 value = 1;
1548 p = xstrdup(arg);
1549 }
1550 if (*activep && *intptr == -1) {
1551 *intptr = value;
1552 *charptr = p;
1553 p = NULL;
1554 }
1555 free(p);
1556 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001557
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001558 case sCompression:
1559 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001560 multistate_ptr = multistate_compression;
1561 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001562
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001563 case sRekeyLimit:
1564 arg = strdelim(&cp);
1565 if (!arg || *arg == '\0')
1566 fatal("%.200s line %d: Missing argument.", filename,
1567 linenum);
1568 if (strcmp(arg, "default") == 0) {
1569 val64 = 0;
1570 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001571 if (scan_scaled(arg, &val64) == -1)
1572 fatal("%.200s line %d: Bad number '%s': %s",
1573 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001574 if (val64 != 0 && val64 < 16)
1575 fatal("%.200s line %d: RekeyLimit too small",
1576 filename, linenum);
1577 }
1578 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001579 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001580 if (cp != NULL) { /* optional rekey interval present */
1581 if (strcmp(cp, "none") == 0) {
1582 (void)strdelim(&cp); /* discard */
1583 break;
1584 }
1585 intptr = &options->rekey_interval;
1586 goto parse_time;
1587 }
1588 break;
1589
Ben Lindstromade03f62001-12-06 18:22:17 +00001590 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001591 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001592 multistate_ptr = multistate_gatewayports;
1593 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001594
Damien Miller3a961dc2003-06-03 10:25:48 +10001595 case sUseDNS:
1596 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001597 goto parse_flag;
1598
1599 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001600 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001601 arg = strdelim(&cp);
1602 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001603 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001604 fatal("%.200s line %d: unsupported log facility '%s'",
1605 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001606 if (*log_facility_ptr == -1)
1607 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001608 break;
1609
1610 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001611 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001612 arg = strdelim(&cp);
1613 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001614 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001615 fatal("%.200s line %d: unsupported log level '%s'",
1616 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001617 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001618 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001619 break;
1620
1621 case sAllowTcpForwarding:
1622 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001623 multistate_ptr = multistate_tcpfwd;
1624 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001625
Damien Miller7acefbb2014-07-18 14:11:24 +10001626 case sAllowStreamLocalForwarding:
1627 intptr = &options->allow_streamlocal_forwarding;
1628 multistate_ptr = multistate_tcpfwd;
1629 goto parse_multistate;
1630
Damien Miller4f755cd2008-05-19 14:57:41 +10001631 case sAllowAgentForwarding:
1632 intptr = &options->allow_agent_forwarding;
1633 goto parse_flag;
1634
djm@openbsd.org7844f352016-11-30 03:00:05 +00001635 case sDisableForwarding:
1636 intptr = &options->disable_forwarding;
1637 goto parse_flag;
1638
Ben Lindstromade03f62001-12-06 18:22:17 +00001639 case sAllowUsers:
1640 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001641 if (match_user(NULL, NULL, NULL, arg) == -1)
1642 fatal("%s line %d: invalid AllowUsers pattern: "
1643 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001644 if (!*activep)
1645 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001646 array_append(filename, linenum, "AllowUsers",
1647 &options->allow_users, &options->num_allow_users,
1648 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001649 }
1650 break;
1651
1652 case sDenyUsers:
1653 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001654 if (match_user(NULL, NULL, NULL, arg) == -1)
1655 fatal("%s line %d: invalid DenyUsers pattern: "
1656 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001657 if (!*activep)
1658 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001659 array_append(filename, linenum, "DenyUsers",
1660 &options->deny_users, &options->num_deny_users,
1661 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001662 }
1663 break;
1664
1665 case sAllowGroups:
1666 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001667 if (!*activep)
1668 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001669 array_append(filename, linenum, "AllowGroups",
1670 &options->allow_groups, &options->num_allow_groups,
1671 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001672 }
1673 break;
1674
1675 case sDenyGroups:
1676 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001677 if (!*activep)
1678 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001679 array_append(filename, linenum, "DenyGroups",
1680 &options->deny_groups, &options->num_deny_groups,
1681 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001682 }
1683 break;
1684
1685 case sCiphers:
1686 arg = strdelim(&cp);
1687 if (!arg || *arg == '\0')
1688 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001689 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001690 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1691 filename, linenum, arg ? arg : "<NONE>");
1692 if (options->ciphers == NULL)
1693 options->ciphers = xstrdup(arg);
1694 break;
1695
1696 case sMacs:
1697 arg = strdelim(&cp);
1698 if (!arg || *arg == '\0')
1699 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001700 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001701 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1702 filename, linenum, arg ? arg : "<NONE>");
1703 if (options->macs == NULL)
1704 options->macs = xstrdup(arg);
1705 break;
1706
Damien Millerd5f62bf2010-09-24 22:11:14 +10001707 case sKexAlgorithms:
1708 arg = strdelim(&cp);
1709 if (!arg || *arg == '\0')
1710 fatal("%s line %d: Missing argument.",
1711 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001712 if (*arg != '-' &&
1713 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001714 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1715 filename, linenum, arg ? arg : "<NONE>");
1716 if (options->kex_algorithms == NULL)
1717 options->kex_algorithms = xstrdup(arg);
1718 break;
1719
Ben Lindstromade03f62001-12-06 18:22:17 +00001720 case sSubsystem:
1721 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1722 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001723 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001724 }
1725 arg = strdelim(&cp);
1726 if (!arg || *arg == '\0')
1727 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001728 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001729 if (!*activep) {
1730 arg = strdelim(&cp);
1731 break;
1732 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001733 for (i = 0; i < options->num_subsystems; i++)
1734 if (strcmp(arg, options->subsystem_name[i]) == 0)
1735 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001736 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001737 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1738 arg = strdelim(&cp);
1739 if (!arg || *arg == '\0')
1740 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001741 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001742 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001743
1744 /* Collect arguments (separate to executable) */
1745 p = xstrdup(arg);
1746 len = strlen(p) + 1;
1747 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1748 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001749 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001750 strlcat(p, " ", len);
1751 strlcat(p, arg, len);
1752 }
1753 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001754 options->num_subsystems++;
1755 break;
1756
1757 case sMaxStartups:
1758 arg = strdelim(&cp);
1759 if (!arg || *arg == '\0')
1760 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001761 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001762 if ((n = sscanf(arg, "%d:%d:%d",
1763 &options->max_startups_begin,
1764 &options->max_startups_rate,
1765 &options->max_startups)) == 3) {
1766 if (options->max_startups_begin >
1767 options->max_startups ||
1768 options->max_startups_rate > 100 ||
1769 options->max_startups_rate < 1)
1770 fatal("%s line %d: Illegal MaxStartups spec.",
1771 filename, linenum);
1772 } else if (n != 1)
1773 fatal("%s line %d: Illegal MaxStartups spec.",
1774 filename, linenum);
1775 else
1776 options->max_startups = options->max_startups_begin;
1777 break;
1778
Darren Tucker89413db2004-05-24 10:36:23 +10001779 case sMaxAuthTries:
1780 intptr = &options->max_authtries;
1781 goto parse_int;
1782
Damien Miller7207f642008-05-19 15:34:50 +10001783 case sMaxSessions:
1784 intptr = &options->max_sessions;
1785 goto parse_int;
1786
Ben Lindstromade03f62001-12-06 18:22:17 +00001787 case sBanner:
1788 charptr = &options->banner;
1789 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001790
Ben Lindstromade03f62001-12-06 18:22:17 +00001791 /*
1792 * These options can contain %X options expanded at
1793 * connect time, so that you can specify paths like:
1794 *
1795 * AuthorizedKeysFile /etc/ssh_keys/%u
1796 */
1797 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001798 if (*activep && options->num_authkeys_files == 0) {
1799 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001800 arg = tilde_expand_filename(arg, getuid());
1801 array_append(filename, linenum,
1802 "AuthorizedKeysFile",
1803 &options->authorized_keys_files,
1804 &options->num_authkeys_files, arg);
1805 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001806 }
1807 }
1808 return 0;
1809
Damien Miller30da3442010-05-10 11:58:03 +10001810 case sAuthorizedPrincipalsFile:
1811 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001812 arg = strdelim(&cp);
1813 if (!arg || *arg == '\0')
1814 fatal("%s line %d: missing file name.",
1815 filename, linenum);
1816 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001817 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001818 /* increase optional counter */
1819 if (intptr != NULL)
1820 *intptr = *intptr + 1;
1821 }
1822 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001823
1824 case sClientAliveInterval:
1825 intptr = &options->client_alive_interval;
1826 goto parse_time;
1827
1828 case sClientAliveCountMax:
1829 intptr = &options->client_alive_count_max;
1830 goto parse_int;
1831
Darren Tucker46bc0752004-05-02 22:11:30 +10001832 case sAcceptEnv:
1833 while ((arg = strdelim(&cp)) && *arg != '\0') {
1834 if (strchr(arg, '=') != NULL)
1835 fatal("%s line %d: Invalid environment name.",
1836 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001837 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001838 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001839 array_append(filename, linenum, "AcceptEnv",
1840 &options->accept_env, &options->num_accept_env,
1841 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001842 }
1843 break;
1844
djm@openbsd.org28013752018-06-09 03:03:10 +00001845 case sSetEnv:
1846 uvalue = options->num_setenv;
1847 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1848 if (strchr(arg, '=') == NULL)
1849 fatal("%s line %d: Invalid environment.",
1850 filename, linenum);
1851 if (!*activep || uvalue != 0)
1852 continue;
1853 array_append(filename, linenum, "SetEnv",
1854 &options->setenv, &options->num_setenv, arg);
1855 }
1856 break;
1857
Damien Millerd27b9472005-12-13 19:29:02 +11001858 case sPermitTunnel:
1859 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001860 arg = strdelim(&cp);
1861 if (!arg || *arg == '\0')
1862 fatal("%s line %d: Missing yes/point-to-point/"
1863 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001864 value = -1;
1865 for (i = 0; tunmode_desc[i].val != -1; i++)
1866 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1867 value = tunmode_desc[i].val;
1868 break;
1869 }
1870 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001871 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1872 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001873 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001874 *intptr = value;
1875 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001876
Darren Tucker45150472006-07-12 22:34:17 +10001877 case sMatch:
1878 if (cmdline)
1879 fatal("Match directive not supported as a command-line "
1880 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001881 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001882 if (value < 0)
1883 fatal("%s line %d: Bad Match condition", filename,
1884 linenum);
1885 *activep = value;
1886 break;
1887
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001888 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001889 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001890 if (opcode == sPermitListen) {
1891 uintptr = &options->num_permitted_listens;
1892 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001893 } else {
1894 uintptr = &options->num_permitted_opens;
1895 chararrayptr = &options->permitted_opens;
1896 }
Damien Miller9b439df2006-07-24 14:04:00 +10001897 arg = strdelim(&cp);
1898 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001899 fatal("%s line %d: missing %s specification",
1900 filename, linenum, lookup_opcode_name(opcode));
1901 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001902 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001903 if (*activep && uvalue == 0) {
1904 *uintptr = 1;
1905 *chararrayptr = xcalloc(1,
1906 sizeof(**chararrayptr));
1907 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001908 }
Damien Millerc6081482012-04-22 11:18:53 +10001909 break;
1910 }
Damien Millera765cf42006-07-24 14:08:13 +10001911 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001912 if (opcode == sPermitListen &&
1913 strchr(arg, ':') == NULL) {
1914 /*
1915 * Allow bare port number for PermitListen
1916 * to indicate a wildcard listen host.
1917 */
1918 xasprintf(&arg2, "*:%s", arg);
1919 } else {
1920 arg2 = xstrdup(arg);
1921 p = hpdelim(&arg);
1922 if (p == NULL) {
1923 fatal("%s line %d: missing host in %s",
1924 filename, linenum,
1925 lookup_opcode_name(opcode));
1926 }
1927 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001928 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001929 if (arg == NULL ||
1930 ((port = permitopen_port(arg)) < 0)) {
1931 fatal("%s line %d: bad port number in %s",
1932 filename, linenum,
1933 lookup_opcode_name(opcode));
1934 }
1935 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001936 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001937 lookup_opcode_name(opcode),
1938 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001939 }
1940 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001941 }
Damien Miller9b439df2006-07-24 14:04:00 +10001942 break;
1943
Damien Millere2754432006-07-24 14:06:47 +10001944 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001945 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001946 fatal("%.200s line %d: Missing argument.", filename,
1947 linenum);
1948 len = strspn(cp, WHITESPACE);
1949 if (*activep && options->adm_forced_command == NULL)
1950 options->adm_forced_command = xstrdup(cp + len);
1951 return 0;
1952
Damien Millerd8cb1f12008-02-10 22:40:12 +11001953 case sChrootDirectory:
1954 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001955
1956 arg = strdelim(&cp);
1957 if (!arg || *arg == '\0')
1958 fatal("%s line %d: missing file name.",
1959 filename, linenum);
1960 if (*activep && *charptr == NULL)
1961 *charptr = xstrdup(arg);
1962 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001963
Damien Miller1aed65e2010-03-04 21:53:35 +11001964 case sTrustedUserCAKeys:
1965 charptr = &options->trusted_user_ca_keys;
1966 goto parse_filename;
1967
1968 case sRevokedKeys:
1969 charptr = &options->revoked_keys_file;
1970 goto parse_filename;
1971
Damien Miller0dac6fb2010-11-20 15:19:38 +11001972 case sIPQoS:
1973 arg = strdelim(&cp);
1974 if ((value = parse_ipqos(arg)) == -1)
1975 fatal("%s line %d: Bad IPQoS value: %s",
1976 filename, linenum, arg);
1977 arg = strdelim(&cp);
1978 if (arg == NULL)
1979 value2 = value;
1980 else if ((value2 = parse_ipqos(arg)) == -1)
1981 fatal("%s line %d: Bad IPQoS value: %s",
1982 filename, linenum, arg);
1983 if (*activep) {
1984 options->ip_qos_interactive = value;
1985 options->ip_qos_bulk = value2;
1986 }
1987 break;
1988
Damien Miller23528812012-04-22 11:24:43 +10001989 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001990 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001991 fatal("%.200s line %d: Missing argument.", filename,
1992 linenum);
1993 len = strspn(cp, WHITESPACE);
1994 if (*activep && options->version_addendum == NULL) {
1995 if (strcasecmp(cp + len, "none") == 0)
1996 options->version_addendum = xstrdup("");
1997 else if (strchr(cp + len, '\r') != NULL)
1998 fatal("%.200s line %d: Invalid argument",
1999 filename, linenum);
2000 else
2001 options->version_addendum = xstrdup(cp + len);
2002 }
2003 return 0;
2004
Damien Miller09d3e122012-10-31 08:58:58 +11002005 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002006 if (cp == NULL)
2007 fatal("%.200s line %d: Missing argument.", filename,
2008 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002009 len = strspn(cp, WHITESPACE);
2010 if (*activep && options->authorized_keys_command == NULL) {
2011 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2012 fatal("%.200s line %d: AuthorizedKeysCommand "
2013 "must be an absolute path",
2014 filename, linenum);
2015 options->authorized_keys_command = xstrdup(cp + len);
2016 }
2017 return 0;
2018
2019 case sAuthorizedKeysCommandUser:
2020 charptr = &options->authorized_keys_command_user;
2021
2022 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002023 if (!arg || *arg == '\0')
2024 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2025 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002026 if (*activep && *charptr == NULL)
2027 *charptr = xstrdup(arg);
2028 break;
2029
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002030 case sAuthorizedPrincipalsCommand:
2031 if (cp == NULL)
2032 fatal("%.200s line %d: Missing argument.", filename,
2033 linenum);
2034 len = strspn(cp, WHITESPACE);
2035 if (*activep &&
2036 options->authorized_principals_command == NULL) {
2037 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2038 fatal("%.200s line %d: "
2039 "AuthorizedPrincipalsCommand must be "
2040 "an absolute path", filename, linenum);
2041 options->authorized_principals_command =
2042 xstrdup(cp + len);
2043 }
2044 return 0;
2045
2046 case sAuthorizedPrincipalsCommandUser:
2047 charptr = &options->authorized_principals_command_user;
2048
2049 arg = strdelim(&cp);
2050 if (!arg || *arg == '\0')
2051 fatal("%s line %d: missing "
2052 "AuthorizedPrincipalsCommandUser argument.",
2053 filename, linenum);
2054 if (*activep && *charptr == NULL)
2055 *charptr = xstrdup(arg);
2056 break;
2057
Damien Millera6e3f012012-11-04 23:21:40 +11002058 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002059 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002060 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002061 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002062 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002063 if (strcmp(arg, "any") == 0) {
2064 if (options->num_auth_methods > 0) {
2065 fatal("%s line %d: \"any\" "
2066 "must appear alone in "
2067 "AuthenticationMethods",
2068 filename, linenum);
2069 }
2070 value = 1;
2071 } else if (value) {
2072 fatal("%s line %d: \"any\" must appear "
2073 "alone in AuthenticationMethods",
2074 filename, linenum);
2075 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002076 fatal("%s line %d: invalid "
2077 "authentication method list.",
2078 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002079 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002080 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002081 if (!*activep)
2082 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002083 array_append(filename, linenum,
2084 "AuthenticationMethods",
2085 &options->auth_methods,
2086 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002087 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002088 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002089 fatal("%s line %d: no AuthenticationMethods "
2090 "specified", filename, linenum);
2091 }
Damien Millera6e3f012012-11-04 23:21:40 +11002092 }
2093 return 0;
2094
Damien Miller7acefbb2014-07-18 14:11:24 +10002095 case sStreamLocalBindMask:
2096 arg = strdelim(&cp);
2097 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002098 fatal("%s line %d: missing StreamLocalBindMask "
2099 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002100 /* Parse mode in octal format */
2101 value = strtol(arg, &p, 8);
2102 if (arg == p || value < 0 || value > 0777)
2103 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002104 if (*activep)
2105 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002106 break;
2107
2108 case sStreamLocalBindUnlink:
2109 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2110 goto parse_flag;
2111
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002112 case sFingerprintHash:
2113 arg = strdelim(&cp);
2114 if (!arg || *arg == '\0')
2115 fatal("%.200s line %d: Missing argument.",
2116 filename, linenum);
2117 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2118 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2119 filename, linenum, arg);
2120 if (*activep)
2121 options->fingerprint_hash = value;
2122 break;
2123
djm@openbsd.org8f574952017-06-24 06:34:38 +00002124 case sExposeAuthInfo:
2125 intptr = &options->expose_userauth_info;
2126 goto parse_flag;
2127
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002128 case sRDomain:
2129 charptr = &options->routing_domain;
2130 arg = strdelim(&cp);
2131 if (!arg || *arg == '\0')
2132 fatal("%.200s line %d: Missing argument.",
2133 filename, linenum);
2134 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2135 !valid_rdomain(arg))
2136 fatal("%s line %d: bad routing domain",
2137 filename, linenum);
2138 if (*activep && *charptr == NULL)
2139 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002140 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002141
Ben Lindstromade03f62001-12-06 18:22:17 +00002142 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002143 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002144 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002145 do_log2(opcode == sIgnore ?
2146 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2147 "%s line %d: %s option %s", filename, linenum,
2148 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002149 while (arg)
2150 arg = strdelim(&cp);
2151 break;
2152
Ben Lindstromade03f62001-12-06 18:22:17 +00002153 default:
2154 fatal("%s line %d: Missing handler for opcode %s (%d)",
2155 filename, linenum, arg, opcode);
2156 }
2157 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2158 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2159 filename, linenum, arg);
2160 return 0;
2161}
2162
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002163/* Reads the server configuration file. */
2164
Damien Miller4af51302000-04-16 11:18:38 +10002165void
Darren Tucker645ab752004-06-25 13:33:20 +10002166load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002167{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002168 char *line = NULL, *cp;
2169 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002170 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10002171 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002172
Darren Tucker645ab752004-06-25 13:33:20 +10002173 debug2("%s: filename %s", __func__, filename);
2174 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002175 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002176 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002177 }
Darren Tucker645ab752004-06-25 13:33:20 +10002178 buffer_clear(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002179 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002180 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002181 /*
2182 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002183 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002184 * line numbers later for error messages
2185 */
2186 if ((cp = strchr(line, '#')) != NULL)
2187 memcpy(cp, "\n", 2);
2188 cp = line + strspn(line, " \t\r");
2189
2190 buffer_append(conf, cp, strlen(cp));
2191 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002192 free(line);
Darren Tucker645ab752004-06-25 13:33:20 +10002193 buffer_append(conf, "\0", 1);
2194 fclose(f);
2195 debug2("%s: done config len = %d", __func__, buffer_len(conf));
2196}
2197
2198void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002199parse_server_match_config(ServerOptions *options,
2200 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002201{
Darren Tucker45150472006-07-12 22:34:17 +10002202 ServerOptions mo;
2203
2204 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002205 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002206 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002207}
2208
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002209int parse_server_match_testspec(struct connection_info *ci, char *spec)
2210{
2211 char *p;
2212
2213 while ((p = strsep(&spec, ",")) && *p != '\0') {
2214 if (strncmp(p, "addr=", 5) == 0) {
2215 ci->address = xstrdup(p + 5);
2216 } else if (strncmp(p, "host=", 5) == 0) {
2217 ci->host = xstrdup(p + 5);
2218 } else if (strncmp(p, "user=", 5) == 0) {
2219 ci->user = xstrdup(p + 5);
2220 } else if (strncmp(p, "laddr=", 6) == 0) {
2221 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002222 } else if (strncmp(p, "rdomain=", 8) == 0) {
2223 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002224 } else if (strncmp(p, "lport=", 6) == 0) {
2225 ci->lport = a2port(p + 6);
2226 if (ci->lport == -1) {
2227 fprintf(stderr, "Invalid port '%s' in test mode"
2228 " specification %s\n", p+6, p);
2229 return -1;
2230 }
2231 } else {
2232 fprintf(stderr, "Invalid test mode specification %s\n",
2233 p);
2234 return -1;
2235 }
2236 }
2237 return 0;
2238}
2239
2240/*
Darren Tucker1629c072007-02-19 22:25:37 +11002241 * Copy any supported values that are set.
2242 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002243 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002244 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002245 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002246 */
Darren Tucker45150472006-07-12 22:34:17 +10002247void
Darren Tucker1629c072007-02-19 22:25:37 +11002248copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002249{
Damien Miller534b2cc2013-12-05 14:07:27 +11002250#define M_CP_INTOPT(n) do {\
2251 if (src->n != -1) \
2252 dst->n = src->n; \
2253} while (0)
2254
Darren Tucker1629c072007-02-19 22:25:37 +11002255 M_CP_INTOPT(password_authentication);
2256 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002257 M_CP_INTOPT(pubkey_authentication);
2258 M_CP_INTOPT(kerberos_authentication);
2259 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002260 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002261 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002262 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002263 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002264
2265 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002266 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002267 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002268 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002269 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002270 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002271 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002272 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002273 M_CP_INTOPT(x11_display_offset);
2274 M_CP_INTOPT(x11_forwarding);
2275 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002276 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002277 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002278 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002279 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002280 M_CP_INTOPT(client_alive_count_max);
2281 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002282 M_CP_INTOPT(ip_qos_interactive);
2283 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002284 M_CP_INTOPT(rekey_limit);
2285 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002286 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002287
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002288 /*
2289 * The bind_mask is a mode_t that may be unsigned, so we can't use
2290 * M_CP_INTOPT - it does a signed comparison that causes compiler
2291 * warnings.
2292 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002293 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002294 dst->fwd_opts.streamlocal_bind_mask =
2295 src->fwd_opts.streamlocal_bind_mask;
2296 }
2297
Damien Miller534b2cc2013-12-05 14:07:27 +11002298 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2299#define M_CP_STROPT(n) do {\
2300 if (src->n != NULL && dst->n != src->n) { \
2301 free(dst->n); \
2302 dst->n = src->n; \
2303 } \
2304} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002305#define M_CP_STRARRAYOPT(s, num_s) do {\
2306 u_int i; \
2307 if (src->num_s != 0) { \
2308 for (i = 0; i < dst->num_s; i++) \
2309 free(dst->s[i]); \
2310 free(dst->s); \
2311 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2312 for (i = 0; i < src->num_s; i++) \
2313 dst->s[i] = xstrdup(src->s[i]); \
2314 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002315 } \
2316} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002317
Damien Millerf2e407e2011-05-20 19:04:14 +10002318 /* See comment in servconf.h */
2319 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002320
djm@openbsd.orged085102015-10-29 08:05:01 +00002321 /* Arguments that accept '+...' need to be expanded */
2322 assemble_algorithms(dst);
2323
Damien Millerc2411902011-05-20 19:03:49 +10002324 /*
2325 * The only things that should be below this point are string options
2326 * which are only used after authentication.
2327 */
Damien Miller5d74e582011-05-20 19:03:31 +10002328 if (preauth)
2329 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002330
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002331 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002332 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002333 if (option_clear_or_none(dst->adm_forced_command)) {
2334 free(dst->adm_forced_command);
2335 dst->adm_forced_command = NULL;
2336 }
Damien Miller5d74e582011-05-20 19:03:31 +10002337 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002338 if (option_clear_or_none(dst->chroot_directory)) {
2339 free(dst->chroot_directory);
2340 dst->chroot_directory = NULL;
2341 }
Darren Tucker45150472006-07-12 22:34:17 +10002342}
2343
Darren Tucker1629c072007-02-19 22:25:37 +11002344#undef M_CP_INTOPT
2345#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002346#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002347
Darren Tucker45150472006-07-12 22:34:17 +10002348void
2349parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002350 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002351{
2352 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002353 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002354
2355 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2356
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002357 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2358 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002359 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002360 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002361 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002362 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002363 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002364 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002365 }
Darren Tuckera627d422013-06-02 07:31:17 +10002366 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002367 if (bad_options > 0)
2368 fatal("%s: terminating, %d bad configuration options",
2369 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002370 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002371}
Darren Tuckere7140f22008-06-10 23:01:51 +10002372
2373static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002374fmt_multistate_int(int val, const struct multistate *m)
2375{
2376 u_int i;
2377
2378 for (i = 0; m[i].key != NULL; i++) {
2379 if (m[i].value == val)
2380 return m[i].key;
2381 }
2382 return "UNKNOWN";
2383}
2384
2385static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002386fmt_intarg(ServerOpCodes code, int val)
2387{
Damien Miller82c55872011-06-23 08:20:30 +10002388 if (val == -1)
2389 return "unset";
2390 switch (code) {
2391 case sAddressFamily:
2392 return fmt_multistate_int(val, multistate_addressfamily);
2393 case sPermitRootLogin:
2394 return fmt_multistate_int(val, multistate_permitrootlogin);
2395 case sGatewayPorts:
2396 return fmt_multistate_int(val, multistate_gatewayports);
2397 case sCompression:
2398 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002399 case sAllowTcpForwarding:
2400 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002401 case sAllowStreamLocalForwarding:
2402 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002403 case sFingerprintHash:
2404 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002405 default:
2406 switch (val) {
2407 case 0:
2408 return "no";
2409 case 1:
2410 return "yes";
2411 default:
2412 return "UNKNOWN";
2413 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002414 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002415}
2416
Darren Tuckere7140f22008-06-10 23:01:51 +10002417static void
2418dump_cfg_int(ServerOpCodes code, int val)
2419{
2420 printf("%s %d\n", lookup_opcode_name(code), val);
2421}
2422
2423static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002424dump_cfg_oct(ServerOpCodes code, int val)
2425{
2426 printf("%s 0%o\n", lookup_opcode_name(code), val);
2427}
2428
2429static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002430dump_cfg_fmtint(ServerOpCodes code, int val)
2431{
2432 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2433}
2434
2435static void
2436dump_cfg_string(ServerOpCodes code, const char *val)
2437{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002438 printf("%s %s\n", lookup_opcode_name(code),
2439 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002440}
2441
2442static void
2443dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2444{
2445 u_int i;
2446
2447 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002448 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2449}
2450
2451static void
2452dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2453{
2454 u_int i;
2455
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002456 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002457 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002458 printf("%s", lookup_opcode_name(code));
2459 for (i = 0; i < count; i++)
2460 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002461 if (code == sAuthenticationMethods && count == 0)
2462 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002463 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002464}
2465
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002466static char *
2467format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002468{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002469 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002470 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002471 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002472 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002473
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002474 /*
2475 * ListenAddress must be after Port. add_one_listen_addr pushes
2476 * addresses onto a stack, so to maintain ordering we need to
2477 * print these in reverse order.
2478 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002479 for (ai = la->addrs; ai; ai = ai->ai_next) {
2480 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002481 sizeof(addr), port, sizeof(port),
2482 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002483 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2484 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002485 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002486 laddr2 = laddr1;
2487 if (ai->ai_family == AF_INET6) {
2488 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2489 addr, port,
2490 la->rdomain == NULL ? "" : " rdomain ",
2491 la->rdomain == NULL ? "" : la->rdomain,
2492 laddr2);
2493 } else {
2494 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2495 addr, port,
2496 la->rdomain == NULL ? "" : " rdomain ",
2497 la->rdomain == NULL ? "" : la->rdomain,
2498 laddr2);
2499 }
2500 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002501 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002502 return laddr1;
2503}
2504
2505void
2506dump_config(ServerOptions *o)
2507{
2508 char *s;
2509 u_int i;
2510
2511 /* these are usually at the top of the config */
2512 for (i = 0; i < o->num_ports; i++)
2513 printf("port %d\n", o->ports[i]);
2514 dump_cfg_fmtint(sAddressFamily, o->address_family);
2515
2516 for (i = 0; i < o->num_listen_addrs; i++) {
2517 s = format_listen_addrs(&o->listen_addrs[i]);
2518 printf("%s", s);
2519 free(s);
2520 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002521
2522 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002523#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002524 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002525#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002526 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002527 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2528 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002529 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002530 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2531 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002532 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002533
2534 /* formatted integer arguments */
2535 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2536 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2537 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002538 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2539 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2540 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002541 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002542#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002543 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2544 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2545 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002546# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002547 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002548# endif
2549#endif
2550#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002551 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2552 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002553#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002554 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2555 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2556 o->kbd_interactive_authentication);
2557 dump_cfg_fmtint(sChallengeResponseAuthentication,
2558 o->challenge_response_authentication);
2559 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002560#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002561 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002562#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002563 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2564 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002565 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002566 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002567 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2568 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2569 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002570 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002571 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002572 dump_cfg_fmtint(sUseDNS, o->use_dns);
2573 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002574 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002575 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002576 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002577 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002578 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002579 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002580
2581 /* string arguments */
2582 dump_cfg_string(sPidFile, o->pid_file);
2583 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002584 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2585 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002586 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002587 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002588 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002589 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2590 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002591 dump_cfg_string(sAuthorizedPrincipalsFile,
2592 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002593 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2594 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002595 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2596 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002597 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2598 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002599 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002600 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002601 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002602 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2603 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002604 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2605 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002606 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2607 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002608 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002609
2610 /* string arguments requiring a lookup */
2611 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2612 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2613
2614 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002615 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2616 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002617 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2618 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002619 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002620 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002621 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2622 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2623 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2624 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2625 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002626 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002627 dump_cfg_strarray_oneline(sAuthenticationMethods,
2628 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002629
2630 /* other arguments */
2631 for (i = 0; i < o->num_subsystems; i++)
2632 printf("subsystem %s %s\n", o->subsystem_name[i],
2633 o->subsystem_args[i]);
2634
2635 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2636 o->max_startups_rate, o->max_startups);
2637
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002638 s = NULL;
2639 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002640 if (tunmode_desc[i].val == o->permit_tun) {
2641 s = tunmode_desc[i].text;
2642 break;
2643 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002644 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002645 dump_cfg_string(sPermitTunnel, s);
2646
Damien Miller91475862011-05-05 14:14:34 +10002647 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2648 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002649
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002650 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002651 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002652
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002653 printf("permitopen");
2654 if (o->num_permitted_opens == 0)
2655 printf(" any");
2656 else {
2657 for (i = 0; i < o->num_permitted_opens; i++)
2658 printf(" %s", o->permitted_opens[i]);
2659 }
2660 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002661 printf("permitlisten");
2662 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002663 printf(" any");
2664 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002665 for (i = 0; i < o->num_permitted_listens; i++)
2666 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002667 }
2668 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002669
2670 if (o->permit_user_env_whitelist == NULL) {
2671 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2672 } else {
2673 printf("permituserenvironment %s\n",
2674 o->permit_user_env_whitelist);
2675 }
2676
Darren Tuckere7140f22008-06-10 23:01:51 +10002677}