blob: 5411640fcfd990712f7cbca89039210b025bb615 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org86e57372018-09-20 03:28:06 +00002/* $OpenBSD: servconf.c,v 1.341 2018/09/20 03:28:06 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);
213 ASSEMBLE(pubkey_key_types, KEX_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
224array_append(const char *file, const int line, const char *directive,
225 char ***array, u_int *lp, const char *s)
226{
227
228 if (*lp >= INT_MAX)
229 fatal("%s line %d: Too many %s entries", file, line, directive);
230
231 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
232 (*array)[*lp] = xstrdup(s);
233 (*lp)++;
234}
235
236void
237servconf_add_hostkey(const char *file, const int line,
238 ServerOptions *options, const char *path)
239{
240 char *apath = derelativise_path(path);
241
242 array_append(file, line, "HostKey",
243 &options->host_key_files, &options->num_host_key_files, apath);
244 free(apath);
245}
246
247void
248servconf_add_hostcert(const char *file, const int line,
249 ServerOptions *options, const char *path)
250{
251 char *apath = derelativise_path(path);
252
253 array_append(file, line, "HostCertificate",
254 &options->host_cert_files, &options->num_host_cert_files, apath);
255 free(apath);
256}
257
Damien Miller4af51302000-04-16 11:18:38 +1000258void
Damien Miller95def091999-11-25 00:26:21 +1100259fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000261 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000262
Damien Miller726273e2001-11-12 11:40:11 +1100263 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000264 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000265 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100266
267 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100268 if (options->num_host_key_files == 0) {
269 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000270 servconf_add_hostkey("[default]", 0, options,
271 _PATH_HOST_RSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100272#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000273 servconf_add_hostkey("[default]", 0, options,
274 _PATH_HOST_ECDSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100275#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000276 servconf_add_hostkey("[default]", 0, options,
277 _PATH_HOST_ED25519_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000278#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000279 servconf_add_hostkey("[default]", 0, options,
280 _PATH_HOST_XMSS_KEY_FILE);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000281#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100282 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100283 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100284 if (options->num_ports == 0)
285 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000286 if (options->address_family == -1)
287 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100288 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000289 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000290 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000291 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100292 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000293 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000294 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000295 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100296 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100297 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100298 if (options->ignore_user_known_hosts == -1)
299 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100300 if (options->print_motd == -1)
301 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000302 if (options->print_lastlog == -1)
303 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100304 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100305 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100306 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100307 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100308 if (options->x11_use_localhost == -1)
309 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000310 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000311 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100312 if (options->permit_tty == -1)
313 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000314 if (options->permit_user_rc == -1)
315 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100316 if (options->strict_modes == -1)
317 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100318 if (options->tcp_keep_alive == -1)
319 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100320 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100321 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100322 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000323 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000324 if (options->hostbased_authentication == -1)
325 options->hostbased_authentication = 0;
326 if (options->hostbased_uses_name_from_packet_only == -1)
327 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100328 if (options->pubkey_authentication == -1)
329 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100330 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000331 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100332 if (options->kerberos_or_local_passwd == -1)
333 options->kerberos_or_local_passwd = 1;
334 if (options->kerberos_ticket_cleanup == -1)
335 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100336 if (options->kerberos_get_afs_token == -1)
337 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000338 if (options->gss_authentication == -1)
339 options->gss_authentication = 0;
340 if (options->gss_cleanup_creds == -1)
341 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000342 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000343 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100344 if (options->password_authentication == -1)
345 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100346 if (options->kbd_interactive_authentication == -1)
347 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000348 if (options->challenge_response_authentication == -1)
349 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100350 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100351 options->permit_empty_passwd = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000352 if (options->permit_user_env == -1) {
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000353 options->permit_user_env = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000354 options->permit_user_env_whitelist = NULL;
355 }
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000356 if (options->compression == -1)
sf@openbsd.org168b46f2018-07-09 13:37:10 +0000357 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000358 if (options->rekey_limit == -1)
359 options->rekey_limit = 0;
360 if (options->rekey_interval == -1)
361 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100362 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100363 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000364 if (options->allow_streamlocal_forwarding == -1)
365 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000366 if (options->allow_agent_forwarding == -1)
367 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000368 if (options->fwd_opts.gateway_ports == -1)
369 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000370 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100371 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000372 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100373 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000374 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100375 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000376 if (options->max_authtries == -1)
377 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000378 if (options->max_sessions == -1)
379 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000380 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000381 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000382 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100383 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000384 if (options->client_alive_count_max == -1)
385 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000386 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000387 array_append("[default]", 0, "AuthorizedKeysFiles",
388 &options->authorized_keys_files,
389 &options->num_authkeys_files,
390 _PATH_SSH_USER_PERMITTED_KEYS);
391 array_append("[default]", 0, "AuthorizedKeysFiles",
392 &options->authorized_keys_files,
393 &options->num_authkeys_files,
394 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000395 }
Damien Millerd27b9472005-12-13 19:29:02 +1100396 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100397 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100398 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000399 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100400 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000401 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000402 if (options->version_addendum == NULL)
403 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000404 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
405 options->fwd_opts.streamlocal_bind_mask = 0177;
406 if (options->fwd_opts.streamlocal_bind_unlink == -1)
407 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000408 if (options->fingerprint_hash == -1)
409 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000410 if (options->disable_forwarding == -1)
411 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000412 if (options->expose_userauth_info == -1)
413 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000414
djm@openbsd.orged085102015-10-29 08:05:01 +0000415 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000416
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000417 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000418 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000419 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000420
djm@openbsd.org161cf412014-12-22 07:55:51 +0000421#define CLEAR_ON_NONE(v) \
422 do { \
423 if (option_clear_or_none(v)) { \
424 free(v); \
425 v = NULL; \
426 } \
427 } while(0)
428 CLEAR_ON_NONE(options->pid_file);
429 CLEAR_ON_NONE(options->xauth_location);
430 CLEAR_ON_NONE(options->banner);
431 CLEAR_ON_NONE(options->trusted_user_ca_keys);
432 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000433 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000434 CLEAR_ON_NONE(options->adm_forced_command);
435 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000436 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000437 for (i = 0; i < options->num_host_key_files; i++)
438 CLEAR_ON_NONE(options->host_key_files[i]);
439 for (i = 0; i < options->num_host_cert_files; i++)
440 CLEAR_ON_NONE(options->host_cert_files[i]);
441#undef CLEAR_ON_NONE
442
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000443 /* Similar handling for AuthenticationMethods=any */
444 if (options->num_auth_methods == 1 &&
445 strcmp(options->auth_methods[0], "any") == 0) {
446 free(options->auth_methods[0]);
447 options->auth_methods[0] = NULL;
448 options->num_auth_methods = 0;
449 }
450
Tim Rice40017b02002-07-14 13:36:49 -0700451#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000452 if (use_privsep && options->compression == 1) {
453 error("This platform does not support both privilege "
454 "separation and compression");
455 error("Compression disabled");
456 options->compression = 0;
457 }
458#endif
459
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000460}
461
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000462/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100463typedef enum {
464 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100465 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000466 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100467 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000468 sPort, sHostKeyFile, sLoginGraceTime,
469 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000470 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100471 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000472 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100473 sPasswordAuthentication, sKbdInteractiveAuthentication,
474 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000475 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100476 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100477 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000478 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000479 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000480 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000481 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
482 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000483 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000484 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000485 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000486 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000487 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000488 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000489 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100490 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100491 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000492 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000493 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
djm@openbsd.org86e57372018-09-20 03:28:06 +0000494 sKexAlgorithms, sCASignatureAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100495 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000496 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000497 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000498 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000499 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000500 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000501} ServerOpCodes;
502
Darren Tucker45150472006-07-12 22:34:17 +1000503#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
504#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
505#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
506
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000507/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100508static struct {
509 const char *name;
510 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000511 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100512} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100513 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000514#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000515 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000516#else
Darren Tucker45150472006-07-12 22:34:17 +1000517 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000518#endif
Darren Tucker45150472006-07-12 22:34:17 +1000519 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100520 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000521 { "port", sPort, SSHCFG_GLOBAL },
522 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
523 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000524 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000526 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000527 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000528 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100529 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000530 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000531 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000532 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000533 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100534 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000535 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000536 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000537 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000538 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100539 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000540 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000541 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000542#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100543 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000544 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
545 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100546#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000547 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000548#else
Darren Tucker45150472006-07-12 22:34:17 +1000549 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100550#endif
551#else
Darren Tucker1629c072007-02-19 22:25:37 +1100552 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000553 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
554 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
555 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000556#endif
Darren Tucker45150472006-07-12 22:34:17 +1000557 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
558 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000559#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100560 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000561 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000562 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000563#else
Darren Tucker1629c072007-02-19 22:25:37 +1100564 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000565 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000566 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000567#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100568 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
569 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100570 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Damien Miller87f08be2018-07-20 13:18:28 +1000571 { "skeyauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000572 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
573 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
574 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
575 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100576#ifdef DISABLE_LASTLOG
577 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
578#else
Darren Tucker45150472006-07-12 22:34:17 +1000579 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100580#endif
Darren Tucker45150472006-07-12 22:34:17 +1000581 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
582 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000583 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
584 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
585 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000586 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
587 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100588 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000589 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000590 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000591 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000592 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000593 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
594 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
595 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000596 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000597 { "allowusers", sAllowUsers, SSHCFG_ALL },
598 { "denyusers", sDenyUsers, SSHCFG_ALL },
599 { "allowgroups", sAllowGroups, SSHCFG_ALL },
600 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000601 { "ciphers", sCiphers, SSHCFG_GLOBAL },
602 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000603 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000604 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
605 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
606 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000607 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000608 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100609 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000610 { "usedns", sUseDNS, SSHCFG_GLOBAL },
611 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
612 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000613 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
614 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000615 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000616 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000617 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000618 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000619 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000620 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100621 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000622 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000623 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000624 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000625 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000626 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100627 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100628 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100629 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
630 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000631 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000632 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100633 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100634 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
635 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000636 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
637 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000638 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100639 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000640 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
641 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
642 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000643 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000644 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000645 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000646 { "rdomain", sRDomain, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000647 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000648};
649
Darren Tuckere7140f22008-06-10 23:01:51 +1000650static struct {
651 int val;
652 char *text;
653} tunmode_desc[] = {
654 { SSH_TUNMODE_NO, "no" },
655 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
656 { SSH_TUNMODE_ETHERNET, "ethernet" },
657 { SSH_TUNMODE_YES, "yes" },
658 { -1, NULL }
659};
660
djm@openbsd.org115063a2018-06-06 18:22:41 +0000661/* Returns an opcode name from its number */
662
663static const char *
664lookup_opcode_name(ServerOpCodes code)
665{
666 u_int i;
667
668 for (i = 0; keywords[i].name != NULL; i++)
669 if (keywords[i].opcode == code)
670 return(keywords[i].name);
671 return "UNKNOWN";
672}
673
674
Damien Miller5428f641999-11-25 11:54:57 +1100675/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000676 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100677 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000678
Damien Miller4af51302000-04-16 11:18:38 +1000679static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100680parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000681 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000682{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000683 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000684
Damien Miller95def091999-11-25 00:26:21 +1100685 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000686 if (strcasecmp(cp, keywords[i].name) == 0) {
687 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100688 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000689 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000690
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000691 error("%s: line %d: Bad configuration option: %s",
692 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100693 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000694}
695
Darren Tucker88b6fb22010-01-13 22:44:29 +1100696char *
697derelativise_path(const char *path)
698{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000699 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100700
djm@openbsd.org161cf412014-12-22 07:55:51 +0000701 if (strcasecmp(path, "none") == 0)
702 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100703 expanded = tilde_expand_filename(path, getuid());
704 if (*expanded == '/')
705 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100706 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100707 fatal("%s: getcwd: %s", __func__, strerror(errno));
708 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000709 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100710 return ret;
711}
712
Ben Lindstrombba81212001-06-25 05:01:22 +0000713static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000714add_listen_addr(ServerOptions *options, const char *addr,
715 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100716{
Damien Millereccb9de2005-06-17 12:59:34 +1000717 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100718
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000719 if (port > 0)
720 add_one_listen_addr(options, addr, rdomain, port);
721 else {
722 for (i = 0; i < options->num_ports; i++) {
723 add_one_listen_addr(options, addr, rdomain,
724 options->ports[i]);
725 }
726 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000727}
728
Ben Lindstrombba81212001-06-25 05:01:22 +0000729static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000730add_one_listen_addr(ServerOptions *options, const char *addr,
731 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000732{
733 struct addrinfo hints, *ai, *aitop;
734 char strport[NI_MAXSERV];
735 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000736 u_int i;
737
738 /* Find listen_addrs entry for this rdomain */
739 for (i = 0; i < options->num_listen_addrs; i++) {
740 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
741 break;
742 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
743 continue;
744 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
745 break;
746 }
747 if (i >= options->num_listen_addrs) {
748 /* No entry for this rdomain; allocate one */
749 if (i >= INT_MAX)
750 fatal("%s: too many listen addresses", __func__);
751 options->listen_addrs = xrecallocarray(options->listen_addrs,
752 options->num_listen_addrs, options->num_listen_addrs + 1,
753 sizeof(*options->listen_addrs));
754 i = options->num_listen_addrs++;
755 if (rdomain != NULL)
756 options->listen_addrs[i].rdomain = xstrdup(rdomain);
757 }
758 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000759
760 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100761 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000762 hints.ai_socktype = SOCK_STREAM;
763 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100764 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000765 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
766 fatal("bad addr or host: %s (%s)",
767 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100768 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000769 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
770 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000771 ai->ai_next = options->listen_addrs[i].addrs;
772 options->listen_addrs[i].addrs = aitop;
773}
774
775/* Returns nonzero if the routing domain name is valid */
776static int
777valid_rdomain(const char *name)
778{
Damien Miller43c29bb2017-10-25 13:10:59 +1100779#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100780 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100781#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000782 const char *errstr;
783 long long num;
784 struct rt_tableinfo info;
785 int mib[6];
786 size_t miblen = sizeof(mib);
787
788 if (name == NULL)
789 return 1;
790
791 num = strtonum(name, 0, 255, &errstr);
792 if (errstr != NULL)
793 return 0;
794
795 /* Check whether the table actually exists */
796 memset(mib, 0, sizeof(mib));
797 mib[0] = CTL_NET;
798 mib[1] = PF_ROUTE;
799 mib[4] = NET_RT_TABLE;
800 mib[5] = (int)num;
801 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
802 return 0;
803
804 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100805#else /* defined(__OpenBSD__) */
806 error("Routing domains are not supported on this platform");
807 return 0;
808#endif
Damien Miller34132e52000-01-14 15:45:46 +1100809}
810
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000811/*
812 * Queue a ListenAddress to be processed once we have all of the Ports
813 * and AddressFamily options.
814 */
815static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000816queue_listen_addr(ServerOptions *options, const char *addr,
817 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000818{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000819 struct queued_listenaddr *qla;
820
821 options->queued_listen_addrs = xrecallocarray(
822 options->queued_listen_addrs,
823 options->num_queued_listens, options->num_queued_listens + 1,
824 sizeof(*options->queued_listen_addrs));
825 qla = &options->queued_listen_addrs[options->num_queued_listens++];
826 qla->addr = xstrdup(addr);
827 qla->port = port;
828 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000829}
830
831/*
832 * Process queued (text) ListenAddress entries.
833 */
834static void
835process_queued_listen_addrs(ServerOptions *options)
836{
837 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000838 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000839
840 if (options->num_ports == 0)
841 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
842 if (options->address_family == -1)
843 options->address_family = AF_UNSPEC;
844
845 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000846 qla = &options->queued_listen_addrs[i];
847 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
848 free(qla->addr);
849 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000850 }
851 free(options->queued_listen_addrs);
852 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000853 options->num_queued_listens = 0;
854}
855
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000856/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000857 * Inform channels layer of permitopen options for a single forwarding
858 * direction (local/remote).
859 */
860static void
861process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
862 char **opens, u_int num_opens)
863{
864 u_int i;
865 int port;
866 char *host, *arg, *oarg;
867 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
868 const char *what = lookup_opcode_name(opcode);
869
870 channel_clear_permission(ssh, FORWARD_ADM, where);
871 if (num_opens == 0)
872 return; /* permit any */
873
874 /* handle keywords: "any" / "none" */
875 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
876 return;
877 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
878 channel_disable_admin(ssh, where);
879 return;
880 }
881 /* Otherwise treat it as a list of permitted host:port */
882 for (i = 0; i < num_opens; i++) {
883 oarg = arg = xstrdup(opens[i]);
884 host = hpdelim(&arg);
885 if (host == NULL)
886 fatal("%s: missing host in %s", __func__, what);
887 host = cleanhostname(host);
888 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
889 fatal("%s: bad port number in %s", __func__, what);
890 /* Send it to channels layer */
891 channel_add_permission(ssh, FORWARD_ADM,
892 where, host, port);
893 free(oarg);
894 }
895}
896
897/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000898 * Inform channels layer of permitopen options from configuration.
899 */
900void
901process_permitopen(struct ssh *ssh, ServerOptions *options)
902{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000903 process_permitopen_list(ssh, sPermitOpen,
904 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000905 process_permitopen_list(ssh, sPermitListen,
906 options->permitted_listens,
907 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000908}
909
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000910struct connection_info *
911get_connection_info(int populate, int use_dns)
912{
djm@openbsd.org95767262016-03-07 19:02:43 +0000913 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000914 static struct connection_info ci;
915
916 if (!populate)
917 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000918 ci.host = auth_get_canonical_hostname(ssh, use_dns);
919 ci.address = ssh_remote_ipaddr(ssh);
920 ci.laddress = ssh_local_ipaddr(ssh);
921 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000922 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000923 return &ci;
924}
925
Darren Tucker45150472006-07-12 22:34:17 +1000926/*
927 * The strategy for the Match blocks is that the config file is parsed twice.
928 *
929 * The first time is at startup. activep is initialized to 1 and the
930 * directives in the global context are processed and acted on. Hitting a
931 * Match directive unsets activep and the directives inside the block are
932 * checked for syntax only.
933 *
934 * The second time is after a connection has been established but before
935 * authentication. activep is initialized to 2 and global config directives
936 * are ignored since they have already been processed. If the criteria in a
937 * Match block is met, activep is set and the subsequent directives
938 * processed and actioned until EOF or another Match block unsets it. Any
939 * options set are copied into the main server config.
940 *
941 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000942 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000943 *
944 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
945 * Match Address 192.168.0.*
946 * Tag trusted
947 * Match Group wheel
948 * Tag trusted
949 * Match Tag trusted
950 * AllowTcpForwarding yes
951 * GatewayPorts clientspecified
952 * [...]
953 *
954 * - Add a PermittedChannelRequests directive
955 * Match Group shell
956 * PermittedChannelRequests session,forwarded-tcpip
957 */
958
959static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000960match_cfg_line_group(const char *grps, int line, const char *user)
961{
962 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000963 struct passwd *pw;
964
Damien Miller565ca3f2006-08-19 00:23:15 +1000965 if (user == NULL)
966 goto out;
967
968 if ((pw = getpwnam(user)) == NULL) {
969 debug("Can't match group at line %d because user %.100s does "
970 "not exist", line, user);
971 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
972 debug("Can't Match group because user %.100s not in any group "
973 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000974 } else if (ga_match_pattern_list(grps) != 1) {
975 debug("user %.100s does not match group list %.100s at line %d",
976 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000977 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000978 debug("user %.100s matched group list %.100s at line %d", user,
979 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000980 result = 1;
981 }
982out:
983 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000984 return result;
985}
986
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +0000987static void
988match_test_missing_fatal(const char *criteria, const char *attrib)
989{
990 fatal("'Match %s' in configuration but '%s' not in connection "
991 "test specification.", criteria, attrib);
992}
993
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000994/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000995 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100996 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000997 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000998 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000999static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001000match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +10001001{
Damien Millercf31f382013-10-24 21:02:56 +11001002 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +10001003 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +10001004
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001005 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001006 debug3("checking syntax for 'Match %s'", cp);
1007 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001008 debug3("checking match for '%s' user %s host %s addr %s "
1009 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
1010 ci->host ? ci->host : "(null)",
1011 ci->address ? ci->address : "(null)",
1012 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +10001013
1014 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +11001015 attributes++;
1016 if (strcasecmp(attrib, "all") == 0) {
1017 if (attributes != 1 ||
1018 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1019 error("'all' cannot be combined with other "
1020 "Match attributes");
1021 return -1;
1022 }
1023 *condition = cp;
1024 return 1;
1025 }
Darren Tucker45150472006-07-12 22:34:17 +10001026 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1027 error("Missing Match criteria for %s", attrib);
1028 return -1;
1029 }
Darren Tucker45150472006-07-12 22:34:17 +10001030 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001031 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001032 result = 0;
1033 continue;
1034 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001035 if (ci->user == NULL)
1036 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001037 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001038 result = 0;
1039 else
1040 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001041 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001042 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001043 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001044 result = 0;
1045 continue;
1046 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001047 if (ci->user == NULL)
1048 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001049 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001050 case -1:
1051 return -1;
1052 case 0:
1053 result = 0;
1054 }
Darren Tucker45150472006-07-12 22:34:17 +10001055 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001056 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001057 result = 0;
1058 continue;
1059 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001060 if (ci->host == NULL)
1061 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001062 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001063 result = 0;
1064 else
1065 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001066 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001067 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001068 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001069 result = 0;
1070 continue;
1071 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001072 if (ci->address == NULL)
1073 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001074 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001075 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001076 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001077 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001078 break;
1079 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001080 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001081 result = 0;
1082 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001083 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001084 return -1;
1085 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001086 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001087 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001088 result = 0;
1089 continue;
1090 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001091 if (ci->laddress == NULL)
1092 match_test_missing_fatal("LocalAddress",
1093 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001094 switch (addr_match_list(ci->laddress, arg)) {
1095 case 1:
1096 debug("connection from %.100s matched "
1097 "'LocalAddress %.100s' at line %d",
1098 ci->laddress, arg, line);
1099 break;
1100 case 0:
1101 case -1:
1102 result = 0;
1103 break;
1104 case -2:
1105 return -1;
1106 }
1107 } else if (strcasecmp(attrib, "localport") == 0) {
1108 if ((port = a2port(arg)) == -1) {
1109 error("Invalid LocalPort '%s' on Match line",
1110 arg);
1111 return -1;
1112 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001113 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001114 result = 0;
1115 continue;
1116 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001117 if (ci->lport == 0)
1118 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001119 /* TODO support port lists */
1120 if (port == ci->lport)
1121 debug("connection from %.100s matched "
1122 "'LocalPort %d' at line %d",
1123 ci->laddress, port, line);
1124 else
1125 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001126 } else if (strcasecmp(attrib, "rdomain") == 0) {
1127 if (ci == NULL || ci->rdomain == NULL) {
1128 result = 0;
1129 continue;
1130 }
1131 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1132 result = 0;
1133 else
1134 debug("user %.100s matched 'RDomain %.100s' at "
1135 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001136 } else {
1137 error("Unsupported Match attribute %s", attrib);
1138 return -1;
1139 }
1140 }
Damien Millercf31f382013-10-24 21:02:56 +11001141 if (attributes == 0) {
1142 error("One or more attributes required for Match");
1143 return -1;
1144 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001145 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001146 debug3("match %sfound", result ? "" : "not ");
1147 *condition = cp;
1148 return result;
1149}
1150
Damien Millere2754432006-07-24 14:06:47 +10001151#define WHITESPACE " \t\r\n"
1152
Damien Miller33322122011-06-20 14:43:11 +10001153/* Multistate option parsing */
1154struct multistate {
1155 char *key;
1156 int value;
1157};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001158static const struct multistate multistate_flag[] = {
1159 { "yes", 1 },
1160 { "no", 0 },
1161 { NULL, -1 }
1162};
Damien Miller33322122011-06-20 14:43:11 +10001163static const struct multistate multistate_addressfamily[] = {
1164 { "inet", AF_INET },
1165 { "inet6", AF_INET6 },
1166 { "any", AF_UNSPEC },
1167 { NULL, -1 }
1168};
1169static const struct multistate multistate_permitrootlogin[] = {
1170 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001171 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001172 { "forced-commands-only", PERMIT_FORCED_ONLY },
1173 { "yes", PERMIT_YES },
1174 { "no", PERMIT_NO },
1175 { NULL, -1 }
1176};
1177static const struct multistate multistate_compression[] = {
sf@openbsd.org168b46f2018-07-09 13:37:10 +00001178 { "yes", COMP_DELAYED },
1179 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001180 { "no", COMP_NONE },
1181 { NULL, -1 }
1182};
1183static const struct multistate multistate_gatewayports[] = {
1184 { "clientspecified", 2 },
1185 { "yes", 1 },
1186 { "no", 0 },
1187 { NULL, -1 }
1188};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001189static const struct multistate multistate_tcpfwd[] = {
1190 { "yes", FORWARD_ALLOW },
1191 { "all", FORWARD_ALLOW },
1192 { "no", FORWARD_DENY },
1193 { "remote", FORWARD_REMOTE },
1194 { "local", FORWARD_LOCAL },
1195 { NULL, -1 }
1196};
Damien Miller33322122011-06-20 14:43:11 +10001197
Ben Lindstromade03f62001-12-06 18:22:17 +00001198int
1199process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001200 const char *filename, int linenum, int *activep,
1201 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001202{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001203 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001204 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001205 SyslogFacility *log_facility_ptr;
1206 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001207 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001208 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001209 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001210 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001211 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001212 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001213
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001214 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1215 if ((len = strlen(line)) == 0)
1216 return 0;
1217 for (len--; len > 0; len--) {
1218 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1219 break;
1220 line[len] = '\0';
1221 }
1222
Ben Lindstromade03f62001-12-06 18:22:17 +00001223 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001224 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001225 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001226 /* Ignore leading whitespace */
1227 if (*arg == '\0')
1228 arg = strdelim(&cp);
1229 if (!arg || !*arg || *arg == '#')
1230 return 0;
1231 intptr = NULL;
1232 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001233 opcode = parse_token(arg, filename, linenum, &flags);
1234
1235 if (activep == NULL) { /* We are processing a command line directive */
1236 cmdline = 1;
1237 activep = &cmdline;
1238 }
1239 if (*activep && opcode != sMatch)
1240 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1241 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001242 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001243 fatal("%s line %d: Directive '%s' is not allowed "
1244 "within a Match block", filename, linenum, arg);
1245 } else { /* this is a directive we have already processed */
1246 while (arg)
1247 arg = strdelim(&cp);
1248 return 0;
1249 }
1250 }
1251
Ben Lindstromade03f62001-12-06 18:22:17 +00001252 switch (opcode) {
1253 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001254 case sUsePAM:
1255 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001256 goto parse_flag;
1257
1258 /* Standard Options */
1259 case sBadOption:
1260 return -1;
1261 case sPort:
1262 /* ignore ports from configfile if cmdline specifies ports */
1263 if (options->ports_from_cmdline)
1264 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001265 if (options->num_ports >= MAX_PORTS)
1266 fatal("%s line %d: too many ports.",
1267 filename, linenum);
1268 arg = strdelim(&cp);
1269 if (!arg || *arg == '\0')
1270 fatal("%s line %d: missing port number.",
1271 filename, linenum);
1272 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001273 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001274 fatal("%s line %d: Badly formatted port number.",
1275 filename, linenum);
1276 break;
1277
Ben Lindstromade03f62001-12-06 18:22:17 +00001278 case sLoginGraceTime:
1279 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001280 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001281 arg = strdelim(&cp);
1282 if (!arg || *arg == '\0')
1283 fatal("%s line %d: missing time value.",
1284 filename, linenum);
1285 if ((value = convtime(arg)) == -1)
1286 fatal("%s line %d: invalid time value.",
1287 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001288 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001289 *intptr = value;
1290 break;
1291
Ben Lindstromade03f62001-12-06 18:22:17 +00001292 case sListenAddress:
1293 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001294 if (arg == NULL || *arg == '\0')
1295 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001296 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001297 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1298 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1299 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001300 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001301 p = arg;
1302 } else {
1303 p = hpdelim(&arg);
1304 if (p == NULL)
1305 fatal("%s line %d: bad address:port usage",
1306 filename, linenum);
1307 p = cleanhostname(p);
1308 if (arg == NULL)
1309 port = 0;
1310 else if ((port = a2port(arg)) <= 0)
1311 fatal("%s line %d: bad port number",
1312 filename, linenum);
1313 }
1314 /* Optional routing table */
1315 arg2 = NULL;
1316 if ((arg = strdelim(&cp)) != NULL) {
1317 if (strcmp(arg, "rdomain") != 0 ||
1318 (arg2 = strdelim(&cp)) == NULL)
1319 fatal("%s line %d: bad ListenAddress syntax",
1320 filename, linenum);
1321 if (!valid_rdomain(arg2))
1322 fatal("%s line %d: bad routing domain",
1323 filename, linenum);
1324 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001325
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001326 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001327
Ben Lindstromade03f62001-12-06 18:22:17 +00001328 break;
1329
Darren Tucker0f383232005-01-20 10:57:56 +11001330 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001331 intptr = &options->address_family;
1332 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001333 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001334 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001335 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001336 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001337 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001338 value = -1;
1339 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1340 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1341 value = multistate_ptr[i].value;
1342 break;
1343 }
1344 }
1345 if (value == -1)
1346 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001347 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001348 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001349 *intptr = value;
1350 break;
1351
Ben Lindstromade03f62001-12-06 18:22:17 +00001352 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 arg = strdelim(&cp);
1354 if (!arg || *arg == '\0')
1355 fatal("%s line %d: missing file name.",
1356 filename, linenum);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001357 if (*activep)
1358 servconf_add_hostkey(filename, linenum, options, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001359 break;
1360
Damien Miller85b45e02013-07-20 13:21:52 +10001361 case sHostKeyAgent:
1362 charptr = &options->host_key_agent;
1363 arg = strdelim(&cp);
1364 if (!arg || *arg == '\0')
1365 fatal("%s line %d: missing socket name.",
1366 filename, linenum);
1367 if (*activep && *charptr == NULL)
1368 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1369 xstrdup(arg) : derelativise_path(arg);
1370 break;
1371
Damien Miller0a80ca12010-02-27 07:55:05 +11001372 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001373 arg = strdelim(&cp);
1374 if (!arg || *arg == '\0')
1375 fatal("%s line %d: missing file name.",
1376 filename, linenum);
1377 if (*activep)
1378 servconf_add_hostcert(filename, linenum, options, arg);
1379 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001380
Ben Lindstromade03f62001-12-06 18:22:17 +00001381 case sPidFile:
1382 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001383 parse_filename:
1384 arg = strdelim(&cp);
1385 if (!arg || *arg == '\0')
1386 fatal("%s line %d: missing file name.",
1387 filename, linenum);
1388 if (*activep && *charptr == NULL) {
1389 *charptr = derelativise_path(arg);
1390 /* increase optional counter */
1391 if (intptr != NULL)
1392 *intptr = *intptr + 1;
1393 }
1394 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001395
1396 case sPermitRootLogin:
1397 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001398 multistate_ptr = multistate_permitrootlogin;
1399 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001400
1401 case sIgnoreRhosts:
1402 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001403 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001404 multistate_ptr = multistate_flag;
1405 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001406
1407 case sIgnoreUserKnownHosts:
1408 intptr = &options->ignore_user_known_hosts;
1409 goto parse_flag;
1410
Ben Lindstromade03f62001-12-06 18:22:17 +00001411 case sHostbasedAuthentication:
1412 intptr = &options->hostbased_authentication;
1413 goto parse_flag;
1414
1415 case sHostbasedUsesNameFromPacketOnly:
1416 intptr = &options->hostbased_uses_name_from_packet_only;
1417 goto parse_flag;
1418
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001419 case sHostbasedAcceptedKeyTypes:
1420 charptr = &options->hostbased_key_types;
1421 parse_keytypes:
1422 arg = strdelim(&cp);
1423 if (!arg || *arg == '\0')
1424 fatal("%s line %d: Missing argument.",
1425 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001426 if (*arg != '-' &&
1427 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001428 fatal("%s line %d: Bad key types '%s'.",
1429 filename, linenum, arg ? arg : "<NONE>");
1430 if (*activep && *charptr == NULL)
1431 *charptr = xstrdup(arg);
1432 break;
1433
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001434 case sHostKeyAlgorithms:
1435 charptr = &options->hostkeyalgorithms;
1436 goto parse_keytypes;
1437
djm@openbsd.org86e57372018-09-20 03:28:06 +00001438 case sCASignatureAlgorithms:
1439 charptr = &options->ca_sign_algorithms;
1440 goto parse_keytypes;
1441
Ben Lindstromade03f62001-12-06 18:22:17 +00001442 case sPubkeyAuthentication:
1443 intptr = &options->pubkey_authentication;
1444 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001445
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001446 case sPubkeyAcceptedKeyTypes:
1447 charptr = &options->pubkey_key_types;
1448 goto parse_keytypes;
1449
Ben Lindstromade03f62001-12-06 18:22:17 +00001450 case sKerberosAuthentication:
1451 intptr = &options->kerberos_authentication;
1452 goto parse_flag;
1453
1454 case sKerberosOrLocalPasswd:
1455 intptr = &options->kerberos_or_local_passwd;
1456 goto parse_flag;
1457
1458 case sKerberosTicketCleanup:
1459 intptr = &options->kerberos_ticket_cleanup;
1460 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001461
Darren Tucker22ef5082003-12-31 11:37:34 +11001462 case sKerberosGetAFSToken:
1463 intptr = &options->kerberos_get_afs_token;
1464 goto parse_flag;
1465
Darren Tucker0efd1552003-08-26 11:49:55 +10001466 case sGssAuthentication:
1467 intptr = &options->gss_authentication;
1468 goto parse_flag;
1469
1470 case sGssCleanupCreds:
1471 intptr = &options->gss_cleanup_creds;
1472 goto parse_flag;
1473
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001474 case sGssStrictAcceptor:
1475 intptr = &options->gss_strict_acceptor;
1476 goto parse_flag;
1477
Ben Lindstromade03f62001-12-06 18:22:17 +00001478 case sPasswordAuthentication:
1479 intptr = &options->password_authentication;
1480 goto parse_flag;
1481
1482 case sKbdInteractiveAuthentication:
1483 intptr = &options->kbd_interactive_authentication;
1484 goto parse_flag;
1485
1486 case sChallengeResponseAuthentication:
1487 intptr = &options->challenge_response_authentication;
1488 goto parse_flag;
1489
1490 case sPrintMotd:
1491 intptr = &options->print_motd;
1492 goto parse_flag;
1493
1494 case sPrintLastLog:
1495 intptr = &options->print_lastlog;
1496 goto parse_flag;
1497
1498 case sX11Forwarding:
1499 intptr = &options->x11_forwarding;
1500 goto parse_flag;
1501
1502 case sX11DisplayOffset:
1503 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001504 parse_int:
1505 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001506 if ((errstr = atoi_err(arg, &value)) != NULL)
1507 fatal("%s line %d: integer value %s.",
1508 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001509 if (*activep && *intptr == -1)
1510 *intptr = value;
1511 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001512
Damien Miller95c249f2002-02-05 12:11:34 +11001513 case sX11UseLocalhost:
1514 intptr = &options->x11_use_localhost;
1515 goto parse_flag;
1516
Ben Lindstromade03f62001-12-06 18:22:17 +00001517 case sXAuthLocation:
1518 charptr = &options->xauth_location;
1519 goto parse_filename;
1520
Damien Miller5ff30c62013-10-30 22:21:50 +11001521 case sPermitTTY:
1522 intptr = &options->permit_tty;
1523 goto parse_flag;
1524
Damien Miller72e6b5c2014-07-04 09:00:04 +10001525 case sPermitUserRC:
1526 intptr = &options->permit_user_rc;
1527 goto parse_flag;
1528
Ben Lindstromade03f62001-12-06 18:22:17 +00001529 case sStrictModes:
1530 intptr = &options->strict_modes;
1531 goto parse_flag;
1532
Damien Miller12c150e2003-12-17 16:31:10 +11001533 case sTCPKeepAlive:
1534 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001535 goto parse_flag;
1536
1537 case sEmptyPasswd:
1538 intptr = &options->permit_empty_passwd;
1539 goto parse_flag;
1540
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001541 case sPermitUserEnvironment:
1542 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001543 charptr = &options->permit_user_env_whitelist;
1544 arg = strdelim(&cp);
1545 if (!arg || *arg == '\0')
1546 fatal("%s line %d: missing argument.",
1547 filename, linenum);
1548 value = 0;
1549 p = NULL;
1550 if (strcmp(arg, "yes") == 0)
1551 value = 1;
1552 else if (strcmp(arg, "no") == 0)
1553 value = 0;
1554 else {
1555 /* Pattern-list specified */
1556 value = 1;
1557 p = xstrdup(arg);
1558 }
1559 if (*activep && *intptr == -1) {
1560 *intptr = value;
1561 *charptr = p;
1562 p = NULL;
1563 }
1564 free(p);
1565 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001566
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001567 case sCompression:
1568 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001569 multistate_ptr = multistate_compression;
1570 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001571
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001572 case sRekeyLimit:
1573 arg = strdelim(&cp);
1574 if (!arg || *arg == '\0')
1575 fatal("%.200s line %d: Missing argument.", filename,
1576 linenum);
1577 if (strcmp(arg, "default") == 0) {
1578 val64 = 0;
1579 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001580 if (scan_scaled(arg, &val64) == -1)
1581 fatal("%.200s line %d: Bad number '%s': %s",
1582 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001583 if (val64 != 0 && val64 < 16)
1584 fatal("%.200s line %d: RekeyLimit too small",
1585 filename, linenum);
1586 }
1587 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001588 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001589 if (cp != NULL) { /* optional rekey interval present */
1590 if (strcmp(cp, "none") == 0) {
1591 (void)strdelim(&cp); /* discard */
1592 break;
1593 }
1594 intptr = &options->rekey_interval;
1595 goto parse_time;
1596 }
1597 break;
1598
Ben Lindstromade03f62001-12-06 18:22:17 +00001599 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001600 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001601 multistate_ptr = multistate_gatewayports;
1602 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001603
Damien Miller3a961dc2003-06-03 10:25:48 +10001604 case sUseDNS:
1605 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001606 goto parse_flag;
1607
1608 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001609 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001610 arg = strdelim(&cp);
1611 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001612 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001613 fatal("%.200s line %d: unsupported log facility '%s'",
1614 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001615 if (*log_facility_ptr == -1)
1616 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001617 break;
1618
1619 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001620 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001621 arg = strdelim(&cp);
1622 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001623 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001624 fatal("%.200s line %d: unsupported log level '%s'",
1625 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001626 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001627 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001628 break;
1629
1630 case sAllowTcpForwarding:
1631 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001632 multistate_ptr = multistate_tcpfwd;
1633 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001634
Damien Miller7acefbb2014-07-18 14:11:24 +10001635 case sAllowStreamLocalForwarding:
1636 intptr = &options->allow_streamlocal_forwarding;
1637 multistate_ptr = multistate_tcpfwd;
1638 goto parse_multistate;
1639
Damien Miller4f755cd2008-05-19 14:57:41 +10001640 case sAllowAgentForwarding:
1641 intptr = &options->allow_agent_forwarding;
1642 goto parse_flag;
1643
djm@openbsd.org7844f352016-11-30 03:00:05 +00001644 case sDisableForwarding:
1645 intptr = &options->disable_forwarding;
1646 goto parse_flag;
1647
Ben Lindstromade03f62001-12-06 18:22:17 +00001648 case sAllowUsers:
1649 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001650 if (match_user(NULL, NULL, NULL, arg) == -1)
1651 fatal("%s line %d: invalid AllowUsers pattern: "
1652 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001653 if (!*activep)
1654 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001655 array_append(filename, linenum, "AllowUsers",
1656 &options->allow_users, &options->num_allow_users,
1657 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001658 }
1659 break;
1660
1661 case sDenyUsers:
1662 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001663 if (match_user(NULL, NULL, NULL, arg) == -1)
1664 fatal("%s line %d: invalid DenyUsers pattern: "
1665 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001666 if (!*activep)
1667 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001668 array_append(filename, linenum, "DenyUsers",
1669 &options->deny_users, &options->num_deny_users,
1670 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001671 }
1672 break;
1673
1674 case sAllowGroups:
1675 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001676 if (!*activep)
1677 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001678 array_append(filename, linenum, "AllowGroups",
1679 &options->allow_groups, &options->num_allow_groups,
1680 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001681 }
1682 break;
1683
1684 case sDenyGroups:
1685 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001686 if (!*activep)
1687 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001688 array_append(filename, linenum, "DenyGroups",
1689 &options->deny_groups, &options->num_deny_groups,
1690 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001691 }
1692 break;
1693
1694 case sCiphers:
1695 arg = strdelim(&cp);
1696 if (!arg || *arg == '\0')
1697 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001698 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001699 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1700 filename, linenum, arg ? arg : "<NONE>");
1701 if (options->ciphers == NULL)
1702 options->ciphers = xstrdup(arg);
1703 break;
1704
1705 case sMacs:
1706 arg = strdelim(&cp);
1707 if (!arg || *arg == '\0')
1708 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001709 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001710 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1711 filename, linenum, arg ? arg : "<NONE>");
1712 if (options->macs == NULL)
1713 options->macs = xstrdup(arg);
1714 break;
1715
Damien Millerd5f62bf2010-09-24 22:11:14 +10001716 case sKexAlgorithms:
1717 arg = strdelim(&cp);
1718 if (!arg || *arg == '\0')
1719 fatal("%s line %d: Missing argument.",
1720 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001721 if (*arg != '-' &&
1722 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001723 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1724 filename, linenum, arg ? arg : "<NONE>");
1725 if (options->kex_algorithms == NULL)
1726 options->kex_algorithms = xstrdup(arg);
1727 break;
1728
Ben Lindstromade03f62001-12-06 18:22:17 +00001729 case sSubsystem:
1730 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1731 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001732 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001733 }
1734 arg = strdelim(&cp);
1735 if (!arg || *arg == '\0')
1736 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001737 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001738 if (!*activep) {
1739 arg = strdelim(&cp);
1740 break;
1741 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001742 for (i = 0; i < options->num_subsystems; i++)
1743 if (strcmp(arg, options->subsystem_name[i]) == 0)
1744 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001745 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001746 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1747 arg = strdelim(&cp);
1748 if (!arg || *arg == '\0')
1749 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001750 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001751 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001752
1753 /* Collect arguments (separate to executable) */
1754 p = xstrdup(arg);
1755 len = strlen(p) + 1;
1756 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1757 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001758 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001759 strlcat(p, " ", len);
1760 strlcat(p, arg, len);
1761 }
1762 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001763 options->num_subsystems++;
1764 break;
1765
1766 case sMaxStartups:
1767 arg = strdelim(&cp);
1768 if (!arg || *arg == '\0')
1769 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001770 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001771 if ((n = sscanf(arg, "%d:%d:%d",
1772 &options->max_startups_begin,
1773 &options->max_startups_rate,
1774 &options->max_startups)) == 3) {
1775 if (options->max_startups_begin >
1776 options->max_startups ||
1777 options->max_startups_rate > 100 ||
1778 options->max_startups_rate < 1)
1779 fatal("%s line %d: Illegal MaxStartups spec.",
1780 filename, linenum);
1781 } else if (n != 1)
1782 fatal("%s line %d: Illegal MaxStartups spec.",
1783 filename, linenum);
1784 else
1785 options->max_startups = options->max_startups_begin;
1786 break;
1787
Darren Tucker89413db2004-05-24 10:36:23 +10001788 case sMaxAuthTries:
1789 intptr = &options->max_authtries;
1790 goto parse_int;
1791
Damien Miller7207f642008-05-19 15:34:50 +10001792 case sMaxSessions:
1793 intptr = &options->max_sessions;
1794 goto parse_int;
1795
Ben Lindstromade03f62001-12-06 18:22:17 +00001796 case sBanner:
1797 charptr = &options->banner;
1798 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001799
Ben Lindstromade03f62001-12-06 18:22:17 +00001800 /*
1801 * These options can contain %X options expanded at
1802 * connect time, so that you can specify paths like:
1803 *
1804 * AuthorizedKeysFile /etc/ssh_keys/%u
1805 */
1806 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001807 if (*activep && options->num_authkeys_files == 0) {
1808 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001809 arg = tilde_expand_filename(arg, getuid());
1810 array_append(filename, linenum,
1811 "AuthorizedKeysFile",
1812 &options->authorized_keys_files,
1813 &options->num_authkeys_files, arg);
1814 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001815 }
1816 }
1817 return 0;
1818
Damien Miller30da3442010-05-10 11:58:03 +10001819 case sAuthorizedPrincipalsFile:
1820 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001821 arg = strdelim(&cp);
1822 if (!arg || *arg == '\0')
1823 fatal("%s line %d: missing file name.",
1824 filename, linenum);
1825 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001826 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001827 /* increase optional counter */
1828 if (intptr != NULL)
1829 *intptr = *intptr + 1;
1830 }
1831 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001832
1833 case sClientAliveInterval:
1834 intptr = &options->client_alive_interval;
1835 goto parse_time;
1836
1837 case sClientAliveCountMax:
1838 intptr = &options->client_alive_count_max;
1839 goto parse_int;
1840
Darren Tucker46bc0752004-05-02 22:11:30 +10001841 case sAcceptEnv:
1842 while ((arg = strdelim(&cp)) && *arg != '\0') {
1843 if (strchr(arg, '=') != NULL)
1844 fatal("%s line %d: Invalid environment name.",
1845 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001846 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001847 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001848 array_append(filename, linenum, "AcceptEnv",
1849 &options->accept_env, &options->num_accept_env,
1850 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001851 }
1852 break;
1853
djm@openbsd.org28013752018-06-09 03:03:10 +00001854 case sSetEnv:
1855 uvalue = options->num_setenv;
1856 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1857 if (strchr(arg, '=') == NULL)
1858 fatal("%s line %d: Invalid environment.",
1859 filename, linenum);
1860 if (!*activep || uvalue != 0)
1861 continue;
1862 array_append(filename, linenum, "SetEnv",
1863 &options->setenv, &options->num_setenv, arg);
1864 }
1865 break;
1866
Damien Millerd27b9472005-12-13 19:29:02 +11001867 case sPermitTunnel:
1868 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001869 arg = strdelim(&cp);
1870 if (!arg || *arg == '\0')
1871 fatal("%s line %d: Missing yes/point-to-point/"
1872 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001873 value = -1;
1874 for (i = 0; tunmode_desc[i].val != -1; i++)
1875 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1876 value = tunmode_desc[i].val;
1877 break;
1878 }
1879 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001880 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1881 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001882 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001883 *intptr = value;
1884 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001885
Darren Tucker45150472006-07-12 22:34:17 +10001886 case sMatch:
1887 if (cmdline)
1888 fatal("Match directive not supported as a command-line "
1889 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001890 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001891 if (value < 0)
1892 fatal("%s line %d: Bad Match condition", filename,
1893 linenum);
1894 *activep = value;
1895 break;
1896
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001897 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001898 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001899 if (opcode == sPermitListen) {
1900 uintptr = &options->num_permitted_listens;
1901 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001902 } else {
1903 uintptr = &options->num_permitted_opens;
1904 chararrayptr = &options->permitted_opens;
1905 }
Damien Miller9b439df2006-07-24 14:04:00 +10001906 arg = strdelim(&cp);
1907 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001908 fatal("%s line %d: missing %s specification",
1909 filename, linenum, lookup_opcode_name(opcode));
1910 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001911 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001912 if (*activep && uvalue == 0) {
1913 *uintptr = 1;
1914 *chararrayptr = xcalloc(1,
1915 sizeof(**chararrayptr));
1916 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001917 }
Damien Millerc6081482012-04-22 11:18:53 +10001918 break;
1919 }
Damien Millera765cf42006-07-24 14:08:13 +10001920 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001921 if (opcode == sPermitListen &&
1922 strchr(arg, ':') == NULL) {
1923 /*
1924 * Allow bare port number for PermitListen
1925 * to indicate a wildcard listen host.
1926 */
1927 xasprintf(&arg2, "*:%s", arg);
1928 } else {
1929 arg2 = xstrdup(arg);
1930 p = hpdelim(&arg);
1931 if (p == NULL) {
1932 fatal("%s line %d: missing host in %s",
1933 filename, linenum,
1934 lookup_opcode_name(opcode));
1935 }
1936 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001937 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001938 if (arg == NULL ||
1939 ((port = permitopen_port(arg)) < 0)) {
1940 fatal("%s line %d: bad port number in %s",
1941 filename, linenum,
1942 lookup_opcode_name(opcode));
1943 }
1944 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001945 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001946 lookup_opcode_name(opcode),
1947 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001948 }
1949 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001950 }
Damien Miller9b439df2006-07-24 14:04:00 +10001951 break;
1952
Damien Millere2754432006-07-24 14:06:47 +10001953 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001954 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001955 fatal("%.200s line %d: Missing argument.", filename,
1956 linenum);
1957 len = strspn(cp, WHITESPACE);
1958 if (*activep && options->adm_forced_command == NULL)
1959 options->adm_forced_command = xstrdup(cp + len);
1960 return 0;
1961
Damien Millerd8cb1f12008-02-10 22:40:12 +11001962 case sChrootDirectory:
1963 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001964
1965 arg = strdelim(&cp);
1966 if (!arg || *arg == '\0')
1967 fatal("%s line %d: missing file name.",
1968 filename, linenum);
1969 if (*activep && *charptr == NULL)
1970 *charptr = xstrdup(arg);
1971 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001972
Damien Miller1aed65e2010-03-04 21:53:35 +11001973 case sTrustedUserCAKeys:
1974 charptr = &options->trusted_user_ca_keys;
1975 goto parse_filename;
1976
1977 case sRevokedKeys:
1978 charptr = &options->revoked_keys_file;
1979 goto parse_filename;
1980
Damien Miller0dac6fb2010-11-20 15:19:38 +11001981 case sIPQoS:
1982 arg = strdelim(&cp);
1983 if ((value = parse_ipqos(arg)) == -1)
1984 fatal("%s line %d: Bad IPQoS value: %s",
1985 filename, linenum, arg);
1986 arg = strdelim(&cp);
1987 if (arg == NULL)
1988 value2 = value;
1989 else if ((value2 = parse_ipqos(arg)) == -1)
1990 fatal("%s line %d: Bad IPQoS value: %s",
1991 filename, linenum, arg);
1992 if (*activep) {
1993 options->ip_qos_interactive = value;
1994 options->ip_qos_bulk = value2;
1995 }
1996 break;
1997
Damien Miller23528812012-04-22 11:24:43 +10001998 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001999 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10002000 fatal("%.200s line %d: Missing argument.", filename,
2001 linenum);
2002 len = strspn(cp, WHITESPACE);
2003 if (*activep && options->version_addendum == NULL) {
2004 if (strcasecmp(cp + len, "none") == 0)
2005 options->version_addendum = xstrdup("");
2006 else if (strchr(cp + len, '\r') != NULL)
2007 fatal("%.200s line %d: Invalid argument",
2008 filename, linenum);
2009 else
2010 options->version_addendum = xstrdup(cp + len);
2011 }
2012 return 0;
2013
Damien Miller09d3e122012-10-31 08:58:58 +11002014 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002015 if (cp == NULL)
2016 fatal("%.200s line %d: Missing argument.", filename,
2017 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002018 len = strspn(cp, WHITESPACE);
2019 if (*activep && options->authorized_keys_command == NULL) {
2020 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2021 fatal("%.200s line %d: AuthorizedKeysCommand "
2022 "must be an absolute path",
2023 filename, linenum);
2024 options->authorized_keys_command = xstrdup(cp + len);
2025 }
2026 return 0;
2027
2028 case sAuthorizedKeysCommandUser:
2029 charptr = &options->authorized_keys_command_user;
2030
2031 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002032 if (!arg || *arg == '\0')
2033 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2034 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002035 if (*activep && *charptr == NULL)
2036 *charptr = xstrdup(arg);
2037 break;
2038
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002039 case sAuthorizedPrincipalsCommand:
2040 if (cp == NULL)
2041 fatal("%.200s line %d: Missing argument.", filename,
2042 linenum);
2043 len = strspn(cp, WHITESPACE);
2044 if (*activep &&
2045 options->authorized_principals_command == NULL) {
2046 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2047 fatal("%.200s line %d: "
2048 "AuthorizedPrincipalsCommand must be "
2049 "an absolute path", filename, linenum);
2050 options->authorized_principals_command =
2051 xstrdup(cp + len);
2052 }
2053 return 0;
2054
2055 case sAuthorizedPrincipalsCommandUser:
2056 charptr = &options->authorized_principals_command_user;
2057
2058 arg = strdelim(&cp);
2059 if (!arg || *arg == '\0')
2060 fatal("%s line %d: missing "
2061 "AuthorizedPrincipalsCommandUser argument.",
2062 filename, linenum);
2063 if (*activep && *charptr == NULL)
2064 *charptr = xstrdup(arg);
2065 break;
2066
Damien Millera6e3f012012-11-04 23:21:40 +11002067 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002068 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002069 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002070 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002071 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002072 if (strcmp(arg, "any") == 0) {
2073 if (options->num_auth_methods > 0) {
2074 fatal("%s line %d: \"any\" "
2075 "must appear alone in "
2076 "AuthenticationMethods",
2077 filename, linenum);
2078 }
2079 value = 1;
2080 } else if (value) {
2081 fatal("%s line %d: \"any\" must appear "
2082 "alone in AuthenticationMethods",
2083 filename, linenum);
2084 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002085 fatal("%s line %d: invalid "
2086 "authentication method list.",
2087 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002088 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002089 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002090 if (!*activep)
2091 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002092 array_append(filename, linenum,
2093 "AuthenticationMethods",
2094 &options->auth_methods,
2095 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002096 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002097 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002098 fatal("%s line %d: no AuthenticationMethods "
2099 "specified", filename, linenum);
2100 }
Damien Millera6e3f012012-11-04 23:21:40 +11002101 }
2102 return 0;
2103
Damien Miller7acefbb2014-07-18 14:11:24 +10002104 case sStreamLocalBindMask:
2105 arg = strdelim(&cp);
2106 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002107 fatal("%s line %d: missing StreamLocalBindMask "
2108 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002109 /* Parse mode in octal format */
2110 value = strtol(arg, &p, 8);
2111 if (arg == p || value < 0 || value > 0777)
2112 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002113 if (*activep)
2114 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002115 break;
2116
2117 case sStreamLocalBindUnlink:
2118 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2119 goto parse_flag;
2120
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002121 case sFingerprintHash:
2122 arg = strdelim(&cp);
2123 if (!arg || *arg == '\0')
2124 fatal("%.200s line %d: Missing argument.",
2125 filename, linenum);
2126 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2127 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2128 filename, linenum, arg);
2129 if (*activep)
2130 options->fingerprint_hash = value;
2131 break;
2132
djm@openbsd.org8f574952017-06-24 06:34:38 +00002133 case sExposeAuthInfo:
2134 intptr = &options->expose_userauth_info;
2135 goto parse_flag;
2136
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002137 case sRDomain:
2138 charptr = &options->routing_domain;
2139 arg = strdelim(&cp);
2140 if (!arg || *arg == '\0')
2141 fatal("%.200s line %d: Missing argument.",
2142 filename, linenum);
2143 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2144 !valid_rdomain(arg))
2145 fatal("%s line %d: bad routing domain",
2146 filename, linenum);
2147 if (*activep && *charptr == NULL)
2148 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002149 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002150
Ben Lindstromade03f62001-12-06 18:22:17 +00002151 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002152 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002153 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002154 do_log2(opcode == sIgnore ?
2155 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2156 "%s line %d: %s option %s", filename, linenum,
2157 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002158 while (arg)
2159 arg = strdelim(&cp);
2160 break;
2161
Ben Lindstromade03f62001-12-06 18:22:17 +00002162 default:
2163 fatal("%s line %d: Missing handler for opcode %s (%d)",
2164 filename, linenum, arg, opcode);
2165 }
2166 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2167 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2168 filename, linenum, arg);
2169 return 0;
2170}
2171
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002172/* Reads the server configuration file. */
2173
Damien Miller4af51302000-04-16 11:18:38 +10002174void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002175load_server_config(const char *filename, struct sshbuf *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002176{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002177 char *line = NULL, *cp;
2178 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002179 FILE *f;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002180 int r, lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002181
Darren Tucker645ab752004-06-25 13:33:20 +10002182 debug2("%s: filename %s", __func__, filename);
2183 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002184 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002185 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002186 }
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002187 sshbuf_reset(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002188 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002189 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002190 /*
2191 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002192 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002193 * line numbers later for error messages
2194 */
2195 if ((cp = strchr(line, '#')) != NULL)
2196 memcpy(cp, "\n", 2);
2197 cp = line + strspn(line, " \t\r");
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002198 if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2199 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002200 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002201 free(line);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002202 if ((r = sshbuf_put_u8(conf, 0)) != 0)
2203 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002204 fclose(f);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002205 debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002206}
2207
2208void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002209parse_server_match_config(ServerOptions *options,
2210 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002211{
Darren Tucker45150472006-07-12 22:34:17 +10002212 ServerOptions mo;
2213
2214 initialize_server_options(&mo);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002215 parse_server_config(&mo, "reprocess config", cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002216 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002217}
2218
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002219int parse_server_match_testspec(struct connection_info *ci, char *spec)
2220{
2221 char *p;
2222
2223 while ((p = strsep(&spec, ",")) && *p != '\0') {
2224 if (strncmp(p, "addr=", 5) == 0) {
2225 ci->address = xstrdup(p + 5);
2226 } else if (strncmp(p, "host=", 5) == 0) {
2227 ci->host = xstrdup(p + 5);
2228 } else if (strncmp(p, "user=", 5) == 0) {
2229 ci->user = xstrdup(p + 5);
2230 } else if (strncmp(p, "laddr=", 6) == 0) {
2231 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002232 } else if (strncmp(p, "rdomain=", 8) == 0) {
2233 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002234 } else if (strncmp(p, "lport=", 6) == 0) {
2235 ci->lport = a2port(p + 6);
2236 if (ci->lport == -1) {
2237 fprintf(stderr, "Invalid port '%s' in test mode"
2238 " specification %s\n", p+6, p);
2239 return -1;
2240 }
2241 } else {
2242 fprintf(stderr, "Invalid test mode specification %s\n",
2243 p);
2244 return -1;
2245 }
2246 }
2247 return 0;
2248}
2249
2250/*
Darren Tucker1629c072007-02-19 22:25:37 +11002251 * Copy any supported values that are set.
2252 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002253 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002254 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002255 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002256 */
Darren Tucker45150472006-07-12 22:34:17 +10002257void
Darren Tucker1629c072007-02-19 22:25:37 +11002258copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002259{
Damien Miller534b2cc2013-12-05 14:07:27 +11002260#define M_CP_INTOPT(n) do {\
2261 if (src->n != -1) \
2262 dst->n = src->n; \
2263} while (0)
2264
Darren Tucker1629c072007-02-19 22:25:37 +11002265 M_CP_INTOPT(password_authentication);
2266 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002267 M_CP_INTOPT(pubkey_authentication);
2268 M_CP_INTOPT(kerberos_authentication);
2269 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002270 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002271 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002272 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002273 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002274
2275 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002276 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002277 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002278 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002279 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002280 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002281 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002282 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002283 M_CP_INTOPT(x11_display_offset);
2284 M_CP_INTOPT(x11_forwarding);
2285 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002286 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002287 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002288 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002289 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002290 M_CP_INTOPT(client_alive_count_max);
2291 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002292 M_CP_INTOPT(ip_qos_interactive);
2293 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002294 M_CP_INTOPT(rekey_limit);
2295 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002296 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002297
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002298 /*
2299 * The bind_mask is a mode_t that may be unsigned, so we can't use
2300 * M_CP_INTOPT - it does a signed comparison that causes compiler
2301 * warnings.
2302 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002303 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002304 dst->fwd_opts.streamlocal_bind_mask =
2305 src->fwd_opts.streamlocal_bind_mask;
2306 }
2307
Damien Miller534b2cc2013-12-05 14:07:27 +11002308 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2309#define M_CP_STROPT(n) do {\
2310 if (src->n != NULL && dst->n != src->n) { \
2311 free(dst->n); \
2312 dst->n = src->n; \
2313 } \
2314} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002315#define M_CP_STRARRAYOPT(s, num_s) do {\
2316 u_int i; \
2317 if (src->num_s != 0) { \
2318 for (i = 0; i < dst->num_s; i++) \
2319 free(dst->s[i]); \
2320 free(dst->s); \
2321 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2322 for (i = 0; i < src->num_s; i++) \
2323 dst->s[i] = xstrdup(src->s[i]); \
2324 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002325 } \
2326} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002327
Damien Millerf2e407e2011-05-20 19:04:14 +10002328 /* See comment in servconf.h */
2329 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002330
djm@openbsd.orged085102015-10-29 08:05:01 +00002331 /* Arguments that accept '+...' need to be expanded */
2332 assemble_algorithms(dst);
2333
Damien Millerc2411902011-05-20 19:03:49 +10002334 /*
2335 * The only things that should be below this point are string options
2336 * which are only used after authentication.
2337 */
Damien Miller5d74e582011-05-20 19:03:31 +10002338 if (preauth)
2339 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002340
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002341 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002342 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002343 if (option_clear_or_none(dst->adm_forced_command)) {
2344 free(dst->adm_forced_command);
2345 dst->adm_forced_command = NULL;
2346 }
Damien Miller5d74e582011-05-20 19:03:31 +10002347 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002348 if (option_clear_or_none(dst->chroot_directory)) {
2349 free(dst->chroot_directory);
2350 dst->chroot_directory = NULL;
2351 }
Darren Tucker45150472006-07-12 22:34:17 +10002352}
2353
Darren Tucker1629c072007-02-19 22:25:37 +11002354#undef M_CP_INTOPT
2355#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002356#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002357
Darren Tucker45150472006-07-12 22:34:17 +10002358void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002359parse_server_config(ServerOptions *options, const char *filename,
2360 struct sshbuf *conf, struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002361{
2362 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002363 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002364
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002365 debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002366
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002367 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2368 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002369 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002370 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002371 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002372 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002373 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002374 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002375 }
Darren Tuckera627d422013-06-02 07:31:17 +10002376 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002377 if (bad_options > 0)
2378 fatal("%s: terminating, %d bad configuration options",
2379 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002380 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002381}
Darren Tuckere7140f22008-06-10 23:01:51 +10002382
2383static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002384fmt_multistate_int(int val, const struct multistate *m)
2385{
2386 u_int i;
2387
2388 for (i = 0; m[i].key != NULL; i++) {
2389 if (m[i].value == val)
2390 return m[i].key;
2391 }
2392 return "UNKNOWN";
2393}
2394
2395static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002396fmt_intarg(ServerOpCodes code, int val)
2397{
Damien Miller82c55872011-06-23 08:20:30 +10002398 if (val == -1)
2399 return "unset";
2400 switch (code) {
2401 case sAddressFamily:
2402 return fmt_multistate_int(val, multistate_addressfamily);
2403 case sPermitRootLogin:
2404 return fmt_multistate_int(val, multistate_permitrootlogin);
2405 case sGatewayPorts:
2406 return fmt_multistate_int(val, multistate_gatewayports);
2407 case sCompression:
2408 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002409 case sAllowTcpForwarding:
2410 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002411 case sAllowStreamLocalForwarding:
2412 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002413 case sFingerprintHash:
2414 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002415 default:
2416 switch (val) {
2417 case 0:
2418 return "no";
2419 case 1:
2420 return "yes";
2421 default:
2422 return "UNKNOWN";
2423 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002424 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002425}
2426
Darren Tuckere7140f22008-06-10 23:01:51 +10002427static void
2428dump_cfg_int(ServerOpCodes code, int val)
2429{
2430 printf("%s %d\n", lookup_opcode_name(code), val);
2431}
2432
2433static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002434dump_cfg_oct(ServerOpCodes code, int val)
2435{
2436 printf("%s 0%o\n", lookup_opcode_name(code), val);
2437}
2438
2439static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002440dump_cfg_fmtint(ServerOpCodes code, int val)
2441{
2442 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2443}
2444
2445static void
2446dump_cfg_string(ServerOpCodes code, const char *val)
2447{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002448 printf("%s %s\n", lookup_opcode_name(code),
2449 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002450}
2451
2452static void
2453dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2454{
2455 u_int i;
2456
2457 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002458 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2459}
2460
2461static void
2462dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2463{
2464 u_int i;
2465
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002466 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002467 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002468 printf("%s", lookup_opcode_name(code));
2469 for (i = 0; i < count; i++)
2470 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002471 if (code == sAuthenticationMethods && count == 0)
2472 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002473 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002474}
2475
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002476static char *
2477format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002478{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002479 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002480 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002481 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002482 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002483
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002484 /*
2485 * ListenAddress must be after Port. add_one_listen_addr pushes
2486 * addresses onto a stack, so to maintain ordering we need to
2487 * print these in reverse order.
2488 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002489 for (ai = la->addrs; ai; ai = ai->ai_next) {
2490 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002491 sizeof(addr), port, sizeof(port),
2492 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002493 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2494 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002495 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002496 laddr2 = laddr1;
2497 if (ai->ai_family == AF_INET6) {
2498 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2499 addr, port,
2500 la->rdomain == NULL ? "" : " rdomain ",
2501 la->rdomain == NULL ? "" : la->rdomain,
2502 laddr2);
2503 } else {
2504 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2505 addr, port,
2506 la->rdomain == NULL ? "" : " rdomain ",
2507 la->rdomain == NULL ? "" : la->rdomain,
2508 laddr2);
2509 }
2510 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002511 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002512 return laddr1;
2513}
2514
2515void
2516dump_config(ServerOptions *o)
2517{
2518 char *s;
2519 u_int i;
2520
2521 /* these are usually at the top of the config */
2522 for (i = 0; i < o->num_ports; i++)
2523 printf("port %d\n", o->ports[i]);
2524 dump_cfg_fmtint(sAddressFamily, o->address_family);
2525
2526 for (i = 0; i < o->num_listen_addrs; i++) {
2527 s = format_listen_addrs(&o->listen_addrs[i]);
2528 printf("%s", s);
2529 free(s);
2530 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002531
2532 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002533#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002534 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002535#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002536 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002537 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2538 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002539 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002540 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2541 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002542 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002543
2544 /* formatted integer arguments */
2545 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2546 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2547 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002548 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2549 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2550 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002551 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002552#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002553 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2554 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2555 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002556# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002557 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002558# endif
2559#endif
2560#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002561 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2562 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002563#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002564 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2565 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2566 o->kbd_interactive_authentication);
2567 dump_cfg_fmtint(sChallengeResponseAuthentication,
2568 o->challenge_response_authentication);
2569 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002570#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002571 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002572#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002573 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2574 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002575 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002576 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002577 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2578 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2579 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002580 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002581 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002582 dump_cfg_fmtint(sUseDNS, o->use_dns);
2583 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002584 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002585 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002586 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002587 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002588 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002589 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002590
2591 /* string arguments */
2592 dump_cfg_string(sPidFile, o->pid_file);
2593 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002594 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2595 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002596 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002597 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002598 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002599 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2600 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002601 dump_cfg_string(sAuthorizedPrincipalsFile,
2602 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002603 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2604 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002605 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2606 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002607 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2608 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002609 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002610 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002611 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org86e57372018-09-20 03:28:06 +00002612 dump_cfg_string(sCASignatureAlgorithms, o->ca_sign_algorithms ?
2613 o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002614 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2615 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002616 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2617 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002618 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2619 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002620 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002621
2622 /* string arguments requiring a lookup */
2623 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2624 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2625
2626 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002627 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2628 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002629 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2630 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002631 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002632 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002633 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2634 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2635 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2636 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2637 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002638 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002639 dump_cfg_strarray_oneline(sAuthenticationMethods,
2640 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002641
2642 /* other arguments */
2643 for (i = 0; i < o->num_subsystems; i++)
2644 printf("subsystem %s %s\n", o->subsystem_name[i],
2645 o->subsystem_args[i]);
2646
2647 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2648 o->max_startups_rate, o->max_startups);
2649
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002650 s = NULL;
2651 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002652 if (tunmode_desc[i].val == o->permit_tun) {
2653 s = tunmode_desc[i].text;
2654 break;
2655 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002656 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002657 dump_cfg_string(sPermitTunnel, s);
2658
Damien Miller91475862011-05-05 14:14:34 +10002659 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2660 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002661
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002662 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002663 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002664
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002665 printf("permitopen");
2666 if (o->num_permitted_opens == 0)
2667 printf(" any");
2668 else {
2669 for (i = 0; i < o->num_permitted_opens; i++)
2670 printf(" %s", o->permitted_opens[i]);
2671 }
2672 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002673 printf("permitlisten");
2674 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002675 printf(" any");
2676 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002677 for (i = 0; i < o->num_permitted_listens; i++)
2678 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002679 }
2680 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002681
2682 if (o->permit_user_env_whitelist == NULL) {
2683 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2684 } else {
2685 printf("permituserenvironment %s\n",
2686 o->permit_user_env_whitelist);
2687 }
2688
Darren Tuckere7140f22008-06-10 23:01:51 +10002689}