blob: a41fdc26a7c22df57222b5d51b2b2b11a8bb5e3a [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org95344c22018-07-03 10:59:35 +00002/* $OpenBSD: servconf.c,v 1.334 2018/07/03 10:59:35 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000018#ifdef HAVE_SYS_SYSCTL_H
19#include <sys/sysctl.h>
20#endif
Damien Millere3b60b52006-07-10 21:08:03 +100021
Damien Miller0dac6fb2010-11-20 15:19:38 +110022#include <netinet/in.h>
23#include <netinet/in_systm.h>
24#include <netinet/ip.h>
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000025#ifdef HAVE_NET_ROUTE_H
26#include <net/route.h>
27#endif
Damien Miller0dac6fb2010-11-20 15:19:38 +110028
Darren Tucker5f96f3b2013-05-16 20:29:28 +100029#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100030#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100031#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100032#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100033#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100034#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100035#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100036#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000037#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100038#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100039#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100040#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100041#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100042#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100043
Damien Millerb84886b2008-05-19 15:05:07 +100044#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100045#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100049#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100050#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100051#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000052#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000053#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100054#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000055#include "kex.h"
56#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100057#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100058#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100059#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100060#include "canohost.h"
61#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110062#include "hostfile.h"
63#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000064#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000065#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000066
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000067static void add_listen_addr(ServerOptions *, const char *,
68 const char *, int);
69static void add_one_listen_addr(ServerOptions *, const char *,
70 const char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110071
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000072/* Use of privilege separation or not */
73extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100074extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000075
Damien Millerd4a8b7e1999-10-27 13:42:43 +100076/* Initializes the server options to their default values. */
77
Damien Miller4af51302000-04-16 11:18:38 +100078void
Damien Miller95def091999-11-25 00:26:21 +110079initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080{
Damien Miller95def091999-11-25 00:26:21 +110081 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110082
83 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100084 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110085
86 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110087 options->num_ports = 0;
88 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000089 options->queued_listen_addrs = NULL;
90 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110091 options->listen_addrs = NULL;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000092 options->num_listen_addrs = 0;
Darren Tucker0f383232005-01-20 10:57:56 +110093 options->address_family = -1;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +000094 options->routing_domain = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110095 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110096 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100097 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100098 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110099 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000100 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->ignore_rhosts = -1;
102 options->ignore_user_known_hosts = -1;
103 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000104 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +1100105 options->x11_forwarding = -1;
106 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +1100107 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100108 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000109 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000110 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100112 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100113 options->log_facility = SYSLOG_FACILITY_NOT_SET;
114 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000115 options->hostbased_authentication = -1;
116 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000117 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000118 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100119 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000120 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->kerberos_authentication = -1;
122 options->kerberos_or_local_passwd = -1;
123 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100124 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000125 options->gss_authentication=-1;
126 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000127 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100128 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100129 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000130 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100131 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000132 options->permit_user_env = -1;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000133 options->permit_user_env_whitelist = NULL;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000134 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000135 options->rekey_limit = -1;
136 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100137 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000138 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000139 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100140 options->num_allow_users = 0;
141 options->num_deny_users = 0;
142 options->num_allow_groups = 0;
143 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000144 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000145 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000146 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000147 options->fwd_opts.gateway_ports = -1;
148 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
149 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000150 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000151 options->max_startups_begin = -1;
152 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000153 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000154 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000155 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000156 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000157 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000158 options->client_alive_interval = -1;
159 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000160 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000161 options->num_accept_env = 0;
djm@openbsd.org28013752018-06-09 03:03:10 +0000162 options->num_setenv = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100163 options->permit_tun = -1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000164 options->permitted_opens = NULL;
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000165 options->permitted_listens = NULL;
Damien Millere2754432006-07-24 14:06:47 +1000166 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100167 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100168 options->authorized_keys_command = NULL;
169 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100170 options->revoked_keys_file = NULL;
171 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000172 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000173 options->authorized_principals_command = NULL;
174 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100175 options->ip_qos_interactive = -1;
176 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000177 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000178 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000179 options->disable_forwarding = -1;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000180 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000181}
182
djm@openbsd.org161cf412014-12-22 07:55:51 +0000183/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
184static int
185option_clear_or_none(const char *o)
186{
187 return o == NULL || strcasecmp(o, "none") == 0;
188}
189
djm@openbsd.orged085102015-10-29 08:05:01 +0000190static void
191assemble_algorithms(ServerOptions *o)
192{
193 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
194 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
195 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
196 kex_assemble_names(KEX_DEFAULT_PK_ALG,
197 &o->hostkeyalgorithms) != 0 ||
198 kex_assemble_names(KEX_DEFAULT_PK_ALG,
199 &o->hostbased_key_types) != 0 ||
200 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
201 fatal("kex_assemble_names failed");
202}
203
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000204static void
205array_append(const char *file, const int line, const char *directive,
206 char ***array, u_int *lp, const char *s)
207{
208
209 if (*lp >= INT_MAX)
210 fatal("%s line %d: Too many %s entries", file, line, directive);
211
212 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
213 (*array)[*lp] = xstrdup(s);
214 (*lp)++;
215}
216
217void
218servconf_add_hostkey(const char *file, const int line,
219 ServerOptions *options, const char *path)
220{
221 char *apath = derelativise_path(path);
222
223 array_append(file, line, "HostKey",
224 &options->host_key_files, &options->num_host_key_files, apath);
225 free(apath);
226}
227
228void
229servconf_add_hostcert(const char *file, const int line,
230 ServerOptions *options, const char *path)
231{
232 char *apath = derelativise_path(path);
233
234 array_append(file, line, "HostCertificate",
235 &options->host_cert_files, &options->num_host_cert_files, apath);
236 free(apath);
237}
238
Damien Miller4af51302000-04-16 11:18:38 +1000239void
Damien Miller95def091999-11-25 00:26:21 +1100240fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000241{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000242 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000243
Damien Miller726273e2001-11-12 11:40:11 +1100244 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000245 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000246 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100247
248 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100249 if (options->num_host_key_files == 0) {
250 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000251 servconf_add_hostkey("[default]", 0, options,
252 _PATH_HOST_RSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100253#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000254 servconf_add_hostkey("[default]", 0, options,
255 _PATH_HOST_ECDSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100256#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000257 servconf_add_hostkey("[default]", 0, options,
258 _PATH_HOST_ED25519_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000259#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000260 servconf_add_hostkey("[default]", 0, options,
261 _PATH_HOST_XMSS_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000262#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100263 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100264 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100265 if (options->num_ports == 0)
266 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000267 if (options->address_family == -1)
268 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100269 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000270 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000271 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000272 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100273 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000274 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000275 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000276 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100277 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100278 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100279 if (options->ignore_user_known_hosts == -1)
280 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100281 if (options->print_motd == -1)
282 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000283 if (options->print_lastlog == -1)
284 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100285 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100286 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100287 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100288 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100289 if (options->x11_use_localhost == -1)
290 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000291 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000292 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100293 if (options->permit_tty == -1)
294 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000295 if (options->permit_user_rc == -1)
296 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100297 if (options->strict_modes == -1)
298 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100299 if (options->tcp_keep_alive == -1)
300 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100301 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100302 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100303 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000304 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000305 if (options->hostbased_authentication == -1)
306 options->hostbased_authentication = 0;
307 if (options->hostbased_uses_name_from_packet_only == -1)
308 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100309 if (options->pubkey_authentication == -1)
310 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100311 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000312 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100313 if (options->kerberos_or_local_passwd == -1)
314 options->kerberos_or_local_passwd = 1;
315 if (options->kerberos_ticket_cleanup == -1)
316 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100317 if (options->kerberos_get_afs_token == -1)
318 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000319 if (options->gss_authentication == -1)
320 options->gss_authentication = 0;
321 if (options->gss_cleanup_creds == -1)
322 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000323 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000324 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100325 if (options->password_authentication == -1)
326 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100327 if (options->kbd_interactive_authentication == -1)
328 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000329 if (options->challenge_response_authentication == -1)
330 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100331 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100332 options->permit_empty_passwd = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000333 if (options->permit_user_env == -1) {
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000334 options->permit_user_env = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000335 options->permit_user_env_whitelist = NULL;
336 }
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000337 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000338 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000339 if (options->rekey_limit == -1)
340 options->rekey_limit = 0;
341 if (options->rekey_interval == -1)
342 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100343 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100344 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000345 if (options->allow_streamlocal_forwarding == -1)
346 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000347 if (options->allow_agent_forwarding == -1)
348 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000349 if (options->fwd_opts.gateway_ports == -1)
350 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000351 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100352 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000353 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100354 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000355 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100356 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000357 if (options->max_authtries == -1)
358 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000359 if (options->max_sessions == -1)
360 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000361 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000362 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000363 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100364 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000365 if (options->client_alive_count_max == -1)
366 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000367 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000368 array_append("[default]", 0, "AuthorizedKeysFiles",
369 &options->authorized_keys_files,
370 &options->num_authkeys_files,
371 _PATH_SSH_USER_PERMITTED_KEYS);
372 array_append("[default]", 0, "AuthorizedKeysFiles",
373 &options->authorized_keys_files,
374 &options->num_authkeys_files,
375 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000376 }
Damien Millerd27b9472005-12-13 19:29:02 +1100377 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100378 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100379 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000380 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100381 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000382 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000383 if (options->version_addendum == NULL)
384 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000385 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
386 options->fwd_opts.streamlocal_bind_mask = 0177;
387 if (options->fwd_opts.streamlocal_bind_unlink == -1)
388 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000389 if (options->fingerprint_hash == -1)
390 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000391 if (options->disable_forwarding == -1)
392 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000393 if (options->expose_userauth_info == -1)
394 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000395
djm@openbsd.orged085102015-10-29 08:05:01 +0000396 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000397
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000398 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000399 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000400 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000401
djm@openbsd.org161cf412014-12-22 07:55:51 +0000402#define CLEAR_ON_NONE(v) \
403 do { \
404 if (option_clear_or_none(v)) { \
405 free(v); \
406 v = NULL; \
407 } \
408 } while(0)
409 CLEAR_ON_NONE(options->pid_file);
410 CLEAR_ON_NONE(options->xauth_location);
411 CLEAR_ON_NONE(options->banner);
412 CLEAR_ON_NONE(options->trusted_user_ca_keys);
413 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000414 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000415 CLEAR_ON_NONE(options->adm_forced_command);
416 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000417 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000418 for (i = 0; i < options->num_host_key_files; i++)
419 CLEAR_ON_NONE(options->host_key_files[i]);
420 for (i = 0; i < options->num_host_cert_files; i++)
421 CLEAR_ON_NONE(options->host_cert_files[i]);
422#undef CLEAR_ON_NONE
423
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000424 /* Similar handling for AuthenticationMethods=any */
425 if (options->num_auth_methods == 1 &&
426 strcmp(options->auth_methods[0], "any") == 0) {
427 free(options->auth_methods[0]);
428 options->auth_methods[0] = NULL;
429 options->num_auth_methods = 0;
430 }
431
Tim Rice40017b02002-07-14 13:36:49 -0700432#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000433 if (use_privsep && options->compression == 1) {
434 error("This platform does not support both privilege "
435 "separation and compression");
436 error("Compression disabled");
437 options->compression = 0;
438 }
439#endif
440
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000441}
442
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000443/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100444typedef enum {
445 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100446 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000447 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100448 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000449 sPort, sHostKeyFile, sLoginGraceTime,
450 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000451 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100452 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000453 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100454 sPasswordAuthentication, sKbdInteractiveAuthentication,
455 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000456 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100457 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100458 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000459 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000460 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000461 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000462 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
463 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000464 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000465 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000466 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000467 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000468 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000469 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000470 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100471 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100472 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000473 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000474 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000475 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100476 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000477 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000478 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000479 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000480 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000481 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000482} ServerOpCodes;
483
Darren Tucker45150472006-07-12 22:34:17 +1000484#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
485#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
486#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
487
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000488/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100489static struct {
490 const char *name;
491 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000492 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100493} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100494 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000495#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000496 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000497#else
Darren Tucker45150472006-07-12 22:34:17 +1000498 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000499#endif
Darren Tucker45150472006-07-12 22:34:17 +1000500 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100501 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "port", sPort, SSHCFG_GLOBAL },
503 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
504 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000505 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000506 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000507 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000508 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000509 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100510 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000512 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000513 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000514 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100515 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000516 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000517 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000518 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000519 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100520 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000521 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000522 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000523#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100524 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
526 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100527#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000528 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000529#else
Darren Tucker45150472006-07-12 22:34:17 +1000530 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100531#endif
532#else
Darren Tucker1629c072007-02-19 22:25:37 +1100533 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000534 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
535 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
536 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000537#endif
Darren Tucker45150472006-07-12 22:34:17 +1000538 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
539 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000540#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100541 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000542 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000543 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000544#else
Darren Tucker1629c072007-02-19 22:25:37 +1100545 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000546 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000547 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000548#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100549 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
550 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100551 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000552 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
553 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
554 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
555 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
556 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100557#ifdef DISABLE_LASTLOG
558 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
559#else
Darren Tucker45150472006-07-12 22:34:17 +1000560 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100561#endif
Darren Tucker45150472006-07-12 22:34:17 +1000562 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
563 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000564 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
565 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
566 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000567 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
568 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100569 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000570 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000571 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000572 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000573 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000574 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
575 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
576 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000577 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000578 { "allowusers", sAllowUsers, SSHCFG_ALL },
579 { "denyusers", sDenyUsers, SSHCFG_ALL },
580 { "allowgroups", sAllowGroups, SSHCFG_ALL },
581 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000582 { "ciphers", sCiphers, SSHCFG_GLOBAL },
583 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000584 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000585 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
586 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
587 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000588 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000589 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100590 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000591 { "usedns", sUseDNS, SSHCFG_GLOBAL },
592 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
593 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000594 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
595 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000596 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000597 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000598 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000599 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000600 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000601 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100602 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000603 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000604 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000605 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000606 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000607 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100608 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100609 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100610 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
611 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000612 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000613 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100614 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100615 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
616 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000617 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
618 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000619 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100620 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000621 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
622 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
623 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000624 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000625 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000626 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000627 { "rdomain", sRDomain, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000628 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000629};
630
Darren Tuckere7140f22008-06-10 23:01:51 +1000631static struct {
632 int val;
633 char *text;
634} tunmode_desc[] = {
635 { SSH_TUNMODE_NO, "no" },
636 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
637 { SSH_TUNMODE_ETHERNET, "ethernet" },
638 { SSH_TUNMODE_YES, "yes" },
639 { -1, NULL }
640};
641
djm@openbsd.org115063a2018-06-06 18:22:41 +0000642/* Returns an opcode name from its number */
643
644static const char *
645lookup_opcode_name(ServerOpCodes code)
646{
647 u_int i;
648
649 for (i = 0; keywords[i].name != NULL; i++)
650 if (keywords[i].opcode == code)
651 return(keywords[i].name);
652 return "UNKNOWN";
653}
654
655
Damien Miller5428f641999-11-25 11:54:57 +1100656/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000657 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100658 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000659
Damien Miller4af51302000-04-16 11:18:38 +1000660static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100661parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000662 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000663{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000664 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000665
Damien Miller95def091999-11-25 00:26:21 +1100666 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000667 if (strcasecmp(cp, keywords[i].name) == 0) {
668 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100669 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000670 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000671
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000672 error("%s: line %d: Bad configuration option: %s",
673 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100674 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000675}
676
Darren Tucker88b6fb22010-01-13 22:44:29 +1100677char *
678derelativise_path(const char *path)
679{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000680 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100681
djm@openbsd.org161cf412014-12-22 07:55:51 +0000682 if (strcasecmp(path, "none") == 0)
683 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100684 expanded = tilde_expand_filename(path, getuid());
685 if (*expanded == '/')
686 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100687 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100688 fatal("%s: getcwd: %s", __func__, strerror(errno));
689 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000690 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100691 return ret;
692}
693
Ben Lindstrombba81212001-06-25 05:01:22 +0000694static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000695add_listen_addr(ServerOptions *options, const char *addr,
696 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100697{
Damien Millereccb9de2005-06-17 12:59:34 +1000698 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100699
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000700 if (port > 0)
701 add_one_listen_addr(options, addr, rdomain, port);
702 else {
703 for (i = 0; i < options->num_ports; i++) {
704 add_one_listen_addr(options, addr, rdomain,
705 options->ports[i]);
706 }
707 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000708}
709
Ben Lindstrombba81212001-06-25 05:01:22 +0000710static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000711add_one_listen_addr(ServerOptions *options, const char *addr,
712 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000713{
714 struct addrinfo hints, *ai, *aitop;
715 char strport[NI_MAXSERV];
716 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000717 u_int i;
718
719 /* Find listen_addrs entry for this rdomain */
720 for (i = 0; i < options->num_listen_addrs; i++) {
721 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
722 break;
723 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
724 continue;
725 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
726 break;
727 }
728 if (i >= options->num_listen_addrs) {
729 /* No entry for this rdomain; allocate one */
730 if (i >= INT_MAX)
731 fatal("%s: too many listen addresses", __func__);
732 options->listen_addrs = xrecallocarray(options->listen_addrs,
733 options->num_listen_addrs, options->num_listen_addrs + 1,
734 sizeof(*options->listen_addrs));
735 i = options->num_listen_addrs++;
736 if (rdomain != NULL)
737 options->listen_addrs[i].rdomain = xstrdup(rdomain);
738 }
739 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000740
741 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100742 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000743 hints.ai_socktype = SOCK_STREAM;
744 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100745 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000746 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
747 fatal("bad addr or host: %s (%s)",
748 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100749 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000750 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
751 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000752 ai->ai_next = options->listen_addrs[i].addrs;
753 options->listen_addrs[i].addrs = aitop;
754}
755
756/* Returns nonzero if the routing domain name is valid */
757static int
758valid_rdomain(const char *name)
759{
Damien Miller43c29bb2017-10-25 13:10:59 +1100760#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100761 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100762#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000763 const char *errstr;
764 long long num;
765 struct rt_tableinfo info;
766 int mib[6];
767 size_t miblen = sizeof(mib);
768
769 if (name == NULL)
770 return 1;
771
772 num = strtonum(name, 0, 255, &errstr);
773 if (errstr != NULL)
774 return 0;
775
776 /* Check whether the table actually exists */
777 memset(mib, 0, sizeof(mib));
778 mib[0] = CTL_NET;
779 mib[1] = PF_ROUTE;
780 mib[4] = NET_RT_TABLE;
781 mib[5] = (int)num;
782 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
783 return 0;
784
785 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100786#else /* defined(__OpenBSD__) */
787 error("Routing domains are not supported on this platform");
788 return 0;
789#endif
Damien Miller34132e52000-01-14 15:45:46 +1100790}
791
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000792/*
793 * Queue a ListenAddress to be processed once we have all of the Ports
794 * and AddressFamily options.
795 */
796static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000797queue_listen_addr(ServerOptions *options, const char *addr,
798 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000799{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000800 struct queued_listenaddr *qla;
801
802 options->queued_listen_addrs = xrecallocarray(
803 options->queued_listen_addrs,
804 options->num_queued_listens, options->num_queued_listens + 1,
805 sizeof(*options->queued_listen_addrs));
806 qla = &options->queued_listen_addrs[options->num_queued_listens++];
807 qla->addr = xstrdup(addr);
808 qla->port = port;
809 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000810}
811
812/*
813 * Process queued (text) ListenAddress entries.
814 */
815static void
816process_queued_listen_addrs(ServerOptions *options)
817{
818 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000819 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000820
821 if (options->num_ports == 0)
822 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
823 if (options->address_family == -1)
824 options->address_family = AF_UNSPEC;
825
826 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000827 qla = &options->queued_listen_addrs[i];
828 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
829 free(qla->addr);
830 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000831 }
832 free(options->queued_listen_addrs);
833 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000834 options->num_queued_listens = 0;
835}
836
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000837/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000838 * Inform channels layer of permitopen options for a single forwarding
839 * direction (local/remote).
840 */
841static void
842process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
843 char **opens, u_int num_opens)
844{
845 u_int i;
846 int port;
847 char *host, *arg, *oarg;
848 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
849 const char *what = lookup_opcode_name(opcode);
850
851 channel_clear_permission(ssh, FORWARD_ADM, where);
852 if (num_opens == 0)
853 return; /* permit any */
854
855 /* handle keywords: "any" / "none" */
856 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
857 return;
858 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
859 channel_disable_admin(ssh, where);
860 return;
861 }
862 /* Otherwise treat it as a list of permitted host:port */
863 for (i = 0; i < num_opens; i++) {
864 oarg = arg = xstrdup(opens[i]);
865 host = hpdelim(&arg);
866 if (host == NULL)
867 fatal("%s: missing host in %s", __func__, what);
868 host = cleanhostname(host);
869 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
870 fatal("%s: bad port number in %s", __func__, what);
871 /* Send it to channels layer */
872 channel_add_permission(ssh, FORWARD_ADM,
873 where, host, port);
874 free(oarg);
875 }
876}
877
878/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000879 * Inform channels layer of permitopen options from configuration.
880 */
881void
882process_permitopen(struct ssh *ssh, ServerOptions *options)
883{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000884 process_permitopen_list(ssh, sPermitOpen,
885 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000886 process_permitopen_list(ssh, sPermitListen,
887 options->permitted_listens,
888 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000889}
890
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000891struct connection_info *
892get_connection_info(int populate, int use_dns)
893{
djm@openbsd.org95767262016-03-07 19:02:43 +0000894 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000895 static struct connection_info ci;
896
897 if (!populate)
898 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000899 ci.host = auth_get_canonical_hostname(ssh, use_dns);
900 ci.address = ssh_remote_ipaddr(ssh);
901 ci.laddress = ssh_local_ipaddr(ssh);
902 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000903 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000904 return &ci;
905}
906
Darren Tucker45150472006-07-12 22:34:17 +1000907/*
908 * The strategy for the Match blocks is that the config file is parsed twice.
909 *
910 * The first time is at startup. activep is initialized to 1 and the
911 * directives in the global context are processed and acted on. Hitting a
912 * Match directive unsets activep and the directives inside the block are
913 * checked for syntax only.
914 *
915 * The second time is after a connection has been established but before
916 * authentication. activep is initialized to 2 and global config directives
917 * are ignored since they have already been processed. If the criteria in a
918 * Match block is met, activep is set and the subsequent directives
919 * processed and actioned until EOF or another Match block unsets it. Any
920 * options set are copied into the main server config.
921 *
922 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000923 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000924 *
925 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
926 * Match Address 192.168.0.*
927 * Tag trusted
928 * Match Group wheel
929 * Tag trusted
930 * Match Tag trusted
931 * AllowTcpForwarding yes
932 * GatewayPorts clientspecified
933 * [...]
934 *
935 * - Add a PermittedChannelRequests directive
936 * Match Group shell
937 * PermittedChannelRequests session,forwarded-tcpip
938 */
939
940static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000941match_cfg_line_group(const char *grps, int line, const char *user)
942{
943 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000944 struct passwd *pw;
945
Damien Miller565ca3f2006-08-19 00:23:15 +1000946 if (user == NULL)
947 goto out;
948
949 if ((pw = getpwnam(user)) == NULL) {
950 debug("Can't match group at line %d because user %.100s does "
951 "not exist", line, user);
952 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
953 debug("Can't Match group because user %.100s not in any group "
954 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000955 } else if (ga_match_pattern_list(grps) != 1) {
956 debug("user %.100s does not match group list %.100s at line %d",
957 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000958 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000959 debug("user %.100s matched group list %.100s at line %d", user,
960 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000961 result = 1;
962 }
963out:
964 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000965 return result;
966}
967
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +0000968static void
969match_test_missing_fatal(const char *criteria, const char *attrib)
970{
971 fatal("'Match %s' in configuration but '%s' not in connection "
972 "test specification.", criteria, attrib);
973}
974
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000975/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000976 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100977 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000978 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000979 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000980static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000981match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000982{
Damien Millercf31f382013-10-24 21:02:56 +1100983 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000984 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000985
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000986 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000987 debug3("checking syntax for 'Match %s'", cp);
988 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000989 debug3("checking match for '%s' user %s host %s addr %s "
990 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
991 ci->host ? ci->host : "(null)",
992 ci->address ? ci->address : "(null)",
993 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000994
995 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100996 attributes++;
997 if (strcasecmp(attrib, "all") == 0) {
998 if (attributes != 1 ||
999 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1000 error("'all' cannot be combined with other "
1001 "Match attributes");
1002 return -1;
1003 }
1004 *condition = cp;
1005 return 1;
1006 }
Darren Tucker45150472006-07-12 22:34:17 +10001007 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1008 error("Missing Match criteria for %s", attrib);
1009 return -1;
1010 }
Darren Tucker45150472006-07-12 22:34:17 +10001011 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001012 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001013 result = 0;
1014 continue;
1015 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001016 if (ci->user == NULL)
1017 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001018 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001019 result = 0;
1020 else
1021 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001022 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001023 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001024 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001025 result = 0;
1026 continue;
1027 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001028 if (ci->user == NULL)
1029 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001030 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001031 case -1:
1032 return -1;
1033 case 0:
1034 result = 0;
1035 }
Darren Tucker45150472006-07-12 22:34:17 +10001036 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001037 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001038 result = 0;
1039 continue;
1040 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001041 if (ci->host == NULL)
1042 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001043 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001044 result = 0;
1045 else
1046 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001047 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001048 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001049 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001050 result = 0;
1051 continue;
1052 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001053 if (ci->address == NULL)
1054 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001055 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001056 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001057 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001058 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001059 break;
1060 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001061 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001062 result = 0;
1063 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001064 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001065 return -1;
1066 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001067 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001068 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001069 result = 0;
1070 continue;
1071 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001072 if (ci->laddress == NULL)
1073 match_test_missing_fatal("LocalAddress",
1074 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001075 switch (addr_match_list(ci->laddress, arg)) {
1076 case 1:
1077 debug("connection from %.100s matched "
1078 "'LocalAddress %.100s' at line %d",
1079 ci->laddress, arg, line);
1080 break;
1081 case 0:
1082 case -1:
1083 result = 0;
1084 break;
1085 case -2:
1086 return -1;
1087 }
1088 } else if (strcasecmp(attrib, "localport") == 0) {
1089 if ((port = a2port(arg)) == -1) {
1090 error("Invalid LocalPort '%s' on Match line",
1091 arg);
1092 return -1;
1093 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001094 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001095 result = 0;
1096 continue;
1097 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001098 if (ci->lport == 0)
1099 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001100 /* TODO support port lists */
1101 if (port == ci->lport)
1102 debug("connection from %.100s matched "
1103 "'LocalPort %d' at line %d",
1104 ci->laddress, port, line);
1105 else
1106 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001107 } else if (strcasecmp(attrib, "rdomain") == 0) {
1108 if (ci == NULL || ci->rdomain == NULL) {
1109 result = 0;
1110 continue;
1111 }
1112 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1113 result = 0;
1114 else
1115 debug("user %.100s matched 'RDomain %.100s' at "
1116 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001117 } else {
1118 error("Unsupported Match attribute %s", attrib);
1119 return -1;
1120 }
1121 }
Damien Millercf31f382013-10-24 21:02:56 +11001122 if (attributes == 0) {
1123 error("One or more attributes required for Match");
1124 return -1;
1125 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001126 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001127 debug3("match %sfound", result ? "" : "not ");
1128 *condition = cp;
1129 return result;
1130}
1131
Damien Millere2754432006-07-24 14:06:47 +10001132#define WHITESPACE " \t\r\n"
1133
Damien Miller33322122011-06-20 14:43:11 +10001134/* Multistate option parsing */
1135struct multistate {
1136 char *key;
1137 int value;
1138};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001139static const struct multistate multistate_flag[] = {
1140 { "yes", 1 },
1141 { "no", 0 },
1142 { NULL, -1 }
1143};
Damien Miller33322122011-06-20 14:43:11 +10001144static const struct multistate multistate_addressfamily[] = {
1145 { "inet", AF_INET },
1146 { "inet6", AF_INET6 },
1147 { "any", AF_UNSPEC },
1148 { NULL, -1 }
1149};
1150static const struct multistate multistate_permitrootlogin[] = {
1151 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001152 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001153 { "forced-commands-only", PERMIT_FORCED_ONLY },
1154 { "yes", PERMIT_YES },
1155 { "no", PERMIT_NO },
1156 { NULL, -1 }
1157};
1158static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +00001159 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +00001160 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001161 { "no", COMP_NONE },
1162 { NULL, -1 }
1163};
1164static const struct multistate multistate_gatewayports[] = {
1165 { "clientspecified", 2 },
1166 { "yes", 1 },
1167 { "no", 0 },
1168 { NULL, -1 }
1169};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001170static const struct multistate multistate_tcpfwd[] = {
1171 { "yes", FORWARD_ALLOW },
1172 { "all", FORWARD_ALLOW },
1173 { "no", FORWARD_DENY },
1174 { "remote", FORWARD_REMOTE },
1175 { "local", FORWARD_LOCAL },
1176 { NULL, -1 }
1177};
Damien Miller33322122011-06-20 14:43:11 +10001178
Ben Lindstromade03f62001-12-06 18:22:17 +00001179int
1180process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001181 const char *filename, int linenum, int *activep,
1182 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001183{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001184 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001185 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001186 SyslogFacility *log_facility_ptr;
1187 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001188 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001189 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001190 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001191 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001192 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001193 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001194
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001195 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1196 if ((len = strlen(line)) == 0)
1197 return 0;
1198 for (len--; len > 0; len--) {
1199 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1200 break;
1201 line[len] = '\0';
1202 }
1203
Ben Lindstromade03f62001-12-06 18:22:17 +00001204 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001205 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001206 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001207 /* Ignore leading whitespace */
1208 if (*arg == '\0')
1209 arg = strdelim(&cp);
1210 if (!arg || !*arg || *arg == '#')
1211 return 0;
1212 intptr = NULL;
1213 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001214 opcode = parse_token(arg, filename, linenum, &flags);
1215
1216 if (activep == NULL) { /* We are processing a command line directive */
1217 cmdline = 1;
1218 activep = &cmdline;
1219 }
1220 if (*activep && opcode != sMatch)
1221 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1222 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001223 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001224 fatal("%s line %d: Directive '%s' is not allowed "
1225 "within a Match block", filename, linenum, arg);
1226 } else { /* this is a directive we have already processed */
1227 while (arg)
1228 arg = strdelim(&cp);
1229 return 0;
1230 }
1231 }
1232
Ben Lindstromade03f62001-12-06 18:22:17 +00001233 switch (opcode) {
1234 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001235 case sUsePAM:
1236 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001237 goto parse_flag;
1238
1239 /* Standard Options */
1240 case sBadOption:
1241 return -1;
1242 case sPort:
1243 /* ignore ports from configfile if cmdline specifies ports */
1244 if (options->ports_from_cmdline)
1245 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001246 if (options->num_ports >= MAX_PORTS)
1247 fatal("%s line %d: too many ports.",
1248 filename, linenum);
1249 arg = strdelim(&cp);
1250 if (!arg || *arg == '\0')
1251 fatal("%s line %d: missing port number.",
1252 filename, linenum);
1253 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001254 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001255 fatal("%s line %d: Badly formatted port number.",
1256 filename, linenum);
1257 break;
1258
Ben Lindstromade03f62001-12-06 18:22:17 +00001259 case sLoginGraceTime:
1260 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001261 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001262 arg = strdelim(&cp);
1263 if (!arg || *arg == '\0')
1264 fatal("%s line %d: missing time value.",
1265 filename, linenum);
1266 if ((value = convtime(arg)) == -1)
1267 fatal("%s line %d: invalid time value.",
1268 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001269 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001270 *intptr = value;
1271 break;
1272
Ben Lindstromade03f62001-12-06 18:22:17 +00001273 case sListenAddress:
1274 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001275 if (arg == NULL || *arg == '\0')
1276 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001277 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001278 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1279 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1280 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001281 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001282 p = arg;
1283 } else {
1284 p = hpdelim(&arg);
1285 if (p == NULL)
1286 fatal("%s line %d: bad address:port usage",
1287 filename, linenum);
1288 p = cleanhostname(p);
1289 if (arg == NULL)
1290 port = 0;
1291 else if ((port = a2port(arg)) <= 0)
1292 fatal("%s line %d: bad port number",
1293 filename, linenum);
1294 }
1295 /* Optional routing table */
1296 arg2 = NULL;
1297 if ((arg = strdelim(&cp)) != NULL) {
1298 if (strcmp(arg, "rdomain") != 0 ||
1299 (arg2 = strdelim(&cp)) == NULL)
1300 fatal("%s line %d: bad ListenAddress syntax",
1301 filename, linenum);
1302 if (!valid_rdomain(arg2))
1303 fatal("%s line %d: bad routing domain",
1304 filename, linenum);
1305 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001306
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001307 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001308
Ben Lindstromade03f62001-12-06 18:22:17 +00001309 break;
1310
Darren Tucker0f383232005-01-20 10:57:56 +11001311 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001312 intptr = &options->address_family;
1313 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001314 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001315 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001316 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001317 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001318 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001319 value = -1;
1320 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1321 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1322 value = multistate_ptr[i].value;
1323 break;
1324 }
1325 }
1326 if (value == -1)
1327 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001328 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001329 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001330 *intptr = value;
1331 break;
1332
Ben Lindstromade03f62001-12-06 18:22:17 +00001333 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001334 arg = strdelim(&cp);
1335 if (!arg || *arg == '\0')
1336 fatal("%s line %d: missing file name.",
1337 filename, linenum);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001338 if (*activep)
1339 servconf_add_hostkey(filename, linenum, options, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001340 break;
1341
Damien Miller85b45e02013-07-20 13:21:52 +10001342 case sHostKeyAgent:
1343 charptr = &options->host_key_agent;
1344 arg = strdelim(&cp);
1345 if (!arg || *arg == '\0')
1346 fatal("%s line %d: missing socket name.",
1347 filename, linenum);
1348 if (*activep && *charptr == NULL)
1349 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1350 xstrdup(arg) : derelativise_path(arg);
1351 break;
1352
Damien Miller0a80ca12010-02-27 07:55:05 +11001353 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001354 arg = strdelim(&cp);
1355 if (!arg || *arg == '\0')
1356 fatal("%s line %d: missing file name.",
1357 filename, linenum);
1358 if (*activep)
1359 servconf_add_hostcert(filename, linenum, options, arg);
1360 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001361
Ben Lindstromade03f62001-12-06 18:22:17 +00001362 case sPidFile:
1363 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001364 parse_filename:
1365 arg = strdelim(&cp);
1366 if (!arg || *arg == '\0')
1367 fatal("%s line %d: missing file name.",
1368 filename, linenum);
1369 if (*activep && *charptr == NULL) {
1370 *charptr = derelativise_path(arg);
1371 /* increase optional counter */
1372 if (intptr != NULL)
1373 *intptr = *intptr + 1;
1374 }
1375 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001376
1377 case sPermitRootLogin:
1378 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001379 multistate_ptr = multistate_permitrootlogin;
1380 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001381
1382 case sIgnoreRhosts:
1383 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001384 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001385 multistate_ptr = multistate_flag;
1386 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001387
1388 case sIgnoreUserKnownHosts:
1389 intptr = &options->ignore_user_known_hosts;
1390 goto parse_flag;
1391
Ben Lindstromade03f62001-12-06 18:22:17 +00001392 case sHostbasedAuthentication:
1393 intptr = &options->hostbased_authentication;
1394 goto parse_flag;
1395
1396 case sHostbasedUsesNameFromPacketOnly:
1397 intptr = &options->hostbased_uses_name_from_packet_only;
1398 goto parse_flag;
1399
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001400 case sHostbasedAcceptedKeyTypes:
1401 charptr = &options->hostbased_key_types;
1402 parse_keytypes:
1403 arg = strdelim(&cp);
1404 if (!arg || *arg == '\0')
1405 fatal("%s line %d: Missing argument.",
1406 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001407 if (*arg != '-' &&
1408 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001409 fatal("%s line %d: Bad key types '%s'.",
1410 filename, linenum, arg ? arg : "<NONE>");
1411 if (*activep && *charptr == NULL)
1412 *charptr = xstrdup(arg);
1413 break;
1414
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001415 case sHostKeyAlgorithms:
1416 charptr = &options->hostkeyalgorithms;
1417 goto parse_keytypes;
1418
Ben Lindstromade03f62001-12-06 18:22:17 +00001419 case sPubkeyAuthentication:
1420 intptr = &options->pubkey_authentication;
1421 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001422
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001423 case sPubkeyAcceptedKeyTypes:
1424 charptr = &options->pubkey_key_types;
1425 goto parse_keytypes;
1426
Ben Lindstromade03f62001-12-06 18:22:17 +00001427 case sKerberosAuthentication:
1428 intptr = &options->kerberos_authentication;
1429 goto parse_flag;
1430
1431 case sKerberosOrLocalPasswd:
1432 intptr = &options->kerberos_or_local_passwd;
1433 goto parse_flag;
1434
1435 case sKerberosTicketCleanup:
1436 intptr = &options->kerberos_ticket_cleanup;
1437 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001438
Darren Tucker22ef5082003-12-31 11:37:34 +11001439 case sKerberosGetAFSToken:
1440 intptr = &options->kerberos_get_afs_token;
1441 goto parse_flag;
1442
Darren Tucker0efd1552003-08-26 11:49:55 +10001443 case sGssAuthentication:
1444 intptr = &options->gss_authentication;
1445 goto parse_flag;
1446
1447 case sGssCleanupCreds:
1448 intptr = &options->gss_cleanup_creds;
1449 goto parse_flag;
1450
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001451 case sGssStrictAcceptor:
1452 intptr = &options->gss_strict_acceptor;
1453 goto parse_flag;
1454
Ben Lindstromade03f62001-12-06 18:22:17 +00001455 case sPasswordAuthentication:
1456 intptr = &options->password_authentication;
1457 goto parse_flag;
1458
1459 case sKbdInteractiveAuthentication:
1460 intptr = &options->kbd_interactive_authentication;
1461 goto parse_flag;
1462
1463 case sChallengeResponseAuthentication:
1464 intptr = &options->challenge_response_authentication;
1465 goto parse_flag;
1466
1467 case sPrintMotd:
1468 intptr = &options->print_motd;
1469 goto parse_flag;
1470
1471 case sPrintLastLog:
1472 intptr = &options->print_lastlog;
1473 goto parse_flag;
1474
1475 case sX11Forwarding:
1476 intptr = &options->x11_forwarding;
1477 goto parse_flag;
1478
1479 case sX11DisplayOffset:
1480 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001481 parse_int:
1482 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001483 if ((errstr = atoi_err(arg, &value)) != NULL)
1484 fatal("%s line %d: integer value %s.",
1485 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001486 if (*activep && *intptr == -1)
1487 *intptr = value;
1488 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001489
Damien Miller95c249f2002-02-05 12:11:34 +11001490 case sX11UseLocalhost:
1491 intptr = &options->x11_use_localhost;
1492 goto parse_flag;
1493
Ben Lindstromade03f62001-12-06 18:22:17 +00001494 case sXAuthLocation:
1495 charptr = &options->xauth_location;
1496 goto parse_filename;
1497
Damien Miller5ff30c62013-10-30 22:21:50 +11001498 case sPermitTTY:
1499 intptr = &options->permit_tty;
1500 goto parse_flag;
1501
Damien Miller72e6b5c2014-07-04 09:00:04 +10001502 case sPermitUserRC:
1503 intptr = &options->permit_user_rc;
1504 goto parse_flag;
1505
Ben Lindstromade03f62001-12-06 18:22:17 +00001506 case sStrictModes:
1507 intptr = &options->strict_modes;
1508 goto parse_flag;
1509
Damien Miller12c150e2003-12-17 16:31:10 +11001510 case sTCPKeepAlive:
1511 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001512 goto parse_flag;
1513
1514 case sEmptyPasswd:
1515 intptr = &options->permit_empty_passwd;
1516 goto parse_flag;
1517
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001518 case sPermitUserEnvironment:
1519 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001520 charptr = &options->permit_user_env_whitelist;
1521 arg = strdelim(&cp);
1522 if (!arg || *arg == '\0')
1523 fatal("%s line %d: missing argument.",
1524 filename, linenum);
1525 value = 0;
1526 p = NULL;
1527 if (strcmp(arg, "yes") == 0)
1528 value = 1;
1529 else if (strcmp(arg, "no") == 0)
1530 value = 0;
1531 else {
1532 /* Pattern-list specified */
1533 value = 1;
1534 p = xstrdup(arg);
1535 }
1536 if (*activep && *intptr == -1) {
1537 *intptr = value;
1538 *charptr = p;
1539 p = NULL;
1540 }
1541 free(p);
1542 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001543
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001544 case sCompression:
1545 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001546 multistate_ptr = multistate_compression;
1547 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001548
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001549 case sRekeyLimit:
1550 arg = strdelim(&cp);
1551 if (!arg || *arg == '\0')
1552 fatal("%.200s line %d: Missing argument.", filename,
1553 linenum);
1554 if (strcmp(arg, "default") == 0) {
1555 val64 = 0;
1556 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001557 if (scan_scaled(arg, &val64) == -1)
1558 fatal("%.200s line %d: Bad number '%s': %s",
1559 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001560 if (val64 != 0 && val64 < 16)
1561 fatal("%.200s line %d: RekeyLimit too small",
1562 filename, linenum);
1563 }
1564 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001565 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001566 if (cp != NULL) { /* optional rekey interval present */
1567 if (strcmp(cp, "none") == 0) {
1568 (void)strdelim(&cp); /* discard */
1569 break;
1570 }
1571 intptr = &options->rekey_interval;
1572 goto parse_time;
1573 }
1574 break;
1575
Ben Lindstromade03f62001-12-06 18:22:17 +00001576 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001577 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001578 multistate_ptr = multistate_gatewayports;
1579 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001580
Damien Miller3a961dc2003-06-03 10:25:48 +10001581 case sUseDNS:
1582 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001583 goto parse_flag;
1584
1585 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001586 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001587 arg = strdelim(&cp);
1588 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001589 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001590 fatal("%.200s line %d: unsupported log facility '%s'",
1591 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001592 if (*log_facility_ptr == -1)
1593 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001594 break;
1595
1596 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001597 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001598 arg = strdelim(&cp);
1599 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001600 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001601 fatal("%.200s line %d: unsupported log level '%s'",
1602 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001603 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001604 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001605 break;
1606
1607 case sAllowTcpForwarding:
1608 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001609 multistate_ptr = multistate_tcpfwd;
1610 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001611
Damien Miller7acefbb2014-07-18 14:11:24 +10001612 case sAllowStreamLocalForwarding:
1613 intptr = &options->allow_streamlocal_forwarding;
1614 multistate_ptr = multistate_tcpfwd;
1615 goto parse_multistate;
1616
Damien Miller4f755cd2008-05-19 14:57:41 +10001617 case sAllowAgentForwarding:
1618 intptr = &options->allow_agent_forwarding;
1619 goto parse_flag;
1620
djm@openbsd.org7844f352016-11-30 03:00:05 +00001621 case sDisableForwarding:
1622 intptr = &options->disable_forwarding;
1623 goto parse_flag;
1624
Ben Lindstromade03f62001-12-06 18:22:17 +00001625 case sAllowUsers:
1626 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001627 if (match_user(NULL, NULL, NULL, arg) == -1)
1628 fatal("%s line %d: invalid AllowUsers pattern: "
1629 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001630 if (!*activep)
1631 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001632 array_append(filename, linenum, "AllowUsers",
1633 &options->allow_users, &options->num_allow_users,
1634 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001635 }
1636 break;
1637
1638 case sDenyUsers:
1639 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001640 if (match_user(NULL, NULL, NULL, arg) == -1)
1641 fatal("%s line %d: invalid DenyUsers pattern: "
1642 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001643 if (!*activep)
1644 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001645 array_append(filename, linenum, "DenyUsers",
1646 &options->deny_users, &options->num_deny_users,
1647 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001648 }
1649 break;
1650
1651 case sAllowGroups:
1652 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001653 if (!*activep)
1654 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001655 array_append(filename, linenum, "AllowGroups",
1656 &options->allow_groups, &options->num_allow_groups,
1657 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001658 }
1659 break;
1660
1661 case sDenyGroups:
1662 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001663 if (!*activep)
1664 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001665 array_append(filename, linenum, "DenyGroups",
1666 &options->deny_groups, &options->num_deny_groups,
1667 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001668 }
1669 break;
1670
1671 case sCiphers:
1672 arg = strdelim(&cp);
1673 if (!arg || *arg == '\0')
1674 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001675 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001676 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1677 filename, linenum, arg ? arg : "<NONE>");
1678 if (options->ciphers == NULL)
1679 options->ciphers = xstrdup(arg);
1680 break;
1681
1682 case sMacs:
1683 arg = strdelim(&cp);
1684 if (!arg || *arg == '\0')
1685 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001686 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001687 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1688 filename, linenum, arg ? arg : "<NONE>");
1689 if (options->macs == NULL)
1690 options->macs = xstrdup(arg);
1691 break;
1692
Damien Millerd5f62bf2010-09-24 22:11:14 +10001693 case sKexAlgorithms:
1694 arg = strdelim(&cp);
1695 if (!arg || *arg == '\0')
1696 fatal("%s line %d: Missing argument.",
1697 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001698 if (*arg != '-' &&
1699 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001700 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1701 filename, linenum, arg ? arg : "<NONE>");
1702 if (options->kex_algorithms == NULL)
1703 options->kex_algorithms = xstrdup(arg);
1704 break;
1705
Ben Lindstromade03f62001-12-06 18:22:17 +00001706 case sSubsystem:
1707 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1708 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001709 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001710 }
1711 arg = strdelim(&cp);
1712 if (!arg || *arg == '\0')
1713 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001714 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001715 if (!*activep) {
1716 arg = strdelim(&cp);
1717 break;
1718 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001719 for (i = 0; i < options->num_subsystems; i++)
1720 if (strcmp(arg, options->subsystem_name[i]) == 0)
1721 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001722 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001723 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1724 arg = strdelim(&cp);
1725 if (!arg || *arg == '\0')
1726 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001727 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001728 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001729
1730 /* Collect arguments (separate to executable) */
1731 p = xstrdup(arg);
1732 len = strlen(p) + 1;
1733 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1734 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001735 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001736 strlcat(p, " ", len);
1737 strlcat(p, arg, len);
1738 }
1739 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001740 options->num_subsystems++;
1741 break;
1742
1743 case sMaxStartups:
1744 arg = strdelim(&cp);
1745 if (!arg || *arg == '\0')
1746 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001747 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001748 if ((n = sscanf(arg, "%d:%d:%d",
1749 &options->max_startups_begin,
1750 &options->max_startups_rate,
1751 &options->max_startups)) == 3) {
1752 if (options->max_startups_begin >
1753 options->max_startups ||
1754 options->max_startups_rate > 100 ||
1755 options->max_startups_rate < 1)
1756 fatal("%s line %d: Illegal MaxStartups spec.",
1757 filename, linenum);
1758 } else if (n != 1)
1759 fatal("%s line %d: Illegal MaxStartups spec.",
1760 filename, linenum);
1761 else
1762 options->max_startups = options->max_startups_begin;
1763 break;
1764
Darren Tucker89413db2004-05-24 10:36:23 +10001765 case sMaxAuthTries:
1766 intptr = &options->max_authtries;
1767 goto parse_int;
1768
Damien Miller7207f642008-05-19 15:34:50 +10001769 case sMaxSessions:
1770 intptr = &options->max_sessions;
1771 goto parse_int;
1772
Ben Lindstromade03f62001-12-06 18:22:17 +00001773 case sBanner:
1774 charptr = &options->banner;
1775 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001776
Ben Lindstromade03f62001-12-06 18:22:17 +00001777 /*
1778 * These options can contain %X options expanded at
1779 * connect time, so that you can specify paths like:
1780 *
1781 * AuthorizedKeysFile /etc/ssh_keys/%u
1782 */
1783 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001784 if (*activep && options->num_authkeys_files == 0) {
1785 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001786 arg = tilde_expand_filename(arg, getuid());
1787 array_append(filename, linenum,
1788 "AuthorizedKeysFile",
1789 &options->authorized_keys_files,
1790 &options->num_authkeys_files, arg);
1791 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001792 }
1793 }
1794 return 0;
1795
Damien Miller30da3442010-05-10 11:58:03 +10001796 case sAuthorizedPrincipalsFile:
1797 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001798 arg = strdelim(&cp);
1799 if (!arg || *arg == '\0')
1800 fatal("%s line %d: missing file name.",
1801 filename, linenum);
1802 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001803 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001804 /* increase optional counter */
1805 if (intptr != NULL)
1806 *intptr = *intptr + 1;
1807 }
1808 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001809
1810 case sClientAliveInterval:
1811 intptr = &options->client_alive_interval;
1812 goto parse_time;
1813
1814 case sClientAliveCountMax:
1815 intptr = &options->client_alive_count_max;
1816 goto parse_int;
1817
Darren Tucker46bc0752004-05-02 22:11:30 +10001818 case sAcceptEnv:
1819 while ((arg = strdelim(&cp)) && *arg != '\0') {
1820 if (strchr(arg, '=') != NULL)
1821 fatal("%s line %d: Invalid environment name.",
1822 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001823 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001824 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001825 array_append(filename, linenum, "AcceptEnv",
1826 &options->accept_env, &options->num_accept_env,
1827 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001828 }
1829 break;
1830
djm@openbsd.org28013752018-06-09 03:03:10 +00001831 case sSetEnv:
1832 uvalue = options->num_setenv;
1833 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1834 if (strchr(arg, '=') == NULL)
1835 fatal("%s line %d: Invalid environment.",
1836 filename, linenum);
1837 if (!*activep || uvalue != 0)
1838 continue;
1839 array_append(filename, linenum, "SetEnv",
1840 &options->setenv, &options->num_setenv, arg);
1841 }
1842 break;
1843
Damien Millerd27b9472005-12-13 19:29:02 +11001844 case sPermitTunnel:
1845 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001846 arg = strdelim(&cp);
1847 if (!arg || *arg == '\0')
1848 fatal("%s line %d: Missing yes/point-to-point/"
1849 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001850 value = -1;
1851 for (i = 0; tunmode_desc[i].val != -1; i++)
1852 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1853 value = tunmode_desc[i].val;
1854 break;
1855 }
1856 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001857 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1858 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001859 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001860 *intptr = value;
1861 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001862
Darren Tucker45150472006-07-12 22:34:17 +10001863 case sMatch:
1864 if (cmdline)
1865 fatal("Match directive not supported as a command-line "
1866 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001867 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001868 if (value < 0)
1869 fatal("%s line %d: Bad Match condition", filename,
1870 linenum);
1871 *activep = value;
1872 break;
1873
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001874 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001875 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001876 if (opcode == sPermitListen) {
1877 uintptr = &options->num_permitted_listens;
1878 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001879 } else {
1880 uintptr = &options->num_permitted_opens;
1881 chararrayptr = &options->permitted_opens;
1882 }
Damien Miller9b439df2006-07-24 14:04:00 +10001883 arg = strdelim(&cp);
1884 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001885 fatal("%s line %d: missing %s specification",
1886 filename, linenum, lookup_opcode_name(opcode));
1887 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001888 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001889 if (*activep && uvalue == 0) {
1890 *uintptr = 1;
1891 *chararrayptr = xcalloc(1,
1892 sizeof(**chararrayptr));
1893 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001894 }
Damien Millerc6081482012-04-22 11:18:53 +10001895 break;
1896 }
Damien Millera765cf42006-07-24 14:08:13 +10001897 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001898 if (opcode == sPermitListen &&
1899 strchr(arg, ':') == NULL) {
1900 /*
1901 * Allow bare port number for PermitListen
1902 * to indicate a wildcard listen host.
1903 */
1904 xasprintf(&arg2, "*:%s", arg);
1905 } else {
1906 arg2 = xstrdup(arg);
1907 p = hpdelim(&arg);
1908 if (p == NULL) {
1909 fatal("%s line %d: missing host in %s",
1910 filename, linenum,
1911 lookup_opcode_name(opcode));
1912 }
1913 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001914 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001915 if (arg == NULL ||
1916 ((port = permitopen_port(arg)) < 0)) {
1917 fatal("%s line %d: bad port number in %s",
1918 filename, linenum,
1919 lookup_opcode_name(opcode));
1920 }
1921 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001922 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001923 lookup_opcode_name(opcode),
1924 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001925 }
1926 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001927 }
Damien Miller9b439df2006-07-24 14:04:00 +10001928 break;
1929
Damien Millere2754432006-07-24 14:06:47 +10001930 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001931 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001932 fatal("%.200s line %d: Missing argument.", filename,
1933 linenum);
1934 len = strspn(cp, WHITESPACE);
1935 if (*activep && options->adm_forced_command == NULL)
1936 options->adm_forced_command = xstrdup(cp + len);
1937 return 0;
1938
Damien Millerd8cb1f12008-02-10 22:40:12 +11001939 case sChrootDirectory:
1940 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001941
1942 arg = strdelim(&cp);
1943 if (!arg || *arg == '\0')
1944 fatal("%s line %d: missing file name.",
1945 filename, linenum);
1946 if (*activep && *charptr == NULL)
1947 *charptr = xstrdup(arg);
1948 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001949
Damien Miller1aed65e2010-03-04 21:53:35 +11001950 case sTrustedUserCAKeys:
1951 charptr = &options->trusted_user_ca_keys;
1952 goto parse_filename;
1953
1954 case sRevokedKeys:
1955 charptr = &options->revoked_keys_file;
1956 goto parse_filename;
1957
Damien Miller0dac6fb2010-11-20 15:19:38 +11001958 case sIPQoS:
1959 arg = strdelim(&cp);
1960 if ((value = parse_ipqos(arg)) == -1)
1961 fatal("%s line %d: Bad IPQoS value: %s",
1962 filename, linenum, arg);
1963 arg = strdelim(&cp);
1964 if (arg == NULL)
1965 value2 = value;
1966 else if ((value2 = parse_ipqos(arg)) == -1)
1967 fatal("%s line %d: Bad IPQoS value: %s",
1968 filename, linenum, arg);
1969 if (*activep) {
1970 options->ip_qos_interactive = value;
1971 options->ip_qos_bulk = value2;
1972 }
1973 break;
1974
Damien Miller23528812012-04-22 11:24:43 +10001975 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001976 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001977 fatal("%.200s line %d: Missing argument.", filename,
1978 linenum);
1979 len = strspn(cp, WHITESPACE);
1980 if (*activep && options->version_addendum == NULL) {
1981 if (strcasecmp(cp + len, "none") == 0)
1982 options->version_addendum = xstrdup("");
1983 else if (strchr(cp + len, '\r') != NULL)
1984 fatal("%.200s line %d: Invalid argument",
1985 filename, linenum);
1986 else
1987 options->version_addendum = xstrdup(cp + len);
1988 }
1989 return 0;
1990
Damien Miller09d3e122012-10-31 08:58:58 +11001991 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001992 if (cp == NULL)
1993 fatal("%.200s line %d: Missing argument.", filename,
1994 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001995 len = strspn(cp, WHITESPACE);
1996 if (*activep && options->authorized_keys_command == NULL) {
1997 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1998 fatal("%.200s line %d: AuthorizedKeysCommand "
1999 "must be an absolute path",
2000 filename, linenum);
2001 options->authorized_keys_command = xstrdup(cp + len);
2002 }
2003 return 0;
2004
2005 case sAuthorizedKeysCommandUser:
2006 charptr = &options->authorized_keys_command_user;
2007
2008 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002009 if (!arg || *arg == '\0')
2010 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2011 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002012 if (*activep && *charptr == NULL)
2013 *charptr = xstrdup(arg);
2014 break;
2015
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002016 case sAuthorizedPrincipalsCommand:
2017 if (cp == NULL)
2018 fatal("%.200s line %d: Missing argument.", filename,
2019 linenum);
2020 len = strspn(cp, WHITESPACE);
2021 if (*activep &&
2022 options->authorized_principals_command == NULL) {
2023 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2024 fatal("%.200s line %d: "
2025 "AuthorizedPrincipalsCommand must be "
2026 "an absolute path", filename, linenum);
2027 options->authorized_principals_command =
2028 xstrdup(cp + len);
2029 }
2030 return 0;
2031
2032 case sAuthorizedPrincipalsCommandUser:
2033 charptr = &options->authorized_principals_command_user;
2034
2035 arg = strdelim(&cp);
2036 if (!arg || *arg == '\0')
2037 fatal("%s line %d: missing "
2038 "AuthorizedPrincipalsCommandUser argument.",
2039 filename, linenum);
2040 if (*activep && *charptr == NULL)
2041 *charptr = xstrdup(arg);
2042 break;
2043
Damien Millera6e3f012012-11-04 23:21:40 +11002044 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002045 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002046 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002047 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002048 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002049 if (strcmp(arg, "any") == 0) {
2050 if (options->num_auth_methods > 0) {
2051 fatal("%s line %d: \"any\" "
2052 "must appear alone in "
2053 "AuthenticationMethods",
2054 filename, linenum);
2055 }
2056 value = 1;
2057 } else if (value) {
2058 fatal("%s line %d: \"any\" must appear "
2059 "alone in AuthenticationMethods",
2060 filename, linenum);
2061 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002062 fatal("%s line %d: invalid "
2063 "authentication method list.",
2064 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002065 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002066 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002067 if (!*activep)
2068 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002069 array_append(filename, linenum,
2070 "AuthenticationMethods",
2071 &options->auth_methods,
2072 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002073 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002074 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002075 fatal("%s line %d: no AuthenticationMethods "
2076 "specified", filename, linenum);
2077 }
Damien Millera6e3f012012-11-04 23:21:40 +11002078 }
2079 return 0;
2080
Damien Miller7acefbb2014-07-18 14:11:24 +10002081 case sStreamLocalBindMask:
2082 arg = strdelim(&cp);
2083 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002084 fatal("%s line %d: missing StreamLocalBindMask "
2085 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002086 /* Parse mode in octal format */
2087 value = strtol(arg, &p, 8);
2088 if (arg == p || value < 0 || value > 0777)
2089 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002090 if (*activep)
2091 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002092 break;
2093
2094 case sStreamLocalBindUnlink:
2095 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2096 goto parse_flag;
2097
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002098 case sFingerprintHash:
2099 arg = strdelim(&cp);
2100 if (!arg || *arg == '\0')
2101 fatal("%.200s line %d: Missing argument.",
2102 filename, linenum);
2103 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2104 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2105 filename, linenum, arg);
2106 if (*activep)
2107 options->fingerprint_hash = value;
2108 break;
2109
djm@openbsd.org8f574952017-06-24 06:34:38 +00002110 case sExposeAuthInfo:
2111 intptr = &options->expose_userauth_info;
2112 goto parse_flag;
2113
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002114 case sRDomain:
2115 charptr = &options->routing_domain;
2116 arg = strdelim(&cp);
2117 if (!arg || *arg == '\0')
2118 fatal("%.200s line %d: Missing argument.",
2119 filename, linenum);
2120 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2121 !valid_rdomain(arg))
2122 fatal("%s line %d: bad routing domain",
2123 filename, linenum);
2124 if (*activep && *charptr == NULL)
2125 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002126 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002127
Ben Lindstromade03f62001-12-06 18:22:17 +00002128 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002129 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002130 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002131 do_log2(opcode == sIgnore ?
2132 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2133 "%s line %d: %s option %s", filename, linenum,
2134 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002135 while (arg)
2136 arg = strdelim(&cp);
2137 break;
2138
Ben Lindstromade03f62001-12-06 18:22:17 +00002139 default:
2140 fatal("%s line %d: Missing handler for opcode %s (%d)",
2141 filename, linenum, arg, opcode);
2142 }
2143 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2144 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2145 filename, linenum, arg);
2146 return 0;
2147}
2148
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002149/* Reads the server configuration file. */
2150
Damien Miller4af51302000-04-16 11:18:38 +10002151void
Darren Tucker645ab752004-06-25 13:33:20 +10002152load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002153{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002154 char *line = NULL, *cp;
2155 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002156 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10002157 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002158
Darren Tucker645ab752004-06-25 13:33:20 +10002159 debug2("%s: filename %s", __func__, filename);
2160 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002161 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002162 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002163 }
Darren Tucker645ab752004-06-25 13:33:20 +10002164 buffer_clear(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002165 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002166 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002167 /*
2168 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002169 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002170 * line numbers later for error messages
2171 */
2172 if ((cp = strchr(line, '#')) != NULL)
2173 memcpy(cp, "\n", 2);
2174 cp = line + strspn(line, " \t\r");
2175
2176 buffer_append(conf, cp, strlen(cp));
2177 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002178 free(line);
Darren Tucker645ab752004-06-25 13:33:20 +10002179 buffer_append(conf, "\0", 1);
2180 fclose(f);
2181 debug2("%s: done config len = %d", __func__, buffer_len(conf));
2182}
2183
2184void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002185parse_server_match_config(ServerOptions *options,
2186 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002187{
Darren Tucker45150472006-07-12 22:34:17 +10002188 ServerOptions mo;
2189
2190 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002191 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002192 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002193}
2194
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002195int parse_server_match_testspec(struct connection_info *ci, char *spec)
2196{
2197 char *p;
2198
2199 while ((p = strsep(&spec, ",")) && *p != '\0') {
2200 if (strncmp(p, "addr=", 5) == 0) {
2201 ci->address = xstrdup(p + 5);
2202 } else if (strncmp(p, "host=", 5) == 0) {
2203 ci->host = xstrdup(p + 5);
2204 } else if (strncmp(p, "user=", 5) == 0) {
2205 ci->user = xstrdup(p + 5);
2206 } else if (strncmp(p, "laddr=", 6) == 0) {
2207 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002208 } else if (strncmp(p, "rdomain=", 8) == 0) {
2209 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002210 } else if (strncmp(p, "lport=", 6) == 0) {
2211 ci->lport = a2port(p + 6);
2212 if (ci->lport == -1) {
2213 fprintf(stderr, "Invalid port '%s' in test mode"
2214 " specification %s\n", p+6, p);
2215 return -1;
2216 }
2217 } else {
2218 fprintf(stderr, "Invalid test mode specification %s\n",
2219 p);
2220 return -1;
2221 }
2222 }
2223 return 0;
2224}
2225
2226/*
Darren Tucker1629c072007-02-19 22:25:37 +11002227 * Copy any supported values that are set.
2228 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002229 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002230 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002231 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002232 */
Darren Tucker45150472006-07-12 22:34:17 +10002233void
Darren Tucker1629c072007-02-19 22:25:37 +11002234copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002235{
Damien Miller534b2cc2013-12-05 14:07:27 +11002236#define M_CP_INTOPT(n) do {\
2237 if (src->n != -1) \
2238 dst->n = src->n; \
2239} while (0)
2240
Darren Tucker1629c072007-02-19 22:25:37 +11002241 M_CP_INTOPT(password_authentication);
2242 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002243 M_CP_INTOPT(pubkey_authentication);
2244 M_CP_INTOPT(kerberos_authentication);
2245 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002246 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002247 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002248 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002249 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002250
2251 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002252 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002253 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002254 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002255 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002256 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002257 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002258 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002259 M_CP_INTOPT(x11_display_offset);
2260 M_CP_INTOPT(x11_forwarding);
2261 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002262 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002263 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002264 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002265 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002266 M_CP_INTOPT(client_alive_count_max);
2267 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002268 M_CP_INTOPT(ip_qos_interactive);
2269 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002270 M_CP_INTOPT(rekey_limit);
2271 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002272 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002273
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002274 /*
2275 * The bind_mask is a mode_t that may be unsigned, so we can't use
2276 * M_CP_INTOPT - it does a signed comparison that causes compiler
2277 * warnings.
2278 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002279 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002280 dst->fwd_opts.streamlocal_bind_mask =
2281 src->fwd_opts.streamlocal_bind_mask;
2282 }
2283
Damien Miller534b2cc2013-12-05 14:07:27 +11002284 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2285#define M_CP_STROPT(n) do {\
2286 if (src->n != NULL && dst->n != src->n) { \
2287 free(dst->n); \
2288 dst->n = src->n; \
2289 } \
2290} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002291#define M_CP_STRARRAYOPT(s, num_s) do {\
2292 u_int i; \
2293 if (src->num_s != 0) { \
2294 for (i = 0; i < dst->num_s; i++) \
2295 free(dst->s[i]); \
2296 free(dst->s); \
2297 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2298 for (i = 0; i < src->num_s; i++) \
2299 dst->s[i] = xstrdup(src->s[i]); \
2300 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002301 } \
2302} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002303
Damien Millerf2e407e2011-05-20 19:04:14 +10002304 /* See comment in servconf.h */
2305 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002306
djm@openbsd.orged085102015-10-29 08:05:01 +00002307 /* Arguments that accept '+...' need to be expanded */
2308 assemble_algorithms(dst);
2309
Damien Millerc2411902011-05-20 19:03:49 +10002310 /*
2311 * The only things that should be below this point are string options
2312 * which are only used after authentication.
2313 */
Damien Miller5d74e582011-05-20 19:03:31 +10002314 if (preauth)
2315 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002316
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002317 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002318 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002319 if (option_clear_or_none(dst->adm_forced_command)) {
2320 free(dst->adm_forced_command);
2321 dst->adm_forced_command = NULL;
2322 }
Damien Miller5d74e582011-05-20 19:03:31 +10002323 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002324 if (option_clear_or_none(dst->chroot_directory)) {
2325 free(dst->chroot_directory);
2326 dst->chroot_directory = NULL;
2327 }
Darren Tucker45150472006-07-12 22:34:17 +10002328}
2329
Darren Tucker1629c072007-02-19 22:25:37 +11002330#undef M_CP_INTOPT
2331#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002332#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002333
Darren Tucker45150472006-07-12 22:34:17 +10002334void
2335parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002336 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002337{
2338 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002339 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002340
2341 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2342
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002343 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2344 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002345 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002346 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002347 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002348 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002349 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002350 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002351 }
Darren Tuckera627d422013-06-02 07:31:17 +10002352 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002353 if (bad_options > 0)
2354 fatal("%s: terminating, %d bad configuration options",
2355 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002356 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002357}
Darren Tuckere7140f22008-06-10 23:01:51 +10002358
2359static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002360fmt_multistate_int(int val, const struct multistate *m)
2361{
2362 u_int i;
2363
2364 for (i = 0; m[i].key != NULL; i++) {
2365 if (m[i].value == val)
2366 return m[i].key;
2367 }
2368 return "UNKNOWN";
2369}
2370
2371static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002372fmt_intarg(ServerOpCodes code, int val)
2373{
Damien Miller82c55872011-06-23 08:20:30 +10002374 if (val == -1)
2375 return "unset";
2376 switch (code) {
2377 case sAddressFamily:
2378 return fmt_multistate_int(val, multistate_addressfamily);
2379 case sPermitRootLogin:
2380 return fmt_multistate_int(val, multistate_permitrootlogin);
2381 case sGatewayPorts:
2382 return fmt_multistate_int(val, multistate_gatewayports);
2383 case sCompression:
2384 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002385 case sAllowTcpForwarding:
2386 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002387 case sAllowStreamLocalForwarding:
2388 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002389 case sFingerprintHash:
2390 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002391 default:
2392 switch (val) {
2393 case 0:
2394 return "no";
2395 case 1:
2396 return "yes";
2397 default:
2398 return "UNKNOWN";
2399 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002400 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002401}
2402
Darren Tuckere7140f22008-06-10 23:01:51 +10002403static void
2404dump_cfg_int(ServerOpCodes code, int val)
2405{
2406 printf("%s %d\n", lookup_opcode_name(code), val);
2407}
2408
2409static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002410dump_cfg_oct(ServerOpCodes code, int val)
2411{
2412 printf("%s 0%o\n", lookup_opcode_name(code), val);
2413}
2414
2415static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002416dump_cfg_fmtint(ServerOpCodes code, int val)
2417{
2418 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2419}
2420
2421static void
2422dump_cfg_string(ServerOpCodes code, const char *val)
2423{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002424 printf("%s %s\n", lookup_opcode_name(code),
2425 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002426}
2427
2428static void
2429dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2430{
2431 u_int i;
2432
2433 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002434 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2435}
2436
2437static void
2438dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2439{
2440 u_int i;
2441
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002442 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002443 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002444 printf("%s", lookup_opcode_name(code));
2445 for (i = 0; i < count; i++)
2446 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002447 if (code == sAuthenticationMethods && count == 0)
2448 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002449 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002450}
2451
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002452static char *
2453format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002454{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002455 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002456 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002457 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002458 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002459
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002460 /*
2461 * ListenAddress must be after Port. add_one_listen_addr pushes
2462 * addresses onto a stack, so to maintain ordering we need to
2463 * print these in reverse order.
2464 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002465 for (ai = la->addrs; ai; ai = ai->ai_next) {
2466 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002467 sizeof(addr), port, sizeof(port),
2468 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002469 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2470 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002471 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002472 laddr2 = laddr1;
2473 if (ai->ai_family == AF_INET6) {
2474 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2475 addr, port,
2476 la->rdomain == NULL ? "" : " rdomain ",
2477 la->rdomain == NULL ? "" : la->rdomain,
2478 laddr2);
2479 } else {
2480 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2481 addr, port,
2482 la->rdomain == NULL ? "" : " rdomain ",
2483 la->rdomain == NULL ? "" : la->rdomain,
2484 laddr2);
2485 }
2486 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002487 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002488 return laddr1;
2489}
2490
2491void
2492dump_config(ServerOptions *o)
2493{
2494 char *s;
2495 u_int i;
2496
2497 /* these are usually at the top of the config */
2498 for (i = 0; i < o->num_ports; i++)
2499 printf("port %d\n", o->ports[i]);
2500 dump_cfg_fmtint(sAddressFamily, o->address_family);
2501
2502 for (i = 0; i < o->num_listen_addrs; i++) {
2503 s = format_listen_addrs(&o->listen_addrs[i]);
2504 printf("%s", s);
2505 free(s);
2506 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002507
2508 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002509#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002510 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002511#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002512 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002513 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2514 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002515 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002516 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2517 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002518 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002519
2520 /* formatted integer arguments */
2521 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2522 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2523 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002524 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2525 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2526 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002527 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002528#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002529 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2530 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2531 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002532# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002533 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002534# endif
2535#endif
2536#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002537 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2538 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002539#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002540 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2541 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2542 o->kbd_interactive_authentication);
2543 dump_cfg_fmtint(sChallengeResponseAuthentication,
2544 o->challenge_response_authentication);
2545 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002546#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002547 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002548#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002549 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2550 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002551 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002552 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002553 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2554 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2555 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002556 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002557 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002558 dump_cfg_fmtint(sUseDNS, o->use_dns);
2559 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002560 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002561 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002562 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002563 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002564 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002565 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002566
2567 /* string arguments */
2568 dump_cfg_string(sPidFile, o->pid_file);
2569 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002570 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2571 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002572 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002573 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002574 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002575 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2576 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002577 dump_cfg_string(sAuthorizedPrincipalsFile,
2578 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002579 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2580 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002581 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2582 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002583 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2584 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002585 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002586 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002587 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002588 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2589 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002590 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2591 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002592 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2593 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002594 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002595
2596 /* string arguments requiring a lookup */
2597 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2598 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2599
2600 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002601 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2602 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002603 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2604 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002605 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002606 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002607 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2608 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2609 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2610 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2611 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002612 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002613 dump_cfg_strarray_oneline(sAuthenticationMethods,
2614 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002615
2616 /* other arguments */
2617 for (i = 0; i < o->num_subsystems; i++)
2618 printf("subsystem %s %s\n", o->subsystem_name[i],
2619 o->subsystem_args[i]);
2620
2621 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2622 o->max_startups_rate, o->max_startups);
2623
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002624 s = NULL;
2625 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002626 if (tunmode_desc[i].val == o->permit_tun) {
2627 s = tunmode_desc[i].text;
2628 break;
2629 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002630 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002631 dump_cfg_string(sPermitTunnel, s);
2632
Damien Miller91475862011-05-05 14:14:34 +10002633 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2634 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002635
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002636 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002637 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002638
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002639 printf("permitopen");
2640 if (o->num_permitted_opens == 0)
2641 printf(" any");
2642 else {
2643 for (i = 0; i < o->num_permitted_opens; i++)
2644 printf(" %s", o->permitted_opens[i]);
2645 }
2646 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002647 printf("permitlisten");
2648 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002649 printf(" any");
2650 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002651 for (i = 0; i < o->num_permitted_listens; i++)
2652 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002653 }
2654 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002655
2656 if (o->permit_user_env_whitelist == NULL) {
2657 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2658 } else {
2659 printf("permituserenvironment %s\n",
2660 o->permit_user_env_whitelist);
2661 }
2662
Darren Tuckere7140f22008-06-10 23:01:51 +10002663}