blob: f1010b3b9ddb6dfd0adf75408e3ea1d7222c1206 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
markus@openbsd.org5467fbc2018-07-11 18:53:29 +00002/* $OpenBSD: servconf.c,v 1.339 2018/07/11 18:53:29 markus 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"
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000048#include "sshbuf.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"
markus@openbsd.org5467fbc2018-07-11 18:53:29 +000054#include "sshkey.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"
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000062#include "ssherr.h"
Damien Millera6e3f012012-11-04 23:21:40 +110063#include "hostfile.h"
64#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000065#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000066#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000068static void add_listen_addr(ServerOptions *, const char *,
69 const char *, int);
70static void add_one_listen_addr(ServerOptions *, const char *,
71 const char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110072
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000073/* Use of privilege separation or not */
74extern int use_privsep;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000075extern struct sshbuf *cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000076
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077/* Initializes the server options to their default values. */
78
Damien Miller4af51302000-04-16 11:18:38 +100079void
Damien Miller95def091999-11-25 00:26:21 +110080initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100081{
Damien Miller95def091999-11-25 00:26:21 +110082 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110083
84 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100085 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110086
87 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110088 options->num_ports = 0;
89 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000090 options->queued_listen_addrs = NULL;
91 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110092 options->listen_addrs = NULL;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000093 options->num_listen_addrs = 0;
Darren Tucker0f383232005-01-20 10:57:56 +110094 options->address_family = -1;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +000095 options->routing_domain = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110096 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110097 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100098 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100099 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100100 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000101 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->ignore_rhosts = -1;
103 options->ignore_user_known_hosts = -1;
104 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000105 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->x11_forwarding = -1;
107 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +1100108 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100109 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000110 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000111 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100113 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100114 options->log_facility = SYSLOG_FACILITY_NOT_SET;
115 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000116 options->hostbased_authentication = -1;
117 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000118 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000119 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100120 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000121 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100122 options->kerberos_authentication = -1;
123 options->kerberos_or_local_passwd = -1;
124 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100125 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000126 options->gss_authentication=-1;
127 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000128 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100129 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100130 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000131 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100132 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000133 options->permit_user_env = -1;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000134 options->permit_user_env_whitelist = NULL;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000135 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000136 options->rekey_limit = -1;
137 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100138 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000139 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000140 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100141 options->num_allow_users = 0;
142 options->num_deny_users = 0;
143 options->num_allow_groups = 0;
144 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000145 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000146 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000147 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000148 options->fwd_opts.gateway_ports = -1;
149 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
150 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000151 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000152 options->max_startups_begin = -1;
153 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000154 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000155 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000156 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000157 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000158 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000159 options->client_alive_interval = -1;
160 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000161 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000162 options->num_accept_env = 0;
djm@openbsd.org28013752018-06-09 03:03:10 +0000163 options->num_setenv = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100164 options->permit_tun = -1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000165 options->permitted_opens = NULL;
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000166 options->permitted_listens = NULL;
Damien Millere2754432006-07-24 14:06:47 +1000167 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100168 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100169 options->authorized_keys_command = NULL;
170 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100171 options->revoked_keys_file = NULL;
172 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000173 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000174 options->authorized_principals_command = NULL;
175 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100176 options->ip_qos_interactive = -1;
177 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000178 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000179 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000180 options->disable_forwarding = -1;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000181 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000182}
183
djm@openbsd.org161cf412014-12-22 07:55:51 +0000184/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
185static int
186option_clear_or_none(const char *o)
187{
188 return o == NULL || strcasecmp(o, "none") == 0;
189}
190
djm@openbsd.orged085102015-10-29 08:05:01 +0000191static void
192assemble_algorithms(ServerOptions *o)
193{
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000194 char *all_cipher, *all_mac, *all_kex, *all_key;
195
196 all_cipher = cipher_alg_list(',', 0);
197 all_mac = mac_alg_list(',');
198 all_kex = kex_alg_list(',');
199 all_key = sshkey_alg_list(0, 0, 1, ',');
200 if (kex_assemble_names(&o->ciphers,
201 KEX_SERVER_ENCRYPT, all_cipher) != 0 ||
202 kex_assemble_names(&o->macs,
203 KEX_SERVER_MAC, all_mac) != 0 ||
204 kex_assemble_names(&o->kex_algorithms,
205 KEX_SERVER_KEX, all_kex) != 0 ||
206 kex_assemble_names(&o->hostkeyalgorithms,
207 KEX_DEFAULT_PK_ALG, all_key) != 0 ||
208 kex_assemble_names(&o->hostbased_key_types,
209 KEX_DEFAULT_PK_ALG, all_key) != 0 ||
210 kex_assemble_names(&o->pubkey_key_types,
211 KEX_DEFAULT_PK_ALG, all_key) != 0)
djm@openbsd.orged085102015-10-29 08:05:01 +0000212 fatal("kex_assemble_names failed");
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000213 free(all_cipher);
214 free(all_mac);
215 free(all_kex);
216 free(all_key);
djm@openbsd.orged085102015-10-29 08:05:01 +0000217}
218
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000219static void
220array_append(const char *file, const int line, const char *directive,
221 char ***array, u_int *lp, const char *s)
222{
223
224 if (*lp >= INT_MAX)
225 fatal("%s line %d: Too many %s entries", file, line, directive);
226
227 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
228 (*array)[*lp] = xstrdup(s);
229 (*lp)++;
230}
231
232void
233servconf_add_hostkey(const char *file, const int line,
234 ServerOptions *options, const char *path)
235{
236 char *apath = derelativise_path(path);
237
238 array_append(file, line, "HostKey",
239 &options->host_key_files, &options->num_host_key_files, apath);
240 free(apath);
241}
242
243void
244servconf_add_hostcert(const char *file, const int line,
245 ServerOptions *options, const char *path)
246{
247 char *apath = derelativise_path(path);
248
249 array_append(file, line, "HostCertificate",
250 &options->host_cert_files, &options->num_host_cert_files, apath);
251 free(apath);
252}
253
Damien Miller4af51302000-04-16 11:18:38 +1000254void
Damien Miller95def091999-11-25 00:26:21 +1100255fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000257 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000258
Damien Miller726273e2001-11-12 11:40:11 +1100259 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000260 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000261 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100262
263 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100264 if (options->num_host_key_files == 0) {
265 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000266 servconf_add_hostkey("[default]", 0, options,
267 _PATH_HOST_RSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100268#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000269 servconf_add_hostkey("[default]", 0, options,
270 _PATH_HOST_ECDSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100271#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000272 servconf_add_hostkey("[default]", 0, options,
273 _PATH_HOST_ED25519_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000274#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000275 servconf_add_hostkey("[default]", 0, options,
276 _PATH_HOST_XMSS_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000277#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100278 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100279 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100280 if (options->num_ports == 0)
281 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000282 if (options->address_family == -1)
283 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100284 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000285 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000286 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000287 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100288 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000289 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000290 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000291 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100292 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100293 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100294 if (options->ignore_user_known_hosts == -1)
295 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100296 if (options->print_motd == -1)
297 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000298 if (options->print_lastlog == -1)
299 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100300 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100301 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100302 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100303 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100304 if (options->x11_use_localhost == -1)
305 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000306 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000307 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100308 if (options->permit_tty == -1)
309 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000310 if (options->permit_user_rc == -1)
311 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100312 if (options->strict_modes == -1)
313 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100314 if (options->tcp_keep_alive == -1)
315 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100316 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100317 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100318 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000319 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000320 if (options->hostbased_authentication == -1)
321 options->hostbased_authentication = 0;
322 if (options->hostbased_uses_name_from_packet_only == -1)
323 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100324 if (options->pubkey_authentication == -1)
325 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100326 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000327 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100328 if (options->kerberos_or_local_passwd == -1)
329 options->kerberos_or_local_passwd = 1;
330 if (options->kerberos_ticket_cleanup == -1)
331 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100332 if (options->kerberos_get_afs_token == -1)
333 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000334 if (options->gss_authentication == -1)
335 options->gss_authentication = 0;
336 if (options->gss_cleanup_creds == -1)
337 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000338 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000339 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100340 if (options->password_authentication == -1)
341 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100342 if (options->kbd_interactive_authentication == -1)
343 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000344 if (options->challenge_response_authentication == -1)
345 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100346 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100347 options->permit_empty_passwd = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000348 if (options->permit_user_env == -1) {
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000349 options->permit_user_env = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000350 options->permit_user_env_whitelist = NULL;
351 }
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000352 if (options->compression == -1)
sf@openbsd.org168b46f2018-07-09 13:37:10 +0000353 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000354 if (options->rekey_limit == -1)
355 options->rekey_limit = 0;
356 if (options->rekey_interval == -1)
357 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100358 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100359 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000360 if (options->allow_streamlocal_forwarding == -1)
361 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000362 if (options->allow_agent_forwarding == -1)
363 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000364 if (options->fwd_opts.gateway_ports == -1)
365 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000366 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100367 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000368 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100369 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000370 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100371 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000372 if (options->max_authtries == -1)
373 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000374 if (options->max_sessions == -1)
375 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000376 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000377 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000378 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100379 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000380 if (options->client_alive_count_max == -1)
381 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000382 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000383 array_append("[default]", 0, "AuthorizedKeysFiles",
384 &options->authorized_keys_files,
385 &options->num_authkeys_files,
386 _PATH_SSH_USER_PERMITTED_KEYS);
387 array_append("[default]", 0, "AuthorizedKeysFiles",
388 &options->authorized_keys_files,
389 &options->num_authkeys_files,
390 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000391 }
Damien Millerd27b9472005-12-13 19:29:02 +1100392 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100393 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100394 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000395 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100396 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000397 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000398 if (options->version_addendum == NULL)
399 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000400 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
401 options->fwd_opts.streamlocal_bind_mask = 0177;
402 if (options->fwd_opts.streamlocal_bind_unlink == -1)
403 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000404 if (options->fingerprint_hash == -1)
405 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000406 if (options->disable_forwarding == -1)
407 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000408 if (options->expose_userauth_info == -1)
409 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000410
djm@openbsd.orged085102015-10-29 08:05:01 +0000411 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000412
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000413 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000414 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000415 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000416
djm@openbsd.org161cf412014-12-22 07:55:51 +0000417#define CLEAR_ON_NONE(v) \
418 do { \
419 if (option_clear_or_none(v)) { \
420 free(v); \
421 v = NULL; \
422 } \
423 } while(0)
424 CLEAR_ON_NONE(options->pid_file);
425 CLEAR_ON_NONE(options->xauth_location);
426 CLEAR_ON_NONE(options->banner);
427 CLEAR_ON_NONE(options->trusted_user_ca_keys);
428 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000429 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000430 CLEAR_ON_NONE(options->adm_forced_command);
431 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000432 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000433 for (i = 0; i < options->num_host_key_files; i++)
434 CLEAR_ON_NONE(options->host_key_files[i]);
435 for (i = 0; i < options->num_host_cert_files; i++)
436 CLEAR_ON_NONE(options->host_cert_files[i]);
437#undef CLEAR_ON_NONE
438
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000439 /* Similar handling for AuthenticationMethods=any */
440 if (options->num_auth_methods == 1 &&
441 strcmp(options->auth_methods[0], "any") == 0) {
442 free(options->auth_methods[0]);
443 options->auth_methods[0] = NULL;
444 options->num_auth_methods = 0;
445 }
446
Tim Rice40017b02002-07-14 13:36:49 -0700447#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000448 if (use_privsep && options->compression == 1) {
449 error("This platform does not support both privilege "
450 "separation and compression");
451 error("Compression disabled");
452 options->compression = 0;
453 }
454#endif
455
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000456}
457
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000458/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100459typedef enum {
460 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100461 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000462 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100463 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000464 sPort, sHostKeyFile, sLoginGraceTime,
465 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000466 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100467 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000468 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100469 sPasswordAuthentication, sKbdInteractiveAuthentication,
470 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000471 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100472 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100473 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000474 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000475 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000476 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000477 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
478 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000479 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000480 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000481 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000482 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000483 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000484 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000485 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100486 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100487 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000488 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000489 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000490 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100491 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000492 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000493 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000494 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000495 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000496 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000497} ServerOpCodes;
498
Darren Tucker45150472006-07-12 22:34:17 +1000499#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
500#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
501#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
502
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000503/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100504static struct {
505 const char *name;
506 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000507 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100508} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100509 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000510#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000512#else
Darren Tucker45150472006-07-12 22:34:17 +1000513 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000514#endif
Darren Tucker45150472006-07-12 22:34:17 +1000515 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100516 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000517 { "port", sPort, SSHCFG_GLOBAL },
518 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
519 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000520 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000521 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000522 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000523 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000524 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100525 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000526 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000527 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000528 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000529 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100530 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000531 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000532 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000533 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000534 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100535 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000536 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000537 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000538#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100539 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000540 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
541 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100542#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000543 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000544#else
Darren Tucker45150472006-07-12 22:34:17 +1000545 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100546#endif
547#else
Darren Tucker1629c072007-02-19 22:25:37 +1100548 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000549 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
550 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
551 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000552#endif
Darren Tucker45150472006-07-12 22:34:17 +1000553 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
554 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000555#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100556 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000557 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000558 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000559#else
Darren Tucker1629c072007-02-19 22:25:37 +1100560 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000561 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000562 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000563#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100564 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
565 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100566 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Damien Miller87f08be2018-07-20 13:18:28 +1000567 { "skeyauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000568 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
569 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
570 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
571 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100572#ifdef DISABLE_LASTLOG
573 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
574#else
Darren Tucker45150472006-07-12 22:34:17 +1000575 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100576#endif
Darren Tucker45150472006-07-12 22:34:17 +1000577 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
578 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000579 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
580 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
581 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000582 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
583 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100584 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000585 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000586 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000587 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000588 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000589 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
590 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
591 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000592 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000593 { "allowusers", sAllowUsers, SSHCFG_ALL },
594 { "denyusers", sDenyUsers, SSHCFG_ALL },
595 { "allowgroups", sAllowGroups, SSHCFG_ALL },
596 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000597 { "ciphers", sCiphers, SSHCFG_GLOBAL },
598 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000599 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000600 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
601 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
602 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000603 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000604 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100605 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000606 { "usedns", sUseDNS, SSHCFG_GLOBAL },
607 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
608 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000609 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
610 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000611 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000612 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000613 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000614 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000615 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000616 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100617 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000618 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000619 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000620 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000621 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000622 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100623 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100624 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100625 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
626 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000627 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000628 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100629 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100630 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
631 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000632 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
633 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000634 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100635 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000636 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
637 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
638 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000639 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000640 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000641 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000642 { "rdomain", sRDomain, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000643 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000644};
645
Darren Tuckere7140f22008-06-10 23:01:51 +1000646static struct {
647 int val;
648 char *text;
649} tunmode_desc[] = {
650 { SSH_TUNMODE_NO, "no" },
651 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
652 { SSH_TUNMODE_ETHERNET, "ethernet" },
653 { SSH_TUNMODE_YES, "yes" },
654 { -1, NULL }
655};
656
djm@openbsd.org115063a2018-06-06 18:22:41 +0000657/* Returns an opcode name from its number */
658
659static const char *
660lookup_opcode_name(ServerOpCodes code)
661{
662 u_int i;
663
664 for (i = 0; keywords[i].name != NULL; i++)
665 if (keywords[i].opcode == code)
666 return(keywords[i].name);
667 return "UNKNOWN";
668}
669
670
Damien Miller5428f641999-11-25 11:54:57 +1100671/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000672 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100673 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000674
Damien Miller4af51302000-04-16 11:18:38 +1000675static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100676parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000677 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000678{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000679 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000680
Damien Miller95def091999-11-25 00:26:21 +1100681 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000682 if (strcasecmp(cp, keywords[i].name) == 0) {
683 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100684 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000685 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000686
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000687 error("%s: line %d: Bad configuration option: %s",
688 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100689 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000690}
691
Darren Tucker88b6fb22010-01-13 22:44:29 +1100692char *
693derelativise_path(const char *path)
694{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000695 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100696
djm@openbsd.org161cf412014-12-22 07:55:51 +0000697 if (strcasecmp(path, "none") == 0)
698 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100699 expanded = tilde_expand_filename(path, getuid());
700 if (*expanded == '/')
701 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100702 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100703 fatal("%s: getcwd: %s", __func__, strerror(errno));
704 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000705 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100706 return ret;
707}
708
Ben Lindstrombba81212001-06-25 05:01:22 +0000709static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000710add_listen_addr(ServerOptions *options, const char *addr,
711 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100712{
Damien Millereccb9de2005-06-17 12:59:34 +1000713 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100714
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000715 if (port > 0)
716 add_one_listen_addr(options, addr, rdomain, port);
717 else {
718 for (i = 0; i < options->num_ports; i++) {
719 add_one_listen_addr(options, addr, rdomain,
720 options->ports[i]);
721 }
722 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000723}
724
Ben Lindstrombba81212001-06-25 05:01:22 +0000725static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000726add_one_listen_addr(ServerOptions *options, const char *addr,
727 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000728{
729 struct addrinfo hints, *ai, *aitop;
730 char strport[NI_MAXSERV];
731 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000732 u_int i;
733
734 /* Find listen_addrs entry for this rdomain */
735 for (i = 0; i < options->num_listen_addrs; i++) {
736 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
737 break;
738 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
739 continue;
740 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
741 break;
742 }
743 if (i >= options->num_listen_addrs) {
744 /* No entry for this rdomain; allocate one */
745 if (i >= INT_MAX)
746 fatal("%s: too many listen addresses", __func__);
747 options->listen_addrs = xrecallocarray(options->listen_addrs,
748 options->num_listen_addrs, options->num_listen_addrs + 1,
749 sizeof(*options->listen_addrs));
750 i = options->num_listen_addrs++;
751 if (rdomain != NULL)
752 options->listen_addrs[i].rdomain = xstrdup(rdomain);
753 }
754 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000755
756 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100757 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000758 hints.ai_socktype = SOCK_STREAM;
759 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100760 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000761 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
762 fatal("bad addr or host: %s (%s)",
763 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100764 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000765 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
766 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000767 ai->ai_next = options->listen_addrs[i].addrs;
768 options->listen_addrs[i].addrs = aitop;
769}
770
771/* Returns nonzero if the routing domain name is valid */
772static int
773valid_rdomain(const char *name)
774{
Damien Miller43c29bb2017-10-25 13:10:59 +1100775#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100776 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100777#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000778 const char *errstr;
779 long long num;
780 struct rt_tableinfo info;
781 int mib[6];
782 size_t miblen = sizeof(mib);
783
784 if (name == NULL)
785 return 1;
786
787 num = strtonum(name, 0, 255, &errstr);
788 if (errstr != NULL)
789 return 0;
790
791 /* Check whether the table actually exists */
792 memset(mib, 0, sizeof(mib));
793 mib[0] = CTL_NET;
794 mib[1] = PF_ROUTE;
795 mib[4] = NET_RT_TABLE;
796 mib[5] = (int)num;
797 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
798 return 0;
799
800 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100801#else /* defined(__OpenBSD__) */
802 error("Routing domains are not supported on this platform");
803 return 0;
804#endif
Damien Miller34132e52000-01-14 15:45:46 +1100805}
806
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000807/*
808 * Queue a ListenAddress to be processed once we have all of the Ports
809 * and AddressFamily options.
810 */
811static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000812queue_listen_addr(ServerOptions *options, const char *addr,
813 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000814{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000815 struct queued_listenaddr *qla;
816
817 options->queued_listen_addrs = xrecallocarray(
818 options->queued_listen_addrs,
819 options->num_queued_listens, options->num_queued_listens + 1,
820 sizeof(*options->queued_listen_addrs));
821 qla = &options->queued_listen_addrs[options->num_queued_listens++];
822 qla->addr = xstrdup(addr);
823 qla->port = port;
824 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000825}
826
827/*
828 * Process queued (text) ListenAddress entries.
829 */
830static void
831process_queued_listen_addrs(ServerOptions *options)
832{
833 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000834 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000835
836 if (options->num_ports == 0)
837 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
838 if (options->address_family == -1)
839 options->address_family = AF_UNSPEC;
840
841 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000842 qla = &options->queued_listen_addrs[i];
843 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
844 free(qla->addr);
845 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000846 }
847 free(options->queued_listen_addrs);
848 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000849 options->num_queued_listens = 0;
850}
851
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000852/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000853 * Inform channels layer of permitopen options for a single forwarding
854 * direction (local/remote).
855 */
856static void
857process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
858 char **opens, u_int num_opens)
859{
860 u_int i;
861 int port;
862 char *host, *arg, *oarg;
863 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
864 const char *what = lookup_opcode_name(opcode);
865
866 channel_clear_permission(ssh, FORWARD_ADM, where);
867 if (num_opens == 0)
868 return; /* permit any */
869
870 /* handle keywords: "any" / "none" */
871 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
872 return;
873 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
874 channel_disable_admin(ssh, where);
875 return;
876 }
877 /* Otherwise treat it as a list of permitted host:port */
878 for (i = 0; i < num_opens; i++) {
879 oarg = arg = xstrdup(opens[i]);
880 host = hpdelim(&arg);
881 if (host == NULL)
882 fatal("%s: missing host in %s", __func__, what);
883 host = cleanhostname(host);
884 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
885 fatal("%s: bad port number in %s", __func__, what);
886 /* Send it to channels layer */
887 channel_add_permission(ssh, FORWARD_ADM,
888 where, host, port);
889 free(oarg);
890 }
891}
892
893/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000894 * Inform channels layer of permitopen options from configuration.
895 */
896void
897process_permitopen(struct ssh *ssh, ServerOptions *options)
898{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000899 process_permitopen_list(ssh, sPermitOpen,
900 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000901 process_permitopen_list(ssh, sPermitListen,
902 options->permitted_listens,
903 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000904}
905
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000906struct connection_info *
907get_connection_info(int populate, int use_dns)
908{
djm@openbsd.org95767262016-03-07 19:02:43 +0000909 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000910 static struct connection_info ci;
911
912 if (!populate)
913 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000914 ci.host = auth_get_canonical_hostname(ssh, use_dns);
915 ci.address = ssh_remote_ipaddr(ssh);
916 ci.laddress = ssh_local_ipaddr(ssh);
917 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000918 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000919 return &ci;
920}
921
Darren Tucker45150472006-07-12 22:34:17 +1000922/*
923 * The strategy for the Match blocks is that the config file is parsed twice.
924 *
925 * The first time is at startup. activep is initialized to 1 and the
926 * directives in the global context are processed and acted on. Hitting a
927 * Match directive unsets activep and the directives inside the block are
928 * checked for syntax only.
929 *
930 * The second time is after a connection has been established but before
931 * authentication. activep is initialized to 2 and global config directives
932 * are ignored since they have already been processed. If the criteria in a
933 * Match block is met, activep is set and the subsequent directives
934 * processed and actioned until EOF or another Match block unsets it. Any
935 * options set are copied into the main server config.
936 *
937 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000938 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000939 *
940 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
941 * Match Address 192.168.0.*
942 * Tag trusted
943 * Match Group wheel
944 * Tag trusted
945 * Match Tag trusted
946 * AllowTcpForwarding yes
947 * GatewayPorts clientspecified
948 * [...]
949 *
950 * - Add a PermittedChannelRequests directive
951 * Match Group shell
952 * PermittedChannelRequests session,forwarded-tcpip
953 */
954
955static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000956match_cfg_line_group(const char *grps, int line, const char *user)
957{
958 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000959 struct passwd *pw;
960
Damien Miller565ca3f2006-08-19 00:23:15 +1000961 if (user == NULL)
962 goto out;
963
964 if ((pw = getpwnam(user)) == NULL) {
965 debug("Can't match group at line %d because user %.100s does "
966 "not exist", line, user);
967 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
968 debug("Can't Match group because user %.100s not in any group "
969 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000970 } else if (ga_match_pattern_list(grps) != 1) {
971 debug("user %.100s does not match group list %.100s at line %d",
972 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000973 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000974 debug("user %.100s matched group list %.100s at line %d", user,
975 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000976 result = 1;
977 }
978out:
979 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000980 return result;
981}
982
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +0000983static void
984match_test_missing_fatal(const char *criteria, const char *attrib)
985{
986 fatal("'Match %s' in configuration but '%s' not in connection "
987 "test specification.", criteria, attrib);
988}
989
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000990/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000991 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100992 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000993 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000994 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000995static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000996match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000997{
Damien Millercf31f382013-10-24 21:02:56 +1100998 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000999 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +10001000
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001001 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001002 debug3("checking syntax for 'Match %s'", cp);
1003 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001004 debug3("checking match for '%s' user %s host %s addr %s "
1005 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
1006 ci->host ? ci->host : "(null)",
1007 ci->address ? ci->address : "(null)",
1008 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +10001009
1010 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +11001011 attributes++;
1012 if (strcasecmp(attrib, "all") == 0) {
1013 if (attributes != 1 ||
1014 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1015 error("'all' cannot be combined with other "
1016 "Match attributes");
1017 return -1;
1018 }
1019 *condition = cp;
1020 return 1;
1021 }
Darren Tucker45150472006-07-12 22:34:17 +10001022 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1023 error("Missing Match criteria for %s", attrib);
1024 return -1;
1025 }
Darren Tucker45150472006-07-12 22:34:17 +10001026 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001027 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001028 result = 0;
1029 continue;
1030 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001031 if (ci->user == NULL)
1032 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001033 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001034 result = 0;
1035 else
1036 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001037 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001038 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001039 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001040 result = 0;
1041 continue;
1042 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001043 if (ci->user == NULL)
1044 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001045 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001046 case -1:
1047 return -1;
1048 case 0:
1049 result = 0;
1050 }
Darren Tucker45150472006-07-12 22:34:17 +10001051 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001052 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001053 result = 0;
1054 continue;
1055 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001056 if (ci->host == NULL)
1057 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001058 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001059 result = 0;
1060 else
1061 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001062 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001063 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001064 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001065 result = 0;
1066 continue;
1067 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001068 if (ci->address == NULL)
1069 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001070 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001071 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001072 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001073 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001074 break;
1075 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001076 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001077 result = 0;
1078 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001079 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001080 return -1;
1081 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001082 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001083 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001084 result = 0;
1085 continue;
1086 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001087 if (ci->laddress == NULL)
1088 match_test_missing_fatal("LocalAddress",
1089 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001090 switch (addr_match_list(ci->laddress, arg)) {
1091 case 1:
1092 debug("connection from %.100s matched "
1093 "'LocalAddress %.100s' at line %d",
1094 ci->laddress, arg, line);
1095 break;
1096 case 0:
1097 case -1:
1098 result = 0;
1099 break;
1100 case -2:
1101 return -1;
1102 }
1103 } else if (strcasecmp(attrib, "localport") == 0) {
1104 if ((port = a2port(arg)) == -1) {
1105 error("Invalid LocalPort '%s' on Match line",
1106 arg);
1107 return -1;
1108 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001109 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001110 result = 0;
1111 continue;
1112 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001113 if (ci->lport == 0)
1114 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001115 /* TODO support port lists */
1116 if (port == ci->lport)
1117 debug("connection from %.100s matched "
1118 "'LocalPort %d' at line %d",
1119 ci->laddress, port, line);
1120 else
1121 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001122 } else if (strcasecmp(attrib, "rdomain") == 0) {
1123 if (ci == NULL || ci->rdomain == NULL) {
1124 result = 0;
1125 continue;
1126 }
1127 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1128 result = 0;
1129 else
1130 debug("user %.100s matched 'RDomain %.100s' at "
1131 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001132 } else {
1133 error("Unsupported Match attribute %s", attrib);
1134 return -1;
1135 }
1136 }
Damien Millercf31f382013-10-24 21:02:56 +11001137 if (attributes == 0) {
1138 error("One or more attributes required for Match");
1139 return -1;
1140 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001141 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001142 debug3("match %sfound", result ? "" : "not ");
1143 *condition = cp;
1144 return result;
1145}
1146
Damien Millere2754432006-07-24 14:06:47 +10001147#define WHITESPACE " \t\r\n"
1148
Damien Miller33322122011-06-20 14:43:11 +10001149/* Multistate option parsing */
1150struct multistate {
1151 char *key;
1152 int value;
1153};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001154static const struct multistate multistate_flag[] = {
1155 { "yes", 1 },
1156 { "no", 0 },
1157 { NULL, -1 }
1158};
Damien Miller33322122011-06-20 14:43:11 +10001159static const struct multistate multistate_addressfamily[] = {
1160 { "inet", AF_INET },
1161 { "inet6", AF_INET6 },
1162 { "any", AF_UNSPEC },
1163 { NULL, -1 }
1164};
1165static const struct multistate multistate_permitrootlogin[] = {
1166 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001167 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001168 { "forced-commands-only", PERMIT_FORCED_ONLY },
1169 { "yes", PERMIT_YES },
1170 { "no", PERMIT_NO },
1171 { NULL, -1 }
1172};
1173static const struct multistate multistate_compression[] = {
sf@openbsd.org168b46f2018-07-09 13:37:10 +00001174 { "yes", COMP_DELAYED },
1175 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001176 { "no", COMP_NONE },
1177 { NULL, -1 }
1178};
1179static const struct multistate multistate_gatewayports[] = {
1180 { "clientspecified", 2 },
1181 { "yes", 1 },
1182 { "no", 0 },
1183 { NULL, -1 }
1184};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001185static const struct multistate multistate_tcpfwd[] = {
1186 { "yes", FORWARD_ALLOW },
1187 { "all", FORWARD_ALLOW },
1188 { "no", FORWARD_DENY },
1189 { "remote", FORWARD_REMOTE },
1190 { "local", FORWARD_LOCAL },
1191 { NULL, -1 }
1192};
Damien Miller33322122011-06-20 14:43:11 +10001193
Ben Lindstromade03f62001-12-06 18:22:17 +00001194int
1195process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001196 const char *filename, int linenum, int *activep,
1197 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001198{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001199 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001200 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001201 SyslogFacility *log_facility_ptr;
1202 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001203 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001204 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001205 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001206 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001207 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001208 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001209
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001210 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1211 if ((len = strlen(line)) == 0)
1212 return 0;
1213 for (len--; len > 0; len--) {
1214 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1215 break;
1216 line[len] = '\0';
1217 }
1218
Ben Lindstromade03f62001-12-06 18:22:17 +00001219 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001220 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001221 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001222 /* Ignore leading whitespace */
1223 if (*arg == '\0')
1224 arg = strdelim(&cp);
1225 if (!arg || !*arg || *arg == '#')
1226 return 0;
1227 intptr = NULL;
1228 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001229 opcode = parse_token(arg, filename, linenum, &flags);
1230
1231 if (activep == NULL) { /* We are processing a command line directive */
1232 cmdline = 1;
1233 activep = &cmdline;
1234 }
1235 if (*activep && opcode != sMatch)
1236 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1237 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001238 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001239 fatal("%s line %d: Directive '%s' is not allowed "
1240 "within a Match block", filename, linenum, arg);
1241 } else { /* this is a directive we have already processed */
1242 while (arg)
1243 arg = strdelim(&cp);
1244 return 0;
1245 }
1246 }
1247
Ben Lindstromade03f62001-12-06 18:22:17 +00001248 switch (opcode) {
1249 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001250 case sUsePAM:
1251 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001252 goto parse_flag;
1253
1254 /* Standard Options */
1255 case sBadOption:
1256 return -1;
1257 case sPort:
1258 /* ignore ports from configfile if cmdline specifies ports */
1259 if (options->ports_from_cmdline)
1260 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001261 if (options->num_ports >= MAX_PORTS)
1262 fatal("%s line %d: too many ports.",
1263 filename, linenum);
1264 arg = strdelim(&cp);
1265 if (!arg || *arg == '\0')
1266 fatal("%s line %d: missing port number.",
1267 filename, linenum);
1268 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001269 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001270 fatal("%s line %d: Badly formatted port number.",
1271 filename, linenum);
1272 break;
1273
Ben Lindstromade03f62001-12-06 18:22:17 +00001274 case sLoginGraceTime:
1275 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001276 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001277 arg = strdelim(&cp);
1278 if (!arg || *arg == '\0')
1279 fatal("%s line %d: missing time value.",
1280 filename, linenum);
1281 if ((value = convtime(arg)) == -1)
1282 fatal("%s line %d: invalid time value.",
1283 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001284 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001285 *intptr = value;
1286 break;
1287
Ben Lindstromade03f62001-12-06 18:22:17 +00001288 case sListenAddress:
1289 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001290 if (arg == NULL || *arg == '\0')
1291 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001292 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001293 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1294 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1295 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001296 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001297 p = arg;
1298 } else {
1299 p = hpdelim(&arg);
1300 if (p == NULL)
1301 fatal("%s line %d: bad address:port usage",
1302 filename, linenum);
1303 p = cleanhostname(p);
1304 if (arg == NULL)
1305 port = 0;
1306 else if ((port = a2port(arg)) <= 0)
1307 fatal("%s line %d: bad port number",
1308 filename, linenum);
1309 }
1310 /* Optional routing table */
1311 arg2 = NULL;
1312 if ((arg = strdelim(&cp)) != NULL) {
1313 if (strcmp(arg, "rdomain") != 0 ||
1314 (arg2 = strdelim(&cp)) == NULL)
1315 fatal("%s line %d: bad ListenAddress syntax",
1316 filename, linenum);
1317 if (!valid_rdomain(arg2))
1318 fatal("%s line %d: bad routing domain",
1319 filename, linenum);
1320 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001321
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001322 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001323
Ben Lindstromade03f62001-12-06 18:22:17 +00001324 break;
1325
Darren Tucker0f383232005-01-20 10:57:56 +11001326 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001327 intptr = &options->address_family;
1328 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001329 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001330 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001331 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001332 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001333 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001334 value = -1;
1335 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1336 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1337 value = multistate_ptr[i].value;
1338 break;
1339 }
1340 }
1341 if (value == -1)
1342 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001343 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001344 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001345 *intptr = value;
1346 break;
1347
Ben Lindstromade03f62001-12-06 18:22:17 +00001348 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001349 arg = strdelim(&cp);
1350 if (!arg || *arg == '\0')
1351 fatal("%s line %d: missing file name.",
1352 filename, linenum);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001353 if (*activep)
1354 servconf_add_hostkey(filename, linenum, options, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001355 break;
1356
Damien Miller85b45e02013-07-20 13:21:52 +10001357 case sHostKeyAgent:
1358 charptr = &options->host_key_agent;
1359 arg = strdelim(&cp);
1360 if (!arg || *arg == '\0')
1361 fatal("%s line %d: missing socket name.",
1362 filename, linenum);
1363 if (*activep && *charptr == NULL)
1364 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1365 xstrdup(arg) : derelativise_path(arg);
1366 break;
1367
Damien Miller0a80ca12010-02-27 07:55:05 +11001368 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001369 arg = strdelim(&cp);
1370 if (!arg || *arg == '\0')
1371 fatal("%s line %d: missing file name.",
1372 filename, linenum);
1373 if (*activep)
1374 servconf_add_hostcert(filename, linenum, options, arg);
1375 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001376
Ben Lindstromade03f62001-12-06 18:22:17 +00001377 case sPidFile:
1378 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001379 parse_filename:
1380 arg = strdelim(&cp);
1381 if (!arg || *arg == '\0')
1382 fatal("%s line %d: missing file name.",
1383 filename, linenum);
1384 if (*activep && *charptr == NULL) {
1385 *charptr = derelativise_path(arg);
1386 /* increase optional counter */
1387 if (intptr != NULL)
1388 *intptr = *intptr + 1;
1389 }
1390 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001391
1392 case sPermitRootLogin:
1393 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001394 multistate_ptr = multistate_permitrootlogin;
1395 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001396
1397 case sIgnoreRhosts:
1398 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001399 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001400 multistate_ptr = multistate_flag;
1401 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001402
1403 case sIgnoreUserKnownHosts:
1404 intptr = &options->ignore_user_known_hosts;
1405 goto parse_flag;
1406
Ben Lindstromade03f62001-12-06 18:22:17 +00001407 case sHostbasedAuthentication:
1408 intptr = &options->hostbased_authentication;
1409 goto parse_flag;
1410
1411 case sHostbasedUsesNameFromPacketOnly:
1412 intptr = &options->hostbased_uses_name_from_packet_only;
1413 goto parse_flag;
1414
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001415 case sHostbasedAcceptedKeyTypes:
1416 charptr = &options->hostbased_key_types;
1417 parse_keytypes:
1418 arg = strdelim(&cp);
1419 if (!arg || *arg == '\0')
1420 fatal("%s line %d: Missing argument.",
1421 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001422 if (*arg != '-' &&
1423 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001424 fatal("%s line %d: Bad key types '%s'.",
1425 filename, linenum, arg ? arg : "<NONE>");
1426 if (*activep && *charptr == NULL)
1427 *charptr = xstrdup(arg);
1428 break;
1429
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001430 case sHostKeyAlgorithms:
1431 charptr = &options->hostkeyalgorithms;
1432 goto parse_keytypes;
1433
Ben Lindstromade03f62001-12-06 18:22:17 +00001434 case sPubkeyAuthentication:
1435 intptr = &options->pubkey_authentication;
1436 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001437
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001438 case sPubkeyAcceptedKeyTypes:
1439 charptr = &options->pubkey_key_types;
1440 goto parse_keytypes;
1441
Ben Lindstromade03f62001-12-06 18:22:17 +00001442 case sKerberosAuthentication:
1443 intptr = &options->kerberos_authentication;
1444 goto parse_flag;
1445
1446 case sKerberosOrLocalPasswd:
1447 intptr = &options->kerberos_or_local_passwd;
1448 goto parse_flag;
1449
1450 case sKerberosTicketCleanup:
1451 intptr = &options->kerberos_ticket_cleanup;
1452 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001453
Darren Tucker22ef5082003-12-31 11:37:34 +11001454 case sKerberosGetAFSToken:
1455 intptr = &options->kerberos_get_afs_token;
1456 goto parse_flag;
1457
Darren Tucker0efd1552003-08-26 11:49:55 +10001458 case sGssAuthentication:
1459 intptr = &options->gss_authentication;
1460 goto parse_flag;
1461
1462 case sGssCleanupCreds:
1463 intptr = &options->gss_cleanup_creds;
1464 goto parse_flag;
1465
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001466 case sGssStrictAcceptor:
1467 intptr = &options->gss_strict_acceptor;
1468 goto parse_flag;
1469
Ben Lindstromade03f62001-12-06 18:22:17 +00001470 case sPasswordAuthentication:
1471 intptr = &options->password_authentication;
1472 goto parse_flag;
1473
1474 case sKbdInteractiveAuthentication:
1475 intptr = &options->kbd_interactive_authentication;
1476 goto parse_flag;
1477
1478 case sChallengeResponseAuthentication:
1479 intptr = &options->challenge_response_authentication;
1480 goto parse_flag;
1481
1482 case sPrintMotd:
1483 intptr = &options->print_motd;
1484 goto parse_flag;
1485
1486 case sPrintLastLog:
1487 intptr = &options->print_lastlog;
1488 goto parse_flag;
1489
1490 case sX11Forwarding:
1491 intptr = &options->x11_forwarding;
1492 goto parse_flag;
1493
1494 case sX11DisplayOffset:
1495 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001496 parse_int:
1497 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001498 if ((errstr = atoi_err(arg, &value)) != NULL)
1499 fatal("%s line %d: integer value %s.",
1500 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001501 if (*activep && *intptr == -1)
1502 *intptr = value;
1503 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001504
Damien Miller95c249f2002-02-05 12:11:34 +11001505 case sX11UseLocalhost:
1506 intptr = &options->x11_use_localhost;
1507 goto parse_flag;
1508
Ben Lindstromade03f62001-12-06 18:22:17 +00001509 case sXAuthLocation:
1510 charptr = &options->xauth_location;
1511 goto parse_filename;
1512
Damien Miller5ff30c62013-10-30 22:21:50 +11001513 case sPermitTTY:
1514 intptr = &options->permit_tty;
1515 goto parse_flag;
1516
Damien Miller72e6b5c2014-07-04 09:00:04 +10001517 case sPermitUserRC:
1518 intptr = &options->permit_user_rc;
1519 goto parse_flag;
1520
Ben Lindstromade03f62001-12-06 18:22:17 +00001521 case sStrictModes:
1522 intptr = &options->strict_modes;
1523 goto parse_flag;
1524
Damien Miller12c150e2003-12-17 16:31:10 +11001525 case sTCPKeepAlive:
1526 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001527 goto parse_flag;
1528
1529 case sEmptyPasswd:
1530 intptr = &options->permit_empty_passwd;
1531 goto parse_flag;
1532
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001533 case sPermitUserEnvironment:
1534 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001535 charptr = &options->permit_user_env_whitelist;
1536 arg = strdelim(&cp);
1537 if (!arg || *arg == '\0')
1538 fatal("%s line %d: missing argument.",
1539 filename, linenum);
1540 value = 0;
1541 p = NULL;
1542 if (strcmp(arg, "yes") == 0)
1543 value = 1;
1544 else if (strcmp(arg, "no") == 0)
1545 value = 0;
1546 else {
1547 /* Pattern-list specified */
1548 value = 1;
1549 p = xstrdup(arg);
1550 }
1551 if (*activep && *intptr == -1) {
1552 *intptr = value;
1553 *charptr = p;
1554 p = NULL;
1555 }
1556 free(p);
1557 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001558
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001559 case sCompression:
1560 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001561 multistate_ptr = multistate_compression;
1562 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001563
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001564 case sRekeyLimit:
1565 arg = strdelim(&cp);
1566 if (!arg || *arg == '\0')
1567 fatal("%.200s line %d: Missing argument.", filename,
1568 linenum);
1569 if (strcmp(arg, "default") == 0) {
1570 val64 = 0;
1571 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001572 if (scan_scaled(arg, &val64) == -1)
1573 fatal("%.200s line %d: Bad number '%s': %s",
1574 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001575 if (val64 != 0 && val64 < 16)
1576 fatal("%.200s line %d: RekeyLimit too small",
1577 filename, linenum);
1578 }
1579 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001580 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001581 if (cp != NULL) { /* optional rekey interval present */
1582 if (strcmp(cp, "none") == 0) {
1583 (void)strdelim(&cp); /* discard */
1584 break;
1585 }
1586 intptr = &options->rekey_interval;
1587 goto parse_time;
1588 }
1589 break;
1590
Ben Lindstromade03f62001-12-06 18:22:17 +00001591 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001592 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001593 multistate_ptr = multistate_gatewayports;
1594 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001595
Damien Miller3a961dc2003-06-03 10:25:48 +10001596 case sUseDNS:
1597 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001598 goto parse_flag;
1599
1600 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001601 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001602 arg = strdelim(&cp);
1603 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001604 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001605 fatal("%.200s line %d: unsupported log facility '%s'",
1606 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001607 if (*log_facility_ptr == -1)
1608 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001609 break;
1610
1611 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001612 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001613 arg = strdelim(&cp);
1614 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001615 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001616 fatal("%.200s line %d: unsupported log level '%s'",
1617 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001618 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001619 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001620 break;
1621
1622 case sAllowTcpForwarding:
1623 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001624 multistate_ptr = multistate_tcpfwd;
1625 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001626
Damien Miller7acefbb2014-07-18 14:11:24 +10001627 case sAllowStreamLocalForwarding:
1628 intptr = &options->allow_streamlocal_forwarding;
1629 multistate_ptr = multistate_tcpfwd;
1630 goto parse_multistate;
1631
Damien Miller4f755cd2008-05-19 14:57:41 +10001632 case sAllowAgentForwarding:
1633 intptr = &options->allow_agent_forwarding;
1634 goto parse_flag;
1635
djm@openbsd.org7844f352016-11-30 03:00:05 +00001636 case sDisableForwarding:
1637 intptr = &options->disable_forwarding;
1638 goto parse_flag;
1639
Ben Lindstromade03f62001-12-06 18:22:17 +00001640 case sAllowUsers:
1641 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001642 if (match_user(NULL, NULL, NULL, arg) == -1)
1643 fatal("%s line %d: invalid AllowUsers pattern: "
1644 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001645 if (!*activep)
1646 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001647 array_append(filename, linenum, "AllowUsers",
1648 &options->allow_users, &options->num_allow_users,
1649 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001650 }
1651 break;
1652
1653 case sDenyUsers:
1654 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001655 if (match_user(NULL, NULL, NULL, arg) == -1)
1656 fatal("%s line %d: invalid DenyUsers pattern: "
1657 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001658 if (!*activep)
1659 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001660 array_append(filename, linenum, "DenyUsers",
1661 &options->deny_users, &options->num_deny_users,
1662 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001663 }
1664 break;
1665
1666 case sAllowGroups:
1667 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001668 if (!*activep)
1669 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001670 array_append(filename, linenum, "AllowGroups",
1671 &options->allow_groups, &options->num_allow_groups,
1672 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001673 }
1674 break;
1675
1676 case sDenyGroups:
1677 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001678 if (!*activep)
1679 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001680 array_append(filename, linenum, "DenyGroups",
1681 &options->deny_groups, &options->num_deny_groups,
1682 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001683 }
1684 break;
1685
1686 case sCiphers:
1687 arg = strdelim(&cp);
1688 if (!arg || *arg == '\0')
1689 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001690 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001691 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1692 filename, linenum, arg ? arg : "<NONE>");
1693 if (options->ciphers == NULL)
1694 options->ciphers = xstrdup(arg);
1695 break;
1696
1697 case sMacs:
1698 arg = strdelim(&cp);
1699 if (!arg || *arg == '\0')
1700 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001701 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001702 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1703 filename, linenum, arg ? arg : "<NONE>");
1704 if (options->macs == NULL)
1705 options->macs = xstrdup(arg);
1706 break;
1707
Damien Millerd5f62bf2010-09-24 22:11:14 +10001708 case sKexAlgorithms:
1709 arg = strdelim(&cp);
1710 if (!arg || *arg == '\0')
1711 fatal("%s line %d: Missing argument.",
1712 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001713 if (*arg != '-' &&
1714 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001715 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1716 filename, linenum, arg ? arg : "<NONE>");
1717 if (options->kex_algorithms == NULL)
1718 options->kex_algorithms = xstrdup(arg);
1719 break;
1720
Ben Lindstromade03f62001-12-06 18:22:17 +00001721 case sSubsystem:
1722 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1723 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001724 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001725 }
1726 arg = strdelim(&cp);
1727 if (!arg || *arg == '\0')
1728 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001729 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001730 if (!*activep) {
1731 arg = strdelim(&cp);
1732 break;
1733 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001734 for (i = 0; i < options->num_subsystems; i++)
1735 if (strcmp(arg, options->subsystem_name[i]) == 0)
1736 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001737 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001738 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1739 arg = strdelim(&cp);
1740 if (!arg || *arg == '\0')
1741 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001742 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001743 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001744
1745 /* Collect arguments (separate to executable) */
1746 p = xstrdup(arg);
1747 len = strlen(p) + 1;
1748 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1749 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001750 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001751 strlcat(p, " ", len);
1752 strlcat(p, arg, len);
1753 }
1754 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001755 options->num_subsystems++;
1756 break;
1757
1758 case sMaxStartups:
1759 arg = strdelim(&cp);
1760 if (!arg || *arg == '\0')
1761 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001762 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001763 if ((n = sscanf(arg, "%d:%d:%d",
1764 &options->max_startups_begin,
1765 &options->max_startups_rate,
1766 &options->max_startups)) == 3) {
1767 if (options->max_startups_begin >
1768 options->max_startups ||
1769 options->max_startups_rate > 100 ||
1770 options->max_startups_rate < 1)
1771 fatal("%s line %d: Illegal MaxStartups spec.",
1772 filename, linenum);
1773 } else if (n != 1)
1774 fatal("%s line %d: Illegal MaxStartups spec.",
1775 filename, linenum);
1776 else
1777 options->max_startups = options->max_startups_begin;
1778 break;
1779
Darren Tucker89413db2004-05-24 10:36:23 +10001780 case sMaxAuthTries:
1781 intptr = &options->max_authtries;
1782 goto parse_int;
1783
Damien Miller7207f642008-05-19 15:34:50 +10001784 case sMaxSessions:
1785 intptr = &options->max_sessions;
1786 goto parse_int;
1787
Ben Lindstromade03f62001-12-06 18:22:17 +00001788 case sBanner:
1789 charptr = &options->banner;
1790 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001791
Ben Lindstromade03f62001-12-06 18:22:17 +00001792 /*
1793 * These options can contain %X options expanded at
1794 * connect time, so that you can specify paths like:
1795 *
1796 * AuthorizedKeysFile /etc/ssh_keys/%u
1797 */
1798 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001799 if (*activep && options->num_authkeys_files == 0) {
1800 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001801 arg = tilde_expand_filename(arg, getuid());
1802 array_append(filename, linenum,
1803 "AuthorizedKeysFile",
1804 &options->authorized_keys_files,
1805 &options->num_authkeys_files, arg);
1806 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001807 }
1808 }
1809 return 0;
1810
Damien Miller30da3442010-05-10 11:58:03 +10001811 case sAuthorizedPrincipalsFile:
1812 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001813 arg = strdelim(&cp);
1814 if (!arg || *arg == '\0')
1815 fatal("%s line %d: missing file name.",
1816 filename, linenum);
1817 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001818 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001819 /* increase optional counter */
1820 if (intptr != NULL)
1821 *intptr = *intptr + 1;
1822 }
1823 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001824
1825 case sClientAliveInterval:
1826 intptr = &options->client_alive_interval;
1827 goto parse_time;
1828
1829 case sClientAliveCountMax:
1830 intptr = &options->client_alive_count_max;
1831 goto parse_int;
1832
Darren Tucker46bc0752004-05-02 22:11:30 +10001833 case sAcceptEnv:
1834 while ((arg = strdelim(&cp)) && *arg != '\0') {
1835 if (strchr(arg, '=') != NULL)
1836 fatal("%s line %d: Invalid environment name.",
1837 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001838 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001839 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001840 array_append(filename, linenum, "AcceptEnv",
1841 &options->accept_env, &options->num_accept_env,
1842 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001843 }
1844 break;
1845
djm@openbsd.org28013752018-06-09 03:03:10 +00001846 case sSetEnv:
1847 uvalue = options->num_setenv;
1848 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1849 if (strchr(arg, '=') == NULL)
1850 fatal("%s line %d: Invalid environment.",
1851 filename, linenum);
1852 if (!*activep || uvalue != 0)
1853 continue;
1854 array_append(filename, linenum, "SetEnv",
1855 &options->setenv, &options->num_setenv, arg);
1856 }
1857 break;
1858
Damien Millerd27b9472005-12-13 19:29:02 +11001859 case sPermitTunnel:
1860 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001861 arg = strdelim(&cp);
1862 if (!arg || *arg == '\0')
1863 fatal("%s line %d: Missing yes/point-to-point/"
1864 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001865 value = -1;
1866 for (i = 0; tunmode_desc[i].val != -1; i++)
1867 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1868 value = tunmode_desc[i].val;
1869 break;
1870 }
1871 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001872 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1873 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001874 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001875 *intptr = value;
1876 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001877
Darren Tucker45150472006-07-12 22:34:17 +10001878 case sMatch:
1879 if (cmdline)
1880 fatal("Match directive not supported as a command-line "
1881 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001882 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001883 if (value < 0)
1884 fatal("%s line %d: Bad Match condition", filename,
1885 linenum);
1886 *activep = value;
1887 break;
1888
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001889 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001890 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001891 if (opcode == sPermitListen) {
1892 uintptr = &options->num_permitted_listens;
1893 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001894 } else {
1895 uintptr = &options->num_permitted_opens;
1896 chararrayptr = &options->permitted_opens;
1897 }
Damien Miller9b439df2006-07-24 14:04:00 +10001898 arg = strdelim(&cp);
1899 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001900 fatal("%s line %d: missing %s specification",
1901 filename, linenum, lookup_opcode_name(opcode));
1902 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001903 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001904 if (*activep && uvalue == 0) {
1905 *uintptr = 1;
1906 *chararrayptr = xcalloc(1,
1907 sizeof(**chararrayptr));
1908 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001909 }
Damien Millerc6081482012-04-22 11:18:53 +10001910 break;
1911 }
Damien Millera765cf42006-07-24 14:08:13 +10001912 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001913 if (opcode == sPermitListen &&
1914 strchr(arg, ':') == NULL) {
1915 /*
1916 * Allow bare port number for PermitListen
1917 * to indicate a wildcard listen host.
1918 */
1919 xasprintf(&arg2, "*:%s", arg);
1920 } else {
1921 arg2 = xstrdup(arg);
1922 p = hpdelim(&arg);
1923 if (p == NULL) {
1924 fatal("%s line %d: missing host in %s",
1925 filename, linenum,
1926 lookup_opcode_name(opcode));
1927 }
1928 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001929 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001930 if (arg == NULL ||
1931 ((port = permitopen_port(arg)) < 0)) {
1932 fatal("%s line %d: bad port number in %s",
1933 filename, linenum,
1934 lookup_opcode_name(opcode));
1935 }
1936 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001937 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001938 lookup_opcode_name(opcode),
1939 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001940 }
1941 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001942 }
Damien Miller9b439df2006-07-24 14:04:00 +10001943 break;
1944
Damien Millere2754432006-07-24 14:06:47 +10001945 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001946 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001947 fatal("%.200s line %d: Missing argument.", filename,
1948 linenum);
1949 len = strspn(cp, WHITESPACE);
1950 if (*activep && options->adm_forced_command == NULL)
1951 options->adm_forced_command = xstrdup(cp + len);
1952 return 0;
1953
Damien Millerd8cb1f12008-02-10 22:40:12 +11001954 case sChrootDirectory:
1955 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001956
1957 arg = strdelim(&cp);
1958 if (!arg || *arg == '\0')
1959 fatal("%s line %d: missing file name.",
1960 filename, linenum);
1961 if (*activep && *charptr == NULL)
1962 *charptr = xstrdup(arg);
1963 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001964
Damien Miller1aed65e2010-03-04 21:53:35 +11001965 case sTrustedUserCAKeys:
1966 charptr = &options->trusted_user_ca_keys;
1967 goto parse_filename;
1968
1969 case sRevokedKeys:
1970 charptr = &options->revoked_keys_file;
1971 goto parse_filename;
1972
Damien Miller0dac6fb2010-11-20 15:19:38 +11001973 case sIPQoS:
1974 arg = strdelim(&cp);
1975 if ((value = parse_ipqos(arg)) == -1)
1976 fatal("%s line %d: Bad IPQoS value: %s",
1977 filename, linenum, arg);
1978 arg = strdelim(&cp);
1979 if (arg == NULL)
1980 value2 = value;
1981 else if ((value2 = parse_ipqos(arg)) == -1)
1982 fatal("%s line %d: Bad IPQoS value: %s",
1983 filename, linenum, arg);
1984 if (*activep) {
1985 options->ip_qos_interactive = value;
1986 options->ip_qos_bulk = value2;
1987 }
1988 break;
1989
Damien Miller23528812012-04-22 11:24:43 +10001990 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001991 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001992 fatal("%.200s line %d: Missing argument.", filename,
1993 linenum);
1994 len = strspn(cp, WHITESPACE);
1995 if (*activep && options->version_addendum == NULL) {
1996 if (strcasecmp(cp + len, "none") == 0)
1997 options->version_addendum = xstrdup("");
1998 else if (strchr(cp + len, '\r') != NULL)
1999 fatal("%.200s line %d: Invalid argument",
2000 filename, linenum);
2001 else
2002 options->version_addendum = xstrdup(cp + len);
2003 }
2004 return 0;
2005
Damien Miller09d3e122012-10-31 08:58:58 +11002006 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002007 if (cp == NULL)
2008 fatal("%.200s line %d: Missing argument.", filename,
2009 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002010 len = strspn(cp, WHITESPACE);
2011 if (*activep && options->authorized_keys_command == NULL) {
2012 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2013 fatal("%.200s line %d: AuthorizedKeysCommand "
2014 "must be an absolute path",
2015 filename, linenum);
2016 options->authorized_keys_command = xstrdup(cp + len);
2017 }
2018 return 0;
2019
2020 case sAuthorizedKeysCommandUser:
2021 charptr = &options->authorized_keys_command_user;
2022
2023 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002024 if (!arg || *arg == '\0')
2025 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2026 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002027 if (*activep && *charptr == NULL)
2028 *charptr = xstrdup(arg);
2029 break;
2030
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002031 case sAuthorizedPrincipalsCommand:
2032 if (cp == NULL)
2033 fatal("%.200s line %d: Missing argument.", filename,
2034 linenum);
2035 len = strspn(cp, WHITESPACE);
2036 if (*activep &&
2037 options->authorized_principals_command == NULL) {
2038 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2039 fatal("%.200s line %d: "
2040 "AuthorizedPrincipalsCommand must be "
2041 "an absolute path", filename, linenum);
2042 options->authorized_principals_command =
2043 xstrdup(cp + len);
2044 }
2045 return 0;
2046
2047 case sAuthorizedPrincipalsCommandUser:
2048 charptr = &options->authorized_principals_command_user;
2049
2050 arg = strdelim(&cp);
2051 if (!arg || *arg == '\0')
2052 fatal("%s line %d: missing "
2053 "AuthorizedPrincipalsCommandUser argument.",
2054 filename, linenum);
2055 if (*activep && *charptr == NULL)
2056 *charptr = xstrdup(arg);
2057 break;
2058
Damien Millera6e3f012012-11-04 23:21:40 +11002059 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002060 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002061 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002062 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002063 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002064 if (strcmp(arg, "any") == 0) {
2065 if (options->num_auth_methods > 0) {
2066 fatal("%s line %d: \"any\" "
2067 "must appear alone in "
2068 "AuthenticationMethods",
2069 filename, linenum);
2070 }
2071 value = 1;
2072 } else if (value) {
2073 fatal("%s line %d: \"any\" must appear "
2074 "alone in AuthenticationMethods",
2075 filename, linenum);
2076 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002077 fatal("%s line %d: invalid "
2078 "authentication method list.",
2079 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002080 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002081 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002082 if (!*activep)
2083 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002084 array_append(filename, linenum,
2085 "AuthenticationMethods",
2086 &options->auth_methods,
2087 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002088 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002089 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002090 fatal("%s line %d: no AuthenticationMethods "
2091 "specified", filename, linenum);
2092 }
Damien Millera6e3f012012-11-04 23:21:40 +11002093 }
2094 return 0;
2095
Damien Miller7acefbb2014-07-18 14:11:24 +10002096 case sStreamLocalBindMask:
2097 arg = strdelim(&cp);
2098 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002099 fatal("%s line %d: missing StreamLocalBindMask "
2100 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002101 /* Parse mode in octal format */
2102 value = strtol(arg, &p, 8);
2103 if (arg == p || value < 0 || value > 0777)
2104 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002105 if (*activep)
2106 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002107 break;
2108
2109 case sStreamLocalBindUnlink:
2110 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2111 goto parse_flag;
2112
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002113 case sFingerprintHash:
2114 arg = strdelim(&cp);
2115 if (!arg || *arg == '\0')
2116 fatal("%.200s line %d: Missing argument.",
2117 filename, linenum);
2118 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2119 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2120 filename, linenum, arg);
2121 if (*activep)
2122 options->fingerprint_hash = value;
2123 break;
2124
djm@openbsd.org8f574952017-06-24 06:34:38 +00002125 case sExposeAuthInfo:
2126 intptr = &options->expose_userauth_info;
2127 goto parse_flag;
2128
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002129 case sRDomain:
2130 charptr = &options->routing_domain;
2131 arg = strdelim(&cp);
2132 if (!arg || *arg == '\0')
2133 fatal("%.200s line %d: Missing argument.",
2134 filename, linenum);
2135 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2136 !valid_rdomain(arg))
2137 fatal("%s line %d: bad routing domain",
2138 filename, linenum);
2139 if (*activep && *charptr == NULL)
2140 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002141 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002142
Ben Lindstromade03f62001-12-06 18:22:17 +00002143 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002144 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002145 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002146 do_log2(opcode == sIgnore ?
2147 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2148 "%s line %d: %s option %s", filename, linenum,
2149 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002150 while (arg)
2151 arg = strdelim(&cp);
2152 break;
2153
Ben Lindstromade03f62001-12-06 18:22:17 +00002154 default:
2155 fatal("%s line %d: Missing handler for opcode %s (%d)",
2156 filename, linenum, arg, opcode);
2157 }
2158 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2159 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2160 filename, linenum, arg);
2161 return 0;
2162}
2163
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002164/* Reads the server configuration file. */
2165
Damien Miller4af51302000-04-16 11:18:38 +10002166void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002167load_server_config(const char *filename, struct sshbuf *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002168{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002169 char *line = NULL, *cp;
2170 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002171 FILE *f;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002172 int r, lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002173
Darren Tucker645ab752004-06-25 13:33:20 +10002174 debug2("%s: filename %s", __func__, filename);
2175 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002176 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002177 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002178 }
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002179 sshbuf_reset(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002180 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002181 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002182 /*
2183 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002184 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002185 * line numbers later for error messages
2186 */
2187 if ((cp = strchr(line, '#')) != NULL)
2188 memcpy(cp, "\n", 2);
2189 cp = line + strspn(line, " \t\r");
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002190 if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2191 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002192 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002193 free(line);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002194 if ((r = sshbuf_put_u8(conf, 0)) != 0)
2195 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002196 fclose(f);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002197 debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002198}
2199
2200void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002201parse_server_match_config(ServerOptions *options,
2202 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002203{
Darren Tucker45150472006-07-12 22:34:17 +10002204 ServerOptions mo;
2205
2206 initialize_server_options(&mo);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002207 parse_server_config(&mo, "reprocess config", cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002208 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002209}
2210
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002211int parse_server_match_testspec(struct connection_info *ci, char *spec)
2212{
2213 char *p;
2214
2215 while ((p = strsep(&spec, ",")) && *p != '\0') {
2216 if (strncmp(p, "addr=", 5) == 0) {
2217 ci->address = xstrdup(p + 5);
2218 } else if (strncmp(p, "host=", 5) == 0) {
2219 ci->host = xstrdup(p + 5);
2220 } else if (strncmp(p, "user=", 5) == 0) {
2221 ci->user = xstrdup(p + 5);
2222 } else if (strncmp(p, "laddr=", 6) == 0) {
2223 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002224 } else if (strncmp(p, "rdomain=", 8) == 0) {
2225 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002226 } else if (strncmp(p, "lport=", 6) == 0) {
2227 ci->lport = a2port(p + 6);
2228 if (ci->lport == -1) {
2229 fprintf(stderr, "Invalid port '%s' in test mode"
2230 " specification %s\n", p+6, p);
2231 return -1;
2232 }
2233 } else {
2234 fprintf(stderr, "Invalid test mode specification %s\n",
2235 p);
2236 return -1;
2237 }
2238 }
2239 return 0;
2240}
2241
2242/*
Darren Tucker1629c072007-02-19 22:25:37 +11002243 * Copy any supported values that are set.
2244 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002245 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002246 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002247 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002248 */
Darren Tucker45150472006-07-12 22:34:17 +10002249void
Darren Tucker1629c072007-02-19 22:25:37 +11002250copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002251{
Damien Miller534b2cc2013-12-05 14:07:27 +11002252#define M_CP_INTOPT(n) do {\
2253 if (src->n != -1) \
2254 dst->n = src->n; \
2255} while (0)
2256
Darren Tucker1629c072007-02-19 22:25:37 +11002257 M_CP_INTOPT(password_authentication);
2258 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002259 M_CP_INTOPT(pubkey_authentication);
2260 M_CP_INTOPT(kerberos_authentication);
2261 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002262 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002263 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002264 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002265 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002266
2267 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002268 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002269 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002270 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002271 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002272 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002273 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002274 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002275 M_CP_INTOPT(x11_display_offset);
2276 M_CP_INTOPT(x11_forwarding);
2277 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002278 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002279 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002280 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002281 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002282 M_CP_INTOPT(client_alive_count_max);
2283 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002284 M_CP_INTOPT(ip_qos_interactive);
2285 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002286 M_CP_INTOPT(rekey_limit);
2287 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002288 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002289
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002290 /*
2291 * The bind_mask is a mode_t that may be unsigned, so we can't use
2292 * M_CP_INTOPT - it does a signed comparison that causes compiler
2293 * warnings.
2294 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002295 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002296 dst->fwd_opts.streamlocal_bind_mask =
2297 src->fwd_opts.streamlocal_bind_mask;
2298 }
2299
Damien Miller534b2cc2013-12-05 14:07:27 +11002300 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2301#define M_CP_STROPT(n) do {\
2302 if (src->n != NULL && dst->n != src->n) { \
2303 free(dst->n); \
2304 dst->n = src->n; \
2305 } \
2306} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002307#define M_CP_STRARRAYOPT(s, num_s) do {\
2308 u_int i; \
2309 if (src->num_s != 0) { \
2310 for (i = 0; i < dst->num_s; i++) \
2311 free(dst->s[i]); \
2312 free(dst->s); \
2313 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2314 for (i = 0; i < src->num_s; i++) \
2315 dst->s[i] = xstrdup(src->s[i]); \
2316 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002317 } \
2318} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002319
Damien Millerf2e407e2011-05-20 19:04:14 +10002320 /* See comment in servconf.h */
2321 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002322
djm@openbsd.orged085102015-10-29 08:05:01 +00002323 /* Arguments that accept '+...' need to be expanded */
2324 assemble_algorithms(dst);
2325
Damien Millerc2411902011-05-20 19:03:49 +10002326 /*
2327 * The only things that should be below this point are string options
2328 * which are only used after authentication.
2329 */
Damien Miller5d74e582011-05-20 19:03:31 +10002330 if (preauth)
2331 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002332
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002333 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002334 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002335 if (option_clear_or_none(dst->adm_forced_command)) {
2336 free(dst->adm_forced_command);
2337 dst->adm_forced_command = NULL;
2338 }
Damien Miller5d74e582011-05-20 19:03:31 +10002339 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002340 if (option_clear_or_none(dst->chroot_directory)) {
2341 free(dst->chroot_directory);
2342 dst->chroot_directory = NULL;
2343 }
Darren Tucker45150472006-07-12 22:34:17 +10002344}
2345
Darren Tucker1629c072007-02-19 22:25:37 +11002346#undef M_CP_INTOPT
2347#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002348#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002349
Darren Tucker45150472006-07-12 22:34:17 +10002350void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002351parse_server_config(ServerOptions *options, const char *filename,
2352 struct sshbuf *conf, struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002353{
2354 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002355 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002356
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002357 debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002358
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002359 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2360 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002361 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002362 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002363 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002364 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002365 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002366 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002367 }
Darren Tuckera627d422013-06-02 07:31:17 +10002368 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002369 if (bad_options > 0)
2370 fatal("%s: terminating, %d bad configuration options",
2371 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002372 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002373}
Darren Tuckere7140f22008-06-10 23:01:51 +10002374
2375static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002376fmt_multistate_int(int val, const struct multistate *m)
2377{
2378 u_int i;
2379
2380 for (i = 0; m[i].key != NULL; i++) {
2381 if (m[i].value == val)
2382 return m[i].key;
2383 }
2384 return "UNKNOWN";
2385}
2386
2387static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002388fmt_intarg(ServerOpCodes code, int val)
2389{
Damien Miller82c55872011-06-23 08:20:30 +10002390 if (val == -1)
2391 return "unset";
2392 switch (code) {
2393 case sAddressFamily:
2394 return fmt_multistate_int(val, multistate_addressfamily);
2395 case sPermitRootLogin:
2396 return fmt_multistate_int(val, multistate_permitrootlogin);
2397 case sGatewayPorts:
2398 return fmt_multistate_int(val, multistate_gatewayports);
2399 case sCompression:
2400 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002401 case sAllowTcpForwarding:
2402 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002403 case sAllowStreamLocalForwarding:
2404 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002405 case sFingerprintHash:
2406 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002407 default:
2408 switch (val) {
2409 case 0:
2410 return "no";
2411 case 1:
2412 return "yes";
2413 default:
2414 return "UNKNOWN";
2415 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002416 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002417}
2418
Darren Tuckere7140f22008-06-10 23:01:51 +10002419static void
2420dump_cfg_int(ServerOpCodes code, int val)
2421{
2422 printf("%s %d\n", lookup_opcode_name(code), val);
2423}
2424
2425static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002426dump_cfg_oct(ServerOpCodes code, int val)
2427{
2428 printf("%s 0%o\n", lookup_opcode_name(code), val);
2429}
2430
2431static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002432dump_cfg_fmtint(ServerOpCodes code, int val)
2433{
2434 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2435}
2436
2437static void
2438dump_cfg_string(ServerOpCodes code, const char *val)
2439{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002440 printf("%s %s\n", lookup_opcode_name(code),
2441 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002442}
2443
2444static void
2445dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2446{
2447 u_int i;
2448
2449 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002450 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2451}
2452
2453static void
2454dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2455{
2456 u_int i;
2457
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002458 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002459 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002460 printf("%s", lookup_opcode_name(code));
2461 for (i = 0; i < count; i++)
2462 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002463 if (code == sAuthenticationMethods && count == 0)
2464 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002465 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002466}
2467
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002468static char *
2469format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002470{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002471 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002472 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002473 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002474 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002475
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002476 /*
2477 * ListenAddress must be after Port. add_one_listen_addr pushes
2478 * addresses onto a stack, so to maintain ordering we need to
2479 * print these in reverse order.
2480 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002481 for (ai = la->addrs; ai; ai = ai->ai_next) {
2482 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002483 sizeof(addr), port, sizeof(port),
2484 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002485 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2486 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002487 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002488 laddr2 = laddr1;
2489 if (ai->ai_family == AF_INET6) {
2490 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2491 addr, port,
2492 la->rdomain == NULL ? "" : " rdomain ",
2493 la->rdomain == NULL ? "" : la->rdomain,
2494 laddr2);
2495 } else {
2496 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2497 addr, port,
2498 la->rdomain == NULL ? "" : " rdomain ",
2499 la->rdomain == NULL ? "" : la->rdomain,
2500 laddr2);
2501 }
2502 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002503 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002504 return laddr1;
2505}
2506
2507void
2508dump_config(ServerOptions *o)
2509{
2510 char *s;
2511 u_int i;
2512
2513 /* these are usually at the top of the config */
2514 for (i = 0; i < o->num_ports; i++)
2515 printf("port %d\n", o->ports[i]);
2516 dump_cfg_fmtint(sAddressFamily, o->address_family);
2517
2518 for (i = 0; i < o->num_listen_addrs; i++) {
2519 s = format_listen_addrs(&o->listen_addrs[i]);
2520 printf("%s", s);
2521 free(s);
2522 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002523
2524 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002525#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002526 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002527#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002528 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002529 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2530 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002531 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002532 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2533 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002534 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002535
2536 /* formatted integer arguments */
2537 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2538 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2539 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002540 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2541 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2542 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002543 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002544#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002545 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2546 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2547 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002548# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002549 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002550# endif
2551#endif
2552#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002553 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2554 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002555#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002556 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2557 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2558 o->kbd_interactive_authentication);
2559 dump_cfg_fmtint(sChallengeResponseAuthentication,
2560 o->challenge_response_authentication);
2561 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002562#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002563 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002564#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002565 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2566 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002567 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002568 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002569 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2570 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2571 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002572 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002573 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002574 dump_cfg_fmtint(sUseDNS, o->use_dns);
2575 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002576 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002577 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002578 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002579 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002580 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002581 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002582
2583 /* string arguments */
2584 dump_cfg_string(sPidFile, o->pid_file);
2585 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002586 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2587 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002588 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002589 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002590 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002591 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2592 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002593 dump_cfg_string(sAuthorizedPrincipalsFile,
2594 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002595 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2596 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002597 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2598 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002599 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2600 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002601 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002602 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002603 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002604 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2605 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002606 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2607 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002608 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2609 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002610 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002611
2612 /* string arguments requiring a lookup */
2613 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2614 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2615
2616 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002617 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2618 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002619 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2620 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002621 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002622 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002623 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2624 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2625 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2626 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2627 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002628 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002629 dump_cfg_strarray_oneline(sAuthenticationMethods,
2630 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002631
2632 /* other arguments */
2633 for (i = 0; i < o->num_subsystems; i++)
2634 printf("subsystem %s %s\n", o->subsystem_name[i],
2635 o->subsystem_args[i]);
2636
2637 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2638 o->max_startups_rate, o->max_startups);
2639
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002640 s = NULL;
2641 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002642 if (tunmode_desc[i].val == o->permit_tun) {
2643 s = tunmode_desc[i].text;
2644 break;
2645 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002646 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002647 dump_cfg_string(sPermitTunnel, s);
2648
Damien Miller91475862011-05-05 14:14:34 +10002649 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2650 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002651
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002652 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002653 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002654
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002655 printf("permitopen");
2656 if (o->num_permitted_opens == 0)
2657 printf(" any");
2658 else {
2659 for (i = 0; i < o->num_permitted_opens; i++)
2660 printf(" %s", o->permitted_opens[i]);
2661 }
2662 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002663 printf("permitlisten");
2664 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002665 printf(" any");
2666 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002667 for (i = 0; i < o->num_permitted_listens; i++)
2668 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002669 }
2670 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002671
2672 if (o->permit_user_env_whitelist == NULL) {
2673 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2674 } else {
2675 printf("permituserenvironment %s\n",
2676 o->permit_user_env_whitelist);
2677 }
2678
Darren Tuckere7140f22008-06-10 23:01:51 +10002679}