blob: 52d9be4295be6dbaf27123380b16a4965f643a98 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org928f1232018-11-19 04:12:32 +00002/* $OpenBSD: servconf.c,v 1.344 2018/11/19 04:12:32 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
djm@openbsd.org928f1232018-11-19 04:12:32 +0000224array_append2(const char *file, const int line, const char *directive,
225 char ***array, int **iarray, u_int *lp, const char *s, int i)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000226{
227
228 if (*lp >= INT_MAX)
229 fatal("%s line %d: Too many %s entries", file, line, directive);
230
djm@openbsd.org928f1232018-11-19 04:12:32 +0000231 if (iarray != NULL) {
232 *iarray = xrecallocarray(*iarray, *lp, *lp + 1,
233 sizeof(**iarray));
234 (*iarray)[*lp] = i;
235 }
236
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000237 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
238 (*array)[*lp] = xstrdup(s);
239 (*lp)++;
240}
241
djm@openbsd.org928f1232018-11-19 04:12:32 +0000242static void
243array_append(const char *file, const int line, const char *directive,
244 char ***array, u_int *lp, const char *s)
245{
246 array_append2(file, line, directive, array, NULL, lp, s, 0);
247}
248
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000249void
250servconf_add_hostkey(const char *file, const int line,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000251 ServerOptions *options, const char *path, int userprovided)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000252{
253 char *apath = derelativise_path(path);
254
djm@openbsd.org928f1232018-11-19 04:12:32 +0000255 array_append2(file, line, "HostKey",
256 &options->host_key_files, &options->host_key_file_userprovided,
257 &options->num_host_key_files, apath, userprovided);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000258 free(apath);
259}
260
261void
262servconf_add_hostcert(const char *file, const int line,
263 ServerOptions *options, const char *path)
264{
265 char *apath = derelativise_path(path);
266
267 array_append(file, line, "HostCertificate",
268 &options->host_cert_files, &options->num_host_cert_files, apath);
269 free(apath);
270}
271
Damien Miller4af51302000-04-16 11:18:38 +1000272void
Damien Miller95def091999-11-25 00:26:21 +1100273fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000274{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000275 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000276
Damien Miller726273e2001-11-12 11:40:11 +1100277 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000278 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000279 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100280
281 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100282 if (options->num_host_key_files == 0) {
283 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000284 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000285 _PATH_HOST_RSA_KEY_FILE, 0);
Damien Millerdd190dd2010-11-11 14:17:02 +1100286#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000287 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000288 _PATH_HOST_ECDSA_KEY_FILE, 0);
Damien Millerdd190dd2010-11-11 14:17:02 +1100289#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000290 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000291 _PATH_HOST_ED25519_KEY_FILE, 0);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000292#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000293 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000294 _PATH_HOST_XMSS_KEY_FILE, 0);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000295#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100296 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100297 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100298 if (options->num_ports == 0)
299 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000300 if (options->address_family == -1)
301 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100302 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000303 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000304 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000305 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100306 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000307 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000308 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000309 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100310 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100311 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100312 if (options->ignore_user_known_hosts == -1)
313 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100314 if (options->print_motd == -1)
315 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000316 if (options->print_lastlog == -1)
317 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100318 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100319 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100320 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100321 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100322 if (options->x11_use_localhost == -1)
323 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000324 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000325 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100326 if (options->permit_tty == -1)
327 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000328 if (options->permit_user_rc == -1)
329 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100330 if (options->strict_modes == -1)
331 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100332 if (options->tcp_keep_alive == -1)
333 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100334 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100335 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100336 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000337 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000338 if (options->hostbased_authentication == -1)
339 options->hostbased_authentication = 0;
340 if (options->hostbased_uses_name_from_packet_only == -1)
341 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100342 if (options->pubkey_authentication == -1)
343 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100344 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000345 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100346 if (options->kerberos_or_local_passwd == -1)
347 options->kerberos_or_local_passwd = 1;
348 if (options->kerberos_ticket_cleanup == -1)
349 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100350 if (options->kerberos_get_afs_token == -1)
351 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000352 if (options->gss_authentication == -1)
353 options->gss_authentication = 0;
354 if (options->gss_cleanup_creds == -1)
355 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000356 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000357 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100358 if (options->password_authentication == -1)
359 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100360 if (options->kbd_interactive_authentication == -1)
361 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000362 if (options->challenge_response_authentication == -1)
363 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100364 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100365 options->permit_empty_passwd = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000366 if (options->permit_user_env == -1) {
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000367 options->permit_user_env = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000368 options->permit_user_env_whitelist = NULL;
369 }
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000370 if (options->compression == -1)
sf@openbsd.org168b46f2018-07-09 13:37:10 +0000371 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000372 if (options->rekey_limit == -1)
373 options->rekey_limit = 0;
374 if (options->rekey_interval == -1)
375 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100376 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100377 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000378 if (options->allow_streamlocal_forwarding == -1)
379 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000380 if (options->allow_agent_forwarding == -1)
381 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000382 if (options->fwd_opts.gateway_ports == -1)
383 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000384 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100385 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000386 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100387 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000388 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100389 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000390 if (options->max_authtries == -1)
391 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000392 if (options->max_sessions == -1)
393 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000394 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000395 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000396 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100397 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000398 if (options->client_alive_count_max == -1)
399 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000400 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000401 array_append("[default]", 0, "AuthorizedKeysFiles",
402 &options->authorized_keys_files,
403 &options->num_authkeys_files,
404 _PATH_SSH_USER_PERMITTED_KEYS);
405 array_append("[default]", 0, "AuthorizedKeysFiles",
406 &options->authorized_keys_files,
407 &options->num_authkeys_files,
408 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000409 }
Damien Millerd27b9472005-12-13 19:29:02 +1100410 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100411 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100412 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000413 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100414 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000415 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000416 if (options->version_addendum == NULL)
417 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000418 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
419 options->fwd_opts.streamlocal_bind_mask = 0177;
420 if (options->fwd_opts.streamlocal_bind_unlink == -1)
421 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000422 if (options->fingerprint_hash == -1)
423 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000424 if (options->disable_forwarding == -1)
425 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000426 if (options->expose_userauth_info == -1)
427 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000428
djm@openbsd.orged085102015-10-29 08:05:01 +0000429 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000430
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000431 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000432 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000433 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000434
djm@openbsd.org161cf412014-12-22 07:55:51 +0000435#define CLEAR_ON_NONE(v) \
436 do { \
437 if (option_clear_or_none(v)) { \
438 free(v); \
439 v = NULL; \
440 } \
441 } while(0)
442 CLEAR_ON_NONE(options->pid_file);
443 CLEAR_ON_NONE(options->xauth_location);
444 CLEAR_ON_NONE(options->banner);
445 CLEAR_ON_NONE(options->trusted_user_ca_keys);
446 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000447 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000448 CLEAR_ON_NONE(options->adm_forced_command);
449 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000450 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000451 for (i = 0; i < options->num_host_key_files; i++)
452 CLEAR_ON_NONE(options->host_key_files[i]);
453 for (i = 0; i < options->num_host_cert_files; i++)
454 CLEAR_ON_NONE(options->host_cert_files[i]);
455#undef CLEAR_ON_NONE
456
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000457 /* Similar handling for AuthenticationMethods=any */
458 if (options->num_auth_methods == 1 &&
459 strcmp(options->auth_methods[0], "any") == 0) {
460 free(options->auth_methods[0]);
461 options->auth_methods[0] = NULL;
462 options->num_auth_methods = 0;
463 }
464
Tim Rice40017b02002-07-14 13:36:49 -0700465#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000466 if (use_privsep && options->compression == 1) {
467 error("This platform does not support both privilege "
468 "separation and compression");
469 error("Compression disabled");
470 options->compression = 0;
471 }
472#endif
473
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000474}
475
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000476/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100477typedef enum {
478 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100479 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000480 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100481 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000482 sPort, sHostKeyFile, sLoginGraceTime,
483 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000484 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100485 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000486 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100487 sPasswordAuthentication, sKbdInteractiveAuthentication,
488 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000489 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100490 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100491 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000492 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000493 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000494 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000495 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
496 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000497 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000498 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000499 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000500 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000501 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000502 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000503 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100504 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100505 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000506 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000507 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
djm@openbsd.org86e57372018-09-20 03:28:06 +0000508 sKexAlgorithms, sCASignatureAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100509 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000510 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000511 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000512 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000513 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000514 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000515} ServerOpCodes;
516
Darren Tucker45150472006-07-12 22:34:17 +1000517#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
518#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
519#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
520
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000521/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100522static struct {
523 const char *name;
524 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000525 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100526} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100527 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000528#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000529 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000530#else
Darren Tucker45150472006-07-12 22:34:17 +1000531 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000532#endif
Darren Tucker45150472006-07-12 22:34:17 +1000533 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100534 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000535 { "port", sPort, SSHCFG_GLOBAL },
536 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
537 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000538 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000539 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000540 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000541 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000542 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100543 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000544 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000545 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000546 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000547 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100548 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000549 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000550 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000551 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000552 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100553 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000554 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000555 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000556#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100557 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000558 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
559 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100560#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000561 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000562#else
Darren Tucker45150472006-07-12 22:34:17 +1000563 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100564#endif
565#else
Darren Tucker1629c072007-02-19 22:25:37 +1100566 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000567 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
568 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
569 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000570#endif
Darren Tucker45150472006-07-12 22:34:17 +1000571 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
572 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000573#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100574 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000575 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000576 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000577#else
Darren Tucker1629c072007-02-19 22:25:37 +1100578 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000579 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000580 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000581#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100582 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
583 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100584 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Damien Miller87f08be2018-07-20 13:18:28 +1000585 { "skeyauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000586 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
587 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
588 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
589 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100590#ifdef DISABLE_LASTLOG
591 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
592#else
Darren Tucker45150472006-07-12 22:34:17 +1000593 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100594#endif
Darren Tucker45150472006-07-12 22:34:17 +1000595 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
596 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000597 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
598 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
599 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000600 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
601 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100602 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000603 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000604 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000605 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000606 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000607 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
608 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
609 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000610 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000611 { "allowusers", sAllowUsers, SSHCFG_ALL },
612 { "denyusers", sDenyUsers, SSHCFG_ALL },
613 { "allowgroups", sAllowGroups, SSHCFG_ALL },
614 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000615 { "ciphers", sCiphers, SSHCFG_GLOBAL },
616 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000617 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000618 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
619 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
620 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000621 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000622 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100623 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000624 { "usedns", sUseDNS, SSHCFG_GLOBAL },
625 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
626 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000627 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
628 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000629 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000630 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000631 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000632 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000633 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000634 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100635 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000636 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000637 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000638 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000639 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000640 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100641 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100642 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100643 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
644 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000645 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000646 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100647 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100648 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
649 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000650 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
651 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000652 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100653 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000654 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
655 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
656 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000657 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000658 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000659 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000660 { "rdomain", sRDomain, SSHCFG_ALL },
djm@openbsd.org0cbed242018-09-20 23:40:16 +0000661 { "casignaturealgorithms", sCASignatureAlgorithms, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000662 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000663};
664
Darren Tuckere7140f22008-06-10 23:01:51 +1000665static struct {
666 int val;
667 char *text;
668} tunmode_desc[] = {
669 { SSH_TUNMODE_NO, "no" },
670 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
671 { SSH_TUNMODE_ETHERNET, "ethernet" },
672 { SSH_TUNMODE_YES, "yes" },
673 { -1, NULL }
674};
675
djm@openbsd.org115063a2018-06-06 18:22:41 +0000676/* Returns an opcode name from its number */
677
678static const char *
679lookup_opcode_name(ServerOpCodes code)
680{
681 u_int i;
682
683 for (i = 0; keywords[i].name != NULL; i++)
684 if (keywords[i].opcode == code)
685 return(keywords[i].name);
686 return "UNKNOWN";
687}
688
689
Damien Miller5428f641999-11-25 11:54:57 +1100690/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000691 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100692 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000693
Damien Miller4af51302000-04-16 11:18:38 +1000694static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100695parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000696 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000697{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000698 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000699
Damien Miller95def091999-11-25 00:26:21 +1100700 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000701 if (strcasecmp(cp, keywords[i].name) == 0) {
702 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100703 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000704 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000705
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000706 error("%s: line %d: Bad configuration option: %s",
707 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100708 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000709}
710
Darren Tucker88b6fb22010-01-13 22:44:29 +1100711char *
712derelativise_path(const char *path)
713{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000714 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100715
djm@openbsd.org161cf412014-12-22 07:55:51 +0000716 if (strcasecmp(path, "none") == 0)
717 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100718 expanded = tilde_expand_filename(path, getuid());
djm@openbsd.org2a358622018-11-16 03:26:01 +0000719 if (path_absolute(expanded))
Darren Tucker88b6fb22010-01-13 22:44:29 +1100720 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100721 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100722 fatal("%s: getcwd: %s", __func__, strerror(errno));
723 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000724 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100725 return ret;
726}
727
Ben Lindstrombba81212001-06-25 05:01:22 +0000728static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000729add_listen_addr(ServerOptions *options, const char *addr,
730 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100731{
Damien Millereccb9de2005-06-17 12:59:34 +1000732 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100733
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000734 if (port > 0)
735 add_one_listen_addr(options, addr, rdomain, port);
736 else {
737 for (i = 0; i < options->num_ports; i++) {
738 add_one_listen_addr(options, addr, rdomain,
739 options->ports[i]);
740 }
741 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000742}
743
Ben Lindstrombba81212001-06-25 05:01:22 +0000744static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000745add_one_listen_addr(ServerOptions *options, const char *addr,
746 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000747{
748 struct addrinfo hints, *ai, *aitop;
749 char strport[NI_MAXSERV];
750 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000751 u_int i;
752
753 /* Find listen_addrs entry for this rdomain */
754 for (i = 0; i < options->num_listen_addrs; i++) {
755 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
756 break;
757 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
758 continue;
759 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
760 break;
761 }
762 if (i >= options->num_listen_addrs) {
763 /* No entry for this rdomain; allocate one */
764 if (i >= INT_MAX)
765 fatal("%s: too many listen addresses", __func__);
766 options->listen_addrs = xrecallocarray(options->listen_addrs,
767 options->num_listen_addrs, options->num_listen_addrs + 1,
768 sizeof(*options->listen_addrs));
769 i = options->num_listen_addrs++;
770 if (rdomain != NULL)
771 options->listen_addrs[i].rdomain = xstrdup(rdomain);
772 }
773 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000774
775 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100776 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000777 hints.ai_socktype = SOCK_STREAM;
778 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100779 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000780 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
781 fatal("bad addr or host: %s (%s)",
782 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100783 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000784 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
785 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000786 ai->ai_next = options->listen_addrs[i].addrs;
787 options->listen_addrs[i].addrs = aitop;
788}
789
790/* Returns nonzero if the routing domain name is valid */
791static int
792valid_rdomain(const char *name)
793{
Damien Miller43c29bb2017-10-25 13:10:59 +1100794#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100795 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100796#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000797 const char *errstr;
798 long long num;
799 struct rt_tableinfo info;
800 int mib[6];
801 size_t miblen = sizeof(mib);
802
803 if (name == NULL)
804 return 1;
805
806 num = strtonum(name, 0, 255, &errstr);
807 if (errstr != NULL)
808 return 0;
809
810 /* Check whether the table actually exists */
811 memset(mib, 0, sizeof(mib));
812 mib[0] = CTL_NET;
813 mib[1] = PF_ROUTE;
814 mib[4] = NET_RT_TABLE;
815 mib[5] = (int)num;
816 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
817 return 0;
818
819 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100820#else /* defined(__OpenBSD__) */
821 error("Routing domains are not supported on this platform");
822 return 0;
823#endif
Damien Miller34132e52000-01-14 15:45:46 +1100824}
825
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000826/*
827 * Queue a ListenAddress to be processed once we have all of the Ports
828 * and AddressFamily options.
829 */
830static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000831queue_listen_addr(ServerOptions *options, const char *addr,
832 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000833{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000834 struct queued_listenaddr *qla;
835
836 options->queued_listen_addrs = xrecallocarray(
837 options->queued_listen_addrs,
838 options->num_queued_listens, options->num_queued_listens + 1,
839 sizeof(*options->queued_listen_addrs));
840 qla = &options->queued_listen_addrs[options->num_queued_listens++];
841 qla->addr = xstrdup(addr);
842 qla->port = port;
843 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000844}
845
846/*
847 * Process queued (text) ListenAddress entries.
848 */
849static void
850process_queued_listen_addrs(ServerOptions *options)
851{
852 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000853 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000854
855 if (options->num_ports == 0)
856 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
857 if (options->address_family == -1)
858 options->address_family = AF_UNSPEC;
859
860 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000861 qla = &options->queued_listen_addrs[i];
862 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
863 free(qla->addr);
864 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000865 }
866 free(options->queued_listen_addrs);
867 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000868 options->num_queued_listens = 0;
869}
870
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000871/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000872 * Inform channels layer of permitopen options for a single forwarding
873 * direction (local/remote).
874 */
875static void
876process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
877 char **opens, u_int num_opens)
878{
879 u_int i;
880 int port;
881 char *host, *arg, *oarg;
882 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
883 const char *what = lookup_opcode_name(opcode);
884
885 channel_clear_permission(ssh, FORWARD_ADM, where);
886 if (num_opens == 0)
887 return; /* permit any */
888
889 /* handle keywords: "any" / "none" */
890 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
891 return;
892 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
893 channel_disable_admin(ssh, where);
894 return;
895 }
896 /* Otherwise treat it as a list of permitted host:port */
897 for (i = 0; i < num_opens; i++) {
898 oarg = arg = xstrdup(opens[i]);
899 host = hpdelim(&arg);
900 if (host == NULL)
901 fatal("%s: missing host in %s", __func__, what);
902 host = cleanhostname(host);
903 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
904 fatal("%s: bad port number in %s", __func__, what);
905 /* Send it to channels layer */
906 channel_add_permission(ssh, FORWARD_ADM,
907 where, host, port);
908 free(oarg);
909 }
910}
911
912/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000913 * Inform channels layer of permitopen options from configuration.
914 */
915void
916process_permitopen(struct ssh *ssh, ServerOptions *options)
917{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000918 process_permitopen_list(ssh, sPermitOpen,
919 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000920 process_permitopen_list(ssh, sPermitListen,
921 options->permitted_listens,
922 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000923}
924
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000925struct connection_info *
926get_connection_info(int populate, int use_dns)
927{
djm@openbsd.org95767262016-03-07 19:02:43 +0000928 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000929 static struct connection_info ci;
930
931 if (!populate)
932 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000933 ci.host = auth_get_canonical_hostname(ssh, use_dns);
934 ci.address = ssh_remote_ipaddr(ssh);
935 ci.laddress = ssh_local_ipaddr(ssh);
936 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000937 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000938 return &ci;
939}
940
Darren Tucker45150472006-07-12 22:34:17 +1000941/*
942 * The strategy for the Match blocks is that the config file is parsed twice.
943 *
944 * The first time is at startup. activep is initialized to 1 and the
945 * directives in the global context are processed and acted on. Hitting a
946 * Match directive unsets activep and the directives inside the block are
947 * checked for syntax only.
948 *
949 * The second time is after a connection has been established but before
950 * authentication. activep is initialized to 2 and global config directives
951 * are ignored since they have already been processed. If the criteria in a
952 * Match block is met, activep is set and the subsequent directives
953 * processed and actioned until EOF or another Match block unsets it. Any
954 * options set are copied into the main server config.
955 *
956 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000957 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000958 *
959 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
960 * Match Address 192.168.0.*
961 * Tag trusted
962 * Match Group wheel
963 * Tag trusted
964 * Match Tag trusted
965 * AllowTcpForwarding yes
966 * GatewayPorts clientspecified
967 * [...]
968 *
969 * - Add a PermittedChannelRequests directive
970 * Match Group shell
971 * PermittedChannelRequests session,forwarded-tcpip
972 */
973
974static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000975match_cfg_line_group(const char *grps, int line, const char *user)
976{
977 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000978 struct passwd *pw;
979
Damien Miller565ca3f2006-08-19 00:23:15 +1000980 if (user == NULL)
981 goto out;
982
983 if ((pw = getpwnam(user)) == NULL) {
984 debug("Can't match group at line %d because user %.100s does "
985 "not exist", line, user);
986 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
987 debug("Can't Match group because user %.100s not in any group "
988 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000989 } else if (ga_match_pattern_list(grps) != 1) {
990 debug("user %.100s does not match group list %.100s at line %d",
991 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000992 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000993 debug("user %.100s matched group list %.100s at line %d", user,
994 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000995 result = 1;
996 }
997out:
998 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000999 return result;
1000}
1001
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001002static void
1003match_test_missing_fatal(const char *criteria, const char *attrib)
1004{
1005 fatal("'Match %s' in configuration but '%s' not in connection "
1006 "test specification.", criteria, attrib);
1007}
1008
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001009/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +10001010 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +11001011 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +10001012 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001013 */
Damien Miller565ca3f2006-08-19 00:23:15 +10001014static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001015match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +10001016{
Damien Millercf31f382013-10-24 21:02:56 +11001017 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +10001018 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +10001019
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001020 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001021 debug3("checking syntax for 'Match %s'", cp);
1022 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001023 debug3("checking match for '%s' user %s host %s addr %s "
1024 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
1025 ci->host ? ci->host : "(null)",
1026 ci->address ? ci->address : "(null)",
1027 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +10001028
1029 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +11001030 attributes++;
1031 if (strcasecmp(attrib, "all") == 0) {
1032 if (attributes != 1 ||
1033 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1034 error("'all' cannot be combined with other "
1035 "Match attributes");
1036 return -1;
1037 }
1038 *condition = cp;
1039 return 1;
1040 }
Darren Tucker45150472006-07-12 22:34:17 +10001041 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1042 error("Missing Match criteria for %s", attrib);
1043 return -1;
1044 }
Darren Tucker45150472006-07-12 22:34:17 +10001045 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001046 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001047 result = 0;
1048 continue;
1049 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001050 if (ci->user == NULL)
1051 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001052 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001053 result = 0;
1054 else
1055 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001056 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001057 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001058 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001059 result = 0;
1060 continue;
1061 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001062 if (ci->user == NULL)
1063 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001064 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001065 case -1:
1066 return -1;
1067 case 0:
1068 result = 0;
1069 }
Darren Tucker45150472006-07-12 22:34:17 +10001070 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001071 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001072 result = 0;
1073 continue;
1074 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001075 if (ci->host == NULL)
1076 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001077 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001078 result = 0;
1079 else
1080 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001081 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001082 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001083 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001084 result = 0;
1085 continue;
1086 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001087 if (ci->address == NULL)
1088 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001089 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001090 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001091 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001092 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001093 break;
1094 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001095 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001096 result = 0;
1097 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001098 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001099 return -1;
1100 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001101 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001102 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001103 result = 0;
1104 continue;
1105 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001106 if (ci->laddress == NULL)
1107 match_test_missing_fatal("LocalAddress",
1108 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001109 switch (addr_match_list(ci->laddress, arg)) {
1110 case 1:
1111 debug("connection from %.100s matched "
1112 "'LocalAddress %.100s' at line %d",
1113 ci->laddress, arg, line);
1114 break;
1115 case 0:
1116 case -1:
1117 result = 0;
1118 break;
1119 case -2:
1120 return -1;
1121 }
1122 } else if (strcasecmp(attrib, "localport") == 0) {
1123 if ((port = a2port(arg)) == -1) {
1124 error("Invalid LocalPort '%s' on Match line",
1125 arg);
1126 return -1;
1127 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001128 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001129 result = 0;
1130 continue;
1131 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001132 if (ci->lport == 0)
1133 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001134 /* TODO support port lists */
1135 if (port == ci->lport)
1136 debug("connection from %.100s matched "
1137 "'LocalPort %d' at line %d",
1138 ci->laddress, port, line);
1139 else
1140 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001141 } else if (strcasecmp(attrib, "rdomain") == 0) {
1142 if (ci == NULL || ci->rdomain == NULL) {
1143 result = 0;
1144 continue;
1145 }
1146 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1147 result = 0;
1148 else
1149 debug("user %.100s matched 'RDomain %.100s' at "
1150 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001151 } else {
1152 error("Unsupported Match attribute %s", attrib);
1153 return -1;
1154 }
1155 }
Damien Millercf31f382013-10-24 21:02:56 +11001156 if (attributes == 0) {
1157 error("One or more attributes required for Match");
1158 return -1;
1159 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001160 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001161 debug3("match %sfound", result ? "" : "not ");
1162 *condition = cp;
1163 return result;
1164}
1165
Damien Millere2754432006-07-24 14:06:47 +10001166#define WHITESPACE " \t\r\n"
1167
Damien Miller33322122011-06-20 14:43:11 +10001168/* Multistate option parsing */
1169struct multistate {
1170 char *key;
1171 int value;
1172};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001173static const struct multistate multistate_flag[] = {
1174 { "yes", 1 },
1175 { "no", 0 },
1176 { NULL, -1 }
1177};
Damien Miller33322122011-06-20 14:43:11 +10001178static const struct multistate multistate_addressfamily[] = {
1179 { "inet", AF_INET },
1180 { "inet6", AF_INET6 },
1181 { "any", AF_UNSPEC },
1182 { NULL, -1 }
1183};
1184static const struct multistate multistate_permitrootlogin[] = {
1185 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001186 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001187 { "forced-commands-only", PERMIT_FORCED_ONLY },
1188 { "yes", PERMIT_YES },
1189 { "no", PERMIT_NO },
1190 { NULL, -1 }
1191};
1192static const struct multistate multistate_compression[] = {
sf@openbsd.org168b46f2018-07-09 13:37:10 +00001193 { "yes", COMP_DELAYED },
1194 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001195 { "no", COMP_NONE },
1196 { NULL, -1 }
1197};
1198static const struct multistate multistate_gatewayports[] = {
1199 { "clientspecified", 2 },
1200 { "yes", 1 },
1201 { "no", 0 },
1202 { NULL, -1 }
1203};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001204static const struct multistate multistate_tcpfwd[] = {
1205 { "yes", FORWARD_ALLOW },
1206 { "all", FORWARD_ALLOW },
1207 { "no", FORWARD_DENY },
1208 { "remote", FORWARD_REMOTE },
1209 { "local", FORWARD_LOCAL },
1210 { NULL, -1 }
1211};
Damien Miller33322122011-06-20 14:43:11 +10001212
Ben Lindstromade03f62001-12-06 18:22:17 +00001213int
1214process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001215 const char *filename, int linenum, int *activep,
1216 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001217{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001218 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001219 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001220 SyslogFacility *log_facility_ptr;
1221 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001222 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001223 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001224 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001225 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001226 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001227 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001228
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001229 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1230 if ((len = strlen(line)) == 0)
1231 return 0;
1232 for (len--; len > 0; len--) {
1233 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1234 break;
1235 line[len] = '\0';
1236 }
1237
Ben Lindstromade03f62001-12-06 18:22:17 +00001238 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001239 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001240 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001241 /* Ignore leading whitespace */
1242 if (*arg == '\0')
1243 arg = strdelim(&cp);
1244 if (!arg || !*arg || *arg == '#')
1245 return 0;
1246 intptr = NULL;
1247 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001248 opcode = parse_token(arg, filename, linenum, &flags);
1249
1250 if (activep == NULL) { /* We are processing a command line directive */
1251 cmdline = 1;
1252 activep = &cmdline;
1253 }
1254 if (*activep && opcode != sMatch)
1255 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1256 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001257 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001258 fatal("%s line %d: Directive '%s' is not allowed "
1259 "within a Match block", filename, linenum, arg);
1260 } else { /* this is a directive we have already processed */
1261 while (arg)
1262 arg = strdelim(&cp);
1263 return 0;
1264 }
1265 }
1266
Ben Lindstromade03f62001-12-06 18:22:17 +00001267 switch (opcode) {
1268 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001269 case sUsePAM:
1270 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001271 goto parse_flag;
1272
1273 /* Standard Options */
1274 case sBadOption:
1275 return -1;
1276 case sPort:
1277 /* ignore ports from configfile if cmdline specifies ports */
1278 if (options->ports_from_cmdline)
1279 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001280 if (options->num_ports >= MAX_PORTS)
1281 fatal("%s line %d: too many ports.",
1282 filename, linenum);
1283 arg = strdelim(&cp);
1284 if (!arg || *arg == '\0')
1285 fatal("%s line %d: missing port number.",
1286 filename, linenum);
1287 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001288 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001289 fatal("%s line %d: Badly formatted port number.",
1290 filename, linenum);
1291 break;
1292
Ben Lindstromade03f62001-12-06 18:22:17 +00001293 case sLoginGraceTime:
1294 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001295 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001296 arg = strdelim(&cp);
1297 if (!arg || *arg == '\0')
1298 fatal("%s line %d: missing time value.",
1299 filename, linenum);
1300 if ((value = convtime(arg)) == -1)
1301 fatal("%s line %d: invalid time value.",
1302 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001303 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001304 *intptr = value;
1305 break;
1306
Ben Lindstromade03f62001-12-06 18:22:17 +00001307 case sListenAddress:
1308 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001309 if (arg == NULL || *arg == '\0')
1310 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001311 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001312 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1313 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1314 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001315 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001316 p = arg;
1317 } else {
1318 p = hpdelim(&arg);
1319 if (p == NULL)
1320 fatal("%s line %d: bad address:port usage",
1321 filename, linenum);
1322 p = cleanhostname(p);
1323 if (arg == NULL)
1324 port = 0;
1325 else if ((port = a2port(arg)) <= 0)
1326 fatal("%s line %d: bad port number",
1327 filename, linenum);
1328 }
1329 /* Optional routing table */
1330 arg2 = NULL;
1331 if ((arg = strdelim(&cp)) != NULL) {
1332 if (strcmp(arg, "rdomain") != 0 ||
1333 (arg2 = strdelim(&cp)) == NULL)
1334 fatal("%s line %d: bad ListenAddress syntax",
1335 filename, linenum);
1336 if (!valid_rdomain(arg2))
1337 fatal("%s line %d: bad routing domain",
1338 filename, linenum);
1339 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001340
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001341 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001342
Ben Lindstromade03f62001-12-06 18:22:17 +00001343 break;
1344
Darren Tucker0f383232005-01-20 10:57:56 +11001345 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001346 intptr = &options->address_family;
1347 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001348 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001349 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001350 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001351 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001352 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001353 value = -1;
1354 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1355 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1356 value = multistate_ptr[i].value;
1357 break;
1358 }
1359 }
1360 if (value == -1)
1361 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001362 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001363 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001364 *intptr = value;
1365 break;
1366
Ben Lindstromade03f62001-12-06 18:22:17 +00001367 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001368 arg = strdelim(&cp);
1369 if (!arg || *arg == '\0')
1370 fatal("%s line %d: missing file name.",
1371 filename, linenum);
djm@openbsd.org928f1232018-11-19 04:12:32 +00001372 if (*activep) {
1373 servconf_add_hostkey(filename, linenum,
1374 options, arg, 1);
1375 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001376 break;
1377
Damien Miller85b45e02013-07-20 13:21:52 +10001378 case sHostKeyAgent:
1379 charptr = &options->host_key_agent;
1380 arg = strdelim(&cp);
1381 if (!arg || *arg == '\0')
1382 fatal("%s line %d: missing socket name.",
1383 filename, linenum);
1384 if (*activep && *charptr == NULL)
1385 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1386 xstrdup(arg) : derelativise_path(arg);
1387 break;
1388
Damien Miller0a80ca12010-02-27 07:55:05 +11001389 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001390 arg = strdelim(&cp);
1391 if (!arg || *arg == '\0')
1392 fatal("%s line %d: missing file name.",
1393 filename, linenum);
1394 if (*activep)
1395 servconf_add_hostcert(filename, linenum, options, arg);
1396 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001397
Ben Lindstromade03f62001-12-06 18:22:17 +00001398 case sPidFile:
1399 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001400 parse_filename:
1401 arg = strdelim(&cp);
1402 if (!arg || *arg == '\0')
1403 fatal("%s line %d: missing file name.",
1404 filename, linenum);
1405 if (*activep && *charptr == NULL) {
1406 *charptr = derelativise_path(arg);
1407 /* increase optional counter */
1408 if (intptr != NULL)
1409 *intptr = *intptr + 1;
1410 }
1411 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001412
1413 case sPermitRootLogin:
1414 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001415 multistate_ptr = multistate_permitrootlogin;
1416 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001417
1418 case sIgnoreRhosts:
1419 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001420 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001421 multistate_ptr = multistate_flag;
1422 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001423
1424 case sIgnoreUserKnownHosts:
1425 intptr = &options->ignore_user_known_hosts;
1426 goto parse_flag;
1427
Ben Lindstromade03f62001-12-06 18:22:17 +00001428 case sHostbasedAuthentication:
1429 intptr = &options->hostbased_authentication;
1430 goto parse_flag;
1431
1432 case sHostbasedUsesNameFromPacketOnly:
1433 intptr = &options->hostbased_uses_name_from_packet_only;
1434 goto parse_flag;
1435
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001436 case sHostbasedAcceptedKeyTypes:
1437 charptr = &options->hostbased_key_types;
1438 parse_keytypes:
1439 arg = strdelim(&cp);
1440 if (!arg || *arg == '\0')
1441 fatal("%s line %d: Missing argument.",
1442 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001443 if (*arg != '-' &&
1444 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001445 fatal("%s line %d: Bad key types '%s'.",
1446 filename, linenum, arg ? arg : "<NONE>");
1447 if (*activep && *charptr == NULL)
1448 *charptr = xstrdup(arg);
1449 break;
1450
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001451 case sHostKeyAlgorithms:
1452 charptr = &options->hostkeyalgorithms;
1453 goto parse_keytypes;
1454
djm@openbsd.org86e57372018-09-20 03:28:06 +00001455 case sCASignatureAlgorithms:
1456 charptr = &options->ca_sign_algorithms;
1457 goto parse_keytypes;
1458
Ben Lindstromade03f62001-12-06 18:22:17 +00001459 case sPubkeyAuthentication:
1460 intptr = &options->pubkey_authentication;
1461 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001462
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001463 case sPubkeyAcceptedKeyTypes:
1464 charptr = &options->pubkey_key_types;
1465 goto parse_keytypes;
1466
Ben Lindstromade03f62001-12-06 18:22:17 +00001467 case sKerberosAuthentication:
1468 intptr = &options->kerberos_authentication;
1469 goto parse_flag;
1470
1471 case sKerberosOrLocalPasswd:
1472 intptr = &options->kerberos_or_local_passwd;
1473 goto parse_flag;
1474
1475 case sKerberosTicketCleanup:
1476 intptr = &options->kerberos_ticket_cleanup;
1477 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001478
Darren Tucker22ef5082003-12-31 11:37:34 +11001479 case sKerberosGetAFSToken:
1480 intptr = &options->kerberos_get_afs_token;
1481 goto parse_flag;
1482
Darren Tucker0efd1552003-08-26 11:49:55 +10001483 case sGssAuthentication:
1484 intptr = &options->gss_authentication;
1485 goto parse_flag;
1486
1487 case sGssCleanupCreds:
1488 intptr = &options->gss_cleanup_creds;
1489 goto parse_flag;
1490
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001491 case sGssStrictAcceptor:
1492 intptr = &options->gss_strict_acceptor;
1493 goto parse_flag;
1494
Ben Lindstromade03f62001-12-06 18:22:17 +00001495 case sPasswordAuthentication:
1496 intptr = &options->password_authentication;
1497 goto parse_flag;
1498
1499 case sKbdInteractiveAuthentication:
1500 intptr = &options->kbd_interactive_authentication;
1501 goto parse_flag;
1502
1503 case sChallengeResponseAuthentication:
1504 intptr = &options->challenge_response_authentication;
1505 goto parse_flag;
1506
1507 case sPrintMotd:
1508 intptr = &options->print_motd;
1509 goto parse_flag;
1510
1511 case sPrintLastLog:
1512 intptr = &options->print_lastlog;
1513 goto parse_flag;
1514
1515 case sX11Forwarding:
1516 intptr = &options->x11_forwarding;
1517 goto parse_flag;
1518
1519 case sX11DisplayOffset:
1520 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001521 parse_int:
1522 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001523 if ((errstr = atoi_err(arg, &value)) != NULL)
1524 fatal("%s line %d: integer value %s.",
1525 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001526 if (*activep && *intptr == -1)
1527 *intptr = value;
1528 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001529
Damien Miller95c249f2002-02-05 12:11:34 +11001530 case sX11UseLocalhost:
1531 intptr = &options->x11_use_localhost;
1532 goto parse_flag;
1533
Ben Lindstromade03f62001-12-06 18:22:17 +00001534 case sXAuthLocation:
1535 charptr = &options->xauth_location;
1536 goto parse_filename;
1537
Damien Miller5ff30c62013-10-30 22:21:50 +11001538 case sPermitTTY:
1539 intptr = &options->permit_tty;
1540 goto parse_flag;
1541
Damien Miller72e6b5c2014-07-04 09:00:04 +10001542 case sPermitUserRC:
1543 intptr = &options->permit_user_rc;
1544 goto parse_flag;
1545
Ben Lindstromade03f62001-12-06 18:22:17 +00001546 case sStrictModes:
1547 intptr = &options->strict_modes;
1548 goto parse_flag;
1549
Damien Miller12c150e2003-12-17 16:31:10 +11001550 case sTCPKeepAlive:
1551 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001552 goto parse_flag;
1553
1554 case sEmptyPasswd:
1555 intptr = &options->permit_empty_passwd;
1556 goto parse_flag;
1557
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001558 case sPermitUserEnvironment:
1559 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001560 charptr = &options->permit_user_env_whitelist;
1561 arg = strdelim(&cp);
1562 if (!arg || *arg == '\0')
1563 fatal("%s line %d: missing argument.",
1564 filename, linenum);
1565 value = 0;
1566 p = NULL;
1567 if (strcmp(arg, "yes") == 0)
1568 value = 1;
1569 else if (strcmp(arg, "no") == 0)
1570 value = 0;
1571 else {
1572 /* Pattern-list specified */
1573 value = 1;
1574 p = xstrdup(arg);
1575 }
1576 if (*activep && *intptr == -1) {
1577 *intptr = value;
1578 *charptr = p;
1579 p = NULL;
1580 }
1581 free(p);
1582 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001583
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001584 case sCompression:
1585 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001586 multistate_ptr = multistate_compression;
1587 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001588
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001589 case sRekeyLimit:
1590 arg = strdelim(&cp);
1591 if (!arg || *arg == '\0')
1592 fatal("%.200s line %d: Missing argument.", filename,
1593 linenum);
1594 if (strcmp(arg, "default") == 0) {
1595 val64 = 0;
1596 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001597 if (scan_scaled(arg, &val64) == -1)
1598 fatal("%.200s line %d: Bad number '%s': %s",
1599 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001600 if (val64 != 0 && val64 < 16)
1601 fatal("%.200s line %d: RekeyLimit too small",
1602 filename, linenum);
1603 }
1604 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001605 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001606 if (cp != NULL) { /* optional rekey interval present */
1607 if (strcmp(cp, "none") == 0) {
1608 (void)strdelim(&cp); /* discard */
1609 break;
1610 }
1611 intptr = &options->rekey_interval;
1612 goto parse_time;
1613 }
1614 break;
1615
Ben Lindstromade03f62001-12-06 18:22:17 +00001616 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001617 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001618 multistate_ptr = multistate_gatewayports;
1619 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001620
Damien Miller3a961dc2003-06-03 10:25:48 +10001621 case sUseDNS:
1622 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001623 goto parse_flag;
1624
1625 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001626 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001627 arg = strdelim(&cp);
1628 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001629 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001630 fatal("%.200s line %d: unsupported log facility '%s'",
1631 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001632 if (*log_facility_ptr == -1)
1633 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001634 break;
1635
1636 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001637 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001638 arg = strdelim(&cp);
1639 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001640 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001641 fatal("%.200s line %d: unsupported log level '%s'",
1642 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001643 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001644 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001645 break;
1646
1647 case sAllowTcpForwarding:
1648 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001649 multistate_ptr = multistate_tcpfwd;
1650 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001651
Damien Miller7acefbb2014-07-18 14:11:24 +10001652 case sAllowStreamLocalForwarding:
1653 intptr = &options->allow_streamlocal_forwarding;
1654 multistate_ptr = multistate_tcpfwd;
1655 goto parse_multistate;
1656
Damien Miller4f755cd2008-05-19 14:57:41 +10001657 case sAllowAgentForwarding:
1658 intptr = &options->allow_agent_forwarding;
1659 goto parse_flag;
1660
djm@openbsd.org7844f352016-11-30 03:00:05 +00001661 case sDisableForwarding:
1662 intptr = &options->disable_forwarding;
1663 goto parse_flag;
1664
Ben Lindstromade03f62001-12-06 18:22:17 +00001665 case sAllowUsers:
1666 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001667 if (match_user(NULL, NULL, NULL, arg) == -1)
1668 fatal("%s line %d: invalid AllowUsers pattern: "
1669 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001670 if (!*activep)
1671 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001672 array_append(filename, linenum, "AllowUsers",
1673 &options->allow_users, &options->num_allow_users,
1674 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001675 }
1676 break;
1677
1678 case sDenyUsers:
1679 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001680 if (match_user(NULL, NULL, NULL, arg) == -1)
1681 fatal("%s line %d: invalid DenyUsers pattern: "
1682 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001683 if (!*activep)
1684 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001685 array_append(filename, linenum, "DenyUsers",
1686 &options->deny_users, &options->num_deny_users,
1687 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001688 }
1689 break;
1690
1691 case sAllowGroups:
1692 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001693 if (!*activep)
1694 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001695 array_append(filename, linenum, "AllowGroups",
1696 &options->allow_groups, &options->num_allow_groups,
1697 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001698 }
1699 break;
1700
1701 case sDenyGroups:
1702 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001703 if (!*activep)
1704 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001705 array_append(filename, linenum, "DenyGroups",
1706 &options->deny_groups, &options->num_deny_groups,
1707 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001708 }
1709 break;
1710
1711 case sCiphers:
1712 arg = strdelim(&cp);
1713 if (!arg || *arg == '\0')
1714 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001715 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001716 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1717 filename, linenum, arg ? arg : "<NONE>");
1718 if (options->ciphers == NULL)
1719 options->ciphers = xstrdup(arg);
1720 break;
1721
1722 case sMacs:
1723 arg = strdelim(&cp);
1724 if (!arg || *arg == '\0')
1725 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001726 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001727 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1728 filename, linenum, arg ? arg : "<NONE>");
1729 if (options->macs == NULL)
1730 options->macs = xstrdup(arg);
1731 break;
1732
Damien Millerd5f62bf2010-09-24 22:11:14 +10001733 case sKexAlgorithms:
1734 arg = strdelim(&cp);
1735 if (!arg || *arg == '\0')
1736 fatal("%s line %d: Missing argument.",
1737 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001738 if (*arg != '-' &&
1739 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001740 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1741 filename, linenum, arg ? arg : "<NONE>");
1742 if (options->kex_algorithms == NULL)
1743 options->kex_algorithms = xstrdup(arg);
1744 break;
1745
Ben Lindstromade03f62001-12-06 18:22:17 +00001746 case sSubsystem:
1747 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1748 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001749 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001750 }
1751 arg = strdelim(&cp);
1752 if (!arg || *arg == '\0')
1753 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001754 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001755 if (!*activep) {
1756 arg = strdelim(&cp);
1757 break;
1758 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001759 for (i = 0; i < options->num_subsystems; i++)
1760 if (strcmp(arg, options->subsystem_name[i]) == 0)
1761 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001762 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001763 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1764 arg = strdelim(&cp);
1765 if (!arg || *arg == '\0')
1766 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001767 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001768 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001769
1770 /* Collect arguments (separate to executable) */
1771 p = xstrdup(arg);
1772 len = strlen(p) + 1;
1773 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1774 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001775 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001776 strlcat(p, " ", len);
1777 strlcat(p, arg, len);
1778 }
1779 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001780 options->num_subsystems++;
1781 break;
1782
1783 case sMaxStartups:
1784 arg = strdelim(&cp);
1785 if (!arg || *arg == '\0')
1786 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001787 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001788 if ((n = sscanf(arg, "%d:%d:%d",
1789 &options->max_startups_begin,
1790 &options->max_startups_rate,
1791 &options->max_startups)) == 3) {
1792 if (options->max_startups_begin >
1793 options->max_startups ||
1794 options->max_startups_rate > 100 ||
1795 options->max_startups_rate < 1)
1796 fatal("%s line %d: Illegal MaxStartups spec.",
1797 filename, linenum);
1798 } else if (n != 1)
1799 fatal("%s line %d: Illegal MaxStartups spec.",
1800 filename, linenum);
1801 else
1802 options->max_startups = options->max_startups_begin;
1803 break;
1804
Darren Tucker89413db2004-05-24 10:36:23 +10001805 case sMaxAuthTries:
1806 intptr = &options->max_authtries;
1807 goto parse_int;
1808
Damien Miller7207f642008-05-19 15:34:50 +10001809 case sMaxSessions:
1810 intptr = &options->max_sessions;
1811 goto parse_int;
1812
Ben Lindstromade03f62001-12-06 18:22:17 +00001813 case sBanner:
1814 charptr = &options->banner;
1815 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001816
Ben Lindstromade03f62001-12-06 18:22:17 +00001817 /*
1818 * These options can contain %X options expanded at
1819 * connect time, so that you can specify paths like:
1820 *
1821 * AuthorizedKeysFile /etc/ssh_keys/%u
1822 */
1823 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001824 if (*activep && options->num_authkeys_files == 0) {
1825 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001826 arg = tilde_expand_filename(arg, getuid());
1827 array_append(filename, linenum,
1828 "AuthorizedKeysFile",
1829 &options->authorized_keys_files,
1830 &options->num_authkeys_files, arg);
1831 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001832 }
1833 }
1834 return 0;
1835
Damien Miller30da3442010-05-10 11:58:03 +10001836 case sAuthorizedPrincipalsFile:
1837 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001838 arg = strdelim(&cp);
1839 if (!arg || *arg == '\0')
1840 fatal("%s line %d: missing file name.",
1841 filename, linenum);
1842 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001843 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001844 /* increase optional counter */
1845 if (intptr != NULL)
1846 *intptr = *intptr + 1;
1847 }
1848 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001849
1850 case sClientAliveInterval:
1851 intptr = &options->client_alive_interval;
1852 goto parse_time;
1853
1854 case sClientAliveCountMax:
1855 intptr = &options->client_alive_count_max;
1856 goto parse_int;
1857
Darren Tucker46bc0752004-05-02 22:11:30 +10001858 case sAcceptEnv:
1859 while ((arg = strdelim(&cp)) && *arg != '\0') {
1860 if (strchr(arg, '=') != NULL)
1861 fatal("%s line %d: Invalid environment name.",
1862 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001863 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001864 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001865 array_append(filename, linenum, "AcceptEnv",
1866 &options->accept_env, &options->num_accept_env,
1867 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001868 }
1869 break;
1870
djm@openbsd.org28013752018-06-09 03:03:10 +00001871 case sSetEnv:
1872 uvalue = options->num_setenv;
1873 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1874 if (strchr(arg, '=') == NULL)
1875 fatal("%s line %d: Invalid environment.",
1876 filename, linenum);
1877 if (!*activep || uvalue != 0)
1878 continue;
1879 array_append(filename, linenum, "SetEnv",
1880 &options->setenv, &options->num_setenv, arg);
1881 }
1882 break;
1883
Damien Millerd27b9472005-12-13 19:29:02 +11001884 case sPermitTunnel:
1885 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001886 arg = strdelim(&cp);
1887 if (!arg || *arg == '\0')
1888 fatal("%s line %d: Missing yes/point-to-point/"
1889 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001890 value = -1;
1891 for (i = 0; tunmode_desc[i].val != -1; i++)
1892 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1893 value = tunmode_desc[i].val;
1894 break;
1895 }
1896 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001897 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1898 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001899 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001900 *intptr = value;
1901 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001902
Darren Tucker45150472006-07-12 22:34:17 +10001903 case sMatch:
1904 if (cmdline)
1905 fatal("Match directive not supported as a command-line "
1906 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001907 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001908 if (value < 0)
1909 fatal("%s line %d: Bad Match condition", filename,
1910 linenum);
1911 *activep = value;
1912 break;
1913
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001914 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001915 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001916 if (opcode == sPermitListen) {
1917 uintptr = &options->num_permitted_listens;
1918 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001919 } else {
1920 uintptr = &options->num_permitted_opens;
1921 chararrayptr = &options->permitted_opens;
1922 }
Damien Miller9b439df2006-07-24 14:04:00 +10001923 arg = strdelim(&cp);
1924 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001925 fatal("%s line %d: missing %s specification",
1926 filename, linenum, lookup_opcode_name(opcode));
1927 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001928 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001929 if (*activep && uvalue == 0) {
1930 *uintptr = 1;
1931 *chararrayptr = xcalloc(1,
1932 sizeof(**chararrayptr));
1933 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001934 }
Damien Millerc6081482012-04-22 11:18:53 +10001935 break;
1936 }
Damien Millera765cf42006-07-24 14:08:13 +10001937 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001938 if (opcode == sPermitListen &&
1939 strchr(arg, ':') == NULL) {
1940 /*
1941 * Allow bare port number for PermitListen
1942 * to indicate a wildcard listen host.
1943 */
1944 xasprintf(&arg2, "*:%s", arg);
1945 } else {
1946 arg2 = xstrdup(arg);
1947 p = hpdelim(&arg);
1948 if (p == NULL) {
1949 fatal("%s line %d: missing host in %s",
1950 filename, linenum,
1951 lookup_opcode_name(opcode));
1952 }
1953 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001954 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001955 if (arg == NULL ||
1956 ((port = permitopen_port(arg)) < 0)) {
1957 fatal("%s line %d: bad port number in %s",
1958 filename, linenum,
1959 lookup_opcode_name(opcode));
1960 }
1961 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001962 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001963 lookup_opcode_name(opcode),
1964 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001965 }
1966 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001967 }
Damien Miller9b439df2006-07-24 14:04:00 +10001968 break;
1969
Damien Millere2754432006-07-24 14:06:47 +10001970 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001971 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001972 fatal("%.200s line %d: Missing argument.", filename,
1973 linenum);
1974 len = strspn(cp, WHITESPACE);
1975 if (*activep && options->adm_forced_command == NULL)
1976 options->adm_forced_command = xstrdup(cp + len);
1977 return 0;
1978
Damien Millerd8cb1f12008-02-10 22:40:12 +11001979 case sChrootDirectory:
1980 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001981
1982 arg = strdelim(&cp);
1983 if (!arg || *arg == '\0')
1984 fatal("%s line %d: missing file name.",
1985 filename, linenum);
1986 if (*activep && *charptr == NULL)
1987 *charptr = xstrdup(arg);
1988 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001989
Damien Miller1aed65e2010-03-04 21:53:35 +11001990 case sTrustedUserCAKeys:
1991 charptr = &options->trusted_user_ca_keys;
1992 goto parse_filename;
1993
1994 case sRevokedKeys:
1995 charptr = &options->revoked_keys_file;
1996 goto parse_filename;
1997
Damien Miller0dac6fb2010-11-20 15:19:38 +11001998 case sIPQoS:
1999 arg = strdelim(&cp);
2000 if ((value = parse_ipqos(arg)) == -1)
2001 fatal("%s line %d: Bad IPQoS value: %s",
2002 filename, linenum, arg);
2003 arg = strdelim(&cp);
2004 if (arg == NULL)
2005 value2 = value;
2006 else if ((value2 = parse_ipqos(arg)) == -1)
2007 fatal("%s line %d: Bad IPQoS value: %s",
2008 filename, linenum, arg);
2009 if (*activep) {
2010 options->ip_qos_interactive = value;
2011 options->ip_qos_bulk = value2;
2012 }
2013 break;
2014
Damien Miller23528812012-04-22 11:24:43 +10002015 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00002016 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10002017 fatal("%.200s line %d: Missing argument.", filename,
2018 linenum);
2019 len = strspn(cp, WHITESPACE);
2020 if (*activep && options->version_addendum == NULL) {
2021 if (strcasecmp(cp + len, "none") == 0)
2022 options->version_addendum = xstrdup("");
2023 else if (strchr(cp + len, '\r') != NULL)
2024 fatal("%.200s line %d: Invalid argument",
2025 filename, linenum);
2026 else
2027 options->version_addendum = xstrdup(cp + len);
2028 }
2029 return 0;
2030
Damien Miller09d3e122012-10-31 08:58:58 +11002031 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002032 if (cp == NULL)
2033 fatal("%.200s line %d: Missing argument.", filename,
2034 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002035 len = strspn(cp, WHITESPACE);
2036 if (*activep && options->authorized_keys_command == NULL) {
2037 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2038 fatal("%.200s line %d: AuthorizedKeysCommand "
2039 "must be an absolute path",
2040 filename, linenum);
2041 options->authorized_keys_command = xstrdup(cp + len);
2042 }
2043 return 0;
2044
2045 case sAuthorizedKeysCommandUser:
2046 charptr = &options->authorized_keys_command_user;
2047
2048 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002049 if (!arg || *arg == '\0')
2050 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2051 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002052 if (*activep && *charptr == NULL)
2053 *charptr = xstrdup(arg);
2054 break;
2055
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002056 case sAuthorizedPrincipalsCommand:
2057 if (cp == NULL)
2058 fatal("%.200s line %d: Missing argument.", filename,
2059 linenum);
2060 len = strspn(cp, WHITESPACE);
2061 if (*activep &&
2062 options->authorized_principals_command == NULL) {
2063 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2064 fatal("%.200s line %d: "
2065 "AuthorizedPrincipalsCommand must be "
2066 "an absolute path", filename, linenum);
2067 options->authorized_principals_command =
2068 xstrdup(cp + len);
2069 }
2070 return 0;
2071
2072 case sAuthorizedPrincipalsCommandUser:
2073 charptr = &options->authorized_principals_command_user;
2074
2075 arg = strdelim(&cp);
2076 if (!arg || *arg == '\0')
2077 fatal("%s line %d: missing "
2078 "AuthorizedPrincipalsCommandUser argument.",
2079 filename, linenum);
2080 if (*activep && *charptr == NULL)
2081 *charptr = xstrdup(arg);
2082 break;
2083
Damien Millera6e3f012012-11-04 23:21:40 +11002084 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002085 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002086 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002087 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002088 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002089 if (strcmp(arg, "any") == 0) {
2090 if (options->num_auth_methods > 0) {
2091 fatal("%s line %d: \"any\" "
2092 "must appear alone in "
2093 "AuthenticationMethods",
2094 filename, linenum);
2095 }
2096 value = 1;
2097 } else if (value) {
2098 fatal("%s line %d: \"any\" must appear "
2099 "alone in AuthenticationMethods",
2100 filename, linenum);
2101 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002102 fatal("%s line %d: invalid "
2103 "authentication method list.",
2104 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002105 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002106 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002107 if (!*activep)
2108 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002109 array_append(filename, linenum,
2110 "AuthenticationMethods",
2111 &options->auth_methods,
2112 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002113 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002114 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002115 fatal("%s line %d: no AuthenticationMethods "
2116 "specified", filename, linenum);
2117 }
Damien Millera6e3f012012-11-04 23:21:40 +11002118 }
2119 return 0;
2120
Damien Miller7acefbb2014-07-18 14:11:24 +10002121 case sStreamLocalBindMask:
2122 arg = strdelim(&cp);
2123 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002124 fatal("%s line %d: missing StreamLocalBindMask "
2125 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002126 /* Parse mode in octal format */
2127 value = strtol(arg, &p, 8);
2128 if (arg == p || value < 0 || value > 0777)
2129 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002130 if (*activep)
2131 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002132 break;
2133
2134 case sStreamLocalBindUnlink:
2135 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2136 goto parse_flag;
2137
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002138 case sFingerprintHash:
2139 arg = strdelim(&cp);
2140 if (!arg || *arg == '\0')
2141 fatal("%.200s line %d: Missing argument.",
2142 filename, linenum);
2143 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2144 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2145 filename, linenum, arg);
2146 if (*activep)
2147 options->fingerprint_hash = value;
2148 break;
2149
djm@openbsd.org8f574952017-06-24 06:34:38 +00002150 case sExposeAuthInfo:
2151 intptr = &options->expose_userauth_info;
2152 goto parse_flag;
2153
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002154 case sRDomain:
2155 charptr = &options->routing_domain;
2156 arg = strdelim(&cp);
2157 if (!arg || *arg == '\0')
2158 fatal("%.200s line %d: Missing argument.",
2159 filename, linenum);
2160 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2161 !valid_rdomain(arg))
2162 fatal("%s line %d: bad routing domain",
2163 filename, linenum);
2164 if (*activep && *charptr == NULL)
2165 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002166 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002167
Ben Lindstromade03f62001-12-06 18:22:17 +00002168 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002169 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002170 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002171 do_log2(opcode == sIgnore ?
2172 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2173 "%s line %d: %s option %s", filename, linenum,
2174 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002175 while (arg)
2176 arg = strdelim(&cp);
2177 break;
2178
Ben Lindstromade03f62001-12-06 18:22:17 +00002179 default:
2180 fatal("%s line %d: Missing handler for opcode %s (%d)",
2181 filename, linenum, arg, opcode);
2182 }
2183 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2184 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2185 filename, linenum, arg);
2186 return 0;
2187}
2188
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002189/* Reads the server configuration file. */
2190
Damien Miller4af51302000-04-16 11:18:38 +10002191void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002192load_server_config(const char *filename, struct sshbuf *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002193{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002194 char *line = NULL, *cp;
2195 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002196 FILE *f;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002197 int r, lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002198
Darren Tucker645ab752004-06-25 13:33:20 +10002199 debug2("%s: filename %s", __func__, filename);
2200 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002201 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002202 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002203 }
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002204 sshbuf_reset(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002205 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002206 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002207 /*
2208 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002209 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002210 * line numbers later for error messages
2211 */
2212 if ((cp = strchr(line, '#')) != NULL)
2213 memcpy(cp, "\n", 2);
2214 cp = line + strspn(line, " \t\r");
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002215 if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2216 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002217 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002218 free(line);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002219 if ((r = sshbuf_put_u8(conf, 0)) != 0)
2220 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002221 fclose(f);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002222 debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002223}
2224
2225void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002226parse_server_match_config(ServerOptions *options,
2227 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002228{
Darren Tucker45150472006-07-12 22:34:17 +10002229 ServerOptions mo;
2230
2231 initialize_server_options(&mo);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002232 parse_server_config(&mo, "reprocess config", cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002233 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002234}
2235
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002236int parse_server_match_testspec(struct connection_info *ci, char *spec)
2237{
2238 char *p;
2239
2240 while ((p = strsep(&spec, ",")) && *p != '\0') {
2241 if (strncmp(p, "addr=", 5) == 0) {
2242 ci->address = xstrdup(p + 5);
2243 } else if (strncmp(p, "host=", 5) == 0) {
2244 ci->host = xstrdup(p + 5);
2245 } else if (strncmp(p, "user=", 5) == 0) {
2246 ci->user = xstrdup(p + 5);
2247 } else if (strncmp(p, "laddr=", 6) == 0) {
2248 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002249 } else if (strncmp(p, "rdomain=", 8) == 0) {
2250 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002251 } else if (strncmp(p, "lport=", 6) == 0) {
2252 ci->lport = a2port(p + 6);
2253 if (ci->lport == -1) {
2254 fprintf(stderr, "Invalid port '%s' in test mode"
2255 " specification %s\n", p+6, p);
2256 return -1;
2257 }
2258 } else {
2259 fprintf(stderr, "Invalid test mode specification %s\n",
2260 p);
2261 return -1;
2262 }
2263 }
2264 return 0;
2265}
2266
2267/*
Darren Tucker1629c072007-02-19 22:25:37 +11002268 * Copy any supported values that are set.
2269 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002270 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002271 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002272 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002273 */
Darren Tucker45150472006-07-12 22:34:17 +10002274void
Darren Tucker1629c072007-02-19 22:25:37 +11002275copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002276{
Damien Miller534b2cc2013-12-05 14:07:27 +11002277#define M_CP_INTOPT(n) do {\
2278 if (src->n != -1) \
2279 dst->n = src->n; \
2280} while (0)
2281
Darren Tucker1629c072007-02-19 22:25:37 +11002282 M_CP_INTOPT(password_authentication);
2283 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002284 M_CP_INTOPT(pubkey_authentication);
2285 M_CP_INTOPT(kerberos_authentication);
2286 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002287 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002288 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002289 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002290 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002291
2292 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002293 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002294 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002295 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002296 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002297 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002298 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002299 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002300 M_CP_INTOPT(x11_display_offset);
2301 M_CP_INTOPT(x11_forwarding);
2302 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002303 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002304 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002305 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002306 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002307 M_CP_INTOPT(client_alive_count_max);
2308 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002309 M_CP_INTOPT(ip_qos_interactive);
2310 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002311 M_CP_INTOPT(rekey_limit);
2312 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002313 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002314
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002315 /*
2316 * The bind_mask is a mode_t that may be unsigned, so we can't use
2317 * M_CP_INTOPT - it does a signed comparison that causes compiler
2318 * warnings.
2319 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002320 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002321 dst->fwd_opts.streamlocal_bind_mask =
2322 src->fwd_opts.streamlocal_bind_mask;
2323 }
2324
Damien Miller534b2cc2013-12-05 14:07:27 +11002325 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2326#define M_CP_STROPT(n) do {\
2327 if (src->n != NULL && dst->n != src->n) { \
2328 free(dst->n); \
2329 dst->n = src->n; \
2330 } \
2331} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002332#define M_CP_STRARRAYOPT(s, num_s) do {\
2333 u_int i; \
2334 if (src->num_s != 0) { \
2335 for (i = 0; i < dst->num_s; i++) \
2336 free(dst->s[i]); \
2337 free(dst->s); \
2338 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2339 for (i = 0; i < src->num_s; i++) \
2340 dst->s[i] = xstrdup(src->s[i]); \
2341 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002342 } \
2343} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002344
Damien Millerf2e407e2011-05-20 19:04:14 +10002345 /* See comment in servconf.h */
2346 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002347
djm@openbsd.orged085102015-10-29 08:05:01 +00002348 /* Arguments that accept '+...' need to be expanded */
2349 assemble_algorithms(dst);
2350
Damien Millerc2411902011-05-20 19:03:49 +10002351 /*
2352 * The only things that should be below this point are string options
2353 * which are only used after authentication.
2354 */
Damien Miller5d74e582011-05-20 19:03:31 +10002355 if (preauth)
2356 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002357
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002358 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002359 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002360 if (option_clear_or_none(dst->adm_forced_command)) {
2361 free(dst->adm_forced_command);
2362 dst->adm_forced_command = NULL;
2363 }
Damien Miller5d74e582011-05-20 19:03:31 +10002364 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002365 if (option_clear_or_none(dst->chroot_directory)) {
2366 free(dst->chroot_directory);
2367 dst->chroot_directory = NULL;
2368 }
Darren Tucker45150472006-07-12 22:34:17 +10002369}
2370
Darren Tucker1629c072007-02-19 22:25:37 +11002371#undef M_CP_INTOPT
2372#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002373#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002374
Darren Tucker45150472006-07-12 22:34:17 +10002375void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002376parse_server_config(ServerOptions *options, const char *filename,
2377 struct sshbuf *conf, struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002378{
2379 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002380 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002381
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002382 debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002383
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002384 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2385 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002386 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002387 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002388 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002389 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002390 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002391 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002392 }
Darren Tuckera627d422013-06-02 07:31:17 +10002393 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002394 if (bad_options > 0)
2395 fatal("%s: terminating, %d bad configuration options",
2396 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002397 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002398}
Darren Tuckere7140f22008-06-10 23:01:51 +10002399
2400static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002401fmt_multistate_int(int val, const struct multistate *m)
2402{
2403 u_int i;
2404
2405 for (i = 0; m[i].key != NULL; i++) {
2406 if (m[i].value == val)
2407 return m[i].key;
2408 }
2409 return "UNKNOWN";
2410}
2411
2412static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002413fmt_intarg(ServerOpCodes code, int val)
2414{
Damien Miller82c55872011-06-23 08:20:30 +10002415 if (val == -1)
2416 return "unset";
2417 switch (code) {
2418 case sAddressFamily:
2419 return fmt_multistate_int(val, multistate_addressfamily);
2420 case sPermitRootLogin:
2421 return fmt_multistate_int(val, multistate_permitrootlogin);
2422 case sGatewayPorts:
2423 return fmt_multistate_int(val, multistate_gatewayports);
2424 case sCompression:
2425 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002426 case sAllowTcpForwarding:
2427 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002428 case sAllowStreamLocalForwarding:
2429 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002430 case sFingerprintHash:
2431 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002432 default:
2433 switch (val) {
2434 case 0:
2435 return "no";
2436 case 1:
2437 return "yes";
2438 default:
2439 return "UNKNOWN";
2440 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002441 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002442}
2443
Darren Tuckere7140f22008-06-10 23:01:51 +10002444static void
2445dump_cfg_int(ServerOpCodes code, int val)
2446{
2447 printf("%s %d\n", lookup_opcode_name(code), val);
2448}
2449
2450static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002451dump_cfg_oct(ServerOpCodes code, int val)
2452{
2453 printf("%s 0%o\n", lookup_opcode_name(code), val);
2454}
2455
2456static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002457dump_cfg_fmtint(ServerOpCodes code, int val)
2458{
2459 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2460}
2461
2462static void
2463dump_cfg_string(ServerOpCodes code, const char *val)
2464{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002465 printf("%s %s\n", lookup_opcode_name(code),
2466 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002467}
2468
2469static void
2470dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2471{
2472 u_int i;
2473
2474 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002475 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2476}
2477
2478static void
2479dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2480{
2481 u_int i;
2482
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002483 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002484 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002485 printf("%s", lookup_opcode_name(code));
2486 for (i = 0; i < count; i++)
2487 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002488 if (code == sAuthenticationMethods && count == 0)
2489 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002490 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002491}
2492
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002493static char *
2494format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002495{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002496 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002497 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002498 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002499 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002500
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002501 /*
2502 * ListenAddress must be after Port. add_one_listen_addr pushes
2503 * addresses onto a stack, so to maintain ordering we need to
2504 * print these in reverse order.
2505 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002506 for (ai = la->addrs; ai; ai = ai->ai_next) {
2507 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002508 sizeof(addr), port, sizeof(port),
2509 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002510 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2511 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002512 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002513 laddr2 = laddr1;
2514 if (ai->ai_family == AF_INET6) {
2515 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2516 addr, port,
2517 la->rdomain == NULL ? "" : " rdomain ",
2518 la->rdomain == NULL ? "" : la->rdomain,
2519 laddr2);
2520 } else {
2521 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2522 addr, port,
2523 la->rdomain == NULL ? "" : " rdomain ",
2524 la->rdomain == NULL ? "" : la->rdomain,
2525 laddr2);
2526 }
2527 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002528 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002529 return laddr1;
2530}
2531
2532void
2533dump_config(ServerOptions *o)
2534{
2535 char *s;
2536 u_int i;
2537
2538 /* these are usually at the top of the config */
2539 for (i = 0; i < o->num_ports; i++)
2540 printf("port %d\n", o->ports[i]);
2541 dump_cfg_fmtint(sAddressFamily, o->address_family);
2542
2543 for (i = 0; i < o->num_listen_addrs; i++) {
2544 s = format_listen_addrs(&o->listen_addrs[i]);
2545 printf("%s", s);
2546 free(s);
2547 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002548
2549 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002550#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002551 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002552#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002553 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002554 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2555 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002556 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002557 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2558 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002559 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002560
2561 /* formatted integer arguments */
2562 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2563 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2564 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002565 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2566 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2567 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002568 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002569#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002570 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2571 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2572 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002573# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002574 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002575# endif
2576#endif
2577#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002578 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2579 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002580#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002581 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2582 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2583 o->kbd_interactive_authentication);
2584 dump_cfg_fmtint(sChallengeResponseAuthentication,
2585 o->challenge_response_authentication);
2586 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002587#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002588 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002589#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002590 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2591 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002592 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002593 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002594 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2595 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2596 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002597 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002598 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002599 dump_cfg_fmtint(sUseDNS, o->use_dns);
2600 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002601 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002602 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002603 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002604 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002605 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002606 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002607
2608 /* string arguments */
2609 dump_cfg_string(sPidFile, o->pid_file);
2610 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002611 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2612 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002613 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002614 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002615 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002616 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2617 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002618 dump_cfg_string(sAuthorizedPrincipalsFile,
2619 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002620 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2621 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002622 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2623 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002624 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2625 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002626 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002627 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002628 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org86e57372018-09-20 03:28:06 +00002629 dump_cfg_string(sCASignatureAlgorithms, o->ca_sign_algorithms ?
2630 o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002631 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2632 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002633 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2634 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002635 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2636 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002637 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002638
2639 /* string arguments requiring a lookup */
2640 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2641 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2642
2643 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002644 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2645 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002646 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2647 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002648 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002649 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002650 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2651 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2652 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2653 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2654 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002655 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002656 dump_cfg_strarray_oneline(sAuthenticationMethods,
2657 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002658
2659 /* other arguments */
2660 for (i = 0; i < o->num_subsystems; i++)
2661 printf("subsystem %s %s\n", o->subsystem_name[i],
2662 o->subsystem_args[i]);
2663
2664 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2665 o->max_startups_rate, o->max_startups);
2666
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002667 s = NULL;
2668 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002669 if (tunmode_desc[i].val == o->permit_tun) {
2670 s = tunmode_desc[i].text;
2671 break;
2672 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002673 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002674 dump_cfg_string(sPermitTunnel, s);
2675
Damien Miller91475862011-05-05 14:14:34 +10002676 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2677 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002678
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002679 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002680 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002681
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002682 printf("permitopen");
2683 if (o->num_permitted_opens == 0)
2684 printf(" any");
2685 else {
2686 for (i = 0; i < o->num_permitted_opens; i++)
2687 printf(" %s", o->permitted_opens[i]);
2688 }
2689 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002690 printf("permitlisten");
2691 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002692 printf(" any");
2693 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002694 for (i = 0; i < o->num_permitted_listens; i++)
2695 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002696 }
2697 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002698
2699 if (o->permit_user_env_whitelist == NULL) {
2700 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2701 } else {
2702 printf("permituserenvironment %s\n",
2703 o->permit_user_env_whitelist);
2704 }
2705
Darren Tuckere7140f22008-06-10 23:01:51 +10002706}