blob: e2f44d38df5d245fd00b533773270e9faf00d8de [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org01a06702019-10-31 21:17:49 +00002/* $OpenBSD: servconf.c,v 1.353 2019/10/31 21:17:49 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"
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000048#include "sshbuf.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100049#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100050#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100051#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000052#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000053#include "cipher.h"
markus@openbsd.org5467fbc2018-07-11 18:53:29 +000054#include "sshkey.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000055#include "kex.h"
56#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100057#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100058#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100059#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100060#include "canohost.h"
61#include "packet.h"
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000062#include "ssherr.h"
Damien Millera6e3f012012-11-04 23:21:40 +110063#include "hostfile.h"
64#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000065#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000066#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000068static void add_listen_addr(ServerOptions *, const char *,
69 const char *, int);
70static void add_one_listen_addr(ServerOptions *, const char *,
71 const char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110072
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000073/* Use of privilege separation or not */
74extern int use_privsep;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000075extern struct sshbuf *cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000076
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077/* Initializes the server options to their default values. */
78
Damien Miller4af51302000-04-16 11:18:38 +100079void
Damien Miller95def091999-11-25 00:26:21 +110080initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100081{
Damien Miller95def091999-11-25 00:26:21 +110082 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110083
84 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100085 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110086
87 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110088 options->num_ports = 0;
89 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000090 options->queued_listen_addrs = NULL;
91 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110092 options->listen_addrs = NULL;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000093 options->num_listen_addrs = 0;
Darren Tucker0f383232005-01-20 10:57:56 +110094 options->address_family = -1;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +000095 options->routing_domain = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110096 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110097 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100098 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100099 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100100 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000101 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->ignore_rhosts = -1;
103 options->ignore_user_known_hosts = -1;
104 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000105 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->x11_forwarding = -1;
107 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +1100108 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100109 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000110 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000111 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100113 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100114 options->log_facility = SYSLOG_FACILITY_NOT_SET;
115 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000116 options->hostbased_authentication = -1;
117 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000118 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000119 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100120 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000121 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100122 options->kerberos_authentication = -1;
123 options->kerberos_or_local_passwd = -1;
124 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100125 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000126 options->gss_authentication=-1;
127 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000128 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100129 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100130 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000131 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100132 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000133 options->permit_user_env = -1;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000134 options->permit_user_env_whitelist = NULL;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000135 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000136 options->rekey_limit = -1;
137 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100138 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000139 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000140 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100141 options->num_allow_users = 0;
142 options->num_deny_users = 0;
143 options->num_allow_groups = 0;
144 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000145 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000146 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000147 options->kex_algorithms = NULL;
djm@openbsd.org86e57372018-09-20 03:28:06 +0000148 options->ca_sign_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000149 options->fwd_opts.gateway_ports = -1;
150 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
151 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000152 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000153 options->max_startups_begin = -1;
154 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000155 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000156 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000157 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000158 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000159 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000160 options->client_alive_interval = -1;
161 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000162 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000163 options->num_accept_env = 0;
djm@openbsd.org28013752018-06-09 03:03:10 +0000164 options->num_setenv = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100165 options->permit_tun = -1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000166 options->permitted_opens = NULL;
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000167 options->permitted_listens = NULL;
Damien Millere2754432006-07-24 14:06:47 +1000168 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100169 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100170 options->authorized_keys_command = NULL;
171 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100172 options->revoked_keys_file = NULL;
173 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000174 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000175 options->authorized_principals_command = NULL;
176 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100177 options->ip_qos_interactive = -1;
178 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000179 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000180 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000181 options->disable_forwarding = -1;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000182 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000183}
184
djm@openbsd.org161cf412014-12-22 07:55:51 +0000185/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
186static int
187option_clear_or_none(const char *o)
188{
189 return o == NULL || strcasecmp(o, "none") == 0;
190}
191
djm@openbsd.orged085102015-10-29 08:05:01 +0000192static void
193assemble_algorithms(ServerOptions *o)
194{
djm@openbsd.org86e57372018-09-20 03:28:06 +0000195 char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +0000196 int r;
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000197
198 all_cipher = cipher_alg_list(',', 0);
199 all_mac = mac_alg_list(',');
200 all_kex = kex_alg_list(',');
201 all_key = sshkey_alg_list(0, 0, 1, ',');
djm@openbsd.org86e57372018-09-20 03:28:06 +0000202 all_sig = sshkey_alg_list(0, 1, 1, ',');
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +0000203#define ASSEMBLE(what, defaults, all) \
204 do { \
205 if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
206 fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
207 } while (0)
208 ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher);
209 ASSEMBLE(macs, KEX_SERVER_MAC, all_mac);
210 ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex);
211 ASSEMBLE(hostkeyalgorithms, KEX_DEFAULT_PK_ALG, all_key);
212 ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
djm@openbsd.org01a06702019-10-31 21:17:49 +0000213 ASSEMBLE(pubkey_key_types, PUBKEY_DEFAULT_PK_ALG, all_key);
djm@openbsd.org86e57372018-09-20 03:28:06 +0000214 ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +0000215#undef ASSEMBLE
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000216 free(all_cipher);
217 free(all_mac);
218 free(all_kex);
219 free(all_key);
djm@openbsd.org86e57372018-09-20 03:28:06 +0000220 free(all_sig);
djm@openbsd.orged085102015-10-29 08:05:01 +0000221}
222
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000223static void
djm@openbsd.org928f1232018-11-19 04:12:32 +0000224array_append2(const char *file, const int line, const char *directive,
225 char ***array, int **iarray, u_int *lp, const char *s, int i)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000226{
227
228 if (*lp >= INT_MAX)
229 fatal("%s line %d: Too many %s entries", file, line, directive);
230
djm@openbsd.org928f1232018-11-19 04:12:32 +0000231 if (iarray != NULL) {
232 *iarray = xrecallocarray(*iarray, *lp, *lp + 1,
233 sizeof(**iarray));
234 (*iarray)[*lp] = i;
235 }
236
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000237 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
238 (*array)[*lp] = xstrdup(s);
239 (*lp)++;
240}
241
djm@openbsd.org928f1232018-11-19 04:12:32 +0000242static void
243array_append(const char *file, const int line, const char *directive,
244 char ***array, u_int *lp, const char *s)
245{
246 array_append2(file, line, directive, array, NULL, lp, s, 0);
247}
248
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000249void
250servconf_add_hostkey(const char *file, const int line,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000251 ServerOptions *options, const char *path, int userprovided)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000252{
253 char *apath = derelativise_path(path);
254
djm@openbsd.org928f1232018-11-19 04:12:32 +0000255 array_append2(file, line, "HostKey",
256 &options->host_key_files, &options->host_key_file_userprovided,
257 &options->num_host_key_files, apath, userprovided);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000258 free(apath);
259}
260
261void
262servconf_add_hostcert(const char *file, const int line,
263 ServerOptions *options, const char *path)
264{
265 char *apath = derelativise_path(path);
266
267 array_append(file, line, "HostCertificate",
268 &options->host_cert_files, &options->num_host_cert_files, apath);
269 free(apath);
270}
271
Damien Miller4af51302000-04-16 11:18:38 +1000272void
Damien Miller95def091999-11-25 00:26:21 +1100273fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000274{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000275 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000276
Damien Miller726273e2001-11-12 11:40:11 +1100277 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000278 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000279 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100280
281 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100282 if (options->num_host_key_files == 0) {
283 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000284 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000285 _PATH_HOST_RSA_KEY_FILE, 0);
Damien Millerdd190dd2010-11-11 14:17:02 +1100286#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000287 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000288 _PATH_HOST_ECDSA_KEY_FILE, 0);
Damien Millerdd190dd2010-11-11 14:17:02 +1100289#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000290 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000291 _PATH_HOST_ED25519_KEY_FILE, 0);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000292#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000293 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000294 _PATH_HOST_XMSS_KEY_FILE, 0);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000295#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100296 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100297 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100298 if (options->num_ports == 0)
299 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000300 if (options->address_family == -1)
301 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100302 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000303 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000304 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000305 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100306 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000307 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000308 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000309 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100310 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100311 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100312 if (options->ignore_user_known_hosts == -1)
313 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100314 if (options->print_motd == -1)
315 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000316 if (options->print_lastlog == -1)
317 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100318 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100319 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100320 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100321 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100322 if (options->x11_use_localhost == -1)
323 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000324 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000325 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100326 if (options->permit_tty == -1)
327 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000328 if (options->permit_user_rc == -1)
329 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100330 if (options->strict_modes == -1)
331 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100332 if (options->tcp_keep_alive == -1)
333 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100334 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100335 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100336 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000337 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000338 if (options->hostbased_authentication == -1)
339 options->hostbased_authentication = 0;
340 if (options->hostbased_uses_name_from_packet_only == -1)
341 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100342 if (options->pubkey_authentication == -1)
343 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100344 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000345 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100346 if (options->kerberos_or_local_passwd == -1)
347 options->kerberos_or_local_passwd = 1;
348 if (options->kerberos_ticket_cleanup == -1)
349 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100350 if (options->kerberos_get_afs_token == -1)
351 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000352 if (options->gss_authentication == -1)
353 options->gss_authentication = 0;
354 if (options->gss_cleanup_creds == -1)
355 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000356 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000357 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100358 if (options->password_authentication == -1)
359 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100360 if (options->kbd_interactive_authentication == -1)
361 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000362 if (options->challenge_response_authentication == -1)
363 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100364 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100365 options->permit_empty_passwd = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000366 if (options->permit_user_env == -1) {
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000367 options->permit_user_env = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000368 options->permit_user_env_whitelist = NULL;
369 }
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000370 if (options->compression == -1)
sf@openbsd.org168b46f2018-07-09 13:37:10 +0000371 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000372 if (options->rekey_limit == -1)
373 options->rekey_limit = 0;
374 if (options->rekey_interval == -1)
375 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100376 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100377 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000378 if (options->allow_streamlocal_forwarding == -1)
379 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000380 if (options->allow_agent_forwarding == -1)
381 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000382 if (options->fwd_opts.gateway_ports == -1)
383 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000384 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100385 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000386 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100387 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000388 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100389 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000390 if (options->max_authtries == -1)
391 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000392 if (options->max_sessions == -1)
393 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000394 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000395 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000396 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100397 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000398 if (options->client_alive_count_max == -1)
399 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000400 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000401 array_append("[default]", 0, "AuthorizedKeysFiles",
402 &options->authorized_keys_files,
403 &options->num_authkeys_files,
404 _PATH_SSH_USER_PERMITTED_KEYS);
405 array_append("[default]", 0, "AuthorizedKeysFiles",
406 &options->authorized_keys_files,
407 &options->num_authkeys_files,
408 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000409 }
Damien Millerd27b9472005-12-13 19:29:02 +1100410 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100411 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100412 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000413 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100414 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000415 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000416 if (options->version_addendum == NULL)
417 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000418 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
419 options->fwd_opts.streamlocal_bind_mask = 0177;
420 if (options->fwd_opts.streamlocal_bind_unlink == -1)
421 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000422 if (options->fingerprint_hash == -1)
423 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000424 if (options->disable_forwarding == -1)
425 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000426 if (options->expose_userauth_info == -1)
427 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000428
djm@openbsd.orged085102015-10-29 08:05:01 +0000429 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000430
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000431 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000432 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000433 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000434
djm@openbsd.org161cf412014-12-22 07:55:51 +0000435#define CLEAR_ON_NONE(v) \
436 do { \
437 if (option_clear_or_none(v)) { \
438 free(v); \
439 v = NULL; \
440 } \
441 } while(0)
442 CLEAR_ON_NONE(options->pid_file);
443 CLEAR_ON_NONE(options->xauth_location);
444 CLEAR_ON_NONE(options->banner);
445 CLEAR_ON_NONE(options->trusted_user_ca_keys);
446 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000447 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000448 CLEAR_ON_NONE(options->adm_forced_command);
449 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000450 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000451 for (i = 0; i < options->num_host_key_files; i++)
452 CLEAR_ON_NONE(options->host_key_files[i]);
453 for (i = 0; i < options->num_host_cert_files; i++)
454 CLEAR_ON_NONE(options->host_cert_files[i]);
455#undef CLEAR_ON_NONE
456
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000457 /* Similar handling for AuthenticationMethods=any */
458 if (options->num_auth_methods == 1 &&
459 strcmp(options->auth_methods[0], "any") == 0) {
460 free(options->auth_methods[0]);
461 options->auth_methods[0] = NULL;
462 options->num_auth_methods = 0;
463 }
464
Tim Rice40017b02002-07-14 13:36:49 -0700465#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000466 if (use_privsep && options->compression == 1) {
467 error("This platform does not support both privilege "
468 "separation and compression");
469 error("Compression disabled");
470 options->compression = 0;
471 }
472#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000473}
474
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000475/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100476typedef enum {
477 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100478 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000479 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100480 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000481 sPort, sHostKeyFile, sLoginGraceTime,
482 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000483 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100484 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000485 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100486 sPasswordAuthentication, sKbdInteractiveAuthentication,
487 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000488 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100489 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100490 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000491 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000492 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000493 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000494 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
495 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000496 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000497 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000498 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000499 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000500 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000501 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000502 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100503 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100504 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000505 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000506 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
djm@openbsd.org86e57372018-09-20 03:28:06 +0000507 sKexAlgorithms, sCASignatureAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100508 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000509 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000510 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000511 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000512 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000513 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000514} ServerOpCodes;
515
Darren Tucker45150472006-07-12 22:34:17 +1000516#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
517#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
518#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
519
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000520/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100521static struct {
522 const char *name;
523 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000524 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100525} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100526 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000527#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000528 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000529#else
Darren Tucker45150472006-07-12 22:34:17 +1000530 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000531#endif
Darren Tucker45150472006-07-12 22:34:17 +1000532 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100533 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000534 { "port", sPort, SSHCFG_GLOBAL },
535 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
536 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000537 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000538 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000539 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000540 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000541 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100542 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000543 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000544 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000545 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000546 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100547 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000548 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000549 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000550 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000551 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100552 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000553 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000554 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000555#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100556 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000557 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
558 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100559#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000560 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000561#else
Darren Tucker45150472006-07-12 22:34:17 +1000562 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100563#endif
564#else
Darren Tucker1629c072007-02-19 22:25:37 +1100565 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000566 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
567 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
568 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000569#endif
Darren Tucker45150472006-07-12 22:34:17 +1000570 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
571 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000572#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100573 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000574 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000575 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000576#else
Darren Tucker1629c072007-02-19 22:25:37 +1100577 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000578 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000579 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000580#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100581 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
582 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100583 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Damien Miller87f08be2018-07-20 13:18:28 +1000584 { "skeyauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000585 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
586 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
587 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
588 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100589#ifdef DISABLE_LASTLOG
590 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
591#else
Darren Tucker45150472006-07-12 22:34:17 +1000592 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100593#endif
Darren Tucker45150472006-07-12 22:34:17 +1000594 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
595 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000596 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
597 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
598 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000599 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
600 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100601 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000602 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000603 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000604 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000605 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000606 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
607 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
608 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000609 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000610 { "allowusers", sAllowUsers, SSHCFG_ALL },
611 { "denyusers", sDenyUsers, SSHCFG_ALL },
612 { "allowgroups", sAllowGroups, SSHCFG_ALL },
613 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000614 { "ciphers", sCiphers, SSHCFG_GLOBAL },
615 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000616 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000617 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
618 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
619 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000620 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000621 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100622 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000623 { "usedns", sUseDNS, SSHCFG_GLOBAL },
624 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
625 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000626 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
627 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000628 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000629 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000630 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000631 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000632 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000633 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100634 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000635 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000636 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000637 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000638 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000639 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100640 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100641 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100642 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
643 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000644 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000645 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100646 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100647 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
648 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000649 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
650 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000651 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100652 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000653 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
654 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
655 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000656 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000657 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000658 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000659 { "rdomain", sRDomain, SSHCFG_ALL },
djm@openbsd.org0cbed242018-09-20 23:40:16 +0000660 { "casignaturealgorithms", sCASignatureAlgorithms, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000661 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000662};
663
Darren Tuckere7140f22008-06-10 23:01:51 +1000664static struct {
665 int val;
666 char *text;
667} tunmode_desc[] = {
668 { SSH_TUNMODE_NO, "no" },
669 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
670 { SSH_TUNMODE_ETHERNET, "ethernet" },
671 { SSH_TUNMODE_YES, "yes" },
672 { -1, NULL }
673};
674
djm@openbsd.org115063a2018-06-06 18:22:41 +0000675/* Returns an opcode name from its number */
676
677static const char *
678lookup_opcode_name(ServerOpCodes code)
679{
680 u_int i;
681
682 for (i = 0; keywords[i].name != NULL; i++)
683 if (keywords[i].opcode == code)
684 return(keywords[i].name);
685 return "UNKNOWN";
686}
687
688
Damien Miller5428f641999-11-25 11:54:57 +1100689/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000690 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100691 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000692
Damien Miller4af51302000-04-16 11:18:38 +1000693static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100694parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000695 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000696{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000697 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000698
Damien Miller95def091999-11-25 00:26:21 +1100699 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000700 if (strcasecmp(cp, keywords[i].name) == 0) {
701 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100702 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000703 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000704
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000705 error("%s: line %d: Bad configuration option: %s",
706 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100707 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000708}
709
Darren Tucker88b6fb22010-01-13 22:44:29 +1100710char *
711derelativise_path(const char *path)
712{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000713 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100714
djm@openbsd.org161cf412014-12-22 07:55:51 +0000715 if (strcasecmp(path, "none") == 0)
716 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100717 expanded = tilde_expand_filename(path, getuid());
djm@openbsd.org2a358622018-11-16 03:26:01 +0000718 if (path_absolute(expanded))
Darren Tucker88b6fb22010-01-13 22:44:29 +1100719 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100720 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100721 fatal("%s: getcwd: %s", __func__, strerror(errno));
722 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000723 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100724 return ret;
725}
726
Ben Lindstrombba81212001-06-25 05:01:22 +0000727static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000728add_listen_addr(ServerOptions *options, const char *addr,
729 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100730{
Damien Millereccb9de2005-06-17 12:59:34 +1000731 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100732
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000733 if (port > 0)
734 add_one_listen_addr(options, addr, rdomain, port);
735 else {
736 for (i = 0; i < options->num_ports; i++) {
737 add_one_listen_addr(options, addr, rdomain,
738 options->ports[i]);
739 }
740 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000741}
742
Ben Lindstrombba81212001-06-25 05:01:22 +0000743static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000744add_one_listen_addr(ServerOptions *options, const char *addr,
745 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000746{
747 struct addrinfo hints, *ai, *aitop;
748 char strport[NI_MAXSERV];
749 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000750 u_int i;
751
752 /* Find listen_addrs entry for this rdomain */
753 for (i = 0; i < options->num_listen_addrs; i++) {
754 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
755 break;
756 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
757 continue;
758 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
759 break;
760 }
761 if (i >= options->num_listen_addrs) {
762 /* No entry for this rdomain; allocate one */
763 if (i >= INT_MAX)
764 fatal("%s: too many listen addresses", __func__);
765 options->listen_addrs = xrecallocarray(options->listen_addrs,
766 options->num_listen_addrs, options->num_listen_addrs + 1,
767 sizeof(*options->listen_addrs));
768 i = options->num_listen_addrs++;
769 if (rdomain != NULL)
770 options->listen_addrs[i].rdomain = xstrdup(rdomain);
771 }
772 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000773
774 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100775 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000776 hints.ai_socktype = SOCK_STREAM;
777 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100778 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000779 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
780 fatal("bad addr or host: %s (%s)",
781 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100782 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000783 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
784 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000785 ai->ai_next = options->listen_addrs[i].addrs;
786 options->listen_addrs[i].addrs = aitop;
787}
788
789/* Returns nonzero if the routing domain name is valid */
790static int
791valid_rdomain(const char *name)
792{
Damien Miller43c29bb2017-10-25 13:10:59 +1100793#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100794 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100795#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000796 const char *errstr;
797 long long num;
798 struct rt_tableinfo info;
799 int mib[6];
800 size_t miblen = sizeof(mib);
801
802 if (name == NULL)
803 return 1;
804
805 num = strtonum(name, 0, 255, &errstr);
806 if (errstr != NULL)
807 return 0;
808
809 /* Check whether the table actually exists */
810 memset(mib, 0, sizeof(mib));
811 mib[0] = CTL_NET;
812 mib[1] = PF_ROUTE;
813 mib[4] = NET_RT_TABLE;
814 mib[5] = (int)num;
815 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
816 return 0;
817
818 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100819#else /* defined(__OpenBSD__) */
820 error("Routing domains are not supported on this platform");
821 return 0;
822#endif
Damien Miller34132e52000-01-14 15:45:46 +1100823}
824
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000825/*
826 * Queue a ListenAddress to be processed once we have all of the Ports
827 * and AddressFamily options.
828 */
829static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000830queue_listen_addr(ServerOptions *options, const char *addr,
831 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000832{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000833 struct queued_listenaddr *qla;
834
835 options->queued_listen_addrs = xrecallocarray(
836 options->queued_listen_addrs,
837 options->num_queued_listens, options->num_queued_listens + 1,
838 sizeof(*options->queued_listen_addrs));
839 qla = &options->queued_listen_addrs[options->num_queued_listens++];
840 qla->addr = xstrdup(addr);
841 qla->port = port;
842 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000843}
844
845/*
846 * Process queued (text) ListenAddress entries.
847 */
848static void
849process_queued_listen_addrs(ServerOptions *options)
850{
851 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000852 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000853
854 if (options->num_ports == 0)
855 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
856 if (options->address_family == -1)
857 options->address_family = AF_UNSPEC;
858
859 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000860 qla = &options->queued_listen_addrs[i];
861 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
862 free(qla->addr);
863 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000864 }
865 free(options->queued_listen_addrs);
866 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000867 options->num_queued_listens = 0;
868}
869
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000870/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000871 * Inform channels layer of permitopen options for a single forwarding
872 * direction (local/remote).
873 */
874static void
875process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
876 char **opens, u_int num_opens)
877{
878 u_int i;
879 int port;
dtucker@openbsd.orgd05ea252019-01-23 21:50:56 +0000880 char *host, *arg, *oarg, ch;
djm@openbsd.org115063a2018-06-06 18:22:41 +0000881 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
882 const char *what = lookup_opcode_name(opcode);
883
884 channel_clear_permission(ssh, FORWARD_ADM, where);
885 if (num_opens == 0)
886 return; /* permit any */
887
888 /* handle keywords: "any" / "none" */
889 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
890 return;
891 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
892 channel_disable_admin(ssh, where);
893 return;
894 }
895 /* Otherwise treat it as a list of permitted host:port */
896 for (i = 0; i < num_opens; i++) {
897 oarg = arg = xstrdup(opens[i]);
dtucker@openbsd.org281ce042019-01-24 02:34:52 +0000898 ch = '\0';
dtucker@openbsd.orgd05ea252019-01-23 21:50:56 +0000899 host = hpdelim2(&arg, &ch);
900 if (host == NULL || ch == '/')
djm@openbsd.org115063a2018-06-06 18:22:41 +0000901 fatal("%s: missing host in %s", __func__, what);
902 host = cleanhostname(host);
903 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
904 fatal("%s: bad port number in %s", __func__, what);
905 /* Send it to channels layer */
906 channel_add_permission(ssh, FORWARD_ADM,
907 where, host, port);
908 free(oarg);
909 }
910}
911
912/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000913 * Inform channels layer of permitopen options from configuration.
914 */
915void
916process_permitopen(struct ssh *ssh, ServerOptions *options)
917{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000918 process_permitopen_list(ssh, sPermitOpen,
919 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000920 process_permitopen_list(ssh, sPermitListen,
921 options->permitted_listens,
922 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000923}
924
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000925struct connection_info *
djm@openbsd.org172a5922019-01-19 21:37:48 +0000926get_connection_info(struct ssh *ssh, int populate, int use_dns)
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000927{
928 static struct connection_info ci;
929
djm@openbsd.org172a5922019-01-19 21:37:48 +0000930 if (ssh == NULL || !populate)
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000931 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000932 ci.host = auth_get_canonical_hostname(ssh, use_dns);
933 ci.address = ssh_remote_ipaddr(ssh);
934 ci.laddress = ssh_local_ipaddr(ssh);
935 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000936 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000937 return &ci;
938}
939
Darren Tucker45150472006-07-12 22:34:17 +1000940/*
941 * The strategy for the Match blocks is that the config file is parsed twice.
942 *
943 * The first time is at startup. activep is initialized to 1 and the
944 * directives in the global context are processed and acted on. Hitting a
945 * Match directive unsets activep and the directives inside the block are
946 * checked for syntax only.
947 *
948 * The second time is after a connection has been established but before
949 * authentication. activep is initialized to 2 and global config directives
950 * are ignored since they have already been processed. If the criteria in a
951 * Match block is met, activep is set and the subsequent directives
952 * processed and actioned until EOF or another Match block unsets it. Any
953 * options set are copied into the main server config.
954 *
955 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000956 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000957 *
958 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
959 * Match Address 192.168.0.*
960 * Tag trusted
961 * Match Group wheel
962 * Tag trusted
963 * Match Tag trusted
964 * AllowTcpForwarding yes
965 * GatewayPorts clientspecified
966 * [...]
967 *
968 * - Add a PermittedChannelRequests directive
969 * Match Group shell
970 * PermittedChannelRequests session,forwarded-tcpip
971 */
972
973static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000974match_cfg_line_group(const char *grps, int line, const char *user)
975{
976 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000977 struct passwd *pw;
978
Damien Miller565ca3f2006-08-19 00:23:15 +1000979 if (user == NULL)
980 goto out;
981
982 if ((pw = getpwnam(user)) == NULL) {
983 debug("Can't match group at line %d because user %.100s does "
984 "not exist", line, user);
985 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
986 debug("Can't Match group because user %.100s not in any group "
987 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000988 } else if (ga_match_pattern_list(grps) != 1) {
989 debug("user %.100s does not match group list %.100s at line %d",
990 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000991 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000992 debug("user %.100s matched group list %.100s at line %d", user,
993 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000994 result = 1;
995 }
996out:
997 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000998 return result;
999}
1000
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001001static void
1002match_test_missing_fatal(const char *criteria, const char *attrib)
1003{
1004 fatal("'Match %s' in configuration but '%s' not in connection "
1005 "test specification.", criteria, attrib);
1006}
1007
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001008/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +10001009 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +11001010 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +10001011 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001012 */
Damien Miller565ca3f2006-08-19 00:23:15 +10001013static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001014match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +10001015{
Damien Millercf31f382013-10-24 21:02:56 +11001016 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +10001017 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +10001018
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001019 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001020 debug3("checking syntax for 'Match %s'", cp);
1021 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001022 debug3("checking match for '%s' user %s host %s addr %s "
1023 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
1024 ci->host ? ci->host : "(null)",
1025 ci->address ? ci->address : "(null)",
1026 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +10001027
1028 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +11001029 attributes++;
1030 if (strcasecmp(attrib, "all") == 0) {
1031 if (attributes != 1 ||
1032 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1033 error("'all' cannot be combined with other "
1034 "Match attributes");
1035 return -1;
1036 }
1037 *condition = cp;
1038 return 1;
1039 }
Darren Tucker45150472006-07-12 22:34:17 +10001040 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1041 error("Missing Match criteria for %s", attrib);
1042 return -1;
1043 }
Darren Tucker45150472006-07-12 22:34:17 +10001044 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001045 if (ci == NULL || (ci->test && ci->user == NULL)) {
Darren Tucker45150472006-07-12 22:34:17 +10001046 result = 0;
1047 continue;
1048 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001049 if (ci->user == NULL)
1050 match_test_missing_fatal("User", "user");
dtucker@openbsd.orgfd10cf02019-03-06 22:14:23 +00001051 if (match_usergroup_pattern_list(ci->user, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001052 result = 0;
1053 else
1054 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001055 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001056 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001057 if (ci == NULL || (ci->test && ci->user == NULL)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001058 result = 0;
1059 continue;
1060 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001061 if (ci->user == NULL)
1062 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001063 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001064 case -1:
1065 return -1;
1066 case 0:
1067 result = 0;
1068 }
Darren Tucker45150472006-07-12 22:34:17 +10001069 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001070 if (ci == NULL || (ci->test && ci->host == NULL)) {
Darren Tucker45150472006-07-12 22:34:17 +10001071 result = 0;
1072 continue;
1073 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001074 if (ci->host == NULL)
1075 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001076 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001077 result = 0;
1078 else
1079 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001080 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001081 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001082 if (ci == NULL || (ci->test && ci->address == NULL)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001083 result = 0;
1084 continue;
1085 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001086 if (ci->address == NULL)
1087 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001088 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001089 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001090 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001091 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001092 break;
1093 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001094 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001095 result = 0;
1096 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001097 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001098 return -1;
1099 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001100 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001101 if (ci == NULL || (ci->test && ci->laddress == NULL)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001102 result = 0;
1103 continue;
1104 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001105 if (ci->laddress == NULL)
1106 match_test_missing_fatal("LocalAddress",
1107 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001108 switch (addr_match_list(ci->laddress, arg)) {
1109 case 1:
1110 debug("connection from %.100s matched "
1111 "'LocalAddress %.100s' at line %d",
1112 ci->laddress, arg, line);
1113 break;
1114 case 0:
1115 case -1:
1116 result = 0;
1117 break;
1118 case -2:
1119 return -1;
1120 }
1121 } else if (strcasecmp(attrib, "localport") == 0) {
1122 if ((port = a2port(arg)) == -1) {
1123 error("Invalid LocalPort '%s' on Match line",
1124 arg);
1125 return -1;
1126 }
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001127 if (ci == NULL || (ci->test && ci->lport == -1)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001128 result = 0;
1129 continue;
1130 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001131 if (ci->lport == 0)
1132 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001133 /* TODO support port lists */
1134 if (port == ci->lport)
1135 debug("connection from %.100s matched "
1136 "'LocalPort %d' at line %d",
1137 ci->laddress, port, line);
1138 else
1139 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001140 } else if (strcasecmp(attrib, "rdomain") == 0) {
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001141 if (ci == NULL || (ci->test && ci->rdomain == NULL)) {
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001142 result = 0;
1143 continue;
1144 }
dtucker@openbsd.orge826bbc2019-04-18 18:56:16 +00001145 if (ci->rdomain == NULL)
1146 match_test_missing_fatal("RDomain", "rdomain");
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001147 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1148 result = 0;
1149 else
1150 debug("user %.100s matched 'RDomain %.100s' at "
1151 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001152 } else {
1153 error("Unsupported Match attribute %s", attrib);
1154 return -1;
1155 }
1156 }
Damien Millercf31f382013-10-24 21:02:56 +11001157 if (attributes == 0) {
1158 error("One or more attributes required for Match");
1159 return -1;
1160 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001161 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001162 debug3("match %sfound", result ? "" : "not ");
1163 *condition = cp;
1164 return result;
1165}
1166
Damien Millere2754432006-07-24 14:06:47 +10001167#define WHITESPACE " \t\r\n"
1168
Damien Miller33322122011-06-20 14:43:11 +10001169/* Multistate option parsing */
1170struct multistate {
1171 char *key;
1172 int value;
1173};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001174static const struct multistate multistate_flag[] = {
1175 { "yes", 1 },
1176 { "no", 0 },
1177 { NULL, -1 }
1178};
Damien Miller33322122011-06-20 14:43:11 +10001179static const struct multistate multistate_addressfamily[] = {
1180 { "inet", AF_INET },
1181 { "inet6", AF_INET6 },
1182 { "any", AF_UNSPEC },
1183 { NULL, -1 }
1184};
1185static const struct multistate multistate_permitrootlogin[] = {
1186 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001187 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001188 { "forced-commands-only", PERMIT_FORCED_ONLY },
1189 { "yes", PERMIT_YES },
1190 { "no", PERMIT_NO },
1191 { NULL, -1 }
1192};
1193static const struct multistate multistate_compression[] = {
sf@openbsd.org168b46f2018-07-09 13:37:10 +00001194 { "yes", COMP_DELAYED },
1195 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001196 { "no", COMP_NONE },
1197 { NULL, -1 }
1198};
1199static const struct multistate multistate_gatewayports[] = {
1200 { "clientspecified", 2 },
1201 { "yes", 1 },
1202 { "no", 0 },
1203 { NULL, -1 }
1204};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001205static const struct multistate multistate_tcpfwd[] = {
1206 { "yes", FORWARD_ALLOW },
1207 { "all", FORWARD_ALLOW },
1208 { "no", FORWARD_DENY },
1209 { "remote", FORWARD_REMOTE },
1210 { "local", FORWARD_LOCAL },
1211 { NULL, -1 }
1212};
Damien Miller33322122011-06-20 14:43:11 +10001213
Ben Lindstromade03f62001-12-06 18:22:17 +00001214int
1215process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001216 const char *filename, int linenum, int *activep,
1217 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001218{
dtucker@openbsd.org281ce042019-01-24 02:34:52 +00001219 char ch, *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001220 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001221 SyslogFacility *log_facility_ptr;
1222 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001223 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001224 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001225 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001226 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001227 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001228 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001229
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001230 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1231 if ((len = strlen(line)) == 0)
1232 return 0;
1233 for (len--; len > 0; len--) {
1234 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1235 break;
1236 line[len] = '\0';
1237 }
1238
Ben Lindstromade03f62001-12-06 18:22:17 +00001239 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001240 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001241 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001242 /* Ignore leading whitespace */
1243 if (*arg == '\0')
1244 arg = strdelim(&cp);
1245 if (!arg || !*arg || *arg == '#')
1246 return 0;
1247 intptr = NULL;
1248 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001249 opcode = parse_token(arg, filename, linenum, &flags);
1250
1251 if (activep == NULL) { /* We are processing a command line directive */
1252 cmdline = 1;
1253 activep = &cmdline;
1254 }
1255 if (*activep && opcode != sMatch)
1256 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1257 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001258 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001259 fatal("%s line %d: Directive '%s' is not allowed "
1260 "within a Match block", filename, linenum, arg);
1261 } else { /* this is a directive we have already processed */
1262 while (arg)
1263 arg = strdelim(&cp);
1264 return 0;
1265 }
1266 }
1267
Ben Lindstromade03f62001-12-06 18:22:17 +00001268 switch (opcode) {
1269 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001270 case sUsePAM:
1271 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001272 goto parse_flag;
1273
1274 /* Standard Options */
1275 case sBadOption:
1276 return -1;
1277 case sPort:
1278 /* ignore ports from configfile if cmdline specifies ports */
1279 if (options->ports_from_cmdline)
1280 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001281 if (options->num_ports >= MAX_PORTS)
1282 fatal("%s line %d: too many ports.",
1283 filename, linenum);
1284 arg = strdelim(&cp);
1285 if (!arg || *arg == '\0')
1286 fatal("%s line %d: missing port number.",
1287 filename, linenum);
1288 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001289 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001290 fatal("%s line %d: Badly formatted port number.",
1291 filename, linenum);
1292 break;
1293
Ben Lindstromade03f62001-12-06 18:22:17 +00001294 case sLoginGraceTime:
1295 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001296 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001297 arg = strdelim(&cp);
1298 if (!arg || *arg == '\0')
1299 fatal("%s line %d: missing time value.",
1300 filename, linenum);
1301 if ((value = convtime(arg)) == -1)
1302 fatal("%s line %d: invalid time value.",
1303 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001304 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001305 *intptr = value;
1306 break;
1307
Ben Lindstromade03f62001-12-06 18:22:17 +00001308 case sListenAddress:
1309 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001310 if (arg == NULL || *arg == '\0')
1311 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001312 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001313 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1314 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1315 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001316 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001317 p = arg;
1318 } else {
dtucker@openbsd.orgd05ea252019-01-23 21:50:56 +00001319 arg2 = NULL;
dtucker@openbsd.org281ce042019-01-24 02:34:52 +00001320 ch = '\0';
dtucker@openbsd.orgd05ea252019-01-23 21:50:56 +00001321 p = hpdelim2(&arg, &ch);
1322 if (p == NULL || ch == '/')
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001323 fatal("%s line %d: bad address:port usage",
1324 filename, linenum);
1325 p = cleanhostname(p);
1326 if (arg == NULL)
1327 port = 0;
1328 else if ((port = a2port(arg)) <= 0)
1329 fatal("%s line %d: bad port number",
1330 filename, linenum);
1331 }
1332 /* Optional routing table */
1333 arg2 = NULL;
1334 if ((arg = strdelim(&cp)) != NULL) {
1335 if (strcmp(arg, "rdomain") != 0 ||
1336 (arg2 = strdelim(&cp)) == NULL)
1337 fatal("%s line %d: bad ListenAddress syntax",
1338 filename, linenum);
1339 if (!valid_rdomain(arg2))
1340 fatal("%s line %d: bad routing domain",
1341 filename, linenum);
1342 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001343
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001344 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001345
Ben Lindstromade03f62001-12-06 18:22:17 +00001346 break;
1347
Darren Tucker0f383232005-01-20 10:57:56 +11001348 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001349 intptr = &options->address_family;
1350 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001351 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001352 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001353 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001354 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001355 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001356 value = -1;
1357 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1358 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1359 value = multistate_ptr[i].value;
1360 break;
1361 }
1362 }
1363 if (value == -1)
1364 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001365 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001366 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001367 *intptr = value;
1368 break;
1369
Ben Lindstromade03f62001-12-06 18:22:17 +00001370 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 arg = strdelim(&cp);
1372 if (!arg || *arg == '\0')
1373 fatal("%s line %d: missing file name.",
1374 filename, linenum);
djm@openbsd.org928f1232018-11-19 04:12:32 +00001375 if (*activep) {
1376 servconf_add_hostkey(filename, linenum,
1377 options, arg, 1);
1378 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001379 break;
1380
Damien Miller85b45e02013-07-20 13:21:52 +10001381 case sHostKeyAgent:
1382 charptr = &options->host_key_agent;
1383 arg = strdelim(&cp);
1384 if (!arg || *arg == '\0')
1385 fatal("%s line %d: missing socket name.",
1386 filename, linenum);
1387 if (*activep && *charptr == NULL)
1388 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1389 xstrdup(arg) : derelativise_path(arg);
1390 break;
1391
Damien Miller0a80ca12010-02-27 07:55:05 +11001392 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001393 arg = strdelim(&cp);
1394 if (!arg || *arg == '\0')
1395 fatal("%s line %d: missing file name.",
1396 filename, linenum);
1397 if (*activep)
1398 servconf_add_hostcert(filename, linenum, options, arg);
1399 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001400
Ben Lindstromade03f62001-12-06 18:22:17 +00001401 case sPidFile:
1402 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001403 parse_filename:
1404 arg = strdelim(&cp);
1405 if (!arg || *arg == '\0')
1406 fatal("%s line %d: missing file name.",
1407 filename, linenum);
1408 if (*activep && *charptr == NULL) {
1409 *charptr = derelativise_path(arg);
1410 /* increase optional counter */
1411 if (intptr != NULL)
1412 *intptr = *intptr + 1;
1413 }
1414 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001415
1416 case sPermitRootLogin:
1417 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001418 multistate_ptr = multistate_permitrootlogin;
1419 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001420
1421 case sIgnoreRhosts:
1422 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001423 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001424 multistate_ptr = multistate_flag;
1425 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001426
1427 case sIgnoreUserKnownHosts:
1428 intptr = &options->ignore_user_known_hosts;
1429 goto parse_flag;
1430
Ben Lindstromade03f62001-12-06 18:22:17 +00001431 case sHostbasedAuthentication:
1432 intptr = &options->hostbased_authentication;
1433 goto parse_flag;
1434
1435 case sHostbasedUsesNameFromPacketOnly:
1436 intptr = &options->hostbased_uses_name_from_packet_only;
1437 goto parse_flag;
1438
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001439 case sHostbasedAcceptedKeyTypes:
1440 charptr = &options->hostbased_key_types;
1441 parse_keytypes:
1442 arg = strdelim(&cp);
1443 if (!arg || *arg == '\0')
1444 fatal("%s line %d: Missing argument.",
1445 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001446 if (*arg != '-' &&
naddy@openbsd.org91a21352019-09-06 14:45:34 +00001447 !sshkey_names_valid2(*arg == '+' || *arg == '^' ?
1448 arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001449 fatal("%s line %d: Bad key types '%s'.",
1450 filename, linenum, arg ? arg : "<NONE>");
1451 if (*activep && *charptr == NULL)
1452 *charptr = xstrdup(arg);
1453 break;
1454
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001455 case sHostKeyAlgorithms:
1456 charptr = &options->hostkeyalgorithms;
1457 goto parse_keytypes;
1458
djm@openbsd.org86e57372018-09-20 03:28:06 +00001459 case sCASignatureAlgorithms:
1460 charptr = &options->ca_sign_algorithms;
1461 goto parse_keytypes;
1462
Ben Lindstromade03f62001-12-06 18:22:17 +00001463 case sPubkeyAuthentication:
1464 intptr = &options->pubkey_authentication;
1465 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001466
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001467 case sPubkeyAcceptedKeyTypes:
1468 charptr = &options->pubkey_key_types;
1469 goto parse_keytypes;
1470
Ben Lindstromade03f62001-12-06 18:22:17 +00001471 case sKerberosAuthentication:
1472 intptr = &options->kerberos_authentication;
1473 goto parse_flag;
1474
1475 case sKerberosOrLocalPasswd:
1476 intptr = &options->kerberos_or_local_passwd;
1477 goto parse_flag;
1478
1479 case sKerberosTicketCleanup:
1480 intptr = &options->kerberos_ticket_cleanup;
1481 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001482
Darren Tucker22ef5082003-12-31 11:37:34 +11001483 case sKerberosGetAFSToken:
1484 intptr = &options->kerberos_get_afs_token;
1485 goto parse_flag;
1486
Darren Tucker0efd1552003-08-26 11:49:55 +10001487 case sGssAuthentication:
1488 intptr = &options->gss_authentication;
1489 goto parse_flag;
1490
1491 case sGssCleanupCreds:
1492 intptr = &options->gss_cleanup_creds;
1493 goto parse_flag;
1494
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001495 case sGssStrictAcceptor:
1496 intptr = &options->gss_strict_acceptor;
1497 goto parse_flag;
1498
Ben Lindstromade03f62001-12-06 18:22:17 +00001499 case sPasswordAuthentication:
1500 intptr = &options->password_authentication;
1501 goto parse_flag;
1502
1503 case sKbdInteractiveAuthentication:
1504 intptr = &options->kbd_interactive_authentication;
1505 goto parse_flag;
1506
1507 case sChallengeResponseAuthentication:
1508 intptr = &options->challenge_response_authentication;
1509 goto parse_flag;
1510
1511 case sPrintMotd:
1512 intptr = &options->print_motd;
1513 goto parse_flag;
1514
1515 case sPrintLastLog:
1516 intptr = &options->print_lastlog;
1517 goto parse_flag;
1518
1519 case sX11Forwarding:
1520 intptr = &options->x11_forwarding;
1521 goto parse_flag;
1522
1523 case sX11DisplayOffset:
1524 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001525 parse_int:
1526 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001527 if ((errstr = atoi_err(arg, &value)) != NULL)
1528 fatal("%s line %d: integer value %s.",
1529 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001530 if (*activep && *intptr == -1)
1531 *intptr = value;
1532 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001533
Damien Miller95c249f2002-02-05 12:11:34 +11001534 case sX11UseLocalhost:
1535 intptr = &options->x11_use_localhost;
1536 goto parse_flag;
1537
Ben Lindstromade03f62001-12-06 18:22:17 +00001538 case sXAuthLocation:
1539 charptr = &options->xauth_location;
1540 goto parse_filename;
1541
Damien Miller5ff30c62013-10-30 22:21:50 +11001542 case sPermitTTY:
1543 intptr = &options->permit_tty;
1544 goto parse_flag;
1545
Damien Miller72e6b5c2014-07-04 09:00:04 +10001546 case sPermitUserRC:
1547 intptr = &options->permit_user_rc;
1548 goto parse_flag;
1549
Ben Lindstromade03f62001-12-06 18:22:17 +00001550 case sStrictModes:
1551 intptr = &options->strict_modes;
1552 goto parse_flag;
1553
Damien Miller12c150e2003-12-17 16:31:10 +11001554 case sTCPKeepAlive:
1555 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001556 goto parse_flag;
1557
1558 case sEmptyPasswd:
1559 intptr = &options->permit_empty_passwd;
1560 goto parse_flag;
1561
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001562 case sPermitUserEnvironment:
1563 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001564 charptr = &options->permit_user_env_whitelist;
1565 arg = strdelim(&cp);
1566 if (!arg || *arg == '\0')
1567 fatal("%s line %d: missing argument.",
1568 filename, linenum);
1569 value = 0;
1570 p = NULL;
1571 if (strcmp(arg, "yes") == 0)
1572 value = 1;
1573 else if (strcmp(arg, "no") == 0)
1574 value = 0;
1575 else {
1576 /* Pattern-list specified */
1577 value = 1;
1578 p = xstrdup(arg);
1579 }
1580 if (*activep && *intptr == -1) {
1581 *intptr = value;
1582 *charptr = p;
1583 p = NULL;
1584 }
1585 free(p);
1586 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001587
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001588 case sCompression:
1589 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001590 multistate_ptr = multistate_compression;
1591 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001592
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001593 case sRekeyLimit:
1594 arg = strdelim(&cp);
1595 if (!arg || *arg == '\0')
1596 fatal("%.200s line %d: Missing argument.", filename,
1597 linenum);
1598 if (strcmp(arg, "default") == 0) {
1599 val64 = 0;
1600 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001601 if (scan_scaled(arg, &val64) == -1)
1602 fatal("%.200s line %d: Bad number '%s': %s",
1603 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001604 if (val64 != 0 && val64 < 16)
1605 fatal("%.200s line %d: RekeyLimit too small",
1606 filename, linenum);
1607 }
1608 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001609 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001610 if (cp != NULL) { /* optional rekey interval present */
1611 if (strcmp(cp, "none") == 0) {
1612 (void)strdelim(&cp); /* discard */
1613 break;
1614 }
1615 intptr = &options->rekey_interval;
1616 goto parse_time;
1617 }
1618 break;
1619
Ben Lindstromade03f62001-12-06 18:22:17 +00001620 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001621 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001622 multistate_ptr = multistate_gatewayports;
1623 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001624
Damien Miller3a961dc2003-06-03 10:25:48 +10001625 case sUseDNS:
1626 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001627 goto parse_flag;
1628
1629 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001630 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001631 arg = strdelim(&cp);
1632 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001633 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001634 fatal("%.200s line %d: unsupported log facility '%s'",
1635 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001636 if (*log_facility_ptr == -1)
1637 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001638 break;
1639
1640 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001641 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001642 arg = strdelim(&cp);
1643 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001644 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001645 fatal("%.200s line %d: unsupported log level '%s'",
1646 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001647 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001648 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001649 break;
1650
1651 case sAllowTcpForwarding:
1652 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001653 multistate_ptr = multistate_tcpfwd;
1654 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001655
Damien Miller7acefbb2014-07-18 14:11:24 +10001656 case sAllowStreamLocalForwarding:
1657 intptr = &options->allow_streamlocal_forwarding;
1658 multistate_ptr = multistate_tcpfwd;
1659 goto parse_multistate;
1660
Damien Miller4f755cd2008-05-19 14:57:41 +10001661 case sAllowAgentForwarding:
1662 intptr = &options->allow_agent_forwarding;
1663 goto parse_flag;
1664
djm@openbsd.org7844f352016-11-30 03:00:05 +00001665 case sDisableForwarding:
1666 intptr = &options->disable_forwarding;
1667 goto parse_flag;
1668
Ben Lindstromade03f62001-12-06 18:22:17 +00001669 case sAllowUsers:
1670 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001671 if (match_user(NULL, NULL, NULL, arg) == -1)
1672 fatal("%s line %d: invalid AllowUsers pattern: "
1673 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001674 if (!*activep)
1675 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001676 array_append(filename, linenum, "AllowUsers",
1677 &options->allow_users, &options->num_allow_users,
1678 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001679 }
1680 break;
1681
1682 case sDenyUsers:
1683 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001684 if (match_user(NULL, NULL, NULL, arg) == -1)
1685 fatal("%s line %d: invalid DenyUsers pattern: "
1686 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001687 if (!*activep)
1688 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001689 array_append(filename, linenum, "DenyUsers",
1690 &options->deny_users, &options->num_deny_users,
1691 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001692 }
1693 break;
1694
1695 case sAllowGroups:
1696 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001697 if (!*activep)
1698 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001699 array_append(filename, linenum, "AllowGroups",
1700 &options->allow_groups, &options->num_allow_groups,
1701 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001702 }
1703 break;
1704
1705 case sDenyGroups:
1706 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001707 if (!*activep)
1708 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001709 array_append(filename, linenum, "DenyGroups",
1710 &options->deny_groups, &options->num_deny_groups,
1711 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001712 }
1713 break;
1714
1715 case sCiphers:
1716 arg = strdelim(&cp);
1717 if (!arg || *arg == '\0')
1718 fatal("%s line %d: Missing argument.", filename, linenum);
naddy@openbsd.org91a21352019-09-06 14:45:34 +00001719 if (*arg != '-' &&
1720 !ciphers_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001721 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1722 filename, linenum, arg ? arg : "<NONE>");
1723 if (options->ciphers == NULL)
1724 options->ciphers = xstrdup(arg);
1725 break;
1726
1727 case sMacs:
1728 arg = strdelim(&cp);
1729 if (!arg || *arg == '\0')
1730 fatal("%s line %d: Missing argument.", filename, linenum);
naddy@openbsd.org91a21352019-09-06 14:45:34 +00001731 if (*arg != '-' &&
1732 !mac_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001733 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1734 filename, linenum, arg ? arg : "<NONE>");
1735 if (options->macs == NULL)
1736 options->macs = xstrdup(arg);
1737 break;
1738
Damien Millerd5f62bf2010-09-24 22:11:14 +10001739 case sKexAlgorithms:
1740 arg = strdelim(&cp);
1741 if (!arg || *arg == '\0')
1742 fatal("%s line %d: Missing argument.",
1743 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001744 if (*arg != '-' &&
naddy@openbsd.org91a21352019-09-06 14:45:34 +00001745 !kex_names_valid(*arg == '+' || *arg == '^' ?
1746 arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001747 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1748 filename, linenum, arg ? arg : "<NONE>");
1749 if (options->kex_algorithms == NULL)
1750 options->kex_algorithms = xstrdup(arg);
1751 break;
1752
Ben Lindstromade03f62001-12-06 18:22:17 +00001753 case sSubsystem:
1754 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1755 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001756 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001757 }
1758 arg = strdelim(&cp);
1759 if (!arg || *arg == '\0')
1760 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001761 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001762 if (!*activep) {
1763 arg = strdelim(&cp);
1764 break;
1765 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001766 for (i = 0; i < options->num_subsystems; i++)
1767 if (strcmp(arg, options->subsystem_name[i]) == 0)
1768 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001769 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001770 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1771 arg = strdelim(&cp);
1772 if (!arg || *arg == '\0')
1773 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001774 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001775 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001776
1777 /* Collect arguments (separate to executable) */
1778 p = xstrdup(arg);
1779 len = strlen(p) + 1;
1780 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1781 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001782 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001783 strlcat(p, " ", len);
1784 strlcat(p, arg, len);
1785 }
1786 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001787 options->num_subsystems++;
1788 break;
1789
1790 case sMaxStartups:
1791 arg = strdelim(&cp);
1792 if (!arg || *arg == '\0')
1793 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001794 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001795 if ((n = sscanf(arg, "%d:%d:%d",
1796 &options->max_startups_begin,
1797 &options->max_startups_rate,
1798 &options->max_startups)) == 3) {
1799 if (options->max_startups_begin >
1800 options->max_startups ||
1801 options->max_startups_rate > 100 ||
1802 options->max_startups_rate < 1)
1803 fatal("%s line %d: Illegal MaxStartups spec.",
1804 filename, linenum);
1805 } else if (n != 1)
1806 fatal("%s line %d: Illegal MaxStartups spec.",
1807 filename, linenum);
1808 else
1809 options->max_startups = options->max_startups_begin;
1810 break;
1811
Darren Tucker89413db2004-05-24 10:36:23 +10001812 case sMaxAuthTries:
1813 intptr = &options->max_authtries;
1814 goto parse_int;
1815
Damien Miller7207f642008-05-19 15:34:50 +10001816 case sMaxSessions:
1817 intptr = &options->max_sessions;
1818 goto parse_int;
1819
Ben Lindstromade03f62001-12-06 18:22:17 +00001820 case sBanner:
1821 charptr = &options->banner;
1822 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001823
Ben Lindstromade03f62001-12-06 18:22:17 +00001824 /*
1825 * These options can contain %X options expanded at
1826 * connect time, so that you can specify paths like:
1827 *
1828 * AuthorizedKeysFile /etc/ssh_keys/%u
1829 */
1830 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001831 if (*activep && options->num_authkeys_files == 0) {
1832 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001833 arg = tilde_expand_filename(arg, getuid());
1834 array_append(filename, linenum,
1835 "AuthorizedKeysFile",
1836 &options->authorized_keys_files,
1837 &options->num_authkeys_files, arg);
1838 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001839 }
1840 }
1841 return 0;
1842
Damien Miller30da3442010-05-10 11:58:03 +10001843 case sAuthorizedPrincipalsFile:
1844 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001845 arg = strdelim(&cp);
1846 if (!arg || *arg == '\0')
1847 fatal("%s line %d: missing file name.",
1848 filename, linenum);
1849 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001850 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001851 /* increase optional counter */
1852 if (intptr != NULL)
1853 *intptr = *intptr + 1;
1854 }
1855 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001856
1857 case sClientAliveInterval:
1858 intptr = &options->client_alive_interval;
1859 goto parse_time;
1860
1861 case sClientAliveCountMax:
1862 intptr = &options->client_alive_count_max;
1863 goto parse_int;
1864
Darren Tucker46bc0752004-05-02 22:11:30 +10001865 case sAcceptEnv:
1866 while ((arg = strdelim(&cp)) && *arg != '\0') {
1867 if (strchr(arg, '=') != NULL)
1868 fatal("%s line %d: Invalid environment name.",
1869 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001870 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001871 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001872 array_append(filename, linenum, "AcceptEnv",
1873 &options->accept_env, &options->num_accept_env,
1874 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001875 }
1876 break;
1877
djm@openbsd.org28013752018-06-09 03:03:10 +00001878 case sSetEnv:
1879 uvalue = options->num_setenv;
1880 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1881 if (strchr(arg, '=') == NULL)
1882 fatal("%s line %d: Invalid environment.",
1883 filename, linenum);
1884 if (!*activep || uvalue != 0)
1885 continue;
1886 array_append(filename, linenum, "SetEnv",
1887 &options->setenv, &options->num_setenv, arg);
1888 }
1889 break;
1890
Damien Millerd27b9472005-12-13 19:29:02 +11001891 case sPermitTunnel:
1892 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001893 arg = strdelim(&cp);
1894 if (!arg || *arg == '\0')
1895 fatal("%s line %d: Missing yes/point-to-point/"
1896 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001897 value = -1;
1898 for (i = 0; tunmode_desc[i].val != -1; i++)
1899 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1900 value = tunmode_desc[i].val;
1901 break;
1902 }
1903 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001904 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1905 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001906 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001907 *intptr = value;
1908 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001909
Darren Tucker45150472006-07-12 22:34:17 +10001910 case sMatch:
1911 if (cmdline)
1912 fatal("Match directive not supported as a command-line "
1913 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001914 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001915 if (value < 0)
1916 fatal("%s line %d: Bad Match condition", filename,
1917 linenum);
1918 *activep = value;
1919 break;
1920
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001921 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001922 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001923 if (opcode == sPermitListen) {
1924 uintptr = &options->num_permitted_listens;
1925 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001926 } else {
1927 uintptr = &options->num_permitted_opens;
1928 chararrayptr = &options->permitted_opens;
1929 }
Damien Miller9b439df2006-07-24 14:04:00 +10001930 arg = strdelim(&cp);
1931 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001932 fatal("%s line %d: missing %s specification",
1933 filename, linenum, lookup_opcode_name(opcode));
1934 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001935 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001936 if (*activep && uvalue == 0) {
1937 *uintptr = 1;
1938 *chararrayptr = xcalloc(1,
1939 sizeof(**chararrayptr));
1940 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001941 }
Damien Millerc6081482012-04-22 11:18:53 +10001942 break;
1943 }
Damien Millera765cf42006-07-24 14:08:13 +10001944 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001945 if (opcode == sPermitListen &&
1946 strchr(arg, ':') == NULL) {
1947 /*
1948 * Allow bare port number for PermitListen
1949 * to indicate a wildcard listen host.
1950 */
1951 xasprintf(&arg2, "*:%s", arg);
1952 } else {
1953 arg2 = xstrdup(arg);
dtucker@openbsd.org281ce042019-01-24 02:34:52 +00001954 ch = '\0';
dtucker@openbsd.orgd05ea252019-01-23 21:50:56 +00001955 p = hpdelim2(&arg, &ch);
1956 if (p == NULL || ch == '/') {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001957 fatal("%s line %d: missing host in %s",
1958 filename, linenum,
1959 lookup_opcode_name(opcode));
1960 }
1961 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001962 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001963 if (arg == NULL ||
1964 ((port = permitopen_port(arg)) < 0)) {
1965 fatal("%s line %d: bad port number in %s",
1966 filename, linenum,
1967 lookup_opcode_name(opcode));
1968 }
1969 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001970 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001971 lookup_opcode_name(opcode),
1972 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001973 }
1974 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001975 }
Damien Miller9b439df2006-07-24 14:04:00 +10001976 break;
1977
Damien Millere2754432006-07-24 14:06:47 +10001978 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001979 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001980 fatal("%.200s line %d: Missing argument.", filename,
1981 linenum);
1982 len = strspn(cp, WHITESPACE);
1983 if (*activep && options->adm_forced_command == NULL)
1984 options->adm_forced_command = xstrdup(cp + len);
1985 return 0;
1986
Damien Millerd8cb1f12008-02-10 22:40:12 +11001987 case sChrootDirectory:
1988 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001989
1990 arg = strdelim(&cp);
1991 if (!arg || *arg == '\0')
1992 fatal("%s line %d: missing file name.",
1993 filename, linenum);
1994 if (*activep && *charptr == NULL)
1995 *charptr = xstrdup(arg);
1996 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001997
Damien Miller1aed65e2010-03-04 21:53:35 +11001998 case sTrustedUserCAKeys:
1999 charptr = &options->trusted_user_ca_keys;
2000 goto parse_filename;
2001
2002 case sRevokedKeys:
2003 charptr = &options->revoked_keys_file;
2004 goto parse_filename;
2005
Damien Miller0dac6fb2010-11-20 15:19:38 +11002006 case sIPQoS:
2007 arg = strdelim(&cp);
2008 if ((value = parse_ipqos(arg)) == -1)
2009 fatal("%s line %d: Bad IPQoS value: %s",
2010 filename, linenum, arg);
2011 arg = strdelim(&cp);
2012 if (arg == NULL)
2013 value2 = value;
2014 else if ((value2 = parse_ipqos(arg)) == -1)
2015 fatal("%s line %d: Bad IPQoS value: %s",
2016 filename, linenum, arg);
2017 if (*activep) {
2018 options->ip_qos_interactive = value;
2019 options->ip_qos_bulk = value2;
2020 }
2021 break;
2022
Damien Miller23528812012-04-22 11:24:43 +10002023 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00002024 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10002025 fatal("%.200s line %d: Missing argument.", filename,
2026 linenum);
2027 len = strspn(cp, WHITESPACE);
2028 if (*activep && options->version_addendum == NULL) {
2029 if (strcasecmp(cp + len, "none") == 0)
2030 options->version_addendum = xstrdup("");
2031 else if (strchr(cp + len, '\r') != NULL)
2032 fatal("%.200s line %d: Invalid argument",
2033 filename, linenum);
2034 else
2035 options->version_addendum = xstrdup(cp + len);
2036 }
2037 return 0;
2038
Damien Miller09d3e122012-10-31 08:58:58 +11002039 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002040 if (cp == NULL)
2041 fatal("%.200s line %d: Missing argument.", filename,
2042 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002043 len = strspn(cp, WHITESPACE);
2044 if (*activep && options->authorized_keys_command == NULL) {
2045 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2046 fatal("%.200s line %d: AuthorizedKeysCommand "
2047 "must be an absolute path",
2048 filename, linenum);
2049 options->authorized_keys_command = xstrdup(cp + len);
2050 }
2051 return 0;
2052
2053 case sAuthorizedKeysCommandUser:
2054 charptr = &options->authorized_keys_command_user;
2055
2056 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002057 if (!arg || *arg == '\0')
2058 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2059 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002060 if (*activep && *charptr == NULL)
2061 *charptr = xstrdup(arg);
2062 break;
2063
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002064 case sAuthorizedPrincipalsCommand:
2065 if (cp == NULL)
2066 fatal("%.200s line %d: Missing argument.", filename,
2067 linenum);
2068 len = strspn(cp, WHITESPACE);
2069 if (*activep &&
2070 options->authorized_principals_command == NULL) {
2071 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2072 fatal("%.200s line %d: "
2073 "AuthorizedPrincipalsCommand must be "
2074 "an absolute path", filename, linenum);
2075 options->authorized_principals_command =
2076 xstrdup(cp + len);
2077 }
2078 return 0;
2079
2080 case sAuthorizedPrincipalsCommandUser:
2081 charptr = &options->authorized_principals_command_user;
2082
2083 arg = strdelim(&cp);
2084 if (!arg || *arg == '\0')
2085 fatal("%s line %d: missing "
2086 "AuthorizedPrincipalsCommandUser argument.",
2087 filename, linenum);
2088 if (*activep && *charptr == NULL)
2089 *charptr = xstrdup(arg);
2090 break;
2091
Damien Millera6e3f012012-11-04 23:21:40 +11002092 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002093 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002094 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002095 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002096 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002097 if (strcmp(arg, "any") == 0) {
2098 if (options->num_auth_methods > 0) {
2099 fatal("%s line %d: \"any\" "
2100 "must appear alone in "
2101 "AuthenticationMethods",
2102 filename, linenum);
2103 }
2104 value = 1;
2105 } else if (value) {
2106 fatal("%s line %d: \"any\" must appear "
2107 "alone in AuthenticationMethods",
2108 filename, linenum);
2109 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002110 fatal("%s line %d: invalid "
2111 "authentication method list.",
2112 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002113 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002114 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002115 if (!*activep)
2116 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002117 array_append(filename, linenum,
2118 "AuthenticationMethods",
2119 &options->auth_methods,
2120 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002121 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002122 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002123 fatal("%s line %d: no AuthenticationMethods "
2124 "specified", filename, linenum);
2125 }
Damien Millera6e3f012012-11-04 23:21:40 +11002126 }
2127 return 0;
2128
Damien Miller7acefbb2014-07-18 14:11:24 +10002129 case sStreamLocalBindMask:
2130 arg = strdelim(&cp);
2131 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002132 fatal("%s line %d: missing StreamLocalBindMask "
2133 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002134 /* Parse mode in octal format */
2135 value = strtol(arg, &p, 8);
2136 if (arg == p || value < 0 || value > 0777)
2137 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002138 if (*activep)
2139 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002140 break;
2141
2142 case sStreamLocalBindUnlink:
2143 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2144 goto parse_flag;
2145
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002146 case sFingerprintHash:
2147 arg = strdelim(&cp);
2148 if (!arg || *arg == '\0')
2149 fatal("%.200s line %d: Missing argument.",
2150 filename, linenum);
2151 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2152 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2153 filename, linenum, arg);
2154 if (*activep)
2155 options->fingerprint_hash = value;
2156 break;
2157
djm@openbsd.org8f574952017-06-24 06:34:38 +00002158 case sExposeAuthInfo:
2159 intptr = &options->expose_userauth_info;
2160 goto parse_flag;
2161
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002162 case sRDomain:
2163 charptr = &options->routing_domain;
2164 arg = strdelim(&cp);
2165 if (!arg || *arg == '\0')
2166 fatal("%.200s line %d: Missing argument.",
2167 filename, linenum);
2168 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2169 !valid_rdomain(arg))
2170 fatal("%s line %d: bad routing domain",
2171 filename, linenum);
2172 if (*activep && *charptr == NULL)
2173 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002174 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002175
Ben Lindstromade03f62001-12-06 18:22:17 +00002176 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002177 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002178 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002179 do_log2(opcode == sIgnore ?
2180 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2181 "%s line %d: %s option %s", filename, linenum,
2182 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002183 while (arg)
2184 arg = strdelim(&cp);
2185 break;
2186
Ben Lindstromade03f62001-12-06 18:22:17 +00002187 default:
2188 fatal("%s line %d: Missing handler for opcode %s (%d)",
2189 filename, linenum, arg, opcode);
2190 }
2191 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2192 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2193 filename, linenum, arg);
2194 return 0;
2195}
2196
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002197/* Reads the server configuration file. */
2198
Damien Miller4af51302000-04-16 11:18:38 +10002199void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002200load_server_config(const char *filename, struct sshbuf *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002201{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002202 char *line = NULL, *cp;
2203 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002204 FILE *f;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002205 int r, lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002206
Darren Tucker645ab752004-06-25 13:33:20 +10002207 debug2("%s: filename %s", __func__, filename);
2208 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002209 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002210 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002211 }
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002212 sshbuf_reset(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002213 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002214 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002215 /*
2216 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002217 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002218 * line numbers later for error messages
2219 */
2220 if ((cp = strchr(line, '#')) != NULL)
2221 memcpy(cp, "\n", 2);
2222 cp = line + strspn(line, " \t\r");
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002223 if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2224 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002225 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002226 free(line);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002227 if ((r = sshbuf_put_u8(conf, 0)) != 0)
2228 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002229 fclose(f);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002230 debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002231}
2232
2233void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002234parse_server_match_config(ServerOptions *options,
2235 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002236{
Darren Tucker45150472006-07-12 22:34:17 +10002237 ServerOptions mo;
2238
2239 initialize_server_options(&mo);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002240 parse_server_config(&mo, "reprocess config", cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002241 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002242}
2243
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002244int parse_server_match_testspec(struct connection_info *ci, char *spec)
2245{
2246 char *p;
2247
2248 while ((p = strsep(&spec, ",")) && *p != '\0') {
2249 if (strncmp(p, "addr=", 5) == 0) {
2250 ci->address = xstrdup(p + 5);
2251 } else if (strncmp(p, "host=", 5) == 0) {
2252 ci->host = xstrdup(p + 5);
2253 } else if (strncmp(p, "user=", 5) == 0) {
2254 ci->user = xstrdup(p + 5);
2255 } else if (strncmp(p, "laddr=", 6) == 0) {
2256 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002257 } else if (strncmp(p, "rdomain=", 8) == 0) {
2258 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002259 } else if (strncmp(p, "lport=", 6) == 0) {
2260 ci->lport = a2port(p + 6);
2261 if (ci->lport == -1) {
2262 fprintf(stderr, "Invalid port '%s' in test mode"
2263 " specification %s\n", p+6, p);
2264 return -1;
2265 }
2266 } else {
2267 fprintf(stderr, "Invalid test mode specification %s\n",
2268 p);
2269 return -1;
2270 }
2271 }
2272 return 0;
2273}
2274
2275/*
Darren Tucker1629c072007-02-19 22:25:37 +11002276 * Copy any supported values that are set.
2277 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002278 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002279 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002280 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002281 */
Darren Tucker45150472006-07-12 22:34:17 +10002282void
Darren Tucker1629c072007-02-19 22:25:37 +11002283copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002284{
Damien Miller534b2cc2013-12-05 14:07:27 +11002285#define M_CP_INTOPT(n) do {\
2286 if (src->n != -1) \
2287 dst->n = src->n; \
2288} while (0)
2289
Darren Tucker1629c072007-02-19 22:25:37 +11002290 M_CP_INTOPT(password_authentication);
2291 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002292 M_CP_INTOPT(pubkey_authentication);
2293 M_CP_INTOPT(kerberos_authentication);
2294 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002295 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002296 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002297 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002298 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002299
2300 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002301 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002302 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002303 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002304 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002305 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002306 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002307 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002308 M_CP_INTOPT(x11_display_offset);
2309 M_CP_INTOPT(x11_forwarding);
2310 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002311 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002312 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002313 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002314 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002315 M_CP_INTOPT(client_alive_count_max);
2316 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002317 M_CP_INTOPT(ip_qos_interactive);
2318 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002319 M_CP_INTOPT(rekey_limit);
2320 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002321 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002322
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002323 /*
2324 * The bind_mask is a mode_t that may be unsigned, so we can't use
2325 * M_CP_INTOPT - it does a signed comparison that causes compiler
2326 * warnings.
2327 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002328 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002329 dst->fwd_opts.streamlocal_bind_mask =
2330 src->fwd_opts.streamlocal_bind_mask;
2331 }
2332
Damien Miller534b2cc2013-12-05 14:07:27 +11002333 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2334#define M_CP_STROPT(n) do {\
2335 if (src->n != NULL && dst->n != src->n) { \
2336 free(dst->n); \
2337 dst->n = src->n; \
2338 } \
2339} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002340#define M_CP_STRARRAYOPT(s, num_s) do {\
2341 u_int i; \
2342 if (src->num_s != 0) { \
2343 for (i = 0; i < dst->num_s; i++) \
2344 free(dst->s[i]); \
2345 free(dst->s); \
2346 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2347 for (i = 0; i < src->num_s; i++) \
2348 dst->s[i] = xstrdup(src->s[i]); \
2349 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002350 } \
2351} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002352
Damien Millerf2e407e2011-05-20 19:04:14 +10002353 /* See comment in servconf.h */
2354 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002355
djm@openbsd.orged085102015-10-29 08:05:01 +00002356 /* Arguments that accept '+...' need to be expanded */
2357 assemble_algorithms(dst);
2358
Damien Millerc2411902011-05-20 19:03:49 +10002359 /*
2360 * The only things that should be below this point are string options
2361 * which are only used after authentication.
2362 */
Damien Miller5d74e582011-05-20 19:03:31 +10002363 if (preauth)
2364 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002365
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002366 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002367 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002368 if (option_clear_or_none(dst->adm_forced_command)) {
2369 free(dst->adm_forced_command);
2370 dst->adm_forced_command = NULL;
2371 }
Damien Miller5d74e582011-05-20 19:03:31 +10002372 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002373 if (option_clear_or_none(dst->chroot_directory)) {
2374 free(dst->chroot_directory);
2375 dst->chroot_directory = NULL;
2376 }
Darren Tucker45150472006-07-12 22:34:17 +10002377}
2378
Darren Tucker1629c072007-02-19 22:25:37 +11002379#undef M_CP_INTOPT
2380#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002381#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002382
Darren Tucker45150472006-07-12 22:34:17 +10002383void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002384parse_server_config(ServerOptions *options, const char *filename,
2385 struct sshbuf *conf, struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002386{
2387 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002388 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002389
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002390 debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002391
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002392 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2393 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002394 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002395 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002396 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002397 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002398 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002399 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002400 }
Darren Tuckera627d422013-06-02 07:31:17 +10002401 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002402 if (bad_options > 0)
2403 fatal("%s: terminating, %d bad configuration options",
2404 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002405 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002406}
Darren Tuckere7140f22008-06-10 23:01:51 +10002407
2408static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002409fmt_multistate_int(int val, const struct multistate *m)
2410{
2411 u_int i;
2412
2413 for (i = 0; m[i].key != NULL; i++) {
2414 if (m[i].value == val)
2415 return m[i].key;
2416 }
2417 return "UNKNOWN";
2418}
2419
2420static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002421fmt_intarg(ServerOpCodes code, int val)
2422{
Damien Miller82c55872011-06-23 08:20:30 +10002423 if (val == -1)
2424 return "unset";
2425 switch (code) {
2426 case sAddressFamily:
2427 return fmt_multistate_int(val, multistate_addressfamily);
2428 case sPermitRootLogin:
2429 return fmt_multistate_int(val, multistate_permitrootlogin);
2430 case sGatewayPorts:
2431 return fmt_multistate_int(val, multistate_gatewayports);
2432 case sCompression:
2433 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002434 case sAllowTcpForwarding:
2435 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002436 case sAllowStreamLocalForwarding:
2437 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002438 case sFingerprintHash:
2439 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002440 default:
2441 switch (val) {
2442 case 0:
2443 return "no";
2444 case 1:
2445 return "yes";
2446 default:
2447 return "UNKNOWN";
2448 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002449 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002450}
2451
Darren Tuckere7140f22008-06-10 23:01:51 +10002452static void
2453dump_cfg_int(ServerOpCodes code, int val)
2454{
2455 printf("%s %d\n", lookup_opcode_name(code), val);
2456}
2457
2458static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002459dump_cfg_oct(ServerOpCodes code, int val)
2460{
2461 printf("%s 0%o\n", lookup_opcode_name(code), val);
2462}
2463
2464static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002465dump_cfg_fmtint(ServerOpCodes code, int val)
2466{
2467 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2468}
2469
2470static void
2471dump_cfg_string(ServerOpCodes code, const char *val)
2472{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002473 printf("%s %s\n", lookup_opcode_name(code),
2474 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002475}
2476
2477static void
2478dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2479{
2480 u_int i;
2481
2482 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002483 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2484}
2485
2486static void
2487dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2488{
2489 u_int i;
2490
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002491 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002492 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002493 printf("%s", lookup_opcode_name(code));
2494 for (i = 0; i < count; i++)
2495 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002496 if (code == sAuthenticationMethods && count == 0)
2497 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002498 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002499}
2500
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002501static char *
2502format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002503{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002504 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002505 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002506 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002507 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002508
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002509 /*
2510 * ListenAddress must be after Port. add_one_listen_addr pushes
2511 * addresses onto a stack, so to maintain ordering we need to
2512 * print these in reverse order.
2513 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002514 for (ai = la->addrs; ai; ai = ai->ai_next) {
2515 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002516 sizeof(addr), port, sizeof(port),
2517 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002518 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2519 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002520 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002521 laddr2 = laddr1;
2522 if (ai->ai_family == AF_INET6) {
2523 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2524 addr, port,
2525 la->rdomain == NULL ? "" : " rdomain ",
2526 la->rdomain == NULL ? "" : la->rdomain,
2527 laddr2);
2528 } else {
2529 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2530 addr, port,
2531 la->rdomain == NULL ? "" : " rdomain ",
2532 la->rdomain == NULL ? "" : la->rdomain,
2533 laddr2);
2534 }
2535 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002536 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002537 return laddr1;
2538}
2539
2540void
2541dump_config(ServerOptions *o)
2542{
2543 char *s;
2544 u_int i;
2545
2546 /* these are usually at the top of the config */
2547 for (i = 0; i < o->num_ports; i++)
2548 printf("port %d\n", o->ports[i]);
2549 dump_cfg_fmtint(sAddressFamily, o->address_family);
2550
2551 for (i = 0; i < o->num_listen_addrs; i++) {
2552 s = format_listen_addrs(&o->listen_addrs[i]);
2553 printf("%s", s);
2554 free(s);
2555 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002556
2557 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002558#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002559 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002560#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002561 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002562 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2563 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002564 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002565 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2566 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002567 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002568
2569 /* formatted integer arguments */
2570 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2571 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2572 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002573 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2574 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2575 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002576 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002577#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002578 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2579 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2580 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002581# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002582 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002583# endif
2584#endif
2585#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002586 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2587 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002588#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002589 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2590 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2591 o->kbd_interactive_authentication);
2592 dump_cfg_fmtint(sChallengeResponseAuthentication,
2593 o->challenge_response_authentication);
2594 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002595#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002596 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002597#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002598 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2599 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002600 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002601 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002602 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2603 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2604 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002605 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002606 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002607 dump_cfg_fmtint(sUseDNS, o->use_dns);
2608 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002609 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002610 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002611 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002612 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002613 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002614 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002615
2616 /* string arguments */
2617 dump_cfg_string(sPidFile, o->pid_file);
2618 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002619 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2620 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002621 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002622 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002623 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002624 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2625 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002626 dump_cfg_string(sAuthorizedPrincipalsFile,
2627 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002628 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2629 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002630 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2631 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002632 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2633 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002634 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002635 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002636 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org86e57372018-09-20 03:28:06 +00002637 dump_cfg_string(sCASignatureAlgorithms, o->ca_sign_algorithms ?
2638 o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002639 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2640 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002641 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2642 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002643 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
djm@openbsd.org01a06702019-10-31 21:17:49 +00002644 o->pubkey_key_types : PUBKEY_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002645 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002646
2647 /* string arguments requiring a lookup */
2648 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2649 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2650
2651 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002652 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2653 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002654 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2655 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002656 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002657 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002658 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2659 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2660 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2661 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2662 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002663 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002664 dump_cfg_strarray_oneline(sAuthenticationMethods,
2665 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002666
2667 /* other arguments */
2668 for (i = 0; i < o->num_subsystems; i++)
2669 printf("subsystem %s %s\n", o->subsystem_name[i],
2670 o->subsystem_args[i]);
2671
2672 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2673 o->max_startups_rate, o->max_startups);
2674
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002675 s = NULL;
2676 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002677 if (tunmode_desc[i].val == o->permit_tun) {
2678 s = tunmode_desc[i].text;
2679 break;
2680 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002681 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002682 dump_cfg_string(sPermitTunnel, s);
2683
Damien Miller91475862011-05-05 14:14:34 +10002684 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2685 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002686
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002687 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002688 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002689
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002690 printf("permitopen");
2691 if (o->num_permitted_opens == 0)
2692 printf(" any");
2693 else {
2694 for (i = 0; i < o->num_permitted_opens; i++)
2695 printf(" %s", o->permitted_opens[i]);
2696 }
2697 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002698 printf("permitlisten");
2699 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002700 printf(" any");
2701 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002702 for (i = 0; i < o->num_permitted_listens; i++)
2703 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002704 }
2705 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002706
2707 if (o->permit_user_env_whitelist == NULL) {
2708 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2709 } else {
2710 printf("permituserenvironment %s\n",
2711 o->permit_user_env_whitelist);
2712 }
2713
Darren Tuckere7140f22008-06-10 23:01:51 +10002714}