blob: cb57865835ed5c596b42ee9857b071f3cadef500 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org87ddd672018-06-19 02:59:41 +00002/* $OpenBSD: servconf.c,v 1.333 2018/06/19 02:59:41 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;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000133 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000134 options->rekey_limit = -1;
135 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100136 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000137 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000138 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100139 options->num_allow_users = 0;
140 options->num_deny_users = 0;
141 options->num_allow_groups = 0;
142 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000143 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000144 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000145 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000146 options->fwd_opts.gateway_ports = -1;
147 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
148 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000149 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000150 options->max_startups_begin = -1;
151 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000152 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000153 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000154 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000155 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000156 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000157 options->client_alive_interval = -1;
158 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000159 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000160 options->num_accept_env = 0;
djm@openbsd.org28013752018-06-09 03:03:10 +0000161 options->num_setenv = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100162 options->permit_tun = -1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000163 options->permitted_opens = NULL;
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000164 options->permitted_listens = NULL;
Damien Millere2754432006-07-24 14:06:47 +1000165 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100166 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100167 options->authorized_keys_command = NULL;
168 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100169 options->revoked_keys_file = NULL;
170 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000171 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000172 options->authorized_principals_command = NULL;
173 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100174 options->ip_qos_interactive = -1;
175 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000176 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000177 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000178 options->disable_forwarding = -1;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000179 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000180}
181
djm@openbsd.org161cf412014-12-22 07:55:51 +0000182/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
183static int
184option_clear_or_none(const char *o)
185{
186 return o == NULL || strcasecmp(o, "none") == 0;
187}
188
djm@openbsd.orged085102015-10-29 08:05:01 +0000189static void
190assemble_algorithms(ServerOptions *o)
191{
192 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
193 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
194 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
195 kex_assemble_names(KEX_DEFAULT_PK_ALG,
196 &o->hostkeyalgorithms) != 0 ||
197 kex_assemble_names(KEX_DEFAULT_PK_ALG,
198 &o->hostbased_key_types) != 0 ||
199 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
200 fatal("kex_assemble_names failed");
201}
202
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000203static void
204array_append(const char *file, const int line, const char *directive,
205 char ***array, u_int *lp, const char *s)
206{
207
208 if (*lp >= INT_MAX)
209 fatal("%s line %d: Too many %s entries", file, line, directive);
210
211 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
212 (*array)[*lp] = xstrdup(s);
213 (*lp)++;
214}
215
216void
217servconf_add_hostkey(const char *file, const int line,
218 ServerOptions *options, const char *path)
219{
220 char *apath = derelativise_path(path);
221
222 array_append(file, line, "HostKey",
223 &options->host_key_files, &options->num_host_key_files, apath);
224 free(apath);
225}
226
227void
228servconf_add_hostcert(const char *file, const int line,
229 ServerOptions *options, const char *path)
230{
231 char *apath = derelativise_path(path);
232
233 array_append(file, line, "HostCertificate",
234 &options->host_cert_files, &options->num_host_cert_files, apath);
235 free(apath);
236}
237
Damien Miller4af51302000-04-16 11:18:38 +1000238void
Damien Miller95def091999-11-25 00:26:21 +1100239fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000240{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000241 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000242
Damien Miller726273e2001-11-12 11:40:11 +1100243 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000244 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000245 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100246
247 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100248 if (options->num_host_key_files == 0) {
249 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000250 servconf_add_hostkey("[default]", 0, options,
251 _PATH_HOST_RSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100252#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000253 servconf_add_hostkey("[default]", 0, options,
254 _PATH_HOST_ECDSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100255#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000256 servconf_add_hostkey("[default]", 0, options,
257 _PATH_HOST_ED25519_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000258#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000259 servconf_add_hostkey("[default]", 0, options,
260 _PATH_HOST_XMSS_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000261#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100262 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100263 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100264 if (options->num_ports == 0)
265 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000266 if (options->address_family == -1)
267 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100268 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000269 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000270 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000271 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100272 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000273 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000274 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000275 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100276 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100277 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100278 if (options->ignore_user_known_hosts == -1)
279 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->print_motd == -1)
281 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000282 if (options->print_lastlog == -1)
283 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100284 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100285 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100286 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100287 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100288 if (options->x11_use_localhost == -1)
289 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000290 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000291 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100292 if (options->permit_tty == -1)
293 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000294 if (options->permit_user_rc == -1)
295 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100296 if (options->strict_modes == -1)
297 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100298 if (options->tcp_keep_alive == -1)
299 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100300 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100301 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100302 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000303 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000304 if (options->hostbased_authentication == -1)
305 options->hostbased_authentication = 0;
306 if (options->hostbased_uses_name_from_packet_only == -1)
307 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100308 if (options->pubkey_authentication == -1)
309 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100310 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000311 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100312 if (options->kerberos_or_local_passwd == -1)
313 options->kerberos_or_local_passwd = 1;
314 if (options->kerberos_ticket_cleanup == -1)
315 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100316 if (options->kerberos_get_afs_token == -1)
317 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000318 if (options->gss_authentication == -1)
319 options->gss_authentication = 0;
320 if (options->gss_cleanup_creds == -1)
321 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000322 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000323 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100324 if (options->password_authentication == -1)
325 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100326 if (options->kbd_interactive_authentication == -1)
327 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000328 if (options->challenge_response_authentication == -1)
329 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100330 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100331 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000332 if (options->permit_user_env == -1)
333 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000334 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000335 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000336 if (options->rekey_limit == -1)
337 options->rekey_limit = 0;
338 if (options->rekey_interval == -1)
339 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100340 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100341 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000342 if (options->allow_streamlocal_forwarding == -1)
343 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000344 if (options->allow_agent_forwarding == -1)
345 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000346 if (options->fwd_opts.gateway_ports == -1)
347 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000348 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100349 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000350 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100351 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000352 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100353 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000354 if (options->max_authtries == -1)
355 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000356 if (options->max_sessions == -1)
357 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000358 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000359 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000360 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100361 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000362 if (options->client_alive_count_max == -1)
363 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000364 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000365 array_append("[default]", 0, "AuthorizedKeysFiles",
366 &options->authorized_keys_files,
367 &options->num_authkeys_files,
368 _PATH_SSH_USER_PERMITTED_KEYS);
369 array_append("[default]", 0, "AuthorizedKeysFiles",
370 &options->authorized_keys_files,
371 &options->num_authkeys_files,
372 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000373 }
Damien Millerd27b9472005-12-13 19:29:02 +1100374 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100375 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100376 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000377 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100378 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000379 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000380 if (options->version_addendum == NULL)
381 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000382 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
383 options->fwd_opts.streamlocal_bind_mask = 0177;
384 if (options->fwd_opts.streamlocal_bind_unlink == -1)
385 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000386 if (options->fingerprint_hash == -1)
387 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000388 if (options->disable_forwarding == -1)
389 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000390 if (options->expose_userauth_info == -1)
391 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000392
djm@openbsd.orged085102015-10-29 08:05:01 +0000393 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000394
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000395 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000396 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000397 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000398
djm@openbsd.org161cf412014-12-22 07:55:51 +0000399#define CLEAR_ON_NONE(v) \
400 do { \
401 if (option_clear_or_none(v)) { \
402 free(v); \
403 v = NULL; \
404 } \
405 } while(0)
406 CLEAR_ON_NONE(options->pid_file);
407 CLEAR_ON_NONE(options->xauth_location);
408 CLEAR_ON_NONE(options->banner);
409 CLEAR_ON_NONE(options->trusted_user_ca_keys);
410 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000411 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000412 CLEAR_ON_NONE(options->adm_forced_command);
413 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000414 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000415 for (i = 0; i < options->num_host_key_files; i++)
416 CLEAR_ON_NONE(options->host_key_files[i]);
417 for (i = 0; i < options->num_host_cert_files; i++)
418 CLEAR_ON_NONE(options->host_cert_files[i]);
419#undef CLEAR_ON_NONE
420
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000421 /* Similar handling for AuthenticationMethods=any */
422 if (options->num_auth_methods == 1 &&
423 strcmp(options->auth_methods[0], "any") == 0) {
424 free(options->auth_methods[0]);
425 options->auth_methods[0] = NULL;
426 options->num_auth_methods = 0;
427 }
428
Tim Rice40017b02002-07-14 13:36:49 -0700429#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000430 if (use_privsep && options->compression == 1) {
431 error("This platform does not support both privilege "
432 "separation and compression");
433 error("Compression disabled");
434 options->compression = 0;
435 }
436#endif
437
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000438}
439
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000440/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100441typedef enum {
442 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100443 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000444 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100445 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000446 sPort, sHostKeyFile, sLoginGraceTime,
447 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000448 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100449 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000450 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100451 sPasswordAuthentication, sKbdInteractiveAuthentication,
452 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000453 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100454 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100455 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000456 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000457 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000458 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000459 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
460 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000461 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000462 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000463 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000464 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000465 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000466 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000467 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100468 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100469 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000470 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000471 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000472 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100473 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000474 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000475 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000476 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000477 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000478 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000479} ServerOpCodes;
480
Darren Tucker45150472006-07-12 22:34:17 +1000481#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
482#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
483#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
484
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000485/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100486static struct {
487 const char *name;
488 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000489 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100490} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100491 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000492#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000493 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000494#else
Darren Tucker45150472006-07-12 22:34:17 +1000495 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000496#endif
Darren Tucker45150472006-07-12 22:34:17 +1000497 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100498 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000499 { "port", sPort, SSHCFG_GLOBAL },
500 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
501 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000502 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000503 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000504 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000505 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000506 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100507 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000508 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000509 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000510 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000511 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100512 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000513 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000514 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000515 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000516 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100517 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000518 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000519 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000520#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100521 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
523 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100524#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000526#else
Darren Tucker45150472006-07-12 22:34:17 +1000527 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100528#endif
529#else
Darren Tucker1629c072007-02-19 22:25:37 +1100530 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000531 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
532 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
533 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000534#endif
Darren Tucker45150472006-07-12 22:34:17 +1000535 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
536 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000537#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100538 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000539 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000540 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000541#else
Darren Tucker1629c072007-02-19 22:25:37 +1100542 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000543 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000544 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000545#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100546 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
547 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100548 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000549 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
550 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
551 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
552 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
553 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100554#ifdef DISABLE_LASTLOG
555 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
556#else
Darren Tucker45150472006-07-12 22:34:17 +1000557 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100558#endif
Darren Tucker45150472006-07-12 22:34:17 +1000559 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
560 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000561 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
562 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
563 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000564 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
565 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100566 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000567 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000568 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000569 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000570 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000571 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
572 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
573 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000574 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000575 { "allowusers", sAllowUsers, SSHCFG_ALL },
576 { "denyusers", sDenyUsers, SSHCFG_ALL },
577 { "allowgroups", sAllowGroups, SSHCFG_ALL },
578 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000579 { "ciphers", sCiphers, SSHCFG_GLOBAL },
580 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000581 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000582 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
583 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
584 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000585 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000586 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100587 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000588 { "usedns", sUseDNS, SSHCFG_GLOBAL },
589 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
590 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000591 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
592 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000593 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000594 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000595 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000596 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000597 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000598 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100599 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000600 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000601 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000602 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000603 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000604 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100605 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100606 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100607 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
608 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000609 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000610 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100611 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100612 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
613 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000614 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
615 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000616 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100617 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000618 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
619 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
620 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000621 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000622 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000623 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000624 { "rdomain", sRDomain, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000625 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000626};
627
Darren Tuckere7140f22008-06-10 23:01:51 +1000628static struct {
629 int val;
630 char *text;
631} tunmode_desc[] = {
632 { SSH_TUNMODE_NO, "no" },
633 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
634 { SSH_TUNMODE_ETHERNET, "ethernet" },
635 { SSH_TUNMODE_YES, "yes" },
636 { -1, NULL }
637};
638
djm@openbsd.org115063a2018-06-06 18:22:41 +0000639/* Returns an opcode name from its number */
640
641static const char *
642lookup_opcode_name(ServerOpCodes code)
643{
644 u_int i;
645
646 for (i = 0; keywords[i].name != NULL; i++)
647 if (keywords[i].opcode == code)
648 return(keywords[i].name);
649 return "UNKNOWN";
650}
651
652
Damien Miller5428f641999-11-25 11:54:57 +1100653/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000654 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100655 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000656
Damien Miller4af51302000-04-16 11:18:38 +1000657static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100658parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000659 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000660{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000661 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000662
Damien Miller95def091999-11-25 00:26:21 +1100663 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000664 if (strcasecmp(cp, keywords[i].name) == 0) {
665 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100666 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000667 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000668
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000669 error("%s: line %d: Bad configuration option: %s",
670 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100671 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000672}
673
Darren Tucker88b6fb22010-01-13 22:44:29 +1100674char *
675derelativise_path(const char *path)
676{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000677 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100678
djm@openbsd.org161cf412014-12-22 07:55:51 +0000679 if (strcasecmp(path, "none") == 0)
680 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100681 expanded = tilde_expand_filename(path, getuid());
682 if (*expanded == '/')
683 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100684 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100685 fatal("%s: getcwd: %s", __func__, strerror(errno));
686 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000687 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100688 return ret;
689}
690
Ben Lindstrombba81212001-06-25 05:01:22 +0000691static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000692add_listen_addr(ServerOptions *options, const char *addr,
693 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100694{
Damien Millereccb9de2005-06-17 12:59:34 +1000695 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100696
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000697 if (port > 0)
698 add_one_listen_addr(options, addr, rdomain, port);
699 else {
700 for (i = 0; i < options->num_ports; i++) {
701 add_one_listen_addr(options, addr, rdomain,
702 options->ports[i]);
703 }
704 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000705}
706
Ben Lindstrombba81212001-06-25 05:01:22 +0000707static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000708add_one_listen_addr(ServerOptions *options, const char *addr,
709 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000710{
711 struct addrinfo hints, *ai, *aitop;
712 char strport[NI_MAXSERV];
713 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000714 u_int i;
715
716 /* Find listen_addrs entry for this rdomain */
717 for (i = 0; i < options->num_listen_addrs; i++) {
718 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
719 break;
720 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
721 continue;
722 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
723 break;
724 }
725 if (i >= options->num_listen_addrs) {
726 /* No entry for this rdomain; allocate one */
727 if (i >= INT_MAX)
728 fatal("%s: too many listen addresses", __func__);
729 options->listen_addrs = xrecallocarray(options->listen_addrs,
730 options->num_listen_addrs, options->num_listen_addrs + 1,
731 sizeof(*options->listen_addrs));
732 i = options->num_listen_addrs++;
733 if (rdomain != NULL)
734 options->listen_addrs[i].rdomain = xstrdup(rdomain);
735 }
736 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000737
738 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100739 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000740 hints.ai_socktype = SOCK_STREAM;
741 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100742 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000743 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
744 fatal("bad addr or host: %s (%s)",
745 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100746 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000747 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
748 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000749 ai->ai_next = options->listen_addrs[i].addrs;
750 options->listen_addrs[i].addrs = aitop;
751}
752
753/* Returns nonzero if the routing domain name is valid */
754static int
755valid_rdomain(const char *name)
756{
Damien Miller43c29bb2017-10-25 13:10:59 +1100757#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100758 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100759#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000760 const char *errstr;
761 long long num;
762 struct rt_tableinfo info;
763 int mib[6];
764 size_t miblen = sizeof(mib);
765
766 if (name == NULL)
767 return 1;
768
769 num = strtonum(name, 0, 255, &errstr);
770 if (errstr != NULL)
771 return 0;
772
773 /* Check whether the table actually exists */
774 memset(mib, 0, sizeof(mib));
775 mib[0] = CTL_NET;
776 mib[1] = PF_ROUTE;
777 mib[4] = NET_RT_TABLE;
778 mib[5] = (int)num;
779 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
780 return 0;
781
782 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100783#else /* defined(__OpenBSD__) */
784 error("Routing domains are not supported on this platform");
785 return 0;
786#endif
Damien Miller34132e52000-01-14 15:45:46 +1100787}
788
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000789/*
790 * Queue a ListenAddress to be processed once we have all of the Ports
791 * and AddressFamily options.
792 */
793static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000794queue_listen_addr(ServerOptions *options, const char *addr,
795 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000796{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000797 struct queued_listenaddr *qla;
798
799 options->queued_listen_addrs = xrecallocarray(
800 options->queued_listen_addrs,
801 options->num_queued_listens, options->num_queued_listens + 1,
802 sizeof(*options->queued_listen_addrs));
803 qla = &options->queued_listen_addrs[options->num_queued_listens++];
804 qla->addr = xstrdup(addr);
805 qla->port = port;
806 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000807}
808
809/*
810 * Process queued (text) ListenAddress entries.
811 */
812static void
813process_queued_listen_addrs(ServerOptions *options)
814{
815 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000816 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000817
818 if (options->num_ports == 0)
819 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
820 if (options->address_family == -1)
821 options->address_family = AF_UNSPEC;
822
823 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000824 qla = &options->queued_listen_addrs[i];
825 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
826 free(qla->addr);
827 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000828 }
829 free(options->queued_listen_addrs);
830 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000831 options->num_queued_listens = 0;
832}
833
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000834/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000835 * Inform channels layer of permitopen options for a single forwarding
836 * direction (local/remote).
837 */
838static void
839process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
840 char **opens, u_int num_opens)
841{
842 u_int i;
843 int port;
844 char *host, *arg, *oarg;
845 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
846 const char *what = lookup_opcode_name(opcode);
847
848 channel_clear_permission(ssh, FORWARD_ADM, where);
849 if (num_opens == 0)
850 return; /* permit any */
851
852 /* handle keywords: "any" / "none" */
853 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
854 return;
855 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
856 channel_disable_admin(ssh, where);
857 return;
858 }
859 /* Otherwise treat it as a list of permitted host:port */
860 for (i = 0; i < num_opens; i++) {
861 oarg = arg = xstrdup(opens[i]);
862 host = hpdelim(&arg);
863 if (host == NULL)
864 fatal("%s: missing host in %s", __func__, what);
865 host = cleanhostname(host);
866 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
867 fatal("%s: bad port number in %s", __func__, what);
868 /* Send it to channels layer */
869 channel_add_permission(ssh, FORWARD_ADM,
870 where, host, port);
871 free(oarg);
872 }
873}
874
875/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000876 * Inform channels layer of permitopen options from configuration.
877 */
878void
879process_permitopen(struct ssh *ssh, ServerOptions *options)
880{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000881 process_permitopen_list(ssh, sPermitOpen,
882 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000883 process_permitopen_list(ssh, sPermitListen,
884 options->permitted_listens,
885 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000886}
887
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000888struct connection_info *
889get_connection_info(int populate, int use_dns)
890{
djm@openbsd.org95767262016-03-07 19:02:43 +0000891 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000892 static struct connection_info ci;
893
894 if (!populate)
895 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000896 ci.host = auth_get_canonical_hostname(ssh, use_dns);
897 ci.address = ssh_remote_ipaddr(ssh);
898 ci.laddress = ssh_local_ipaddr(ssh);
899 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000900 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000901 return &ci;
902}
903
Darren Tucker45150472006-07-12 22:34:17 +1000904/*
905 * The strategy for the Match blocks is that the config file is parsed twice.
906 *
907 * The first time is at startup. activep is initialized to 1 and the
908 * directives in the global context are processed and acted on. Hitting a
909 * Match directive unsets activep and the directives inside the block are
910 * checked for syntax only.
911 *
912 * The second time is after a connection has been established but before
913 * authentication. activep is initialized to 2 and global config directives
914 * are ignored since they have already been processed. If the criteria in a
915 * Match block is met, activep is set and the subsequent directives
916 * processed and actioned until EOF or another Match block unsets it. Any
917 * options set are copied into the main server config.
918 *
919 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000920 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000921 *
922 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
923 * Match Address 192.168.0.*
924 * Tag trusted
925 * Match Group wheel
926 * Tag trusted
927 * Match Tag trusted
928 * AllowTcpForwarding yes
929 * GatewayPorts clientspecified
930 * [...]
931 *
932 * - Add a PermittedChannelRequests directive
933 * Match Group shell
934 * PermittedChannelRequests session,forwarded-tcpip
935 */
936
937static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000938match_cfg_line_group(const char *grps, int line, const char *user)
939{
940 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000941 struct passwd *pw;
942
Damien Miller565ca3f2006-08-19 00:23:15 +1000943 if (user == NULL)
944 goto out;
945
946 if ((pw = getpwnam(user)) == NULL) {
947 debug("Can't match group at line %d because user %.100s does "
948 "not exist", line, user);
949 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
950 debug("Can't Match group because user %.100s not in any group "
951 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000952 } else if (ga_match_pattern_list(grps) != 1) {
953 debug("user %.100s does not match group list %.100s at line %d",
954 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000955 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000956 debug("user %.100s matched group list %.100s at line %d", user,
957 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000958 result = 1;
959 }
960out:
961 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000962 return result;
963}
964
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +0000965static void
966match_test_missing_fatal(const char *criteria, const char *attrib)
967{
968 fatal("'Match %s' in configuration but '%s' not in connection "
969 "test specification.", criteria, attrib);
970}
971
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000972/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000973 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100974 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000975 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000976 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000977static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000978match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000979{
Damien Millercf31f382013-10-24 21:02:56 +1100980 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000981 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000982
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000983 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000984 debug3("checking syntax for 'Match %s'", cp);
985 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000986 debug3("checking match for '%s' user %s host %s addr %s "
987 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
988 ci->host ? ci->host : "(null)",
989 ci->address ? ci->address : "(null)",
990 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000991
992 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100993 attributes++;
994 if (strcasecmp(attrib, "all") == 0) {
995 if (attributes != 1 ||
996 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
997 error("'all' cannot be combined with other "
998 "Match attributes");
999 return -1;
1000 }
1001 *condition = cp;
1002 return 1;
1003 }
Darren Tucker45150472006-07-12 22:34:17 +10001004 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1005 error("Missing Match criteria for %s", attrib);
1006 return -1;
1007 }
Darren Tucker45150472006-07-12 22:34:17 +10001008 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001009 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001010 result = 0;
1011 continue;
1012 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001013 if (ci->user == NULL)
1014 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001015 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001016 result = 0;
1017 else
1018 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001019 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001020 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001021 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001022 result = 0;
1023 continue;
1024 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001025 if (ci->user == NULL)
1026 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001027 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001028 case -1:
1029 return -1;
1030 case 0:
1031 result = 0;
1032 }
Darren Tucker45150472006-07-12 22:34:17 +10001033 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001034 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001035 result = 0;
1036 continue;
1037 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001038 if (ci->host == NULL)
1039 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001040 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001041 result = 0;
1042 else
1043 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001044 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001045 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001046 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001047 result = 0;
1048 continue;
1049 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001050 if (ci->address == NULL)
1051 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001052 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001053 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001054 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001055 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001056 break;
1057 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001058 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001059 result = 0;
1060 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001061 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001062 return -1;
1063 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001064 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001065 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001066 result = 0;
1067 continue;
1068 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001069 if (ci->laddress == NULL)
1070 match_test_missing_fatal("LocalAddress",
1071 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001072 switch (addr_match_list(ci->laddress, arg)) {
1073 case 1:
1074 debug("connection from %.100s matched "
1075 "'LocalAddress %.100s' at line %d",
1076 ci->laddress, arg, line);
1077 break;
1078 case 0:
1079 case -1:
1080 result = 0;
1081 break;
1082 case -2:
1083 return -1;
1084 }
1085 } else if (strcasecmp(attrib, "localport") == 0) {
1086 if ((port = a2port(arg)) == -1) {
1087 error("Invalid LocalPort '%s' on Match line",
1088 arg);
1089 return -1;
1090 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001091 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001092 result = 0;
1093 continue;
1094 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001095 if (ci->lport == 0)
1096 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001097 /* TODO support port lists */
1098 if (port == ci->lport)
1099 debug("connection from %.100s matched "
1100 "'LocalPort %d' at line %d",
1101 ci->laddress, port, line);
1102 else
1103 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001104 } else if (strcasecmp(attrib, "rdomain") == 0) {
1105 if (ci == NULL || ci->rdomain == NULL) {
1106 result = 0;
1107 continue;
1108 }
1109 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1110 result = 0;
1111 else
1112 debug("user %.100s matched 'RDomain %.100s' at "
1113 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001114 } else {
1115 error("Unsupported Match attribute %s", attrib);
1116 return -1;
1117 }
1118 }
Damien Millercf31f382013-10-24 21:02:56 +11001119 if (attributes == 0) {
1120 error("One or more attributes required for Match");
1121 return -1;
1122 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001123 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001124 debug3("match %sfound", result ? "" : "not ");
1125 *condition = cp;
1126 return result;
1127}
1128
Damien Millere2754432006-07-24 14:06:47 +10001129#define WHITESPACE " \t\r\n"
1130
Damien Miller33322122011-06-20 14:43:11 +10001131/* Multistate option parsing */
1132struct multistate {
1133 char *key;
1134 int value;
1135};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001136static const struct multistate multistate_flag[] = {
1137 { "yes", 1 },
1138 { "no", 0 },
1139 { NULL, -1 }
1140};
Damien Miller33322122011-06-20 14:43:11 +10001141static const struct multistate multistate_addressfamily[] = {
1142 { "inet", AF_INET },
1143 { "inet6", AF_INET6 },
1144 { "any", AF_UNSPEC },
1145 { NULL, -1 }
1146};
1147static const struct multistate multistate_permitrootlogin[] = {
1148 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001149 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001150 { "forced-commands-only", PERMIT_FORCED_ONLY },
1151 { "yes", PERMIT_YES },
1152 { "no", PERMIT_NO },
1153 { NULL, -1 }
1154};
1155static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +00001156 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +00001157 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001158 { "no", COMP_NONE },
1159 { NULL, -1 }
1160};
1161static const struct multistate multistate_gatewayports[] = {
1162 { "clientspecified", 2 },
1163 { "yes", 1 },
1164 { "no", 0 },
1165 { NULL, -1 }
1166};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001167static const struct multistate multistate_tcpfwd[] = {
1168 { "yes", FORWARD_ALLOW },
1169 { "all", FORWARD_ALLOW },
1170 { "no", FORWARD_DENY },
1171 { "remote", FORWARD_REMOTE },
1172 { "local", FORWARD_LOCAL },
1173 { NULL, -1 }
1174};
Damien Miller33322122011-06-20 14:43:11 +10001175
Ben Lindstromade03f62001-12-06 18:22:17 +00001176int
1177process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001178 const char *filename, int linenum, int *activep,
1179 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001180{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001181 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001182 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001183 SyslogFacility *log_facility_ptr;
1184 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001185 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001186 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001187 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001188 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001189 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001190 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001191
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001192 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1193 if ((len = strlen(line)) == 0)
1194 return 0;
1195 for (len--; len > 0; len--) {
1196 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1197 break;
1198 line[len] = '\0';
1199 }
1200
Ben Lindstromade03f62001-12-06 18:22:17 +00001201 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001202 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001203 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001204 /* Ignore leading whitespace */
1205 if (*arg == '\0')
1206 arg = strdelim(&cp);
1207 if (!arg || !*arg || *arg == '#')
1208 return 0;
1209 intptr = NULL;
1210 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001211 opcode = parse_token(arg, filename, linenum, &flags);
1212
1213 if (activep == NULL) { /* We are processing a command line directive */
1214 cmdline = 1;
1215 activep = &cmdline;
1216 }
1217 if (*activep && opcode != sMatch)
1218 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1219 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001220 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001221 fatal("%s line %d: Directive '%s' is not allowed "
1222 "within a Match block", filename, linenum, arg);
1223 } else { /* this is a directive we have already processed */
1224 while (arg)
1225 arg = strdelim(&cp);
1226 return 0;
1227 }
1228 }
1229
Ben Lindstromade03f62001-12-06 18:22:17 +00001230 switch (opcode) {
1231 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001232 case sUsePAM:
1233 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001234 goto parse_flag;
1235
1236 /* Standard Options */
1237 case sBadOption:
1238 return -1;
1239 case sPort:
1240 /* ignore ports from configfile if cmdline specifies ports */
1241 if (options->ports_from_cmdline)
1242 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001243 if (options->num_ports >= MAX_PORTS)
1244 fatal("%s line %d: too many ports.",
1245 filename, linenum);
1246 arg = strdelim(&cp);
1247 if (!arg || *arg == '\0')
1248 fatal("%s line %d: missing port number.",
1249 filename, linenum);
1250 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001251 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001252 fatal("%s line %d: Badly formatted port number.",
1253 filename, linenum);
1254 break;
1255
Ben Lindstromade03f62001-12-06 18:22:17 +00001256 case sLoginGraceTime:
1257 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001258 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001259 arg = strdelim(&cp);
1260 if (!arg || *arg == '\0')
1261 fatal("%s line %d: missing time value.",
1262 filename, linenum);
1263 if ((value = convtime(arg)) == -1)
1264 fatal("%s line %d: invalid time value.",
1265 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001266 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001267 *intptr = value;
1268 break;
1269
Ben Lindstromade03f62001-12-06 18:22:17 +00001270 case sListenAddress:
1271 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001272 if (arg == NULL || *arg == '\0')
1273 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001274 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001275 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1276 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1277 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001278 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001279 p = arg;
1280 } else {
1281 p = hpdelim(&arg);
1282 if (p == NULL)
1283 fatal("%s line %d: bad address:port usage",
1284 filename, linenum);
1285 p = cleanhostname(p);
1286 if (arg == NULL)
1287 port = 0;
1288 else if ((port = a2port(arg)) <= 0)
1289 fatal("%s line %d: bad port number",
1290 filename, linenum);
1291 }
1292 /* Optional routing table */
1293 arg2 = NULL;
1294 if ((arg = strdelim(&cp)) != NULL) {
1295 if (strcmp(arg, "rdomain") != 0 ||
1296 (arg2 = strdelim(&cp)) == NULL)
1297 fatal("%s line %d: bad ListenAddress syntax",
1298 filename, linenum);
1299 if (!valid_rdomain(arg2))
1300 fatal("%s line %d: bad routing domain",
1301 filename, linenum);
1302 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001303
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001304 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001305
Ben Lindstromade03f62001-12-06 18:22:17 +00001306 break;
1307
Darren Tucker0f383232005-01-20 10:57:56 +11001308 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001309 intptr = &options->address_family;
1310 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001311 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001312 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001313 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001314 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001315 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001316 value = -1;
1317 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1318 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1319 value = multistate_ptr[i].value;
1320 break;
1321 }
1322 }
1323 if (value == -1)
1324 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001325 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001326 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001327 *intptr = value;
1328 break;
1329
Ben Lindstromade03f62001-12-06 18:22:17 +00001330 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001331 arg = strdelim(&cp);
1332 if (!arg || *arg == '\0')
1333 fatal("%s line %d: missing file name.",
1334 filename, linenum);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001335 if (*activep)
1336 servconf_add_hostkey(filename, linenum, options, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001337 break;
1338
Damien Miller85b45e02013-07-20 13:21:52 +10001339 case sHostKeyAgent:
1340 charptr = &options->host_key_agent;
1341 arg = strdelim(&cp);
1342 if (!arg || *arg == '\0')
1343 fatal("%s line %d: missing socket name.",
1344 filename, linenum);
1345 if (*activep && *charptr == NULL)
1346 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1347 xstrdup(arg) : derelativise_path(arg);
1348 break;
1349
Damien Miller0a80ca12010-02-27 07:55:05 +11001350 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001351 arg = strdelim(&cp);
1352 if (!arg || *arg == '\0')
1353 fatal("%s line %d: missing file name.",
1354 filename, linenum);
1355 if (*activep)
1356 servconf_add_hostcert(filename, linenum, options, arg);
1357 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001358
Ben Lindstromade03f62001-12-06 18:22:17 +00001359 case sPidFile:
1360 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001361 parse_filename:
1362 arg = strdelim(&cp);
1363 if (!arg || *arg == '\0')
1364 fatal("%s line %d: missing file name.",
1365 filename, linenum);
1366 if (*activep && *charptr == NULL) {
1367 *charptr = derelativise_path(arg);
1368 /* increase optional counter */
1369 if (intptr != NULL)
1370 *intptr = *intptr + 1;
1371 }
1372 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001373
1374 case sPermitRootLogin:
1375 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001376 multistate_ptr = multistate_permitrootlogin;
1377 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001378
1379 case sIgnoreRhosts:
1380 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001381 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001382 multistate_ptr = multistate_flag;
1383 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001384
1385 case sIgnoreUserKnownHosts:
1386 intptr = &options->ignore_user_known_hosts;
1387 goto parse_flag;
1388
Ben Lindstromade03f62001-12-06 18:22:17 +00001389 case sHostbasedAuthentication:
1390 intptr = &options->hostbased_authentication;
1391 goto parse_flag;
1392
1393 case sHostbasedUsesNameFromPacketOnly:
1394 intptr = &options->hostbased_uses_name_from_packet_only;
1395 goto parse_flag;
1396
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001397 case sHostbasedAcceptedKeyTypes:
1398 charptr = &options->hostbased_key_types;
1399 parse_keytypes:
1400 arg = strdelim(&cp);
1401 if (!arg || *arg == '\0')
1402 fatal("%s line %d: Missing argument.",
1403 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001404 if (*arg != '-' &&
1405 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001406 fatal("%s line %d: Bad key types '%s'.",
1407 filename, linenum, arg ? arg : "<NONE>");
1408 if (*activep && *charptr == NULL)
1409 *charptr = xstrdup(arg);
1410 break;
1411
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001412 case sHostKeyAlgorithms:
1413 charptr = &options->hostkeyalgorithms;
1414 goto parse_keytypes;
1415
Ben Lindstromade03f62001-12-06 18:22:17 +00001416 case sPubkeyAuthentication:
1417 intptr = &options->pubkey_authentication;
1418 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001419
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001420 case sPubkeyAcceptedKeyTypes:
1421 charptr = &options->pubkey_key_types;
1422 goto parse_keytypes;
1423
Ben Lindstromade03f62001-12-06 18:22:17 +00001424 case sKerberosAuthentication:
1425 intptr = &options->kerberos_authentication;
1426 goto parse_flag;
1427
1428 case sKerberosOrLocalPasswd:
1429 intptr = &options->kerberos_or_local_passwd;
1430 goto parse_flag;
1431
1432 case sKerberosTicketCleanup:
1433 intptr = &options->kerberos_ticket_cleanup;
1434 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001435
Darren Tucker22ef5082003-12-31 11:37:34 +11001436 case sKerberosGetAFSToken:
1437 intptr = &options->kerberos_get_afs_token;
1438 goto parse_flag;
1439
Darren Tucker0efd1552003-08-26 11:49:55 +10001440 case sGssAuthentication:
1441 intptr = &options->gss_authentication;
1442 goto parse_flag;
1443
1444 case sGssCleanupCreds:
1445 intptr = &options->gss_cleanup_creds;
1446 goto parse_flag;
1447
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001448 case sGssStrictAcceptor:
1449 intptr = &options->gss_strict_acceptor;
1450 goto parse_flag;
1451
Ben Lindstromade03f62001-12-06 18:22:17 +00001452 case sPasswordAuthentication:
1453 intptr = &options->password_authentication;
1454 goto parse_flag;
1455
1456 case sKbdInteractiveAuthentication:
1457 intptr = &options->kbd_interactive_authentication;
1458 goto parse_flag;
1459
1460 case sChallengeResponseAuthentication:
1461 intptr = &options->challenge_response_authentication;
1462 goto parse_flag;
1463
1464 case sPrintMotd:
1465 intptr = &options->print_motd;
1466 goto parse_flag;
1467
1468 case sPrintLastLog:
1469 intptr = &options->print_lastlog;
1470 goto parse_flag;
1471
1472 case sX11Forwarding:
1473 intptr = &options->x11_forwarding;
1474 goto parse_flag;
1475
1476 case sX11DisplayOffset:
1477 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001478 parse_int:
1479 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001480 if ((errstr = atoi_err(arg, &value)) != NULL)
1481 fatal("%s line %d: integer value %s.",
1482 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001483 if (*activep && *intptr == -1)
1484 *intptr = value;
1485 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001486
Damien Miller95c249f2002-02-05 12:11:34 +11001487 case sX11UseLocalhost:
1488 intptr = &options->x11_use_localhost;
1489 goto parse_flag;
1490
Ben Lindstromade03f62001-12-06 18:22:17 +00001491 case sXAuthLocation:
1492 charptr = &options->xauth_location;
1493 goto parse_filename;
1494
Damien Miller5ff30c62013-10-30 22:21:50 +11001495 case sPermitTTY:
1496 intptr = &options->permit_tty;
1497 goto parse_flag;
1498
Damien Miller72e6b5c2014-07-04 09:00:04 +10001499 case sPermitUserRC:
1500 intptr = &options->permit_user_rc;
1501 goto parse_flag;
1502
Ben Lindstromade03f62001-12-06 18:22:17 +00001503 case sStrictModes:
1504 intptr = &options->strict_modes;
1505 goto parse_flag;
1506
Damien Miller12c150e2003-12-17 16:31:10 +11001507 case sTCPKeepAlive:
1508 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001509 goto parse_flag;
1510
1511 case sEmptyPasswd:
1512 intptr = &options->permit_empty_passwd;
1513 goto parse_flag;
1514
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001515 case sPermitUserEnvironment:
1516 intptr = &options->permit_user_env;
1517 goto parse_flag;
1518
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001519 case sCompression:
1520 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001521 multistate_ptr = multistate_compression;
1522 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001523
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001524 case sRekeyLimit:
1525 arg = strdelim(&cp);
1526 if (!arg || *arg == '\0')
1527 fatal("%.200s line %d: Missing argument.", filename,
1528 linenum);
1529 if (strcmp(arg, "default") == 0) {
1530 val64 = 0;
1531 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001532 if (scan_scaled(arg, &val64) == -1)
1533 fatal("%.200s line %d: Bad number '%s': %s",
1534 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001535 if (val64 != 0 && val64 < 16)
1536 fatal("%.200s line %d: RekeyLimit too small",
1537 filename, linenum);
1538 }
1539 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001540 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001541 if (cp != NULL) { /* optional rekey interval present */
1542 if (strcmp(cp, "none") == 0) {
1543 (void)strdelim(&cp); /* discard */
1544 break;
1545 }
1546 intptr = &options->rekey_interval;
1547 goto parse_time;
1548 }
1549 break;
1550
Ben Lindstromade03f62001-12-06 18:22:17 +00001551 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001552 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001553 multistate_ptr = multistate_gatewayports;
1554 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001555
Damien Miller3a961dc2003-06-03 10:25:48 +10001556 case sUseDNS:
1557 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001558 goto parse_flag;
1559
1560 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001561 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001562 arg = strdelim(&cp);
1563 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001564 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001565 fatal("%.200s line %d: unsupported log facility '%s'",
1566 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001567 if (*log_facility_ptr == -1)
1568 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001569 break;
1570
1571 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001572 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001573 arg = strdelim(&cp);
1574 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001575 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001576 fatal("%.200s line %d: unsupported log level '%s'",
1577 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001578 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001579 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001580 break;
1581
1582 case sAllowTcpForwarding:
1583 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001584 multistate_ptr = multistate_tcpfwd;
1585 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001586
Damien Miller7acefbb2014-07-18 14:11:24 +10001587 case sAllowStreamLocalForwarding:
1588 intptr = &options->allow_streamlocal_forwarding;
1589 multistate_ptr = multistate_tcpfwd;
1590 goto parse_multistate;
1591
Damien Miller4f755cd2008-05-19 14:57:41 +10001592 case sAllowAgentForwarding:
1593 intptr = &options->allow_agent_forwarding;
1594 goto parse_flag;
1595
djm@openbsd.org7844f352016-11-30 03:00:05 +00001596 case sDisableForwarding:
1597 intptr = &options->disable_forwarding;
1598 goto parse_flag;
1599
Ben Lindstromade03f62001-12-06 18:22:17 +00001600 case sAllowUsers:
1601 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001602 if (match_user(NULL, NULL, NULL, arg) == -1)
1603 fatal("%s line %d: invalid AllowUsers pattern: "
1604 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001605 if (!*activep)
1606 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001607 array_append(filename, linenum, "AllowUsers",
1608 &options->allow_users, &options->num_allow_users,
1609 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001610 }
1611 break;
1612
1613 case sDenyUsers:
1614 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001615 if (match_user(NULL, NULL, NULL, arg) == -1)
1616 fatal("%s line %d: invalid DenyUsers pattern: "
1617 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001618 if (!*activep)
1619 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001620 array_append(filename, linenum, "DenyUsers",
1621 &options->deny_users, &options->num_deny_users,
1622 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001623 }
1624 break;
1625
1626 case sAllowGroups:
1627 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001628 if (!*activep)
1629 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001630 array_append(filename, linenum, "AllowGroups",
1631 &options->allow_groups, &options->num_allow_groups,
1632 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001633 }
1634 break;
1635
1636 case sDenyGroups:
1637 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001638 if (!*activep)
1639 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001640 array_append(filename, linenum, "DenyGroups",
1641 &options->deny_groups, &options->num_deny_groups,
1642 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001643 }
1644 break;
1645
1646 case sCiphers:
1647 arg = strdelim(&cp);
1648 if (!arg || *arg == '\0')
1649 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001650 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001651 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1652 filename, linenum, arg ? arg : "<NONE>");
1653 if (options->ciphers == NULL)
1654 options->ciphers = xstrdup(arg);
1655 break;
1656
1657 case sMacs:
1658 arg = strdelim(&cp);
1659 if (!arg || *arg == '\0')
1660 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001661 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001662 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1663 filename, linenum, arg ? arg : "<NONE>");
1664 if (options->macs == NULL)
1665 options->macs = xstrdup(arg);
1666 break;
1667
Damien Millerd5f62bf2010-09-24 22:11:14 +10001668 case sKexAlgorithms:
1669 arg = strdelim(&cp);
1670 if (!arg || *arg == '\0')
1671 fatal("%s line %d: Missing argument.",
1672 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001673 if (*arg != '-' &&
1674 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001675 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1676 filename, linenum, arg ? arg : "<NONE>");
1677 if (options->kex_algorithms == NULL)
1678 options->kex_algorithms = xstrdup(arg);
1679 break;
1680
Ben Lindstromade03f62001-12-06 18:22:17 +00001681 case sSubsystem:
1682 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1683 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001684 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001685 }
1686 arg = strdelim(&cp);
1687 if (!arg || *arg == '\0')
1688 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001689 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001690 if (!*activep) {
1691 arg = strdelim(&cp);
1692 break;
1693 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001694 for (i = 0; i < options->num_subsystems; i++)
1695 if (strcmp(arg, options->subsystem_name[i]) == 0)
1696 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001697 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001698 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1699 arg = strdelim(&cp);
1700 if (!arg || *arg == '\0')
1701 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001702 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001703 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001704
1705 /* Collect arguments (separate to executable) */
1706 p = xstrdup(arg);
1707 len = strlen(p) + 1;
1708 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1709 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001710 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001711 strlcat(p, " ", len);
1712 strlcat(p, arg, len);
1713 }
1714 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001715 options->num_subsystems++;
1716 break;
1717
1718 case sMaxStartups:
1719 arg = strdelim(&cp);
1720 if (!arg || *arg == '\0')
1721 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001722 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001723 if ((n = sscanf(arg, "%d:%d:%d",
1724 &options->max_startups_begin,
1725 &options->max_startups_rate,
1726 &options->max_startups)) == 3) {
1727 if (options->max_startups_begin >
1728 options->max_startups ||
1729 options->max_startups_rate > 100 ||
1730 options->max_startups_rate < 1)
1731 fatal("%s line %d: Illegal MaxStartups spec.",
1732 filename, linenum);
1733 } else if (n != 1)
1734 fatal("%s line %d: Illegal MaxStartups spec.",
1735 filename, linenum);
1736 else
1737 options->max_startups = options->max_startups_begin;
1738 break;
1739
Darren Tucker89413db2004-05-24 10:36:23 +10001740 case sMaxAuthTries:
1741 intptr = &options->max_authtries;
1742 goto parse_int;
1743
Damien Miller7207f642008-05-19 15:34:50 +10001744 case sMaxSessions:
1745 intptr = &options->max_sessions;
1746 goto parse_int;
1747
Ben Lindstromade03f62001-12-06 18:22:17 +00001748 case sBanner:
1749 charptr = &options->banner;
1750 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001751
Ben Lindstromade03f62001-12-06 18:22:17 +00001752 /*
1753 * These options can contain %X options expanded at
1754 * connect time, so that you can specify paths like:
1755 *
1756 * AuthorizedKeysFile /etc/ssh_keys/%u
1757 */
1758 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001759 if (*activep && options->num_authkeys_files == 0) {
1760 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001761 arg = tilde_expand_filename(arg, getuid());
1762 array_append(filename, linenum,
1763 "AuthorizedKeysFile",
1764 &options->authorized_keys_files,
1765 &options->num_authkeys_files, arg);
1766 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001767 }
1768 }
1769 return 0;
1770
Damien Miller30da3442010-05-10 11:58:03 +10001771 case sAuthorizedPrincipalsFile:
1772 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001773 arg = strdelim(&cp);
1774 if (!arg || *arg == '\0')
1775 fatal("%s line %d: missing file name.",
1776 filename, linenum);
1777 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001778 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001779 /* increase optional counter */
1780 if (intptr != NULL)
1781 *intptr = *intptr + 1;
1782 }
1783 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001784
1785 case sClientAliveInterval:
1786 intptr = &options->client_alive_interval;
1787 goto parse_time;
1788
1789 case sClientAliveCountMax:
1790 intptr = &options->client_alive_count_max;
1791 goto parse_int;
1792
Darren Tucker46bc0752004-05-02 22:11:30 +10001793 case sAcceptEnv:
1794 while ((arg = strdelim(&cp)) && *arg != '\0') {
1795 if (strchr(arg, '=') != NULL)
1796 fatal("%s line %d: Invalid environment name.",
1797 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001798 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001799 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001800 array_append(filename, linenum, "AcceptEnv",
1801 &options->accept_env, &options->num_accept_env,
1802 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001803 }
1804 break;
1805
djm@openbsd.org28013752018-06-09 03:03:10 +00001806 case sSetEnv:
1807 uvalue = options->num_setenv;
1808 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1809 if (strchr(arg, '=') == NULL)
1810 fatal("%s line %d: Invalid environment.",
1811 filename, linenum);
1812 if (!*activep || uvalue != 0)
1813 continue;
1814 array_append(filename, linenum, "SetEnv",
1815 &options->setenv, &options->num_setenv, arg);
1816 }
1817 break;
1818
Damien Millerd27b9472005-12-13 19:29:02 +11001819 case sPermitTunnel:
1820 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001821 arg = strdelim(&cp);
1822 if (!arg || *arg == '\0')
1823 fatal("%s line %d: Missing yes/point-to-point/"
1824 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001825 value = -1;
1826 for (i = 0; tunmode_desc[i].val != -1; i++)
1827 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1828 value = tunmode_desc[i].val;
1829 break;
1830 }
1831 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001832 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1833 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001834 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001835 *intptr = value;
1836 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001837
Darren Tucker45150472006-07-12 22:34:17 +10001838 case sMatch:
1839 if (cmdline)
1840 fatal("Match directive not supported as a command-line "
1841 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001842 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001843 if (value < 0)
1844 fatal("%s line %d: Bad Match condition", filename,
1845 linenum);
1846 *activep = value;
1847 break;
1848
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001849 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001850 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001851 if (opcode == sPermitListen) {
1852 uintptr = &options->num_permitted_listens;
1853 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001854 } else {
1855 uintptr = &options->num_permitted_opens;
1856 chararrayptr = &options->permitted_opens;
1857 }
Damien Miller9b439df2006-07-24 14:04:00 +10001858 arg = strdelim(&cp);
1859 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001860 fatal("%s line %d: missing %s specification",
1861 filename, linenum, lookup_opcode_name(opcode));
1862 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001863 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001864 if (*activep && uvalue == 0) {
1865 *uintptr = 1;
1866 *chararrayptr = xcalloc(1,
1867 sizeof(**chararrayptr));
1868 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001869 }
Damien Millerc6081482012-04-22 11:18:53 +10001870 break;
1871 }
Damien Millera765cf42006-07-24 14:08:13 +10001872 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001873 if (opcode == sPermitListen &&
1874 strchr(arg, ':') == NULL) {
1875 /*
1876 * Allow bare port number for PermitListen
1877 * to indicate a wildcard listen host.
1878 */
1879 xasprintf(&arg2, "*:%s", arg);
1880 } else {
1881 arg2 = xstrdup(arg);
1882 p = hpdelim(&arg);
1883 if (p == NULL) {
1884 fatal("%s line %d: missing host in %s",
1885 filename, linenum,
1886 lookup_opcode_name(opcode));
1887 }
1888 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001889 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001890 if (arg == NULL ||
1891 ((port = permitopen_port(arg)) < 0)) {
1892 fatal("%s line %d: bad port number in %s",
1893 filename, linenum,
1894 lookup_opcode_name(opcode));
1895 }
1896 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001897 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001898 lookup_opcode_name(opcode),
1899 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001900 }
1901 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001902 }
Damien Miller9b439df2006-07-24 14:04:00 +10001903 break;
1904
Damien Millere2754432006-07-24 14:06:47 +10001905 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001906 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001907 fatal("%.200s line %d: Missing argument.", filename,
1908 linenum);
1909 len = strspn(cp, WHITESPACE);
1910 if (*activep && options->adm_forced_command == NULL)
1911 options->adm_forced_command = xstrdup(cp + len);
1912 return 0;
1913
Damien Millerd8cb1f12008-02-10 22:40:12 +11001914 case sChrootDirectory:
1915 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001916
1917 arg = strdelim(&cp);
1918 if (!arg || *arg == '\0')
1919 fatal("%s line %d: missing file name.",
1920 filename, linenum);
1921 if (*activep && *charptr == NULL)
1922 *charptr = xstrdup(arg);
1923 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001924
Damien Miller1aed65e2010-03-04 21:53:35 +11001925 case sTrustedUserCAKeys:
1926 charptr = &options->trusted_user_ca_keys;
1927 goto parse_filename;
1928
1929 case sRevokedKeys:
1930 charptr = &options->revoked_keys_file;
1931 goto parse_filename;
1932
Damien Miller0dac6fb2010-11-20 15:19:38 +11001933 case sIPQoS:
1934 arg = strdelim(&cp);
1935 if ((value = parse_ipqos(arg)) == -1)
1936 fatal("%s line %d: Bad IPQoS value: %s",
1937 filename, linenum, arg);
1938 arg = strdelim(&cp);
1939 if (arg == NULL)
1940 value2 = value;
1941 else if ((value2 = parse_ipqos(arg)) == -1)
1942 fatal("%s line %d: Bad IPQoS value: %s",
1943 filename, linenum, arg);
1944 if (*activep) {
1945 options->ip_qos_interactive = value;
1946 options->ip_qos_bulk = value2;
1947 }
1948 break;
1949
Damien Miller23528812012-04-22 11:24:43 +10001950 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001951 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001952 fatal("%.200s line %d: Missing argument.", filename,
1953 linenum);
1954 len = strspn(cp, WHITESPACE);
1955 if (*activep && options->version_addendum == NULL) {
1956 if (strcasecmp(cp + len, "none") == 0)
1957 options->version_addendum = xstrdup("");
1958 else if (strchr(cp + len, '\r') != NULL)
1959 fatal("%.200s line %d: Invalid argument",
1960 filename, linenum);
1961 else
1962 options->version_addendum = xstrdup(cp + len);
1963 }
1964 return 0;
1965
Damien Miller09d3e122012-10-31 08:58:58 +11001966 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001967 if (cp == NULL)
1968 fatal("%.200s line %d: Missing argument.", filename,
1969 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001970 len = strspn(cp, WHITESPACE);
1971 if (*activep && options->authorized_keys_command == NULL) {
1972 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1973 fatal("%.200s line %d: AuthorizedKeysCommand "
1974 "must be an absolute path",
1975 filename, linenum);
1976 options->authorized_keys_command = xstrdup(cp + len);
1977 }
1978 return 0;
1979
1980 case sAuthorizedKeysCommandUser:
1981 charptr = &options->authorized_keys_command_user;
1982
1983 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001984 if (!arg || *arg == '\0')
1985 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1986 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001987 if (*activep && *charptr == NULL)
1988 *charptr = xstrdup(arg);
1989 break;
1990
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001991 case sAuthorizedPrincipalsCommand:
1992 if (cp == NULL)
1993 fatal("%.200s line %d: Missing argument.", filename,
1994 linenum);
1995 len = strspn(cp, WHITESPACE);
1996 if (*activep &&
1997 options->authorized_principals_command == NULL) {
1998 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1999 fatal("%.200s line %d: "
2000 "AuthorizedPrincipalsCommand must be "
2001 "an absolute path", filename, linenum);
2002 options->authorized_principals_command =
2003 xstrdup(cp + len);
2004 }
2005 return 0;
2006
2007 case sAuthorizedPrincipalsCommandUser:
2008 charptr = &options->authorized_principals_command_user;
2009
2010 arg = strdelim(&cp);
2011 if (!arg || *arg == '\0')
2012 fatal("%s line %d: missing "
2013 "AuthorizedPrincipalsCommandUser argument.",
2014 filename, linenum);
2015 if (*activep && *charptr == NULL)
2016 *charptr = xstrdup(arg);
2017 break;
2018
Damien Millera6e3f012012-11-04 23:21:40 +11002019 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002020 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002021 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002022 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002023 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002024 if (strcmp(arg, "any") == 0) {
2025 if (options->num_auth_methods > 0) {
2026 fatal("%s line %d: \"any\" "
2027 "must appear alone in "
2028 "AuthenticationMethods",
2029 filename, linenum);
2030 }
2031 value = 1;
2032 } else if (value) {
2033 fatal("%s line %d: \"any\" must appear "
2034 "alone in AuthenticationMethods",
2035 filename, linenum);
2036 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002037 fatal("%s line %d: invalid "
2038 "authentication method list.",
2039 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002040 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002041 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002042 if (!*activep)
2043 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002044 array_append(filename, linenum,
2045 "AuthenticationMethods",
2046 &options->auth_methods,
2047 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002048 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002049 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002050 fatal("%s line %d: no AuthenticationMethods "
2051 "specified", filename, linenum);
2052 }
Damien Millera6e3f012012-11-04 23:21:40 +11002053 }
2054 return 0;
2055
Damien Miller7acefbb2014-07-18 14:11:24 +10002056 case sStreamLocalBindMask:
2057 arg = strdelim(&cp);
2058 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002059 fatal("%s line %d: missing StreamLocalBindMask "
2060 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002061 /* Parse mode in octal format */
2062 value = strtol(arg, &p, 8);
2063 if (arg == p || value < 0 || value > 0777)
2064 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002065 if (*activep)
2066 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002067 break;
2068
2069 case sStreamLocalBindUnlink:
2070 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2071 goto parse_flag;
2072
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002073 case sFingerprintHash:
2074 arg = strdelim(&cp);
2075 if (!arg || *arg == '\0')
2076 fatal("%.200s line %d: Missing argument.",
2077 filename, linenum);
2078 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2079 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2080 filename, linenum, arg);
2081 if (*activep)
2082 options->fingerprint_hash = value;
2083 break;
2084
djm@openbsd.org8f574952017-06-24 06:34:38 +00002085 case sExposeAuthInfo:
2086 intptr = &options->expose_userauth_info;
2087 goto parse_flag;
2088
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002089 case sRDomain:
2090 charptr = &options->routing_domain;
2091 arg = strdelim(&cp);
2092 if (!arg || *arg == '\0')
2093 fatal("%.200s line %d: Missing argument.",
2094 filename, linenum);
2095 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2096 !valid_rdomain(arg))
2097 fatal("%s line %d: bad routing domain",
2098 filename, linenum);
2099 if (*activep && *charptr == NULL)
2100 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002101 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002102
Ben Lindstromade03f62001-12-06 18:22:17 +00002103 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002104 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002105 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002106 do_log2(opcode == sIgnore ?
2107 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2108 "%s line %d: %s option %s", filename, linenum,
2109 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002110 while (arg)
2111 arg = strdelim(&cp);
2112 break;
2113
Ben Lindstromade03f62001-12-06 18:22:17 +00002114 default:
2115 fatal("%s line %d: Missing handler for opcode %s (%d)",
2116 filename, linenum, arg, opcode);
2117 }
2118 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2119 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2120 filename, linenum, arg);
2121 return 0;
2122}
2123
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002124/* Reads the server configuration file. */
2125
Damien Miller4af51302000-04-16 11:18:38 +10002126void
Darren Tucker645ab752004-06-25 13:33:20 +10002127load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002128{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002129 char *line = NULL, *cp;
2130 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002131 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10002132 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002133
Darren Tucker645ab752004-06-25 13:33:20 +10002134 debug2("%s: filename %s", __func__, filename);
2135 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002136 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002137 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002138 }
Darren Tucker645ab752004-06-25 13:33:20 +10002139 buffer_clear(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002140 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002141 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002142 /*
2143 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002144 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002145 * line numbers later for error messages
2146 */
2147 if ((cp = strchr(line, '#')) != NULL)
2148 memcpy(cp, "\n", 2);
2149 cp = line + strspn(line, " \t\r");
2150
2151 buffer_append(conf, cp, strlen(cp));
2152 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002153 free(line);
Darren Tucker645ab752004-06-25 13:33:20 +10002154 buffer_append(conf, "\0", 1);
2155 fclose(f);
2156 debug2("%s: done config len = %d", __func__, buffer_len(conf));
2157}
2158
2159void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002160parse_server_match_config(ServerOptions *options,
2161 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002162{
Darren Tucker45150472006-07-12 22:34:17 +10002163 ServerOptions mo;
2164
2165 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002166 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002167 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002168}
2169
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002170int parse_server_match_testspec(struct connection_info *ci, char *spec)
2171{
2172 char *p;
2173
2174 while ((p = strsep(&spec, ",")) && *p != '\0') {
2175 if (strncmp(p, "addr=", 5) == 0) {
2176 ci->address = xstrdup(p + 5);
2177 } else if (strncmp(p, "host=", 5) == 0) {
2178 ci->host = xstrdup(p + 5);
2179 } else if (strncmp(p, "user=", 5) == 0) {
2180 ci->user = xstrdup(p + 5);
2181 } else if (strncmp(p, "laddr=", 6) == 0) {
2182 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002183 } else if (strncmp(p, "rdomain=", 8) == 0) {
2184 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002185 } else if (strncmp(p, "lport=", 6) == 0) {
2186 ci->lport = a2port(p + 6);
2187 if (ci->lport == -1) {
2188 fprintf(stderr, "Invalid port '%s' in test mode"
2189 " specification %s\n", p+6, p);
2190 return -1;
2191 }
2192 } else {
2193 fprintf(stderr, "Invalid test mode specification %s\n",
2194 p);
2195 return -1;
2196 }
2197 }
2198 return 0;
2199}
2200
2201/*
Darren Tucker1629c072007-02-19 22:25:37 +11002202 * Copy any supported values that are set.
2203 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002204 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002205 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002206 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002207 */
Darren Tucker45150472006-07-12 22:34:17 +10002208void
Darren Tucker1629c072007-02-19 22:25:37 +11002209copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002210{
Damien Miller534b2cc2013-12-05 14:07:27 +11002211#define M_CP_INTOPT(n) do {\
2212 if (src->n != -1) \
2213 dst->n = src->n; \
2214} while (0)
2215
Darren Tucker1629c072007-02-19 22:25:37 +11002216 M_CP_INTOPT(password_authentication);
2217 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002218 M_CP_INTOPT(pubkey_authentication);
2219 M_CP_INTOPT(kerberos_authentication);
2220 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002221 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002222 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002223 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002224 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002225
2226 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002227 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002228 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002229 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002230 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002231 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002232 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002233 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002234 M_CP_INTOPT(x11_display_offset);
2235 M_CP_INTOPT(x11_forwarding);
2236 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002237 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002238 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002239 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002240 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002241 M_CP_INTOPT(client_alive_count_max);
2242 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002243 M_CP_INTOPT(ip_qos_interactive);
2244 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002245 M_CP_INTOPT(rekey_limit);
2246 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002247 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002248
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002249 /*
2250 * The bind_mask is a mode_t that may be unsigned, so we can't use
2251 * M_CP_INTOPT - it does a signed comparison that causes compiler
2252 * warnings.
2253 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002254 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002255 dst->fwd_opts.streamlocal_bind_mask =
2256 src->fwd_opts.streamlocal_bind_mask;
2257 }
2258
Damien Miller534b2cc2013-12-05 14:07:27 +11002259 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2260#define M_CP_STROPT(n) do {\
2261 if (src->n != NULL && dst->n != src->n) { \
2262 free(dst->n); \
2263 dst->n = src->n; \
2264 } \
2265} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002266#define M_CP_STRARRAYOPT(s, num_s) do {\
2267 u_int i; \
2268 if (src->num_s != 0) { \
2269 for (i = 0; i < dst->num_s; i++) \
2270 free(dst->s[i]); \
2271 free(dst->s); \
2272 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2273 for (i = 0; i < src->num_s; i++) \
2274 dst->s[i] = xstrdup(src->s[i]); \
2275 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002276 } \
2277} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002278
Damien Millerf2e407e2011-05-20 19:04:14 +10002279 /* See comment in servconf.h */
2280 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002281
djm@openbsd.orged085102015-10-29 08:05:01 +00002282 /* Arguments that accept '+...' need to be expanded */
2283 assemble_algorithms(dst);
2284
Damien Millerc2411902011-05-20 19:03:49 +10002285 /*
2286 * The only things that should be below this point are string options
2287 * which are only used after authentication.
2288 */
Damien Miller5d74e582011-05-20 19:03:31 +10002289 if (preauth)
2290 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002291
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002292 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002293 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002294 if (option_clear_or_none(dst->adm_forced_command)) {
2295 free(dst->adm_forced_command);
2296 dst->adm_forced_command = NULL;
2297 }
Damien Miller5d74e582011-05-20 19:03:31 +10002298 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002299 if (option_clear_or_none(dst->chroot_directory)) {
2300 free(dst->chroot_directory);
2301 dst->chroot_directory = NULL;
2302 }
Darren Tucker45150472006-07-12 22:34:17 +10002303}
2304
Darren Tucker1629c072007-02-19 22:25:37 +11002305#undef M_CP_INTOPT
2306#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002307#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002308
Darren Tucker45150472006-07-12 22:34:17 +10002309void
2310parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002311 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002312{
2313 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002314 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002315
2316 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2317
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002318 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2319 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002320 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002321 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002322 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002323 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002324 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002325 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002326 }
Darren Tuckera627d422013-06-02 07:31:17 +10002327 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002328 if (bad_options > 0)
2329 fatal("%s: terminating, %d bad configuration options",
2330 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002331 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002332}
Darren Tuckere7140f22008-06-10 23:01:51 +10002333
2334static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002335fmt_multistate_int(int val, const struct multistate *m)
2336{
2337 u_int i;
2338
2339 for (i = 0; m[i].key != NULL; i++) {
2340 if (m[i].value == val)
2341 return m[i].key;
2342 }
2343 return "UNKNOWN";
2344}
2345
2346static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002347fmt_intarg(ServerOpCodes code, int val)
2348{
Damien Miller82c55872011-06-23 08:20:30 +10002349 if (val == -1)
2350 return "unset";
2351 switch (code) {
2352 case sAddressFamily:
2353 return fmt_multistate_int(val, multistate_addressfamily);
2354 case sPermitRootLogin:
2355 return fmt_multistate_int(val, multistate_permitrootlogin);
2356 case sGatewayPorts:
2357 return fmt_multistate_int(val, multistate_gatewayports);
2358 case sCompression:
2359 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002360 case sAllowTcpForwarding:
2361 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002362 case sAllowStreamLocalForwarding:
2363 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002364 case sFingerprintHash:
2365 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002366 default:
2367 switch (val) {
2368 case 0:
2369 return "no";
2370 case 1:
2371 return "yes";
2372 default:
2373 return "UNKNOWN";
2374 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002375 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002376}
2377
Darren Tuckere7140f22008-06-10 23:01:51 +10002378static void
2379dump_cfg_int(ServerOpCodes code, int val)
2380{
2381 printf("%s %d\n", lookup_opcode_name(code), val);
2382}
2383
2384static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002385dump_cfg_oct(ServerOpCodes code, int val)
2386{
2387 printf("%s 0%o\n", lookup_opcode_name(code), val);
2388}
2389
2390static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002391dump_cfg_fmtint(ServerOpCodes code, int val)
2392{
2393 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2394}
2395
2396static void
2397dump_cfg_string(ServerOpCodes code, const char *val)
2398{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002399 printf("%s %s\n", lookup_opcode_name(code),
2400 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002401}
2402
2403static void
2404dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2405{
2406 u_int i;
2407
2408 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002409 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2410}
2411
2412static void
2413dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2414{
2415 u_int i;
2416
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002417 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002418 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002419 printf("%s", lookup_opcode_name(code));
2420 for (i = 0; i < count; i++)
2421 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002422 if (code == sAuthenticationMethods && count == 0)
2423 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002424 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002425}
2426
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002427static char *
2428format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002429{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002430 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002431 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002432 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002433 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002434
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002435 /*
2436 * ListenAddress must be after Port. add_one_listen_addr pushes
2437 * addresses onto a stack, so to maintain ordering we need to
2438 * print these in reverse order.
2439 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002440 for (ai = la->addrs; ai; ai = ai->ai_next) {
2441 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002442 sizeof(addr), port, sizeof(port),
2443 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002444 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2445 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002446 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002447 laddr2 = laddr1;
2448 if (ai->ai_family == AF_INET6) {
2449 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2450 addr, port,
2451 la->rdomain == NULL ? "" : " rdomain ",
2452 la->rdomain == NULL ? "" : la->rdomain,
2453 laddr2);
2454 } else {
2455 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2456 addr, port,
2457 la->rdomain == NULL ? "" : " rdomain ",
2458 la->rdomain == NULL ? "" : la->rdomain,
2459 laddr2);
2460 }
2461 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002462 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002463 return laddr1;
2464}
2465
2466void
2467dump_config(ServerOptions *o)
2468{
2469 char *s;
2470 u_int i;
2471
2472 /* these are usually at the top of the config */
2473 for (i = 0; i < o->num_ports; i++)
2474 printf("port %d\n", o->ports[i]);
2475 dump_cfg_fmtint(sAddressFamily, o->address_family);
2476
2477 for (i = 0; i < o->num_listen_addrs; i++) {
2478 s = format_listen_addrs(&o->listen_addrs[i]);
2479 printf("%s", s);
2480 free(s);
2481 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002482
2483 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002484#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002485 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002486#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002487 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002488 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2489 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002490 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002491 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2492 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002493 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002494
2495 /* formatted integer arguments */
2496 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2497 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2498 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002499 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2500 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2501 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002502 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002503#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002504 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2505 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2506 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002507# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002508 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002509# endif
2510#endif
2511#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002512 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2513 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002514#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002515 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2516 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2517 o->kbd_interactive_authentication);
2518 dump_cfg_fmtint(sChallengeResponseAuthentication,
2519 o->challenge_response_authentication);
2520 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002521#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002522 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002523#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002524 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2525 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002526 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002527 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002528 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2529 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2530 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2531 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002532 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002533 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002534 dump_cfg_fmtint(sUseDNS, o->use_dns);
2535 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002536 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002537 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002538 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002539 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002540 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002541 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002542
2543 /* string arguments */
2544 dump_cfg_string(sPidFile, o->pid_file);
2545 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002546 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2547 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002548 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002549 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002550 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002551 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2552 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002553 dump_cfg_string(sAuthorizedPrincipalsFile,
2554 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002555 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2556 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002557 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2558 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002559 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2560 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002561 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002562 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002563 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002564 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2565 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002566 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2567 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002568 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2569 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002570 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002571
2572 /* string arguments requiring a lookup */
2573 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2574 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2575
2576 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002577 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2578 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002579 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2580 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002581 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002582 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002583 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2584 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2585 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2586 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2587 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002588 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002589 dump_cfg_strarray_oneline(sAuthenticationMethods,
2590 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002591
2592 /* other arguments */
2593 for (i = 0; i < o->num_subsystems; i++)
2594 printf("subsystem %s %s\n", o->subsystem_name[i],
2595 o->subsystem_args[i]);
2596
2597 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2598 o->max_startups_rate, o->max_startups);
2599
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002600 s = NULL;
2601 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002602 if (tunmode_desc[i].val == o->permit_tun) {
2603 s = tunmode_desc[i].text;
2604 break;
2605 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002606 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002607 dump_cfg_string(sPermitTunnel, s);
2608
Damien Miller91475862011-05-05 14:14:34 +10002609 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2610 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002611
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002612 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002613 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002614
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002615 printf("permitopen");
2616 if (o->num_permitted_opens == 0)
2617 printf(" any");
2618 else {
2619 for (i = 0; i < o->num_permitted_opens; i++)
2620 printf(" %s", o->permitted_opens[i]);
2621 }
2622 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002623 printf("permitlisten");
2624 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002625 printf(" any");
2626 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002627 for (i = 0; i < o->num_permitted_listens; i++)
2628 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002629 }
2630 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002631}