blob: a8727c0fa678ac75557b25793a7a973c220a9d63 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org2a358622018-11-16 03:26:01 +00002/* $OpenBSD: servconf.c,v 1.343 2018/11/16 03:26:01 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 },
djm@openbsd.org0cbed242018-09-20 23:40:16 +0000647 { "casignaturealgorithms", sCASignatureAlgorithms, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000648 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000649};
650
Darren Tuckere7140f22008-06-10 23:01:51 +1000651static struct {
652 int val;
653 char *text;
654} tunmode_desc[] = {
655 { SSH_TUNMODE_NO, "no" },
656 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
657 { SSH_TUNMODE_ETHERNET, "ethernet" },
658 { SSH_TUNMODE_YES, "yes" },
659 { -1, NULL }
660};
661
djm@openbsd.org115063a2018-06-06 18:22:41 +0000662/* Returns an opcode name from its number */
663
664static const char *
665lookup_opcode_name(ServerOpCodes code)
666{
667 u_int i;
668
669 for (i = 0; keywords[i].name != NULL; i++)
670 if (keywords[i].opcode == code)
671 return(keywords[i].name);
672 return "UNKNOWN";
673}
674
675
Damien Miller5428f641999-11-25 11:54:57 +1100676/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000677 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100678 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000679
Damien Miller4af51302000-04-16 11:18:38 +1000680static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100681parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000682 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000683{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000684 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000685
Damien Miller95def091999-11-25 00:26:21 +1100686 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000687 if (strcasecmp(cp, keywords[i].name) == 0) {
688 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100689 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000690 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000691
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000692 error("%s: line %d: Bad configuration option: %s",
693 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100694 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000695}
696
Darren Tucker88b6fb22010-01-13 22:44:29 +1100697char *
698derelativise_path(const char *path)
699{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000700 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100701
djm@openbsd.org161cf412014-12-22 07:55:51 +0000702 if (strcasecmp(path, "none") == 0)
703 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100704 expanded = tilde_expand_filename(path, getuid());
djm@openbsd.org2a358622018-11-16 03:26:01 +0000705 if (path_absolute(expanded))
Darren Tucker88b6fb22010-01-13 22:44:29 +1100706 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100707 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100708 fatal("%s: getcwd: %s", __func__, strerror(errno));
709 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000710 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100711 return ret;
712}
713
Ben Lindstrombba81212001-06-25 05:01:22 +0000714static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000715add_listen_addr(ServerOptions *options, const char *addr,
716 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100717{
Damien Millereccb9de2005-06-17 12:59:34 +1000718 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100719
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000720 if (port > 0)
721 add_one_listen_addr(options, addr, rdomain, port);
722 else {
723 for (i = 0; i < options->num_ports; i++) {
724 add_one_listen_addr(options, addr, rdomain,
725 options->ports[i]);
726 }
727 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000728}
729
Ben Lindstrombba81212001-06-25 05:01:22 +0000730static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000731add_one_listen_addr(ServerOptions *options, const char *addr,
732 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000733{
734 struct addrinfo hints, *ai, *aitop;
735 char strport[NI_MAXSERV];
736 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000737 u_int i;
738
739 /* Find listen_addrs entry for this rdomain */
740 for (i = 0; i < options->num_listen_addrs; i++) {
741 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
742 break;
743 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
744 continue;
745 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
746 break;
747 }
748 if (i >= options->num_listen_addrs) {
749 /* No entry for this rdomain; allocate one */
750 if (i >= INT_MAX)
751 fatal("%s: too many listen addresses", __func__);
752 options->listen_addrs = xrecallocarray(options->listen_addrs,
753 options->num_listen_addrs, options->num_listen_addrs + 1,
754 sizeof(*options->listen_addrs));
755 i = options->num_listen_addrs++;
756 if (rdomain != NULL)
757 options->listen_addrs[i].rdomain = xstrdup(rdomain);
758 }
759 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000760
761 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100762 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000763 hints.ai_socktype = SOCK_STREAM;
764 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100765 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000766 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
767 fatal("bad addr or host: %s (%s)",
768 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100769 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000770 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
771 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000772 ai->ai_next = options->listen_addrs[i].addrs;
773 options->listen_addrs[i].addrs = aitop;
774}
775
776/* Returns nonzero if the routing domain name is valid */
777static int
778valid_rdomain(const char *name)
779{
Damien Miller43c29bb2017-10-25 13:10:59 +1100780#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100781 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100782#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000783 const char *errstr;
784 long long num;
785 struct rt_tableinfo info;
786 int mib[6];
787 size_t miblen = sizeof(mib);
788
789 if (name == NULL)
790 return 1;
791
792 num = strtonum(name, 0, 255, &errstr);
793 if (errstr != NULL)
794 return 0;
795
796 /* Check whether the table actually exists */
797 memset(mib, 0, sizeof(mib));
798 mib[0] = CTL_NET;
799 mib[1] = PF_ROUTE;
800 mib[4] = NET_RT_TABLE;
801 mib[5] = (int)num;
802 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
803 return 0;
804
805 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100806#else /* defined(__OpenBSD__) */
807 error("Routing domains are not supported on this platform");
808 return 0;
809#endif
Damien Miller34132e52000-01-14 15:45:46 +1100810}
811
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000812/*
813 * Queue a ListenAddress to be processed once we have all of the Ports
814 * and AddressFamily options.
815 */
816static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000817queue_listen_addr(ServerOptions *options, const char *addr,
818 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000819{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000820 struct queued_listenaddr *qla;
821
822 options->queued_listen_addrs = xrecallocarray(
823 options->queued_listen_addrs,
824 options->num_queued_listens, options->num_queued_listens + 1,
825 sizeof(*options->queued_listen_addrs));
826 qla = &options->queued_listen_addrs[options->num_queued_listens++];
827 qla->addr = xstrdup(addr);
828 qla->port = port;
829 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000830}
831
832/*
833 * Process queued (text) ListenAddress entries.
834 */
835static void
836process_queued_listen_addrs(ServerOptions *options)
837{
838 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000839 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000840
841 if (options->num_ports == 0)
842 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
843 if (options->address_family == -1)
844 options->address_family = AF_UNSPEC;
845
846 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000847 qla = &options->queued_listen_addrs[i];
848 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
849 free(qla->addr);
850 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000851 }
852 free(options->queued_listen_addrs);
853 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000854 options->num_queued_listens = 0;
855}
856
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000857/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000858 * Inform channels layer of permitopen options for a single forwarding
859 * direction (local/remote).
860 */
861static void
862process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
863 char **opens, u_int num_opens)
864{
865 u_int i;
866 int port;
867 char *host, *arg, *oarg;
868 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
869 const char *what = lookup_opcode_name(opcode);
870
871 channel_clear_permission(ssh, FORWARD_ADM, where);
872 if (num_opens == 0)
873 return; /* permit any */
874
875 /* handle keywords: "any" / "none" */
876 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
877 return;
878 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
879 channel_disable_admin(ssh, where);
880 return;
881 }
882 /* Otherwise treat it as a list of permitted host:port */
883 for (i = 0; i < num_opens; i++) {
884 oarg = arg = xstrdup(opens[i]);
885 host = hpdelim(&arg);
886 if (host == NULL)
887 fatal("%s: missing host in %s", __func__, what);
888 host = cleanhostname(host);
889 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
890 fatal("%s: bad port number in %s", __func__, what);
891 /* Send it to channels layer */
892 channel_add_permission(ssh, FORWARD_ADM,
893 where, host, port);
894 free(oarg);
895 }
896}
897
898/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000899 * Inform channels layer of permitopen options from configuration.
900 */
901void
902process_permitopen(struct ssh *ssh, ServerOptions *options)
903{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000904 process_permitopen_list(ssh, sPermitOpen,
905 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000906 process_permitopen_list(ssh, sPermitListen,
907 options->permitted_listens,
908 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000909}
910
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000911struct connection_info *
912get_connection_info(int populate, int use_dns)
913{
djm@openbsd.org95767262016-03-07 19:02:43 +0000914 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000915 static struct connection_info ci;
916
917 if (!populate)
918 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000919 ci.host = auth_get_canonical_hostname(ssh, use_dns);
920 ci.address = ssh_remote_ipaddr(ssh);
921 ci.laddress = ssh_local_ipaddr(ssh);
922 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000923 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000924 return &ci;
925}
926
Darren Tucker45150472006-07-12 22:34:17 +1000927/*
928 * The strategy for the Match blocks is that the config file is parsed twice.
929 *
930 * The first time is at startup. activep is initialized to 1 and the
931 * directives in the global context are processed and acted on. Hitting a
932 * Match directive unsets activep and the directives inside the block are
933 * checked for syntax only.
934 *
935 * The second time is after a connection has been established but before
936 * authentication. activep is initialized to 2 and global config directives
937 * are ignored since they have already been processed. If the criteria in a
938 * Match block is met, activep is set and the subsequent directives
939 * processed and actioned until EOF or another Match block unsets it. Any
940 * options set are copied into the main server config.
941 *
942 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000943 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000944 *
945 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
946 * Match Address 192.168.0.*
947 * Tag trusted
948 * Match Group wheel
949 * Tag trusted
950 * Match Tag trusted
951 * AllowTcpForwarding yes
952 * GatewayPorts clientspecified
953 * [...]
954 *
955 * - Add a PermittedChannelRequests directive
956 * Match Group shell
957 * PermittedChannelRequests session,forwarded-tcpip
958 */
959
960static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000961match_cfg_line_group(const char *grps, int line, const char *user)
962{
963 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000964 struct passwd *pw;
965
Damien Miller565ca3f2006-08-19 00:23:15 +1000966 if (user == NULL)
967 goto out;
968
969 if ((pw = getpwnam(user)) == NULL) {
970 debug("Can't match group at line %d because user %.100s does "
971 "not exist", line, user);
972 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
973 debug("Can't Match group because user %.100s not in any group "
974 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000975 } else if (ga_match_pattern_list(grps) != 1) {
976 debug("user %.100s does not match group list %.100s at line %d",
977 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000978 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000979 debug("user %.100s matched group list %.100s at line %d", user,
980 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000981 result = 1;
982 }
983out:
984 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000985 return result;
986}
987
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +0000988static void
989match_test_missing_fatal(const char *criteria, const char *attrib)
990{
991 fatal("'Match %s' in configuration but '%s' not in connection "
992 "test specification.", criteria, attrib);
993}
994
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000995/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000996 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100997 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000998 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000999 */
Damien Miller565ca3f2006-08-19 00:23:15 +10001000static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001001match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +10001002{
Damien Millercf31f382013-10-24 21:02:56 +11001003 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +10001004 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +10001005
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001006 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001007 debug3("checking syntax for 'Match %s'", cp);
1008 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001009 debug3("checking match for '%s' user %s host %s addr %s "
1010 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
1011 ci->host ? ci->host : "(null)",
1012 ci->address ? ci->address : "(null)",
1013 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +10001014
1015 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +11001016 attributes++;
1017 if (strcasecmp(attrib, "all") == 0) {
1018 if (attributes != 1 ||
1019 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1020 error("'all' cannot be combined with other "
1021 "Match attributes");
1022 return -1;
1023 }
1024 *condition = cp;
1025 return 1;
1026 }
Darren Tucker45150472006-07-12 22:34:17 +10001027 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1028 error("Missing Match criteria for %s", attrib);
1029 return -1;
1030 }
Darren Tucker45150472006-07-12 22:34:17 +10001031 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001032 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001033 result = 0;
1034 continue;
1035 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001036 if (ci->user == NULL)
1037 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001038 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001039 result = 0;
1040 else
1041 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001042 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001043 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001044 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001045 result = 0;
1046 continue;
1047 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001048 if (ci->user == NULL)
1049 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001050 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001051 case -1:
1052 return -1;
1053 case 0:
1054 result = 0;
1055 }
Darren Tucker45150472006-07-12 22:34:17 +10001056 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001057 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001058 result = 0;
1059 continue;
1060 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001061 if (ci->host == NULL)
1062 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001063 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001064 result = 0;
1065 else
1066 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001067 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001068 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001069 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001070 result = 0;
1071 continue;
1072 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001073 if (ci->address == NULL)
1074 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001075 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001076 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001077 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001078 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001079 break;
1080 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001081 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001082 result = 0;
1083 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001084 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001085 return -1;
1086 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001087 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001088 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001089 result = 0;
1090 continue;
1091 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001092 if (ci->laddress == NULL)
1093 match_test_missing_fatal("LocalAddress",
1094 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001095 switch (addr_match_list(ci->laddress, arg)) {
1096 case 1:
1097 debug("connection from %.100s matched "
1098 "'LocalAddress %.100s' at line %d",
1099 ci->laddress, arg, line);
1100 break;
1101 case 0:
1102 case -1:
1103 result = 0;
1104 break;
1105 case -2:
1106 return -1;
1107 }
1108 } else if (strcasecmp(attrib, "localport") == 0) {
1109 if ((port = a2port(arg)) == -1) {
1110 error("Invalid LocalPort '%s' on Match line",
1111 arg);
1112 return -1;
1113 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001114 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001115 result = 0;
1116 continue;
1117 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001118 if (ci->lport == 0)
1119 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001120 /* TODO support port lists */
1121 if (port == ci->lport)
1122 debug("connection from %.100s matched "
1123 "'LocalPort %d' at line %d",
1124 ci->laddress, port, line);
1125 else
1126 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001127 } else if (strcasecmp(attrib, "rdomain") == 0) {
1128 if (ci == NULL || ci->rdomain == NULL) {
1129 result = 0;
1130 continue;
1131 }
1132 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1133 result = 0;
1134 else
1135 debug("user %.100s matched 'RDomain %.100s' at "
1136 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001137 } else {
1138 error("Unsupported Match attribute %s", attrib);
1139 return -1;
1140 }
1141 }
Damien Millercf31f382013-10-24 21:02:56 +11001142 if (attributes == 0) {
1143 error("One or more attributes required for Match");
1144 return -1;
1145 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001146 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001147 debug3("match %sfound", result ? "" : "not ");
1148 *condition = cp;
1149 return result;
1150}
1151
Damien Millere2754432006-07-24 14:06:47 +10001152#define WHITESPACE " \t\r\n"
1153
Damien Miller33322122011-06-20 14:43:11 +10001154/* Multistate option parsing */
1155struct multistate {
1156 char *key;
1157 int value;
1158};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001159static const struct multistate multistate_flag[] = {
1160 { "yes", 1 },
1161 { "no", 0 },
1162 { NULL, -1 }
1163};
Damien Miller33322122011-06-20 14:43:11 +10001164static const struct multistate multistate_addressfamily[] = {
1165 { "inet", AF_INET },
1166 { "inet6", AF_INET6 },
1167 { "any", AF_UNSPEC },
1168 { NULL, -1 }
1169};
1170static const struct multistate multistate_permitrootlogin[] = {
1171 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001172 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001173 { "forced-commands-only", PERMIT_FORCED_ONLY },
1174 { "yes", PERMIT_YES },
1175 { "no", PERMIT_NO },
1176 { NULL, -1 }
1177};
1178static const struct multistate multistate_compression[] = {
sf@openbsd.org168b46f2018-07-09 13:37:10 +00001179 { "yes", COMP_DELAYED },
1180 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001181 { "no", COMP_NONE },
1182 { NULL, -1 }
1183};
1184static const struct multistate multistate_gatewayports[] = {
1185 { "clientspecified", 2 },
1186 { "yes", 1 },
1187 { "no", 0 },
1188 { NULL, -1 }
1189};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001190static const struct multistate multistate_tcpfwd[] = {
1191 { "yes", FORWARD_ALLOW },
1192 { "all", FORWARD_ALLOW },
1193 { "no", FORWARD_DENY },
1194 { "remote", FORWARD_REMOTE },
1195 { "local", FORWARD_LOCAL },
1196 { NULL, -1 }
1197};
Damien Miller33322122011-06-20 14:43:11 +10001198
Ben Lindstromade03f62001-12-06 18:22:17 +00001199int
1200process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001201 const char *filename, int linenum, int *activep,
1202 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001203{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001204 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001205 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001206 SyslogFacility *log_facility_ptr;
1207 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001208 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001209 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001210 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001211 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001212 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001213 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001214
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001215 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1216 if ((len = strlen(line)) == 0)
1217 return 0;
1218 for (len--; len > 0; len--) {
1219 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1220 break;
1221 line[len] = '\0';
1222 }
1223
Ben Lindstromade03f62001-12-06 18:22:17 +00001224 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001225 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001226 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001227 /* Ignore leading whitespace */
1228 if (*arg == '\0')
1229 arg = strdelim(&cp);
1230 if (!arg || !*arg || *arg == '#')
1231 return 0;
1232 intptr = NULL;
1233 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001234 opcode = parse_token(arg, filename, linenum, &flags);
1235
1236 if (activep == NULL) { /* We are processing a command line directive */
1237 cmdline = 1;
1238 activep = &cmdline;
1239 }
1240 if (*activep && opcode != sMatch)
1241 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1242 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001243 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001244 fatal("%s line %d: Directive '%s' is not allowed "
1245 "within a Match block", filename, linenum, arg);
1246 } else { /* this is a directive we have already processed */
1247 while (arg)
1248 arg = strdelim(&cp);
1249 return 0;
1250 }
1251 }
1252
Ben Lindstromade03f62001-12-06 18:22:17 +00001253 switch (opcode) {
1254 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001255 case sUsePAM:
1256 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001257 goto parse_flag;
1258
1259 /* Standard Options */
1260 case sBadOption:
1261 return -1;
1262 case sPort:
1263 /* ignore ports from configfile if cmdline specifies ports */
1264 if (options->ports_from_cmdline)
1265 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001266 if (options->num_ports >= MAX_PORTS)
1267 fatal("%s line %d: too many ports.",
1268 filename, linenum);
1269 arg = strdelim(&cp);
1270 if (!arg || *arg == '\0')
1271 fatal("%s line %d: missing port number.",
1272 filename, linenum);
1273 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001274 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001275 fatal("%s line %d: Badly formatted port number.",
1276 filename, linenum);
1277 break;
1278
Ben Lindstromade03f62001-12-06 18:22:17 +00001279 case sLoginGraceTime:
1280 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001281 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001282 arg = strdelim(&cp);
1283 if (!arg || *arg == '\0')
1284 fatal("%s line %d: missing time value.",
1285 filename, linenum);
1286 if ((value = convtime(arg)) == -1)
1287 fatal("%s line %d: invalid time value.",
1288 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001289 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001290 *intptr = value;
1291 break;
1292
Ben Lindstromade03f62001-12-06 18:22:17 +00001293 case sListenAddress:
1294 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001295 if (arg == NULL || *arg == '\0')
1296 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001297 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001298 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1299 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1300 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001301 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001302 p = arg;
1303 } else {
1304 p = hpdelim(&arg);
1305 if (p == NULL)
1306 fatal("%s line %d: bad address:port usage",
1307 filename, linenum);
1308 p = cleanhostname(p);
1309 if (arg == NULL)
1310 port = 0;
1311 else if ((port = a2port(arg)) <= 0)
1312 fatal("%s line %d: bad port number",
1313 filename, linenum);
1314 }
1315 /* Optional routing table */
1316 arg2 = NULL;
1317 if ((arg = strdelim(&cp)) != NULL) {
1318 if (strcmp(arg, "rdomain") != 0 ||
1319 (arg2 = strdelim(&cp)) == NULL)
1320 fatal("%s line %d: bad ListenAddress syntax",
1321 filename, linenum);
1322 if (!valid_rdomain(arg2))
1323 fatal("%s line %d: bad routing domain",
1324 filename, linenum);
1325 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001326
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001327 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001328
Ben Lindstromade03f62001-12-06 18:22:17 +00001329 break;
1330
Darren Tucker0f383232005-01-20 10:57:56 +11001331 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001332 intptr = &options->address_family;
1333 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001334 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001335 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001336 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001337 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001338 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001339 value = -1;
1340 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1341 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1342 value = multistate_ptr[i].value;
1343 break;
1344 }
1345 }
1346 if (value == -1)
1347 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001348 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001349 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001350 *intptr = value;
1351 break;
1352
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001354 arg = strdelim(&cp);
1355 if (!arg || *arg == '\0')
1356 fatal("%s line %d: missing file name.",
1357 filename, linenum);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001358 if (*activep)
1359 servconf_add_hostkey(filename, linenum, options, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001360 break;
1361
Damien Miller85b45e02013-07-20 13:21:52 +10001362 case sHostKeyAgent:
1363 charptr = &options->host_key_agent;
1364 arg = strdelim(&cp);
1365 if (!arg || *arg == '\0')
1366 fatal("%s line %d: missing socket name.",
1367 filename, linenum);
1368 if (*activep && *charptr == NULL)
1369 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1370 xstrdup(arg) : derelativise_path(arg);
1371 break;
1372
Damien Miller0a80ca12010-02-27 07:55:05 +11001373 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001374 arg = strdelim(&cp);
1375 if (!arg || *arg == '\0')
1376 fatal("%s line %d: missing file name.",
1377 filename, linenum);
1378 if (*activep)
1379 servconf_add_hostcert(filename, linenum, options, arg);
1380 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001381
Ben Lindstromade03f62001-12-06 18:22:17 +00001382 case sPidFile:
1383 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001384 parse_filename:
1385 arg = strdelim(&cp);
1386 if (!arg || *arg == '\0')
1387 fatal("%s line %d: missing file name.",
1388 filename, linenum);
1389 if (*activep && *charptr == NULL) {
1390 *charptr = derelativise_path(arg);
1391 /* increase optional counter */
1392 if (intptr != NULL)
1393 *intptr = *intptr + 1;
1394 }
1395 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001396
1397 case sPermitRootLogin:
1398 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001399 multistate_ptr = multistate_permitrootlogin;
1400 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001401
1402 case sIgnoreRhosts:
1403 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001404 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001405 multistate_ptr = multistate_flag;
1406 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001407
1408 case sIgnoreUserKnownHosts:
1409 intptr = &options->ignore_user_known_hosts;
1410 goto parse_flag;
1411
Ben Lindstromade03f62001-12-06 18:22:17 +00001412 case sHostbasedAuthentication:
1413 intptr = &options->hostbased_authentication;
1414 goto parse_flag;
1415
1416 case sHostbasedUsesNameFromPacketOnly:
1417 intptr = &options->hostbased_uses_name_from_packet_only;
1418 goto parse_flag;
1419
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001420 case sHostbasedAcceptedKeyTypes:
1421 charptr = &options->hostbased_key_types;
1422 parse_keytypes:
1423 arg = strdelim(&cp);
1424 if (!arg || *arg == '\0')
1425 fatal("%s line %d: Missing argument.",
1426 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001427 if (*arg != '-' &&
1428 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001429 fatal("%s line %d: Bad key types '%s'.",
1430 filename, linenum, arg ? arg : "<NONE>");
1431 if (*activep && *charptr == NULL)
1432 *charptr = xstrdup(arg);
1433 break;
1434
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001435 case sHostKeyAlgorithms:
1436 charptr = &options->hostkeyalgorithms;
1437 goto parse_keytypes;
1438
djm@openbsd.org86e57372018-09-20 03:28:06 +00001439 case sCASignatureAlgorithms:
1440 charptr = &options->ca_sign_algorithms;
1441 goto parse_keytypes;
1442
Ben Lindstromade03f62001-12-06 18:22:17 +00001443 case sPubkeyAuthentication:
1444 intptr = &options->pubkey_authentication;
1445 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001446
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001447 case sPubkeyAcceptedKeyTypes:
1448 charptr = &options->pubkey_key_types;
1449 goto parse_keytypes;
1450
Ben Lindstromade03f62001-12-06 18:22:17 +00001451 case sKerberosAuthentication:
1452 intptr = &options->kerberos_authentication;
1453 goto parse_flag;
1454
1455 case sKerberosOrLocalPasswd:
1456 intptr = &options->kerberos_or_local_passwd;
1457 goto parse_flag;
1458
1459 case sKerberosTicketCleanup:
1460 intptr = &options->kerberos_ticket_cleanup;
1461 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001462
Darren Tucker22ef5082003-12-31 11:37:34 +11001463 case sKerberosGetAFSToken:
1464 intptr = &options->kerberos_get_afs_token;
1465 goto parse_flag;
1466
Darren Tucker0efd1552003-08-26 11:49:55 +10001467 case sGssAuthentication:
1468 intptr = &options->gss_authentication;
1469 goto parse_flag;
1470
1471 case sGssCleanupCreds:
1472 intptr = &options->gss_cleanup_creds;
1473 goto parse_flag;
1474
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001475 case sGssStrictAcceptor:
1476 intptr = &options->gss_strict_acceptor;
1477 goto parse_flag;
1478
Ben Lindstromade03f62001-12-06 18:22:17 +00001479 case sPasswordAuthentication:
1480 intptr = &options->password_authentication;
1481 goto parse_flag;
1482
1483 case sKbdInteractiveAuthentication:
1484 intptr = &options->kbd_interactive_authentication;
1485 goto parse_flag;
1486
1487 case sChallengeResponseAuthentication:
1488 intptr = &options->challenge_response_authentication;
1489 goto parse_flag;
1490
1491 case sPrintMotd:
1492 intptr = &options->print_motd;
1493 goto parse_flag;
1494
1495 case sPrintLastLog:
1496 intptr = &options->print_lastlog;
1497 goto parse_flag;
1498
1499 case sX11Forwarding:
1500 intptr = &options->x11_forwarding;
1501 goto parse_flag;
1502
1503 case sX11DisplayOffset:
1504 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001505 parse_int:
1506 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001507 if ((errstr = atoi_err(arg, &value)) != NULL)
1508 fatal("%s line %d: integer value %s.",
1509 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001510 if (*activep && *intptr == -1)
1511 *intptr = value;
1512 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001513
Damien Miller95c249f2002-02-05 12:11:34 +11001514 case sX11UseLocalhost:
1515 intptr = &options->x11_use_localhost;
1516 goto parse_flag;
1517
Ben Lindstromade03f62001-12-06 18:22:17 +00001518 case sXAuthLocation:
1519 charptr = &options->xauth_location;
1520 goto parse_filename;
1521
Damien Miller5ff30c62013-10-30 22:21:50 +11001522 case sPermitTTY:
1523 intptr = &options->permit_tty;
1524 goto parse_flag;
1525
Damien Miller72e6b5c2014-07-04 09:00:04 +10001526 case sPermitUserRC:
1527 intptr = &options->permit_user_rc;
1528 goto parse_flag;
1529
Ben Lindstromade03f62001-12-06 18:22:17 +00001530 case sStrictModes:
1531 intptr = &options->strict_modes;
1532 goto parse_flag;
1533
Damien Miller12c150e2003-12-17 16:31:10 +11001534 case sTCPKeepAlive:
1535 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001536 goto parse_flag;
1537
1538 case sEmptyPasswd:
1539 intptr = &options->permit_empty_passwd;
1540 goto parse_flag;
1541
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001542 case sPermitUserEnvironment:
1543 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001544 charptr = &options->permit_user_env_whitelist;
1545 arg = strdelim(&cp);
1546 if (!arg || *arg == '\0')
1547 fatal("%s line %d: missing argument.",
1548 filename, linenum);
1549 value = 0;
1550 p = NULL;
1551 if (strcmp(arg, "yes") == 0)
1552 value = 1;
1553 else if (strcmp(arg, "no") == 0)
1554 value = 0;
1555 else {
1556 /* Pattern-list specified */
1557 value = 1;
1558 p = xstrdup(arg);
1559 }
1560 if (*activep && *intptr == -1) {
1561 *intptr = value;
1562 *charptr = p;
1563 p = NULL;
1564 }
1565 free(p);
1566 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001567
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001568 case sCompression:
1569 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001570 multistate_ptr = multistate_compression;
1571 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001572
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001573 case sRekeyLimit:
1574 arg = strdelim(&cp);
1575 if (!arg || *arg == '\0')
1576 fatal("%.200s line %d: Missing argument.", filename,
1577 linenum);
1578 if (strcmp(arg, "default") == 0) {
1579 val64 = 0;
1580 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001581 if (scan_scaled(arg, &val64) == -1)
1582 fatal("%.200s line %d: Bad number '%s': %s",
1583 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001584 if (val64 != 0 && val64 < 16)
1585 fatal("%.200s line %d: RekeyLimit too small",
1586 filename, linenum);
1587 }
1588 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001589 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001590 if (cp != NULL) { /* optional rekey interval present */
1591 if (strcmp(cp, "none") == 0) {
1592 (void)strdelim(&cp); /* discard */
1593 break;
1594 }
1595 intptr = &options->rekey_interval;
1596 goto parse_time;
1597 }
1598 break;
1599
Ben Lindstromade03f62001-12-06 18:22:17 +00001600 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001601 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001602 multistate_ptr = multistate_gatewayports;
1603 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001604
Damien Miller3a961dc2003-06-03 10:25:48 +10001605 case sUseDNS:
1606 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001607 goto parse_flag;
1608
1609 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001610 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001611 arg = strdelim(&cp);
1612 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001613 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001614 fatal("%.200s line %d: unsupported log facility '%s'",
1615 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001616 if (*log_facility_ptr == -1)
1617 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001618 break;
1619
1620 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001621 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001622 arg = strdelim(&cp);
1623 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001624 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001625 fatal("%.200s line %d: unsupported log level '%s'",
1626 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001627 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001628 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001629 break;
1630
1631 case sAllowTcpForwarding:
1632 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001633 multistate_ptr = multistate_tcpfwd;
1634 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001635
Damien Miller7acefbb2014-07-18 14:11:24 +10001636 case sAllowStreamLocalForwarding:
1637 intptr = &options->allow_streamlocal_forwarding;
1638 multistate_ptr = multistate_tcpfwd;
1639 goto parse_multistate;
1640
Damien Miller4f755cd2008-05-19 14:57:41 +10001641 case sAllowAgentForwarding:
1642 intptr = &options->allow_agent_forwarding;
1643 goto parse_flag;
1644
djm@openbsd.org7844f352016-11-30 03:00:05 +00001645 case sDisableForwarding:
1646 intptr = &options->disable_forwarding;
1647 goto parse_flag;
1648
Ben Lindstromade03f62001-12-06 18:22:17 +00001649 case sAllowUsers:
1650 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001651 if (match_user(NULL, NULL, NULL, arg) == -1)
1652 fatal("%s line %d: invalid AllowUsers pattern: "
1653 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001654 if (!*activep)
1655 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001656 array_append(filename, linenum, "AllowUsers",
1657 &options->allow_users, &options->num_allow_users,
1658 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001659 }
1660 break;
1661
1662 case sDenyUsers:
1663 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001664 if (match_user(NULL, NULL, NULL, arg) == -1)
1665 fatal("%s line %d: invalid DenyUsers pattern: "
1666 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001667 if (!*activep)
1668 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001669 array_append(filename, linenum, "DenyUsers",
1670 &options->deny_users, &options->num_deny_users,
1671 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001672 }
1673 break;
1674
1675 case sAllowGroups:
1676 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001677 if (!*activep)
1678 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001679 array_append(filename, linenum, "AllowGroups",
1680 &options->allow_groups, &options->num_allow_groups,
1681 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001682 }
1683 break;
1684
1685 case sDenyGroups:
1686 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001687 if (!*activep)
1688 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001689 array_append(filename, linenum, "DenyGroups",
1690 &options->deny_groups, &options->num_deny_groups,
1691 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001692 }
1693 break;
1694
1695 case sCiphers:
1696 arg = strdelim(&cp);
1697 if (!arg || *arg == '\0')
1698 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001699 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001700 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1701 filename, linenum, arg ? arg : "<NONE>");
1702 if (options->ciphers == NULL)
1703 options->ciphers = xstrdup(arg);
1704 break;
1705
1706 case sMacs:
1707 arg = strdelim(&cp);
1708 if (!arg || *arg == '\0')
1709 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001710 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001711 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1712 filename, linenum, arg ? arg : "<NONE>");
1713 if (options->macs == NULL)
1714 options->macs = xstrdup(arg);
1715 break;
1716
Damien Millerd5f62bf2010-09-24 22:11:14 +10001717 case sKexAlgorithms:
1718 arg = strdelim(&cp);
1719 if (!arg || *arg == '\0')
1720 fatal("%s line %d: Missing argument.",
1721 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001722 if (*arg != '-' &&
1723 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001724 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1725 filename, linenum, arg ? arg : "<NONE>");
1726 if (options->kex_algorithms == NULL)
1727 options->kex_algorithms = xstrdup(arg);
1728 break;
1729
Ben Lindstromade03f62001-12-06 18:22:17 +00001730 case sSubsystem:
1731 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1732 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001733 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001734 }
1735 arg = strdelim(&cp);
1736 if (!arg || *arg == '\0')
1737 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001738 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001739 if (!*activep) {
1740 arg = strdelim(&cp);
1741 break;
1742 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001743 for (i = 0; i < options->num_subsystems; i++)
1744 if (strcmp(arg, options->subsystem_name[i]) == 0)
1745 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001746 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001747 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1748 arg = strdelim(&cp);
1749 if (!arg || *arg == '\0')
1750 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001751 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001752 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001753
1754 /* Collect arguments (separate to executable) */
1755 p = xstrdup(arg);
1756 len = strlen(p) + 1;
1757 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1758 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001759 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001760 strlcat(p, " ", len);
1761 strlcat(p, arg, len);
1762 }
1763 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001764 options->num_subsystems++;
1765 break;
1766
1767 case sMaxStartups:
1768 arg = strdelim(&cp);
1769 if (!arg || *arg == '\0')
1770 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001771 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001772 if ((n = sscanf(arg, "%d:%d:%d",
1773 &options->max_startups_begin,
1774 &options->max_startups_rate,
1775 &options->max_startups)) == 3) {
1776 if (options->max_startups_begin >
1777 options->max_startups ||
1778 options->max_startups_rate > 100 ||
1779 options->max_startups_rate < 1)
1780 fatal("%s line %d: Illegal MaxStartups spec.",
1781 filename, linenum);
1782 } else if (n != 1)
1783 fatal("%s line %d: Illegal MaxStartups spec.",
1784 filename, linenum);
1785 else
1786 options->max_startups = options->max_startups_begin;
1787 break;
1788
Darren Tucker89413db2004-05-24 10:36:23 +10001789 case sMaxAuthTries:
1790 intptr = &options->max_authtries;
1791 goto parse_int;
1792
Damien Miller7207f642008-05-19 15:34:50 +10001793 case sMaxSessions:
1794 intptr = &options->max_sessions;
1795 goto parse_int;
1796
Ben Lindstromade03f62001-12-06 18:22:17 +00001797 case sBanner:
1798 charptr = &options->banner;
1799 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001800
Ben Lindstromade03f62001-12-06 18:22:17 +00001801 /*
1802 * These options can contain %X options expanded at
1803 * connect time, so that you can specify paths like:
1804 *
1805 * AuthorizedKeysFile /etc/ssh_keys/%u
1806 */
1807 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001808 if (*activep && options->num_authkeys_files == 0) {
1809 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001810 arg = tilde_expand_filename(arg, getuid());
1811 array_append(filename, linenum,
1812 "AuthorizedKeysFile",
1813 &options->authorized_keys_files,
1814 &options->num_authkeys_files, arg);
1815 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001816 }
1817 }
1818 return 0;
1819
Damien Miller30da3442010-05-10 11:58:03 +10001820 case sAuthorizedPrincipalsFile:
1821 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001822 arg = strdelim(&cp);
1823 if (!arg || *arg == '\0')
1824 fatal("%s line %d: missing file name.",
1825 filename, linenum);
1826 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001827 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001828 /* increase optional counter */
1829 if (intptr != NULL)
1830 *intptr = *intptr + 1;
1831 }
1832 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001833
1834 case sClientAliveInterval:
1835 intptr = &options->client_alive_interval;
1836 goto parse_time;
1837
1838 case sClientAliveCountMax:
1839 intptr = &options->client_alive_count_max;
1840 goto parse_int;
1841
Darren Tucker46bc0752004-05-02 22:11:30 +10001842 case sAcceptEnv:
1843 while ((arg = strdelim(&cp)) && *arg != '\0') {
1844 if (strchr(arg, '=') != NULL)
1845 fatal("%s line %d: Invalid environment name.",
1846 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001847 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001848 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001849 array_append(filename, linenum, "AcceptEnv",
1850 &options->accept_env, &options->num_accept_env,
1851 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001852 }
1853 break;
1854
djm@openbsd.org28013752018-06-09 03:03:10 +00001855 case sSetEnv:
1856 uvalue = options->num_setenv;
1857 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1858 if (strchr(arg, '=') == NULL)
1859 fatal("%s line %d: Invalid environment.",
1860 filename, linenum);
1861 if (!*activep || uvalue != 0)
1862 continue;
1863 array_append(filename, linenum, "SetEnv",
1864 &options->setenv, &options->num_setenv, arg);
1865 }
1866 break;
1867
Damien Millerd27b9472005-12-13 19:29:02 +11001868 case sPermitTunnel:
1869 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001870 arg = strdelim(&cp);
1871 if (!arg || *arg == '\0')
1872 fatal("%s line %d: Missing yes/point-to-point/"
1873 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001874 value = -1;
1875 for (i = 0; tunmode_desc[i].val != -1; i++)
1876 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1877 value = tunmode_desc[i].val;
1878 break;
1879 }
1880 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001881 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1882 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001883 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001884 *intptr = value;
1885 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001886
Darren Tucker45150472006-07-12 22:34:17 +10001887 case sMatch:
1888 if (cmdline)
1889 fatal("Match directive not supported as a command-line "
1890 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001891 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001892 if (value < 0)
1893 fatal("%s line %d: Bad Match condition", filename,
1894 linenum);
1895 *activep = value;
1896 break;
1897
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001898 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001899 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001900 if (opcode == sPermitListen) {
1901 uintptr = &options->num_permitted_listens;
1902 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001903 } else {
1904 uintptr = &options->num_permitted_opens;
1905 chararrayptr = &options->permitted_opens;
1906 }
Damien Miller9b439df2006-07-24 14:04:00 +10001907 arg = strdelim(&cp);
1908 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001909 fatal("%s line %d: missing %s specification",
1910 filename, linenum, lookup_opcode_name(opcode));
1911 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001912 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001913 if (*activep && uvalue == 0) {
1914 *uintptr = 1;
1915 *chararrayptr = xcalloc(1,
1916 sizeof(**chararrayptr));
1917 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001918 }
Damien Millerc6081482012-04-22 11:18:53 +10001919 break;
1920 }
Damien Millera765cf42006-07-24 14:08:13 +10001921 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001922 if (opcode == sPermitListen &&
1923 strchr(arg, ':') == NULL) {
1924 /*
1925 * Allow bare port number for PermitListen
1926 * to indicate a wildcard listen host.
1927 */
1928 xasprintf(&arg2, "*:%s", arg);
1929 } else {
1930 arg2 = xstrdup(arg);
1931 p = hpdelim(&arg);
1932 if (p == NULL) {
1933 fatal("%s line %d: missing host in %s",
1934 filename, linenum,
1935 lookup_opcode_name(opcode));
1936 }
1937 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001938 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001939 if (arg == NULL ||
1940 ((port = permitopen_port(arg)) < 0)) {
1941 fatal("%s line %d: bad port number in %s",
1942 filename, linenum,
1943 lookup_opcode_name(opcode));
1944 }
1945 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001946 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001947 lookup_opcode_name(opcode),
1948 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001949 }
1950 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001951 }
Damien Miller9b439df2006-07-24 14:04:00 +10001952 break;
1953
Damien Millere2754432006-07-24 14:06:47 +10001954 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001955 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001956 fatal("%.200s line %d: Missing argument.", filename,
1957 linenum);
1958 len = strspn(cp, WHITESPACE);
1959 if (*activep && options->adm_forced_command == NULL)
1960 options->adm_forced_command = xstrdup(cp + len);
1961 return 0;
1962
Damien Millerd8cb1f12008-02-10 22:40:12 +11001963 case sChrootDirectory:
1964 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001965
1966 arg = strdelim(&cp);
1967 if (!arg || *arg == '\0')
1968 fatal("%s line %d: missing file name.",
1969 filename, linenum);
1970 if (*activep && *charptr == NULL)
1971 *charptr = xstrdup(arg);
1972 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001973
Damien Miller1aed65e2010-03-04 21:53:35 +11001974 case sTrustedUserCAKeys:
1975 charptr = &options->trusted_user_ca_keys;
1976 goto parse_filename;
1977
1978 case sRevokedKeys:
1979 charptr = &options->revoked_keys_file;
1980 goto parse_filename;
1981
Damien Miller0dac6fb2010-11-20 15:19:38 +11001982 case sIPQoS:
1983 arg = strdelim(&cp);
1984 if ((value = parse_ipqos(arg)) == -1)
1985 fatal("%s line %d: Bad IPQoS value: %s",
1986 filename, linenum, arg);
1987 arg = strdelim(&cp);
1988 if (arg == NULL)
1989 value2 = value;
1990 else if ((value2 = parse_ipqos(arg)) == -1)
1991 fatal("%s line %d: Bad IPQoS value: %s",
1992 filename, linenum, arg);
1993 if (*activep) {
1994 options->ip_qos_interactive = value;
1995 options->ip_qos_bulk = value2;
1996 }
1997 break;
1998
Damien Miller23528812012-04-22 11:24:43 +10001999 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00002000 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10002001 fatal("%.200s line %d: Missing argument.", filename,
2002 linenum);
2003 len = strspn(cp, WHITESPACE);
2004 if (*activep && options->version_addendum == NULL) {
2005 if (strcasecmp(cp + len, "none") == 0)
2006 options->version_addendum = xstrdup("");
2007 else if (strchr(cp + len, '\r') != NULL)
2008 fatal("%.200s line %d: Invalid argument",
2009 filename, linenum);
2010 else
2011 options->version_addendum = xstrdup(cp + len);
2012 }
2013 return 0;
2014
Damien Miller09d3e122012-10-31 08:58:58 +11002015 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002016 if (cp == NULL)
2017 fatal("%.200s line %d: Missing argument.", filename,
2018 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002019 len = strspn(cp, WHITESPACE);
2020 if (*activep && options->authorized_keys_command == NULL) {
2021 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2022 fatal("%.200s line %d: AuthorizedKeysCommand "
2023 "must be an absolute path",
2024 filename, linenum);
2025 options->authorized_keys_command = xstrdup(cp + len);
2026 }
2027 return 0;
2028
2029 case sAuthorizedKeysCommandUser:
2030 charptr = &options->authorized_keys_command_user;
2031
2032 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002033 if (!arg || *arg == '\0')
2034 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2035 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002036 if (*activep && *charptr == NULL)
2037 *charptr = xstrdup(arg);
2038 break;
2039
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002040 case sAuthorizedPrincipalsCommand:
2041 if (cp == NULL)
2042 fatal("%.200s line %d: Missing argument.", filename,
2043 linenum);
2044 len = strspn(cp, WHITESPACE);
2045 if (*activep &&
2046 options->authorized_principals_command == NULL) {
2047 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2048 fatal("%.200s line %d: "
2049 "AuthorizedPrincipalsCommand must be "
2050 "an absolute path", filename, linenum);
2051 options->authorized_principals_command =
2052 xstrdup(cp + len);
2053 }
2054 return 0;
2055
2056 case sAuthorizedPrincipalsCommandUser:
2057 charptr = &options->authorized_principals_command_user;
2058
2059 arg = strdelim(&cp);
2060 if (!arg || *arg == '\0')
2061 fatal("%s line %d: missing "
2062 "AuthorizedPrincipalsCommandUser argument.",
2063 filename, linenum);
2064 if (*activep && *charptr == NULL)
2065 *charptr = xstrdup(arg);
2066 break;
2067
Damien Millera6e3f012012-11-04 23:21:40 +11002068 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002069 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002070 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002071 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002072 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002073 if (strcmp(arg, "any") == 0) {
2074 if (options->num_auth_methods > 0) {
2075 fatal("%s line %d: \"any\" "
2076 "must appear alone in "
2077 "AuthenticationMethods",
2078 filename, linenum);
2079 }
2080 value = 1;
2081 } else if (value) {
2082 fatal("%s line %d: \"any\" must appear "
2083 "alone in AuthenticationMethods",
2084 filename, linenum);
2085 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002086 fatal("%s line %d: invalid "
2087 "authentication method list.",
2088 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002089 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002090 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002091 if (!*activep)
2092 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002093 array_append(filename, linenum,
2094 "AuthenticationMethods",
2095 &options->auth_methods,
2096 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002097 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002098 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002099 fatal("%s line %d: no AuthenticationMethods "
2100 "specified", filename, linenum);
2101 }
Damien Millera6e3f012012-11-04 23:21:40 +11002102 }
2103 return 0;
2104
Damien Miller7acefbb2014-07-18 14:11:24 +10002105 case sStreamLocalBindMask:
2106 arg = strdelim(&cp);
2107 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002108 fatal("%s line %d: missing StreamLocalBindMask "
2109 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002110 /* Parse mode in octal format */
2111 value = strtol(arg, &p, 8);
2112 if (arg == p || value < 0 || value > 0777)
2113 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002114 if (*activep)
2115 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002116 break;
2117
2118 case sStreamLocalBindUnlink:
2119 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2120 goto parse_flag;
2121
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002122 case sFingerprintHash:
2123 arg = strdelim(&cp);
2124 if (!arg || *arg == '\0')
2125 fatal("%.200s line %d: Missing argument.",
2126 filename, linenum);
2127 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2128 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2129 filename, linenum, arg);
2130 if (*activep)
2131 options->fingerprint_hash = value;
2132 break;
2133
djm@openbsd.org8f574952017-06-24 06:34:38 +00002134 case sExposeAuthInfo:
2135 intptr = &options->expose_userauth_info;
2136 goto parse_flag;
2137
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002138 case sRDomain:
2139 charptr = &options->routing_domain;
2140 arg = strdelim(&cp);
2141 if (!arg || *arg == '\0')
2142 fatal("%.200s line %d: Missing argument.",
2143 filename, linenum);
2144 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2145 !valid_rdomain(arg))
2146 fatal("%s line %d: bad routing domain",
2147 filename, linenum);
2148 if (*activep && *charptr == NULL)
2149 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002150 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002151
Ben Lindstromade03f62001-12-06 18:22:17 +00002152 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002153 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002154 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002155 do_log2(opcode == sIgnore ?
2156 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2157 "%s line %d: %s option %s", filename, linenum,
2158 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002159 while (arg)
2160 arg = strdelim(&cp);
2161 break;
2162
Ben Lindstromade03f62001-12-06 18:22:17 +00002163 default:
2164 fatal("%s line %d: Missing handler for opcode %s (%d)",
2165 filename, linenum, arg, opcode);
2166 }
2167 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2168 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2169 filename, linenum, arg);
2170 return 0;
2171}
2172
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002173/* Reads the server configuration file. */
2174
Damien Miller4af51302000-04-16 11:18:38 +10002175void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002176load_server_config(const char *filename, struct sshbuf *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002177{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002178 char *line = NULL, *cp;
2179 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002180 FILE *f;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002181 int r, lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002182
Darren Tucker645ab752004-06-25 13:33:20 +10002183 debug2("%s: filename %s", __func__, filename);
2184 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002185 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002186 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002187 }
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002188 sshbuf_reset(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002189 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002190 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002191 /*
2192 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002193 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002194 * line numbers later for error messages
2195 */
2196 if ((cp = strchr(line, '#')) != NULL)
2197 memcpy(cp, "\n", 2);
2198 cp = line + strspn(line, " \t\r");
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002199 if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2200 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002201 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002202 free(line);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002203 if ((r = sshbuf_put_u8(conf, 0)) != 0)
2204 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002205 fclose(f);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002206 debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002207}
2208
2209void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002210parse_server_match_config(ServerOptions *options,
2211 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002212{
Darren Tucker45150472006-07-12 22:34:17 +10002213 ServerOptions mo;
2214
2215 initialize_server_options(&mo);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002216 parse_server_config(&mo, "reprocess config", cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002217 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002218}
2219
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002220int parse_server_match_testspec(struct connection_info *ci, char *spec)
2221{
2222 char *p;
2223
2224 while ((p = strsep(&spec, ",")) && *p != '\0') {
2225 if (strncmp(p, "addr=", 5) == 0) {
2226 ci->address = xstrdup(p + 5);
2227 } else if (strncmp(p, "host=", 5) == 0) {
2228 ci->host = xstrdup(p + 5);
2229 } else if (strncmp(p, "user=", 5) == 0) {
2230 ci->user = xstrdup(p + 5);
2231 } else if (strncmp(p, "laddr=", 6) == 0) {
2232 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002233 } else if (strncmp(p, "rdomain=", 8) == 0) {
2234 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002235 } else if (strncmp(p, "lport=", 6) == 0) {
2236 ci->lport = a2port(p + 6);
2237 if (ci->lport == -1) {
2238 fprintf(stderr, "Invalid port '%s' in test mode"
2239 " specification %s\n", p+6, p);
2240 return -1;
2241 }
2242 } else {
2243 fprintf(stderr, "Invalid test mode specification %s\n",
2244 p);
2245 return -1;
2246 }
2247 }
2248 return 0;
2249}
2250
2251/*
Darren Tucker1629c072007-02-19 22:25:37 +11002252 * Copy any supported values that are set.
2253 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002254 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002255 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002256 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002257 */
Darren Tucker45150472006-07-12 22:34:17 +10002258void
Darren Tucker1629c072007-02-19 22:25:37 +11002259copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002260{
Damien Miller534b2cc2013-12-05 14:07:27 +11002261#define M_CP_INTOPT(n) do {\
2262 if (src->n != -1) \
2263 dst->n = src->n; \
2264} while (0)
2265
Darren Tucker1629c072007-02-19 22:25:37 +11002266 M_CP_INTOPT(password_authentication);
2267 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002268 M_CP_INTOPT(pubkey_authentication);
2269 M_CP_INTOPT(kerberos_authentication);
2270 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002271 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002272 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002273 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002274 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002275
2276 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002277 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002278 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002279 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002280 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002281 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002282 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002283 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002284 M_CP_INTOPT(x11_display_offset);
2285 M_CP_INTOPT(x11_forwarding);
2286 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002287 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002288 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002289 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002290 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002291 M_CP_INTOPT(client_alive_count_max);
2292 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002293 M_CP_INTOPT(ip_qos_interactive);
2294 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002295 M_CP_INTOPT(rekey_limit);
2296 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002297 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002298
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002299 /*
2300 * The bind_mask is a mode_t that may be unsigned, so we can't use
2301 * M_CP_INTOPT - it does a signed comparison that causes compiler
2302 * warnings.
2303 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002304 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002305 dst->fwd_opts.streamlocal_bind_mask =
2306 src->fwd_opts.streamlocal_bind_mask;
2307 }
2308
Damien Miller534b2cc2013-12-05 14:07:27 +11002309 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2310#define M_CP_STROPT(n) do {\
2311 if (src->n != NULL && dst->n != src->n) { \
2312 free(dst->n); \
2313 dst->n = src->n; \
2314 } \
2315} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002316#define M_CP_STRARRAYOPT(s, num_s) do {\
2317 u_int i; \
2318 if (src->num_s != 0) { \
2319 for (i = 0; i < dst->num_s; i++) \
2320 free(dst->s[i]); \
2321 free(dst->s); \
2322 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2323 for (i = 0; i < src->num_s; i++) \
2324 dst->s[i] = xstrdup(src->s[i]); \
2325 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002326 } \
2327} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002328
Damien Millerf2e407e2011-05-20 19:04:14 +10002329 /* See comment in servconf.h */
2330 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002331
djm@openbsd.orged085102015-10-29 08:05:01 +00002332 /* Arguments that accept '+...' need to be expanded */
2333 assemble_algorithms(dst);
2334
Damien Millerc2411902011-05-20 19:03:49 +10002335 /*
2336 * The only things that should be below this point are string options
2337 * which are only used after authentication.
2338 */
Damien Miller5d74e582011-05-20 19:03:31 +10002339 if (preauth)
2340 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002341
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002342 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002343 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002344 if (option_clear_or_none(dst->adm_forced_command)) {
2345 free(dst->adm_forced_command);
2346 dst->adm_forced_command = NULL;
2347 }
Damien Miller5d74e582011-05-20 19:03:31 +10002348 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002349 if (option_clear_or_none(dst->chroot_directory)) {
2350 free(dst->chroot_directory);
2351 dst->chroot_directory = NULL;
2352 }
Darren Tucker45150472006-07-12 22:34:17 +10002353}
2354
Darren Tucker1629c072007-02-19 22:25:37 +11002355#undef M_CP_INTOPT
2356#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002357#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002358
Darren Tucker45150472006-07-12 22:34:17 +10002359void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002360parse_server_config(ServerOptions *options, const char *filename,
2361 struct sshbuf *conf, struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002362{
2363 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002364 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002365
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002366 debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002367
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002368 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2369 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002370 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002371 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002372 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002373 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002374 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002375 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002376 }
Darren Tuckera627d422013-06-02 07:31:17 +10002377 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002378 if (bad_options > 0)
2379 fatal("%s: terminating, %d bad configuration options",
2380 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002381 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002382}
Darren Tuckere7140f22008-06-10 23:01:51 +10002383
2384static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002385fmt_multistate_int(int val, const struct multistate *m)
2386{
2387 u_int i;
2388
2389 for (i = 0; m[i].key != NULL; i++) {
2390 if (m[i].value == val)
2391 return m[i].key;
2392 }
2393 return "UNKNOWN";
2394}
2395
2396static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002397fmt_intarg(ServerOpCodes code, int val)
2398{
Damien Miller82c55872011-06-23 08:20:30 +10002399 if (val == -1)
2400 return "unset";
2401 switch (code) {
2402 case sAddressFamily:
2403 return fmt_multistate_int(val, multistate_addressfamily);
2404 case sPermitRootLogin:
2405 return fmt_multistate_int(val, multistate_permitrootlogin);
2406 case sGatewayPorts:
2407 return fmt_multistate_int(val, multistate_gatewayports);
2408 case sCompression:
2409 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002410 case sAllowTcpForwarding:
2411 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002412 case sAllowStreamLocalForwarding:
2413 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002414 case sFingerprintHash:
2415 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002416 default:
2417 switch (val) {
2418 case 0:
2419 return "no";
2420 case 1:
2421 return "yes";
2422 default:
2423 return "UNKNOWN";
2424 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002425 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002426}
2427
Darren Tuckere7140f22008-06-10 23:01:51 +10002428static void
2429dump_cfg_int(ServerOpCodes code, int val)
2430{
2431 printf("%s %d\n", lookup_opcode_name(code), val);
2432}
2433
2434static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002435dump_cfg_oct(ServerOpCodes code, int val)
2436{
2437 printf("%s 0%o\n", lookup_opcode_name(code), val);
2438}
2439
2440static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002441dump_cfg_fmtint(ServerOpCodes code, int val)
2442{
2443 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2444}
2445
2446static void
2447dump_cfg_string(ServerOpCodes code, const char *val)
2448{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002449 printf("%s %s\n", lookup_opcode_name(code),
2450 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002451}
2452
2453static void
2454dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2455{
2456 u_int i;
2457
2458 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002459 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2460}
2461
2462static void
2463dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2464{
2465 u_int i;
2466
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002467 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002468 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002469 printf("%s", lookup_opcode_name(code));
2470 for (i = 0; i < count; i++)
2471 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002472 if (code == sAuthenticationMethods && count == 0)
2473 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002474 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002475}
2476
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002477static char *
2478format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002479{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002480 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002481 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002482 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002483 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002484
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002485 /*
2486 * ListenAddress must be after Port. add_one_listen_addr pushes
2487 * addresses onto a stack, so to maintain ordering we need to
2488 * print these in reverse order.
2489 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002490 for (ai = la->addrs; ai; ai = ai->ai_next) {
2491 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002492 sizeof(addr), port, sizeof(port),
2493 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002494 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2495 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002496 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002497 laddr2 = laddr1;
2498 if (ai->ai_family == AF_INET6) {
2499 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2500 addr, port,
2501 la->rdomain == NULL ? "" : " rdomain ",
2502 la->rdomain == NULL ? "" : la->rdomain,
2503 laddr2);
2504 } else {
2505 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2506 addr, port,
2507 la->rdomain == NULL ? "" : " rdomain ",
2508 la->rdomain == NULL ? "" : la->rdomain,
2509 laddr2);
2510 }
2511 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002512 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002513 return laddr1;
2514}
2515
2516void
2517dump_config(ServerOptions *o)
2518{
2519 char *s;
2520 u_int i;
2521
2522 /* these are usually at the top of the config */
2523 for (i = 0; i < o->num_ports; i++)
2524 printf("port %d\n", o->ports[i]);
2525 dump_cfg_fmtint(sAddressFamily, o->address_family);
2526
2527 for (i = 0; i < o->num_listen_addrs; i++) {
2528 s = format_listen_addrs(&o->listen_addrs[i]);
2529 printf("%s", s);
2530 free(s);
2531 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002532
2533 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002534#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002535 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002536#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002537 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002538 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2539 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002540 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002541 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2542 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002543 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002544
2545 /* formatted integer arguments */
2546 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2547 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2548 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002549 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2550 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2551 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002552 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002553#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002554 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2555 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2556 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002557# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002558 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002559# endif
2560#endif
2561#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002562 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2563 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002564#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002565 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2566 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2567 o->kbd_interactive_authentication);
2568 dump_cfg_fmtint(sChallengeResponseAuthentication,
2569 o->challenge_response_authentication);
2570 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002571#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002572 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002573#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002574 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2575 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002576 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002577 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002578 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2579 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2580 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002581 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002582 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002583 dump_cfg_fmtint(sUseDNS, o->use_dns);
2584 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002585 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002586 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002587 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002588 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002589 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002590 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002591
2592 /* string arguments */
2593 dump_cfg_string(sPidFile, o->pid_file);
2594 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002595 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2596 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002597 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002598 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002599 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002600 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2601 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002602 dump_cfg_string(sAuthorizedPrincipalsFile,
2603 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002604 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2605 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002606 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2607 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002608 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2609 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002610 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002611 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002612 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org86e57372018-09-20 03:28:06 +00002613 dump_cfg_string(sCASignatureAlgorithms, o->ca_sign_algorithms ?
2614 o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002615 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2616 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002617 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2618 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002619 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2620 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002621 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002622
2623 /* string arguments requiring a lookup */
2624 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2625 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2626
2627 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002628 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2629 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002630 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2631 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002632 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002633 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002634 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2635 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2636 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2637 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2638 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002639 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002640 dump_cfg_strarray_oneline(sAuthenticationMethods,
2641 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002642
2643 /* other arguments */
2644 for (i = 0; i < o->num_subsystems; i++)
2645 printf("subsystem %s %s\n", o->subsystem_name[i],
2646 o->subsystem_args[i]);
2647
2648 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2649 o->max_startups_rate, o->max_startups);
2650
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002651 s = NULL;
2652 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002653 if (tunmode_desc[i].val == o->permit_tun) {
2654 s = tunmode_desc[i].text;
2655 break;
2656 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002657 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002658 dump_cfg_string(sPermitTunnel, s);
2659
Damien Miller91475862011-05-05 14:14:34 +10002660 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2661 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002662
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002663 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002664 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002665
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002666 printf("permitopen");
2667 if (o->num_permitted_opens == 0)
2668 printf(" any");
2669 else {
2670 for (i = 0; i < o->num_permitted_opens; i++)
2671 printf(" %s", o->permitted_opens[i]);
2672 }
2673 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002674 printf("permitlisten");
2675 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002676 printf(" any");
2677 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002678 for (i = 0; i < o->num_permitted_listens; i++)
2679 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002680 }
2681 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002682
2683 if (o->permit_user_env_whitelist == NULL) {
2684 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2685 } else {
2686 printf("permituserenvironment %s\n",
2687 o->permit_user_env_whitelist);
2688 }
2689
Darren Tuckere7140f22008-06-10 23:01:51 +10002690}