blob: 0ec095bd0ffd288cd1cfb8168093474b335004d6 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org0fa174e2019-01-19 21:31:32 +00002/* $OpenBSD: servconf.c,v 1.345 2019/01/19 21:31: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.org0fa174e2019-01-19 21:31:32 +000068#include "opacket.h" /* XXX */
69extern struct ssh *active_state; /* XXX */
70
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000071static void add_listen_addr(ServerOptions *, const char *,
72 const char *, int);
73static void add_one_listen_addr(ServerOptions *, const char *,
74 const char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110075
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000076/* Use of privilege separation or not */
77extern int use_privsep;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +000078extern struct sshbuf *cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000079
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080/* Initializes the server options to their default values. */
81
Damien Miller4af51302000-04-16 11:18:38 +100082void
Damien Miller95def091999-11-25 00:26:21 +110083initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100084{
Damien Miller95def091999-11-25 00:26:21 +110085 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110086
87 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100088 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110089
90 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110091 options->num_ports = 0;
92 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000093 options->queued_listen_addrs = NULL;
94 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110095 options->listen_addrs = NULL;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +000096 options->num_listen_addrs = 0;
Darren Tucker0f383232005-01-20 10:57:56 +110097 options->address_family = -1;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +000098 options->routing_domain = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110099 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +1100100 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +1000101 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +1000102 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000104 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100105 options->ignore_rhosts = -1;
106 options->ignore_user_known_hosts = -1;
107 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000108 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +1100109 options->x11_forwarding = -1;
110 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +1100111 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100112 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000113 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000114 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100115 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100116 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100117 options->log_facility = SYSLOG_FACILITY_NOT_SET;
118 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000119 options->hostbased_authentication = -1;
120 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000121 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000122 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100123 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000124 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100125 options->kerberos_authentication = -1;
126 options->kerberos_or_local_passwd = -1;
127 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100128 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000129 options->gss_authentication=-1;
130 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000131 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100132 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100133 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000134 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100135 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000136 options->permit_user_env = -1;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000137 options->permit_user_env_whitelist = NULL;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000138 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000139 options->rekey_limit = -1;
140 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100141 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000142 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000143 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100144 options->num_allow_users = 0;
145 options->num_deny_users = 0;
146 options->num_allow_groups = 0;
147 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000148 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000149 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000150 options->kex_algorithms = NULL;
djm@openbsd.org86e57372018-09-20 03:28:06 +0000151 options->ca_sign_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000152 options->fwd_opts.gateway_ports = -1;
153 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
154 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000155 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000156 options->max_startups_begin = -1;
157 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000158 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000159 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000160 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000161 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000162 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000163 options->client_alive_interval = -1;
164 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000165 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000166 options->num_accept_env = 0;
djm@openbsd.org28013752018-06-09 03:03:10 +0000167 options->num_setenv = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100168 options->permit_tun = -1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000169 options->permitted_opens = NULL;
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000170 options->permitted_listens = NULL;
Damien Millere2754432006-07-24 14:06:47 +1000171 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100172 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100173 options->authorized_keys_command = NULL;
174 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100175 options->revoked_keys_file = NULL;
176 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000177 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000178 options->authorized_principals_command = NULL;
179 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100180 options->ip_qos_interactive = -1;
181 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000182 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000183 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000184 options->disable_forwarding = -1;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000185 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000186}
187
djm@openbsd.org161cf412014-12-22 07:55:51 +0000188/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
189static int
190option_clear_or_none(const char *o)
191{
192 return o == NULL || strcasecmp(o, "none") == 0;
193}
194
djm@openbsd.orged085102015-10-29 08:05:01 +0000195static void
196assemble_algorithms(ServerOptions *o)
197{
djm@openbsd.org86e57372018-09-20 03:28:06 +0000198 char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +0000199 int r;
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000200
201 all_cipher = cipher_alg_list(',', 0);
202 all_mac = mac_alg_list(',');
203 all_kex = kex_alg_list(',');
204 all_key = sshkey_alg_list(0, 0, 1, ',');
djm@openbsd.org86e57372018-09-20 03:28:06 +0000205 all_sig = sshkey_alg_list(0, 1, 1, ',');
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +0000206#define ASSEMBLE(what, defaults, all) \
207 do { \
208 if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
209 fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
210 } while (0)
211 ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher);
212 ASSEMBLE(macs, KEX_SERVER_MAC, all_mac);
213 ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex);
214 ASSEMBLE(hostkeyalgorithms, KEX_DEFAULT_PK_ALG, all_key);
215 ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
216 ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key);
djm@openbsd.org86e57372018-09-20 03:28:06 +0000217 ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +0000218#undef ASSEMBLE
djm@openbsd.org312d2f22018-07-04 13:49:31 +0000219 free(all_cipher);
220 free(all_mac);
221 free(all_kex);
222 free(all_key);
djm@openbsd.org86e57372018-09-20 03:28:06 +0000223 free(all_sig);
djm@openbsd.orged085102015-10-29 08:05:01 +0000224}
225
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000226static void
djm@openbsd.org928f1232018-11-19 04:12:32 +0000227array_append2(const char *file, const int line, const char *directive,
228 char ***array, int **iarray, u_int *lp, const char *s, int i)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000229{
230
231 if (*lp >= INT_MAX)
232 fatal("%s line %d: Too many %s entries", file, line, directive);
233
djm@openbsd.org928f1232018-11-19 04:12:32 +0000234 if (iarray != NULL) {
235 *iarray = xrecallocarray(*iarray, *lp, *lp + 1,
236 sizeof(**iarray));
237 (*iarray)[*lp] = i;
238 }
239
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000240 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
241 (*array)[*lp] = xstrdup(s);
242 (*lp)++;
243}
244
djm@openbsd.org928f1232018-11-19 04:12:32 +0000245static void
246array_append(const char *file, const int line, const char *directive,
247 char ***array, u_int *lp, const char *s)
248{
249 array_append2(file, line, directive, array, NULL, lp, s, 0);
250}
251
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000252void
253servconf_add_hostkey(const char *file, const int line,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000254 ServerOptions *options, const char *path, int userprovided)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000255{
256 char *apath = derelativise_path(path);
257
djm@openbsd.org928f1232018-11-19 04:12:32 +0000258 array_append2(file, line, "HostKey",
259 &options->host_key_files, &options->host_key_file_userprovided,
260 &options->num_host_key_files, apath, userprovided);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000261 free(apath);
262}
263
264void
265servconf_add_hostcert(const char *file, const int line,
266 ServerOptions *options, const char *path)
267{
268 char *apath = derelativise_path(path);
269
270 array_append(file, line, "HostCertificate",
271 &options->host_cert_files, &options->num_host_cert_files, apath);
272 free(apath);
273}
274
Damien Miller4af51302000-04-16 11:18:38 +1000275void
Damien Miller95def091999-11-25 00:26:21 +1100276fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000277{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000278 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000279
Damien Miller726273e2001-11-12 11:40:11 +1100280 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000281 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000282 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100283
284 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100285 if (options->num_host_key_files == 0) {
286 /* fill default hostkeys for protocols */
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_RSA_KEY_FILE, 0);
Damien Millerdd190dd2010-11-11 14:17:02 +1100289#ifdef OPENSSL_HAS_ECC
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_ECDSA_KEY_FILE, 0);
Damien Millerdd190dd2010-11-11 14:17:02 +1100292#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000293 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000294 _PATH_HOST_ED25519_KEY_FILE, 0);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000295#ifdef WITH_XMSS
markus@openbsd.org1b11ea72018-02-23 15:58:37 +0000296 servconf_add_hostkey("[default]", 0, options,
djm@openbsd.org928f1232018-11-19 04:12:32 +0000297 _PATH_HOST_XMSS_KEY_FILE, 0);
markus@openbsd.org5886b922018-03-01 20:32:16 +0000298#endif /* WITH_XMSS */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100299 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100300 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100301 if (options->num_ports == 0)
302 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000303 if (options->address_family == -1)
304 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100305 if (options->listen_addrs == NULL)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000306 add_listen_addr(options, NULL, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000307 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000308 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100309 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000310 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000311 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000312 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100313 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100314 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100315 if (options->ignore_user_known_hosts == -1)
316 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100317 if (options->print_motd == -1)
318 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000319 if (options->print_lastlog == -1)
320 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100321 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100322 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100323 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100324 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100325 if (options->x11_use_localhost == -1)
326 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000327 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000328 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100329 if (options->permit_tty == -1)
330 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000331 if (options->permit_user_rc == -1)
332 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100333 if (options->strict_modes == -1)
334 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100335 if (options->tcp_keep_alive == -1)
336 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100337 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100338 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100339 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000340 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000341 if (options->hostbased_authentication == -1)
342 options->hostbased_authentication = 0;
343 if (options->hostbased_uses_name_from_packet_only == -1)
344 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100345 if (options->pubkey_authentication == -1)
346 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100347 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000348 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100349 if (options->kerberos_or_local_passwd == -1)
350 options->kerberos_or_local_passwd = 1;
351 if (options->kerberos_ticket_cleanup == -1)
352 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100353 if (options->kerberos_get_afs_token == -1)
354 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000355 if (options->gss_authentication == -1)
356 options->gss_authentication = 0;
357 if (options->gss_cleanup_creds == -1)
358 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000359 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000360 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100361 if (options->password_authentication == -1)
362 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100363 if (options->kbd_interactive_authentication == -1)
364 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000365 if (options->challenge_response_authentication == -1)
366 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100367 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100368 options->permit_empty_passwd = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000369 if (options->permit_user_env == -1) {
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000370 options->permit_user_env = 0;
djm@openbsd.org95344c22018-07-03 10:59:35 +0000371 options->permit_user_env_whitelist = NULL;
372 }
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000373 if (options->compression == -1)
sf@openbsd.org168b46f2018-07-09 13:37:10 +0000374 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000375 if (options->rekey_limit == -1)
376 options->rekey_limit = 0;
377 if (options->rekey_interval == -1)
378 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100379 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100380 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000381 if (options->allow_streamlocal_forwarding == -1)
382 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000383 if (options->allow_agent_forwarding == -1)
384 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000385 if (options->fwd_opts.gateway_ports == -1)
386 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000387 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100388 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000389 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100390 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000391 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100392 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000393 if (options->max_authtries == -1)
394 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000395 if (options->max_sessions == -1)
396 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000397 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000398 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000399 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100400 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000401 if (options->client_alive_count_max == -1)
402 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000403 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000404 array_append("[default]", 0, "AuthorizedKeysFiles",
405 &options->authorized_keys_files,
406 &options->num_authkeys_files,
407 _PATH_SSH_USER_PERMITTED_KEYS);
408 array_append("[default]", 0, "AuthorizedKeysFiles",
409 &options->authorized_keys_files,
410 &options->num_authkeys_files,
411 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000412 }
Damien Millerd27b9472005-12-13 19:29:02 +1100413 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100414 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100415 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000416 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100417 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +0000418 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller23528812012-04-22 11:24:43 +1000419 if (options->version_addendum == NULL)
420 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000421 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
422 options->fwd_opts.streamlocal_bind_mask = 0177;
423 if (options->fwd_opts.streamlocal_bind_unlink == -1)
424 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000425 if (options->fingerprint_hash == -1)
426 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000427 if (options->disable_forwarding == -1)
428 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000429 if (options->expose_userauth_info == -1)
430 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000431
djm@openbsd.orged085102015-10-29 08:05:01 +0000432 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000433
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000434 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000435 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000436 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000437
djm@openbsd.org161cf412014-12-22 07:55:51 +0000438#define CLEAR_ON_NONE(v) \
439 do { \
440 if (option_clear_or_none(v)) { \
441 free(v); \
442 v = NULL; \
443 } \
444 } while(0)
445 CLEAR_ON_NONE(options->pid_file);
446 CLEAR_ON_NONE(options->xauth_location);
447 CLEAR_ON_NONE(options->banner);
448 CLEAR_ON_NONE(options->trusted_user_ca_keys);
449 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000450 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000451 CLEAR_ON_NONE(options->adm_forced_command);
452 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000453 CLEAR_ON_NONE(options->routing_domain);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000454 for (i = 0; i < options->num_host_key_files; i++)
455 CLEAR_ON_NONE(options->host_key_files[i]);
456 for (i = 0; i < options->num_host_cert_files; i++)
457 CLEAR_ON_NONE(options->host_cert_files[i]);
458#undef CLEAR_ON_NONE
459
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000460 /* Similar handling for AuthenticationMethods=any */
461 if (options->num_auth_methods == 1 &&
462 strcmp(options->auth_methods[0], "any") == 0) {
463 free(options->auth_methods[0]);
464 options->auth_methods[0] = NULL;
465 options->num_auth_methods = 0;
466 }
467
Tim Rice40017b02002-07-14 13:36:49 -0700468#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000469 if (use_privsep && options->compression == 1) {
470 error("This platform does not support both privilege "
471 "separation and compression");
472 error("Compression disabled");
473 options->compression = 0;
474 }
475#endif
476
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000477}
478
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000479/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100480typedef enum {
481 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100482 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000483 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100484 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000485 sPort, sHostKeyFile, sLoginGraceTime,
486 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000487 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100488 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
dtucker@openbsd.org745771f2018-02-09 02:37:36 +0000489 sKerberosGetAFSToken, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100490 sPasswordAuthentication, sKbdInteractiveAuthentication,
491 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000492 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100493 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100494 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000495 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000496 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000497 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000498 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
499 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000500 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000501 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000502 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000503 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000504 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
djm@openbsd.org28013752018-06-09 03:03:10 +0000505 sAcceptEnv, sSetEnv, sPermitTunnel,
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000506 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100507 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100508 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000509 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000510 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
djm@openbsd.org86e57372018-09-20 03:28:06 +0000511 sKexAlgorithms, sCASignatureAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100512 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000513 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000514 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000515 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000516 sExposeAuthInfo, sRDomain,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000517 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000518} ServerOpCodes;
519
Darren Tucker45150472006-07-12 22:34:17 +1000520#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
521#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
522#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
523
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000524/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100525static struct {
526 const char *name;
527 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000528 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100529} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100530 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000531#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000532 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000533#else
Darren Tucker45150472006-07-12 22:34:17 +1000534 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000535#endif
Darren Tucker45150472006-07-12 22:34:17 +1000536 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100537 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000538 { "port", sPort, SSHCFG_GLOBAL },
539 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
540 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000541 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000542 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000543 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000544 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000545 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100546 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000547 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000548 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000549 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000550 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100551 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000552 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000553 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000554 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000555 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100556 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000557 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000558 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000559#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100560 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000561 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
562 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100563#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000564 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000565#else
Darren Tucker45150472006-07-12 22:34:17 +1000566 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100567#endif
568#else
Darren Tucker1629c072007-02-19 22:25:37 +1100569 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000570 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
571 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
572 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000573#endif
Darren Tucker45150472006-07-12 22:34:17 +1000574 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
575 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000576#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100577 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000578 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000579 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000580#else
Darren Tucker1629c072007-02-19 22:25:37 +1100581 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000582 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000583 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000584#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100585 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
586 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100587 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Damien Miller87f08be2018-07-20 13:18:28 +1000588 { "skeyauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000589 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
590 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
591 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
592 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100593#ifdef DISABLE_LASTLOG
594 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
595#else
Darren Tucker45150472006-07-12 22:34:17 +1000596 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100597#endif
Darren Tucker45150472006-07-12 22:34:17 +1000598 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
599 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000600 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
601 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
602 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000603 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
604 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100605 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000606 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000607 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000608 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000609 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000610 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
611 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
612 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000613 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000614 { "allowusers", sAllowUsers, SSHCFG_ALL },
615 { "denyusers", sDenyUsers, SSHCFG_ALL },
616 { "allowgroups", sAllowGroups, SSHCFG_ALL },
617 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000618 { "ciphers", sCiphers, SSHCFG_GLOBAL },
619 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000620 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000621 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
622 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
623 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000624 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000625 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100626 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000627 { "usedns", sUseDNS, SSHCFG_GLOBAL },
628 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
629 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000630 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
631 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000632 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000633 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000634 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000635 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
djm@openbsd.org28013752018-06-09 03:03:10 +0000636 { "setenv", sSetEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000637 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100638 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000639 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000640 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000641 { "permitopen", sPermitOpen, SSHCFG_ALL },
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000642 { "permitlisten", sPermitListen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000643 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100644 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100645 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100646 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
647 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000648 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000649 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100650 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100651 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
652 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000653 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
654 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000655 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100656 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000657 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
658 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
659 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000660 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000661 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000662 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
djm@openbsd.org35eb33f2017-10-25 00:17:08 +0000663 { "rdomain", sRDomain, SSHCFG_ALL },
djm@openbsd.org0cbed242018-09-20 23:40:16 +0000664 { "casignaturealgorithms", sCASignatureAlgorithms, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000665 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000666};
667
Darren Tuckere7140f22008-06-10 23:01:51 +1000668static struct {
669 int val;
670 char *text;
671} tunmode_desc[] = {
672 { SSH_TUNMODE_NO, "no" },
673 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
674 { SSH_TUNMODE_ETHERNET, "ethernet" },
675 { SSH_TUNMODE_YES, "yes" },
676 { -1, NULL }
677};
678
djm@openbsd.org115063a2018-06-06 18:22:41 +0000679/* Returns an opcode name from its number */
680
681static const char *
682lookup_opcode_name(ServerOpCodes code)
683{
684 u_int i;
685
686 for (i = 0; keywords[i].name != NULL; i++)
687 if (keywords[i].opcode == code)
688 return(keywords[i].name);
689 return "UNKNOWN";
690}
691
692
Damien Miller5428f641999-11-25 11:54:57 +1100693/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000694 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100695 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000696
Damien Miller4af51302000-04-16 11:18:38 +1000697static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100698parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000699 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000700{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000701 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000702
Damien Miller95def091999-11-25 00:26:21 +1100703 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000704 if (strcasecmp(cp, keywords[i].name) == 0) {
705 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100706 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000707 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000708
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000709 error("%s: line %d: Bad configuration option: %s",
710 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100711 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000712}
713
Darren Tucker88b6fb22010-01-13 22:44:29 +1100714char *
715derelativise_path(const char *path)
716{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000717 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100718
djm@openbsd.org161cf412014-12-22 07:55:51 +0000719 if (strcasecmp(path, "none") == 0)
720 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100721 expanded = tilde_expand_filename(path, getuid());
djm@openbsd.org2a358622018-11-16 03:26:01 +0000722 if (path_absolute(expanded))
Darren Tucker88b6fb22010-01-13 22:44:29 +1100723 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100724 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100725 fatal("%s: getcwd: %s", __func__, strerror(errno));
726 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000727 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100728 return ret;
729}
730
Ben Lindstrombba81212001-06-25 05:01:22 +0000731static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000732add_listen_addr(ServerOptions *options, const char *addr,
733 const char *rdomain, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100734{
Damien Millereccb9de2005-06-17 12:59:34 +1000735 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100736
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000737 if (port > 0)
738 add_one_listen_addr(options, addr, rdomain, port);
739 else {
740 for (i = 0; i < options->num_ports; i++) {
741 add_one_listen_addr(options, addr, rdomain,
742 options->ports[i]);
743 }
744 }
Ben Lindstromc510af42001-04-07 17:25:48 +0000745}
746
Ben Lindstrombba81212001-06-25 05:01:22 +0000747static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000748add_one_listen_addr(ServerOptions *options, const char *addr,
749 const char *rdomain, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000750{
751 struct addrinfo hints, *ai, *aitop;
752 char strport[NI_MAXSERV];
753 int gaierr;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000754 u_int i;
755
756 /* Find listen_addrs entry for this rdomain */
757 for (i = 0; i < options->num_listen_addrs; i++) {
758 if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
759 break;
760 if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
761 continue;
762 if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
763 break;
764 }
765 if (i >= options->num_listen_addrs) {
766 /* No entry for this rdomain; allocate one */
767 if (i >= INT_MAX)
768 fatal("%s: too many listen addresses", __func__);
769 options->listen_addrs = xrecallocarray(options->listen_addrs,
770 options->num_listen_addrs, options->num_listen_addrs + 1,
771 sizeof(*options->listen_addrs));
772 i = options->num_listen_addrs++;
773 if (rdomain != NULL)
774 options->listen_addrs[i].rdomain = xstrdup(rdomain);
775 }
776 /* options->listen_addrs[i] points to the addresses for this rdomain */
Ben Lindstromc510af42001-04-07 17:25:48 +0000777
778 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100779 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000780 hints.ai_socktype = SOCK_STREAM;
781 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100782 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000783 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
784 fatal("bad addr or host: %s (%s)",
785 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100786 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000787 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
788 ;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000789 ai->ai_next = options->listen_addrs[i].addrs;
790 options->listen_addrs[i].addrs = aitop;
791}
792
793/* Returns nonzero if the routing domain name is valid */
794static int
795valid_rdomain(const char *name)
796{
Damien Miller43c29bb2017-10-25 13:10:59 +1100797#if defined(HAVE_SYS_VALID_RDOMAIN)
Damien Miller2de5c6b2017-10-27 08:42:33 +1100798 return sys_valid_rdomain(name);
Damien Miller43c29bb2017-10-25 13:10:59 +1100799#elif defined(__OpenBSD__)
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000800 const char *errstr;
801 long long num;
802 struct rt_tableinfo info;
803 int mib[6];
804 size_t miblen = sizeof(mib);
805
806 if (name == NULL)
807 return 1;
808
809 num = strtonum(name, 0, 255, &errstr);
810 if (errstr != NULL)
811 return 0;
812
813 /* Check whether the table actually exists */
814 memset(mib, 0, sizeof(mib));
815 mib[0] = CTL_NET;
816 mib[1] = PF_ROUTE;
817 mib[4] = NET_RT_TABLE;
818 mib[5] = (int)num;
819 if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
820 return 0;
821
822 return 1;
Damien Miller43c29bb2017-10-25 13:10:59 +1100823#else /* defined(__OpenBSD__) */
824 error("Routing domains are not supported on this platform");
825 return 0;
826#endif
Damien Miller34132e52000-01-14 15:45:46 +1100827}
828
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000829/*
830 * Queue a ListenAddress to be processed once we have all of the Ports
831 * and AddressFamily options.
832 */
833static void
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000834queue_listen_addr(ServerOptions *options, const char *addr,
835 const char *rdomain, int port)
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000836{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000837 struct queued_listenaddr *qla;
838
839 options->queued_listen_addrs = xrecallocarray(
840 options->queued_listen_addrs,
841 options->num_queued_listens, options->num_queued_listens + 1,
842 sizeof(*options->queued_listen_addrs));
843 qla = &options->queued_listen_addrs[options->num_queued_listens++];
844 qla->addr = xstrdup(addr);
845 qla->port = port;
846 qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000847}
848
849/*
850 * Process queued (text) ListenAddress entries.
851 */
852static void
853process_queued_listen_addrs(ServerOptions *options)
854{
855 u_int i;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000856 struct queued_listenaddr *qla;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000857
858 if (options->num_ports == 0)
859 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
860 if (options->address_family == -1)
861 options->address_family = AF_UNSPEC;
862
863 for (i = 0; i < options->num_queued_listens; i++) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +0000864 qla = &options->queued_listen_addrs[i];
865 add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
866 free(qla->addr);
867 free(qla->rdomain);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000868 }
869 free(options->queued_listen_addrs);
870 options->queued_listen_addrs = NULL;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000871 options->num_queued_listens = 0;
872}
873
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000874/*
djm@openbsd.org115063a2018-06-06 18:22:41 +0000875 * Inform channels layer of permitopen options for a single forwarding
876 * direction (local/remote).
877 */
878static void
879process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
880 char **opens, u_int num_opens)
881{
882 u_int i;
883 int port;
884 char *host, *arg, *oarg;
885 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
886 const char *what = lookup_opcode_name(opcode);
887
888 channel_clear_permission(ssh, FORWARD_ADM, where);
889 if (num_opens == 0)
890 return; /* permit any */
891
892 /* handle keywords: "any" / "none" */
893 if (num_opens == 1 && strcmp(opens[0], "any") == 0)
894 return;
895 if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
896 channel_disable_admin(ssh, where);
897 return;
898 }
899 /* Otherwise treat it as a list of permitted host:port */
900 for (i = 0; i < num_opens; i++) {
901 oarg = arg = xstrdup(opens[i]);
902 host = hpdelim(&arg);
903 if (host == NULL)
904 fatal("%s: missing host in %s", __func__, what);
905 host = cleanhostname(host);
906 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
907 fatal("%s: bad port number in %s", __func__, what);
908 /* Send it to channels layer */
909 channel_add_permission(ssh, FORWARD_ADM,
910 where, host, port);
911 free(oarg);
912 }
913}
914
915/*
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000916 * Inform channels layer of permitopen options from configuration.
917 */
918void
919process_permitopen(struct ssh *ssh, ServerOptions *options)
920{
djm@openbsd.org115063a2018-06-06 18:22:41 +0000921 process_permitopen_list(ssh, sPermitOpen,
922 options->permitted_opens, options->num_permitted_opens);
djm@openbsd.org93c06ab2018-06-06 18:23:32 +0000923 process_permitopen_list(ssh, sPermitListen,
924 options->permitted_listens,
925 options->num_permitted_listens);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000926}
927
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000928struct connection_info *
929get_connection_info(int populate, int use_dns)
930{
djm@openbsd.org95767262016-03-07 19:02:43 +0000931 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000932 static struct connection_info ci;
933
934 if (!populate)
935 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000936 ci.host = auth_get_canonical_hostname(ssh, use_dns);
937 ci.address = ssh_remote_ipaddr(ssh);
938 ci.laddress = ssh_local_ipaddr(ssh);
939 ci.lport = ssh_local_port(ssh);
djm@openbsd.org68af80e2017-10-25 00:19:47 +0000940 ci.rdomain = ssh_packet_rdomain_in(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000941 return &ci;
942}
943
Darren Tucker45150472006-07-12 22:34:17 +1000944/*
945 * The strategy for the Match blocks is that the config file is parsed twice.
946 *
947 * The first time is at startup. activep is initialized to 1 and the
948 * directives in the global context are processed and acted on. Hitting a
949 * Match directive unsets activep and the directives inside the block are
950 * checked for syntax only.
951 *
952 * The second time is after a connection has been established but before
953 * authentication. activep is initialized to 2 and global config directives
954 * are ignored since they have already been processed. If the criteria in a
955 * Match block is met, activep is set and the subsequent directives
956 * processed and actioned until EOF or another Match block unsets it. Any
957 * options set are copied into the main server config.
958 *
959 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000960 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000961 *
962 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
963 * Match Address 192.168.0.*
964 * Tag trusted
965 * Match Group wheel
966 * Tag trusted
967 * Match Tag trusted
968 * AllowTcpForwarding yes
969 * GatewayPorts clientspecified
970 * [...]
971 *
972 * - Add a PermittedChannelRequests directive
973 * Match Group shell
974 * PermittedChannelRequests session,forwarded-tcpip
975 */
976
977static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000978match_cfg_line_group(const char *grps, int line, const char *user)
979{
980 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000981 struct passwd *pw;
982
Damien Miller565ca3f2006-08-19 00:23:15 +1000983 if (user == NULL)
984 goto out;
985
986 if ((pw = getpwnam(user)) == NULL) {
987 debug("Can't match group at line %d because user %.100s does "
988 "not exist", line, user);
989 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
990 debug("Can't Match group because user %.100s not in any group "
991 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000992 } else if (ga_match_pattern_list(grps) != 1) {
993 debug("user %.100s does not match group list %.100s at line %d",
994 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000995 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000996 debug("user %.100s matched group list %.100s at line %d", user,
997 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000998 result = 1;
999 }
1000out:
1001 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +10001002 return result;
1003}
1004
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001005static void
1006match_test_missing_fatal(const char *criteria, const char *attrib)
1007{
1008 fatal("'Match %s' in configuration but '%s' not in connection "
1009 "test specification.", criteria, attrib);
1010}
1011
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001012/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +10001013 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +11001014 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +10001015 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001016 */
Damien Miller565ca3f2006-08-19 00:23:15 +10001017static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001018match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +10001019{
Damien Millercf31f382013-10-24 21:02:56 +11001020 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +10001021 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +10001022
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001023 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001024 debug3("checking syntax for 'Match %s'", cp);
1025 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001026 debug3("checking match for '%s' user %s host %s addr %s "
1027 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
1028 ci->host ? ci->host : "(null)",
1029 ci->address ? ci->address : "(null)",
1030 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +10001031
1032 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +11001033 attributes++;
1034 if (strcasecmp(attrib, "all") == 0) {
1035 if (attributes != 1 ||
1036 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1037 error("'all' cannot be combined with other "
1038 "Match attributes");
1039 return -1;
1040 }
1041 *condition = cp;
1042 return 1;
1043 }
Darren Tucker45150472006-07-12 22:34:17 +10001044 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
1045 error("Missing Match criteria for %s", attrib);
1046 return -1;
1047 }
Darren Tucker45150472006-07-12 22:34:17 +10001048 if (strcasecmp(attrib, "user") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001049 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001050 result = 0;
1051 continue;
1052 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001053 if (ci->user == NULL)
1054 match_test_missing_fatal("User", "user");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001055 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001056 result = 0;
1057 else
1058 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001059 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +10001060 } else if (strcasecmp(attrib, "group") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001061 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001062 result = 0;
1063 continue;
1064 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001065 if (ci->user == NULL)
1066 match_test_missing_fatal("Group", "user");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001067 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +10001068 case -1:
1069 return -1;
1070 case 0:
1071 result = 0;
1072 }
Darren Tucker45150472006-07-12 22:34:17 +10001073 } else if (strcasecmp(attrib, "host") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001074 if (ci == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001075 result = 0;
1076 continue;
1077 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001078 if (ci->host == NULL)
1079 match_test_missing_fatal("Host", "host");
djm@openbsd.orge661a862015-05-04 06:10:48 +00001080 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +10001081 result = 0;
1082 else
1083 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001084 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001085 } else if (strcasecmp(attrib, "address") == 0) {
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001086 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001087 result = 0;
1088 continue;
1089 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001090 if (ci->address == NULL)
1091 match_test_missing_fatal("Address", "addr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001092 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +10001093 case 1:
Darren Tucker45150472006-07-12 22:34:17 +10001094 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001095 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +10001096 break;
1097 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +10001098 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001099 result = 0;
1100 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +10001101 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +10001102 return -1;
1103 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001104 } else if (strcasecmp(attrib, "localaddress") == 0){
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001105 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001106 result = 0;
1107 continue;
1108 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001109 if (ci->laddress == NULL)
1110 match_test_missing_fatal("LocalAddress",
1111 "laddr");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001112 switch (addr_match_list(ci->laddress, arg)) {
1113 case 1:
1114 debug("connection from %.100s matched "
1115 "'LocalAddress %.100s' at line %d",
1116 ci->laddress, arg, line);
1117 break;
1118 case 0:
1119 case -1:
1120 result = 0;
1121 break;
1122 case -2:
1123 return -1;
1124 }
1125 } else if (strcasecmp(attrib, "localport") == 0) {
1126 if ((port = a2port(arg)) == -1) {
1127 error("Invalid LocalPort '%s' on Match line",
1128 arg);
1129 return -1;
1130 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001131 if (ci == NULL) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001132 result = 0;
1133 continue;
1134 }
dtucker@openbsd.org@openbsd.org0208a482017-11-03 03:18:53 +00001135 if (ci->lport == 0)
1136 match_test_missing_fatal("LocalPort", "lport");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001137 /* TODO support port lists */
1138 if (port == ci->lport)
1139 debug("connection from %.100s matched "
1140 "'LocalPort %d' at line %d",
1141 ci->laddress, port, line);
1142 else
1143 result = 0;
djm@openbsd.org68af80e2017-10-25 00:19:47 +00001144 } else if (strcasecmp(attrib, "rdomain") == 0) {
1145 if (ci == NULL || ci->rdomain == NULL) {
1146 result = 0;
1147 continue;
1148 }
1149 if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1150 result = 0;
1151 else
1152 debug("user %.100s matched 'RDomain %.100s' at "
1153 "line %d", ci->rdomain, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +10001154 } else {
1155 error("Unsupported Match attribute %s", attrib);
1156 return -1;
1157 }
1158 }
Damien Millercf31f382013-10-24 21:02:56 +11001159 if (attributes == 0) {
1160 error("One or more attributes required for Match");
1161 return -1;
1162 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001163 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +10001164 debug3("match %sfound", result ? "" : "not ");
1165 *condition = cp;
1166 return result;
1167}
1168
Damien Millere2754432006-07-24 14:06:47 +10001169#define WHITESPACE " \t\r\n"
1170
Damien Miller33322122011-06-20 14:43:11 +10001171/* Multistate option parsing */
1172struct multistate {
1173 char *key;
1174 int value;
1175};
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001176static const struct multistate multistate_flag[] = {
1177 { "yes", 1 },
1178 { "no", 0 },
1179 { NULL, -1 }
1180};
Damien Miller33322122011-06-20 14:43:11 +10001181static const struct multistate multistate_addressfamily[] = {
1182 { "inet", AF_INET },
1183 { "inet6", AF_INET6 },
1184 { "any", AF_UNSPEC },
1185 { NULL, -1 }
1186};
1187static const struct multistate multistate_permitrootlogin[] = {
1188 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001189 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001190 { "forced-commands-only", PERMIT_FORCED_ONLY },
1191 { "yes", PERMIT_YES },
1192 { "no", PERMIT_NO },
1193 { NULL, -1 }
1194};
1195static const struct multistate multistate_compression[] = {
sf@openbsd.org168b46f2018-07-09 13:37:10 +00001196 { "yes", COMP_DELAYED },
1197 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001198 { "no", COMP_NONE },
1199 { NULL, -1 }
1200};
1201static const struct multistate multistate_gatewayports[] = {
1202 { "clientspecified", 2 },
1203 { "yes", 1 },
1204 { "no", 0 },
1205 { NULL, -1 }
1206};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001207static const struct multistate multistate_tcpfwd[] = {
1208 { "yes", FORWARD_ALLOW },
1209 { "all", FORWARD_ALLOW },
1210 { "no", FORWARD_DENY },
1211 { "remote", FORWARD_REMOTE },
1212 { "local", FORWARD_LOCAL },
1213 { NULL, -1 }
1214};
Damien Miller33322122011-06-20 14:43:11 +10001215
Ben Lindstromade03f62001-12-06 18:22:17 +00001216int
1217process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001218 const char *filename, int linenum, int *activep,
1219 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001220{
djm@openbsd.org115063a2018-06-06 18:22:41 +00001221 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001222 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001223 SyslogFacility *log_facility_ptr;
1224 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001225 ServerOpCodes opcode;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001226 u_int i, *uintptr, uvalue, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001227 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001228 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001229 const struct multistate *multistate_ptr;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001230 const char *errstr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001231
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001232 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1233 if ((len = strlen(line)) == 0)
1234 return 0;
1235 for (len--; len > 0; len--) {
1236 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1237 break;
1238 line[len] = '\0';
1239 }
1240
Ben Lindstromade03f62001-12-06 18:22:17 +00001241 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001242 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001243 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001244 /* Ignore leading whitespace */
1245 if (*arg == '\0')
1246 arg = strdelim(&cp);
1247 if (!arg || !*arg || *arg == '#')
1248 return 0;
1249 intptr = NULL;
1250 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001251 opcode = parse_token(arg, filename, linenum, &flags);
1252
1253 if (activep == NULL) { /* We are processing a command line directive */
1254 cmdline = 1;
1255 activep = &cmdline;
1256 }
1257 if (*activep && opcode != sMatch)
1258 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1259 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001260 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001261 fatal("%s line %d: Directive '%s' is not allowed "
1262 "within a Match block", filename, linenum, arg);
1263 } else { /* this is a directive we have already processed */
1264 while (arg)
1265 arg = strdelim(&cp);
1266 return 0;
1267 }
1268 }
1269
Ben Lindstromade03f62001-12-06 18:22:17 +00001270 switch (opcode) {
1271 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001272 case sUsePAM:
1273 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001274 goto parse_flag;
1275
1276 /* Standard Options */
1277 case sBadOption:
1278 return -1;
1279 case sPort:
1280 /* ignore ports from configfile if cmdline specifies ports */
1281 if (options->ports_from_cmdline)
1282 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001283 if (options->num_ports >= MAX_PORTS)
1284 fatal("%s line %d: too many ports.",
1285 filename, linenum);
1286 arg = strdelim(&cp);
1287 if (!arg || *arg == '\0')
1288 fatal("%s line %d: missing port number.",
1289 filename, linenum);
1290 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001291 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001292 fatal("%s line %d: Badly formatted port number.",
1293 filename, linenum);
1294 break;
1295
Ben Lindstromade03f62001-12-06 18:22:17 +00001296 case sLoginGraceTime:
1297 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001298 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001299 arg = strdelim(&cp);
1300 if (!arg || *arg == '\0')
1301 fatal("%s line %d: missing time value.",
1302 filename, linenum);
1303 if ((value = convtime(arg)) == -1)
1304 fatal("%s line %d: invalid time value.",
1305 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001306 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001307 *intptr = value;
1308 break;
1309
Ben Lindstromade03f62001-12-06 18:22:17 +00001310 case sListenAddress:
1311 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001312 if (arg == NULL || *arg == '\0')
1313 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001314 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001315 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1316 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1317 && strchr(p+1, ':') != NULL) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001318 port = 0;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001319 p = arg;
1320 } else {
1321 p = hpdelim(&arg);
1322 if (p == NULL)
1323 fatal("%s line %d: bad address:port usage",
1324 filename, linenum);
1325 p = cleanhostname(p);
1326 if (arg == NULL)
1327 port = 0;
1328 else if ((port = a2port(arg)) <= 0)
1329 fatal("%s line %d: bad port number",
1330 filename, linenum);
1331 }
1332 /* Optional routing table */
1333 arg2 = NULL;
1334 if ((arg = strdelim(&cp)) != NULL) {
1335 if (strcmp(arg, "rdomain") != 0 ||
1336 (arg2 = strdelim(&cp)) == NULL)
1337 fatal("%s line %d: bad ListenAddress syntax",
1338 filename, linenum);
1339 if (!valid_rdomain(arg2))
1340 fatal("%s line %d: bad routing domain",
1341 filename, linenum);
1342 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001343
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00001344 queue_listen_addr(options, p, arg2, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001345
Ben Lindstromade03f62001-12-06 18:22:17 +00001346 break;
1347
Darren Tucker0f383232005-01-20 10:57:56 +11001348 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001349 intptr = &options->address_family;
1350 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001351 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001352 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001353 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001354 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001355 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001356 value = -1;
1357 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1358 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1359 value = multistate_ptr[i].value;
1360 break;
1361 }
1362 }
1363 if (value == -1)
1364 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001365 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001366 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001367 *intptr = value;
1368 break;
1369
Ben Lindstromade03f62001-12-06 18:22:17 +00001370 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 arg = strdelim(&cp);
1372 if (!arg || *arg == '\0')
1373 fatal("%s line %d: missing file name.",
1374 filename, linenum);
djm@openbsd.org928f1232018-11-19 04:12:32 +00001375 if (*activep) {
1376 servconf_add_hostkey(filename, linenum,
1377 options, arg, 1);
1378 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001379 break;
1380
Damien Miller85b45e02013-07-20 13:21:52 +10001381 case sHostKeyAgent:
1382 charptr = &options->host_key_agent;
1383 arg = strdelim(&cp);
1384 if (!arg || *arg == '\0')
1385 fatal("%s line %d: missing socket name.",
1386 filename, linenum);
1387 if (*activep && *charptr == NULL)
1388 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1389 xstrdup(arg) : derelativise_path(arg);
1390 break;
1391
Damien Miller0a80ca12010-02-27 07:55:05 +11001392 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001393 arg = strdelim(&cp);
1394 if (!arg || *arg == '\0')
1395 fatal("%s line %d: missing file name.",
1396 filename, linenum);
1397 if (*activep)
1398 servconf_add_hostcert(filename, linenum, options, arg);
1399 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001400
Ben Lindstromade03f62001-12-06 18:22:17 +00001401 case sPidFile:
1402 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001403 parse_filename:
1404 arg = strdelim(&cp);
1405 if (!arg || *arg == '\0')
1406 fatal("%s line %d: missing file name.",
1407 filename, linenum);
1408 if (*activep && *charptr == NULL) {
1409 *charptr = derelativise_path(arg);
1410 /* increase optional counter */
1411 if (intptr != NULL)
1412 *intptr = *intptr + 1;
1413 }
1414 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001415
1416 case sPermitRootLogin:
1417 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001418 multistate_ptr = multistate_permitrootlogin;
1419 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001420
1421 case sIgnoreRhosts:
1422 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001423 parse_flag:
djm@openbsd.org@openbsd.org33edb6e2017-11-03 05:18:44 +00001424 multistate_ptr = multistate_flag;
1425 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001426
1427 case sIgnoreUserKnownHosts:
1428 intptr = &options->ignore_user_known_hosts;
1429 goto parse_flag;
1430
Ben Lindstromade03f62001-12-06 18:22:17 +00001431 case sHostbasedAuthentication:
1432 intptr = &options->hostbased_authentication;
1433 goto parse_flag;
1434
1435 case sHostbasedUsesNameFromPacketOnly:
1436 intptr = &options->hostbased_uses_name_from_packet_only;
1437 goto parse_flag;
1438
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001439 case sHostbasedAcceptedKeyTypes:
1440 charptr = &options->hostbased_key_types;
1441 parse_keytypes:
1442 arg = strdelim(&cp);
1443 if (!arg || *arg == '\0')
1444 fatal("%s line %d: Missing argument.",
1445 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001446 if (*arg != '-' &&
1447 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001448 fatal("%s line %d: Bad key types '%s'.",
1449 filename, linenum, arg ? arg : "<NONE>");
1450 if (*activep && *charptr == NULL)
1451 *charptr = xstrdup(arg);
1452 break;
1453
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001454 case sHostKeyAlgorithms:
1455 charptr = &options->hostkeyalgorithms;
1456 goto parse_keytypes;
1457
djm@openbsd.org86e57372018-09-20 03:28:06 +00001458 case sCASignatureAlgorithms:
1459 charptr = &options->ca_sign_algorithms;
1460 goto parse_keytypes;
1461
Ben Lindstromade03f62001-12-06 18:22:17 +00001462 case sPubkeyAuthentication:
1463 intptr = &options->pubkey_authentication;
1464 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001465
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001466 case sPubkeyAcceptedKeyTypes:
1467 charptr = &options->pubkey_key_types;
1468 goto parse_keytypes;
1469
Ben Lindstromade03f62001-12-06 18:22:17 +00001470 case sKerberosAuthentication:
1471 intptr = &options->kerberos_authentication;
1472 goto parse_flag;
1473
1474 case sKerberosOrLocalPasswd:
1475 intptr = &options->kerberos_or_local_passwd;
1476 goto parse_flag;
1477
1478 case sKerberosTicketCleanup:
1479 intptr = &options->kerberos_ticket_cleanup;
1480 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001481
Darren Tucker22ef5082003-12-31 11:37:34 +11001482 case sKerberosGetAFSToken:
1483 intptr = &options->kerberos_get_afs_token;
1484 goto parse_flag;
1485
Darren Tucker0efd1552003-08-26 11:49:55 +10001486 case sGssAuthentication:
1487 intptr = &options->gss_authentication;
1488 goto parse_flag;
1489
1490 case sGssCleanupCreds:
1491 intptr = &options->gss_cleanup_creds;
1492 goto parse_flag;
1493
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001494 case sGssStrictAcceptor:
1495 intptr = &options->gss_strict_acceptor;
1496 goto parse_flag;
1497
Ben Lindstromade03f62001-12-06 18:22:17 +00001498 case sPasswordAuthentication:
1499 intptr = &options->password_authentication;
1500 goto parse_flag;
1501
1502 case sKbdInteractiveAuthentication:
1503 intptr = &options->kbd_interactive_authentication;
1504 goto parse_flag;
1505
1506 case sChallengeResponseAuthentication:
1507 intptr = &options->challenge_response_authentication;
1508 goto parse_flag;
1509
1510 case sPrintMotd:
1511 intptr = &options->print_motd;
1512 goto parse_flag;
1513
1514 case sPrintLastLog:
1515 intptr = &options->print_lastlog;
1516 goto parse_flag;
1517
1518 case sX11Forwarding:
1519 intptr = &options->x11_forwarding;
1520 goto parse_flag;
1521
1522 case sX11DisplayOffset:
1523 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001524 parse_int:
1525 arg = strdelim(&cp);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001526 if ((errstr = atoi_err(arg, &value)) != NULL)
1527 fatal("%s line %d: integer value %s.",
1528 filename, linenum, errstr);
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001529 if (*activep && *intptr == -1)
1530 *intptr = value;
1531 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001532
Damien Miller95c249f2002-02-05 12:11:34 +11001533 case sX11UseLocalhost:
1534 intptr = &options->x11_use_localhost;
1535 goto parse_flag;
1536
Ben Lindstromade03f62001-12-06 18:22:17 +00001537 case sXAuthLocation:
1538 charptr = &options->xauth_location;
1539 goto parse_filename;
1540
Damien Miller5ff30c62013-10-30 22:21:50 +11001541 case sPermitTTY:
1542 intptr = &options->permit_tty;
1543 goto parse_flag;
1544
Damien Miller72e6b5c2014-07-04 09:00:04 +10001545 case sPermitUserRC:
1546 intptr = &options->permit_user_rc;
1547 goto parse_flag;
1548
Ben Lindstromade03f62001-12-06 18:22:17 +00001549 case sStrictModes:
1550 intptr = &options->strict_modes;
1551 goto parse_flag;
1552
Damien Miller12c150e2003-12-17 16:31:10 +11001553 case sTCPKeepAlive:
1554 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001555 goto parse_flag;
1556
1557 case sEmptyPasswd:
1558 intptr = &options->permit_empty_passwd;
1559 goto parse_flag;
1560
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001561 case sPermitUserEnvironment:
1562 intptr = &options->permit_user_env;
djm@openbsd.org95344c22018-07-03 10:59:35 +00001563 charptr = &options->permit_user_env_whitelist;
1564 arg = strdelim(&cp);
1565 if (!arg || *arg == '\0')
1566 fatal("%s line %d: missing argument.",
1567 filename, linenum);
1568 value = 0;
1569 p = NULL;
1570 if (strcmp(arg, "yes") == 0)
1571 value = 1;
1572 else if (strcmp(arg, "no") == 0)
1573 value = 0;
1574 else {
1575 /* Pattern-list specified */
1576 value = 1;
1577 p = xstrdup(arg);
1578 }
1579 if (*activep && *intptr == -1) {
1580 *intptr = value;
1581 *charptr = p;
1582 p = NULL;
1583 }
1584 free(p);
1585 break;
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001586
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001587 case sCompression:
1588 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001589 multistate_ptr = multistate_compression;
1590 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001591
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001592 case sRekeyLimit:
1593 arg = strdelim(&cp);
1594 if (!arg || *arg == '\0')
1595 fatal("%.200s line %d: Missing argument.", filename,
1596 linenum);
1597 if (strcmp(arg, "default") == 0) {
1598 val64 = 0;
1599 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001600 if (scan_scaled(arg, &val64) == -1)
1601 fatal("%.200s line %d: Bad number '%s': %s",
1602 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001603 if (val64 != 0 && val64 < 16)
1604 fatal("%.200s line %d: RekeyLimit too small",
1605 filename, linenum);
1606 }
1607 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001608 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001609 if (cp != NULL) { /* optional rekey interval present */
1610 if (strcmp(cp, "none") == 0) {
1611 (void)strdelim(&cp); /* discard */
1612 break;
1613 }
1614 intptr = &options->rekey_interval;
1615 goto parse_time;
1616 }
1617 break;
1618
Ben Lindstromade03f62001-12-06 18:22:17 +00001619 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001620 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001621 multistate_ptr = multistate_gatewayports;
1622 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001623
Damien Miller3a961dc2003-06-03 10:25:48 +10001624 case sUseDNS:
1625 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001626 goto parse_flag;
1627
1628 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001629 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001630 arg = strdelim(&cp);
1631 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001632 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001633 fatal("%.200s line %d: unsupported log facility '%s'",
1634 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001635 if (*log_facility_ptr == -1)
1636 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001637 break;
1638
1639 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001640 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001641 arg = strdelim(&cp);
1642 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001643 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001644 fatal("%.200s line %d: unsupported log level '%s'",
1645 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001646 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001647 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001648 break;
1649
1650 case sAllowTcpForwarding:
1651 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001652 multistate_ptr = multistate_tcpfwd;
1653 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001654
Damien Miller7acefbb2014-07-18 14:11:24 +10001655 case sAllowStreamLocalForwarding:
1656 intptr = &options->allow_streamlocal_forwarding;
1657 multistate_ptr = multistate_tcpfwd;
1658 goto parse_multistate;
1659
Damien Miller4f755cd2008-05-19 14:57:41 +10001660 case sAllowAgentForwarding:
1661 intptr = &options->allow_agent_forwarding;
1662 goto parse_flag;
1663
djm@openbsd.org7844f352016-11-30 03:00:05 +00001664 case sDisableForwarding:
1665 intptr = &options->disable_forwarding;
1666 goto parse_flag;
1667
Ben Lindstromade03f62001-12-06 18:22:17 +00001668 case sAllowUsers:
1669 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001670 if (match_user(NULL, NULL, NULL, arg) == -1)
1671 fatal("%s line %d: invalid AllowUsers pattern: "
1672 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001673 if (!*activep)
1674 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001675 array_append(filename, linenum, "AllowUsers",
1676 &options->allow_users, &options->num_allow_users,
1677 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001678 }
1679 break;
1680
1681 case sDenyUsers:
1682 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001683 if (match_user(NULL, NULL, NULL, arg) == -1)
1684 fatal("%s line %d: invalid DenyUsers pattern: "
1685 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001686 if (!*activep)
1687 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001688 array_append(filename, linenum, "DenyUsers",
1689 &options->deny_users, &options->num_deny_users,
1690 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001691 }
1692 break;
1693
1694 case sAllowGroups:
1695 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001696 if (!*activep)
1697 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001698 array_append(filename, linenum, "AllowGroups",
1699 &options->allow_groups, &options->num_allow_groups,
1700 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001701 }
1702 break;
1703
1704 case sDenyGroups:
1705 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001706 if (!*activep)
1707 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001708 array_append(filename, linenum, "DenyGroups",
1709 &options->deny_groups, &options->num_deny_groups,
1710 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001711 }
1712 break;
1713
1714 case sCiphers:
1715 arg = strdelim(&cp);
1716 if (!arg || *arg == '\0')
1717 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001718 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001719 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1720 filename, linenum, arg ? arg : "<NONE>");
1721 if (options->ciphers == NULL)
1722 options->ciphers = xstrdup(arg);
1723 break;
1724
1725 case sMacs:
1726 arg = strdelim(&cp);
1727 if (!arg || *arg == '\0')
1728 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001729 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001730 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1731 filename, linenum, arg ? arg : "<NONE>");
1732 if (options->macs == NULL)
1733 options->macs = xstrdup(arg);
1734 break;
1735
Damien Millerd5f62bf2010-09-24 22:11:14 +10001736 case sKexAlgorithms:
1737 arg = strdelim(&cp);
1738 if (!arg || *arg == '\0')
1739 fatal("%s line %d: Missing argument.",
1740 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001741 if (*arg != '-' &&
1742 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001743 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1744 filename, linenum, arg ? arg : "<NONE>");
1745 if (options->kex_algorithms == NULL)
1746 options->kex_algorithms = xstrdup(arg);
1747 break;
1748
Ben Lindstromade03f62001-12-06 18:22:17 +00001749 case sSubsystem:
1750 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1751 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001752 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001753 }
1754 arg = strdelim(&cp);
1755 if (!arg || *arg == '\0')
1756 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001757 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001758 if (!*activep) {
1759 arg = strdelim(&cp);
1760 break;
1761 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001762 for (i = 0; i < options->num_subsystems; i++)
1763 if (strcmp(arg, options->subsystem_name[i]) == 0)
1764 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001765 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001766 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1767 arg = strdelim(&cp);
1768 if (!arg || *arg == '\0')
1769 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001770 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001771 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001772
1773 /* Collect arguments (separate to executable) */
1774 p = xstrdup(arg);
1775 len = strlen(p) + 1;
1776 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1777 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001778 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001779 strlcat(p, " ", len);
1780 strlcat(p, arg, len);
1781 }
1782 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001783 options->num_subsystems++;
1784 break;
1785
1786 case sMaxStartups:
1787 arg = strdelim(&cp);
1788 if (!arg || *arg == '\0')
1789 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001790 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001791 if ((n = sscanf(arg, "%d:%d:%d",
1792 &options->max_startups_begin,
1793 &options->max_startups_rate,
1794 &options->max_startups)) == 3) {
1795 if (options->max_startups_begin >
1796 options->max_startups ||
1797 options->max_startups_rate > 100 ||
1798 options->max_startups_rate < 1)
1799 fatal("%s line %d: Illegal MaxStartups spec.",
1800 filename, linenum);
1801 } else if (n != 1)
1802 fatal("%s line %d: Illegal MaxStartups spec.",
1803 filename, linenum);
1804 else
1805 options->max_startups = options->max_startups_begin;
1806 break;
1807
Darren Tucker89413db2004-05-24 10:36:23 +10001808 case sMaxAuthTries:
1809 intptr = &options->max_authtries;
1810 goto parse_int;
1811
Damien Miller7207f642008-05-19 15:34:50 +10001812 case sMaxSessions:
1813 intptr = &options->max_sessions;
1814 goto parse_int;
1815
Ben Lindstromade03f62001-12-06 18:22:17 +00001816 case sBanner:
1817 charptr = &options->banner;
1818 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001819
Ben Lindstromade03f62001-12-06 18:22:17 +00001820 /*
1821 * These options can contain %X options expanded at
1822 * connect time, so that you can specify paths like:
1823 *
1824 * AuthorizedKeysFile /etc/ssh_keys/%u
1825 */
1826 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001827 if (*activep && options->num_authkeys_files == 0) {
1828 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001829 arg = tilde_expand_filename(arg, getuid());
1830 array_append(filename, linenum,
1831 "AuthorizedKeysFile",
1832 &options->authorized_keys_files,
1833 &options->num_authkeys_files, arg);
1834 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001835 }
1836 }
1837 return 0;
1838
Damien Miller30da3442010-05-10 11:58:03 +10001839 case sAuthorizedPrincipalsFile:
1840 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001841 arg = strdelim(&cp);
1842 if (!arg || *arg == '\0')
1843 fatal("%s line %d: missing file name.",
1844 filename, linenum);
1845 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001846 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001847 /* increase optional counter */
1848 if (intptr != NULL)
1849 *intptr = *intptr + 1;
1850 }
1851 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001852
1853 case sClientAliveInterval:
1854 intptr = &options->client_alive_interval;
1855 goto parse_time;
1856
1857 case sClientAliveCountMax:
1858 intptr = &options->client_alive_count_max;
1859 goto parse_int;
1860
Darren Tucker46bc0752004-05-02 22:11:30 +10001861 case sAcceptEnv:
1862 while ((arg = strdelim(&cp)) && *arg != '\0') {
1863 if (strchr(arg, '=') != NULL)
1864 fatal("%s line %d: Invalid environment name.",
1865 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001866 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001867 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001868 array_append(filename, linenum, "AcceptEnv",
1869 &options->accept_env, &options->num_accept_env,
1870 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001871 }
1872 break;
1873
djm@openbsd.org28013752018-06-09 03:03:10 +00001874 case sSetEnv:
1875 uvalue = options->num_setenv;
1876 while ((arg = strdelimw(&cp)) && *arg != '\0') {
1877 if (strchr(arg, '=') == NULL)
1878 fatal("%s line %d: Invalid environment.",
1879 filename, linenum);
1880 if (!*activep || uvalue != 0)
1881 continue;
1882 array_append(filename, linenum, "SetEnv",
1883 &options->setenv, &options->num_setenv, arg);
1884 }
1885 break;
1886
Damien Millerd27b9472005-12-13 19:29:02 +11001887 case sPermitTunnel:
1888 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001889 arg = strdelim(&cp);
1890 if (!arg || *arg == '\0')
1891 fatal("%s line %d: Missing yes/point-to-point/"
1892 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001893 value = -1;
1894 for (i = 0; tunmode_desc[i].val != -1; i++)
1895 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1896 value = tunmode_desc[i].val;
1897 break;
1898 }
1899 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001900 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1901 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001902 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001903 *intptr = value;
1904 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001905
Darren Tucker45150472006-07-12 22:34:17 +10001906 case sMatch:
1907 if (cmdline)
1908 fatal("Match directive not supported as a command-line "
1909 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001910 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001911 if (value < 0)
1912 fatal("%s line %d: Bad Match condition", filename,
1913 linenum);
1914 *activep = value;
1915 break;
1916
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001917 case sPermitListen:
Damien Miller9b439df2006-07-24 14:04:00 +10001918 case sPermitOpen:
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00001919 if (opcode == sPermitListen) {
1920 uintptr = &options->num_permitted_listens;
1921 chararrayptr = &options->permitted_listens;
djm@openbsd.org115063a2018-06-06 18:22:41 +00001922 } else {
1923 uintptr = &options->num_permitted_opens;
1924 chararrayptr = &options->permitted_opens;
1925 }
Damien Miller9b439df2006-07-24 14:04:00 +10001926 arg = strdelim(&cp);
1927 if (!arg || *arg == '\0')
djm@openbsd.org115063a2018-06-06 18:22:41 +00001928 fatal("%s line %d: missing %s specification",
1929 filename, linenum, lookup_opcode_name(opcode));
1930 uvalue = *uintptr; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001931 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org115063a2018-06-06 18:22:41 +00001932 if (*activep && uvalue == 0) {
1933 *uintptr = 1;
1934 *chararrayptr = xcalloc(1,
1935 sizeof(**chararrayptr));
1936 (*chararrayptr)[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001937 }
Damien Millerc6081482012-04-22 11:18:53 +10001938 break;
1939 }
Damien Millera765cf42006-07-24 14:08:13 +10001940 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.org87ddd672018-06-19 02:59:41 +00001941 if (opcode == sPermitListen &&
1942 strchr(arg, ':') == NULL) {
1943 /*
1944 * Allow bare port number for PermitListen
1945 * to indicate a wildcard listen host.
1946 */
1947 xasprintf(&arg2, "*:%s", arg);
1948 } else {
1949 arg2 = xstrdup(arg);
1950 p = hpdelim(&arg);
1951 if (p == NULL) {
1952 fatal("%s line %d: missing host in %s",
1953 filename, linenum,
1954 lookup_opcode_name(opcode));
1955 }
1956 p = cleanhostname(p);
djm@openbsd.org115063a2018-06-06 18:22:41 +00001957 }
djm@openbsd.org115063a2018-06-06 18:22:41 +00001958 if (arg == NULL ||
1959 ((port = permitopen_port(arg)) < 0)) {
1960 fatal("%s line %d: bad port number in %s",
1961 filename, linenum,
1962 lookup_opcode_name(opcode));
1963 }
1964 if (*activep && uvalue == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001965 array_append(filename, linenum,
djm@openbsd.org115063a2018-06-06 18:22:41 +00001966 lookup_opcode_name(opcode),
1967 chararrayptr, uintptr, arg2);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001968 }
1969 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001970 }
Damien Miller9b439df2006-07-24 14:04:00 +10001971 break;
1972
Damien Millere2754432006-07-24 14:06:47 +10001973 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001974 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001975 fatal("%.200s line %d: Missing argument.", filename,
1976 linenum);
1977 len = strspn(cp, WHITESPACE);
1978 if (*activep && options->adm_forced_command == NULL)
1979 options->adm_forced_command = xstrdup(cp + len);
1980 return 0;
1981
Damien Millerd8cb1f12008-02-10 22:40:12 +11001982 case sChrootDirectory:
1983 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001984
1985 arg = strdelim(&cp);
1986 if (!arg || *arg == '\0')
1987 fatal("%s line %d: missing file name.",
1988 filename, linenum);
1989 if (*activep && *charptr == NULL)
1990 *charptr = xstrdup(arg);
1991 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001992
Damien Miller1aed65e2010-03-04 21:53:35 +11001993 case sTrustedUserCAKeys:
1994 charptr = &options->trusted_user_ca_keys;
1995 goto parse_filename;
1996
1997 case sRevokedKeys:
1998 charptr = &options->revoked_keys_file;
1999 goto parse_filename;
2000
Damien Miller0dac6fb2010-11-20 15:19:38 +11002001 case sIPQoS:
2002 arg = strdelim(&cp);
2003 if ((value = parse_ipqos(arg)) == -1)
2004 fatal("%s line %d: Bad IPQoS value: %s",
2005 filename, linenum, arg);
2006 arg = strdelim(&cp);
2007 if (arg == NULL)
2008 value2 = value;
2009 else if ((value2 = parse_ipqos(arg)) == -1)
2010 fatal("%s line %d: Bad IPQoS value: %s",
2011 filename, linenum, arg);
2012 if (*activep) {
2013 options->ip_qos_interactive = value;
2014 options->ip_qos_bulk = value2;
2015 }
2016 break;
2017
Damien Miller23528812012-04-22 11:24:43 +10002018 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00002019 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10002020 fatal("%.200s line %d: Missing argument.", filename,
2021 linenum);
2022 len = strspn(cp, WHITESPACE);
2023 if (*activep && options->version_addendum == NULL) {
2024 if (strcasecmp(cp + len, "none") == 0)
2025 options->version_addendum = xstrdup("");
2026 else if (strchr(cp + len, '\r') != NULL)
2027 fatal("%.200s line %d: Invalid argument",
2028 filename, linenum);
2029 else
2030 options->version_addendum = xstrdup(cp + len);
2031 }
2032 return 0;
2033
Damien Miller09d3e122012-10-31 08:58:58 +11002034 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002035 if (cp == NULL)
2036 fatal("%.200s line %d: Missing argument.", filename,
2037 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002038 len = strspn(cp, WHITESPACE);
2039 if (*activep && options->authorized_keys_command == NULL) {
2040 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2041 fatal("%.200s line %d: AuthorizedKeysCommand "
2042 "must be an absolute path",
2043 filename, linenum);
2044 options->authorized_keys_command = xstrdup(cp + len);
2045 }
2046 return 0;
2047
2048 case sAuthorizedKeysCommandUser:
2049 charptr = &options->authorized_keys_command_user;
2050
2051 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002052 if (!arg || *arg == '\0')
2053 fatal("%s line %d: missing AuthorizedKeysCommandUser "
2054 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11002055 if (*activep && *charptr == NULL)
2056 *charptr = xstrdup(arg);
2057 break;
2058
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002059 case sAuthorizedPrincipalsCommand:
2060 if (cp == NULL)
2061 fatal("%.200s line %d: Missing argument.", filename,
2062 linenum);
2063 len = strspn(cp, WHITESPACE);
2064 if (*activep &&
2065 options->authorized_principals_command == NULL) {
2066 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2067 fatal("%.200s line %d: "
2068 "AuthorizedPrincipalsCommand must be "
2069 "an absolute path", filename, linenum);
2070 options->authorized_principals_command =
2071 xstrdup(cp + len);
2072 }
2073 return 0;
2074
2075 case sAuthorizedPrincipalsCommandUser:
2076 charptr = &options->authorized_principals_command_user;
2077
2078 arg = strdelim(&cp);
2079 if (!arg || *arg == '\0')
2080 fatal("%s line %d: missing "
2081 "AuthorizedPrincipalsCommandUser argument.",
2082 filename, linenum);
2083 if (*activep && *charptr == NULL)
2084 *charptr = xstrdup(arg);
2085 break;
2086
Damien Millera6e3f012012-11-04 23:21:40 +11002087 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002088 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002089 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org001aa552018-04-10 00:10:49 +00002090 value2 = 0; /* successfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11002091 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002092 if (strcmp(arg, "any") == 0) {
2093 if (options->num_auth_methods > 0) {
2094 fatal("%s line %d: \"any\" "
2095 "must appear alone in "
2096 "AuthenticationMethods",
2097 filename, linenum);
2098 }
2099 value = 1;
2100 } else if (value) {
2101 fatal("%s line %d: \"any\" must appear "
2102 "alone in AuthenticationMethods",
2103 filename, linenum);
2104 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11002105 fatal("%s line %d: invalid "
2106 "authentication method list.",
2107 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002108 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002109 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002110 if (!*activep)
2111 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002112 array_append(filename, linenum,
2113 "AuthenticationMethods",
2114 &options->auth_methods,
2115 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11002116 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002117 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002118 fatal("%s line %d: no AuthenticationMethods "
2119 "specified", filename, linenum);
2120 }
Damien Millera6e3f012012-11-04 23:21:40 +11002121 }
2122 return 0;
2123
Damien Miller7acefbb2014-07-18 14:11:24 +10002124 case sStreamLocalBindMask:
2125 arg = strdelim(&cp);
2126 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002127 fatal("%s line %d: missing StreamLocalBindMask "
2128 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10002129 /* Parse mode in octal format */
2130 value = strtol(arg, &p, 8);
2131 if (arg == p || value < 0 || value > 0777)
2132 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00002133 if (*activep)
2134 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10002135 break;
2136
2137 case sStreamLocalBindUnlink:
2138 intptr = &options->fwd_opts.streamlocal_bind_unlink;
2139 goto parse_flag;
2140
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002141 case sFingerprintHash:
2142 arg = strdelim(&cp);
2143 if (!arg || *arg == '\0')
2144 fatal("%.200s line %d: Missing argument.",
2145 filename, linenum);
2146 if ((value = ssh_digest_alg_by_name(arg)) == -1)
2147 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2148 filename, linenum, arg);
2149 if (*activep)
2150 options->fingerprint_hash = value;
2151 break;
2152
djm@openbsd.org8f574952017-06-24 06:34:38 +00002153 case sExposeAuthInfo:
2154 intptr = &options->expose_userauth_info;
2155 goto parse_flag;
2156
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002157 case sRDomain:
2158 charptr = &options->routing_domain;
2159 arg = strdelim(&cp);
2160 if (!arg || *arg == '\0')
2161 fatal("%.200s line %d: Missing argument.",
2162 filename, linenum);
2163 if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2164 !valid_rdomain(arg))
2165 fatal("%s line %d: bad routing domain",
2166 filename, linenum);
2167 if (*activep && *charptr == NULL)
2168 *charptr = xstrdup(arg);
dtucker@openbsd.org168ecec2017-12-05 23:56:07 +00002169 break;
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002170
Ben Lindstromade03f62001-12-06 18:22:17 +00002171 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002172 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10002173 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00002174 do_log2(opcode == sIgnore ?
2175 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2176 "%s line %d: %s option %s", filename, linenum,
2177 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10002178 while (arg)
2179 arg = strdelim(&cp);
2180 break;
2181
Ben Lindstromade03f62001-12-06 18:22:17 +00002182 default:
2183 fatal("%s line %d: Missing handler for opcode %s (%d)",
2184 filename, linenum, arg, opcode);
2185 }
2186 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2187 fatal("%s line %d: garbage at end of line; \"%.200s\".",
2188 filename, linenum, arg);
2189 return 0;
2190}
2191
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002192/* Reads the server configuration file. */
2193
Damien Miller4af51302000-04-16 11:18:38 +10002194void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002195load_server_config(const char *filename, struct sshbuf *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002196{
markus@openbsd.org7f906352018-06-06 18:29:18 +00002197 char *line = NULL, *cp;
2198 size_t linesize = 0;
Ben Lindstrome1353632002-06-23 21:29:23 +00002199 FILE *f;
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002200 int r, lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002201
Darren Tucker645ab752004-06-25 13:33:20 +10002202 debug2("%s: filename %s", __func__, filename);
2203 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11002204 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002205 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11002206 }
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002207 sshbuf_reset(conf);
markus@openbsd.org7f906352018-06-06 18:29:18 +00002208 while (getline(&line, &linesize, f) != -1) {
Damien Miller46cb75a2012-07-31 12:22:37 +10002209 lineno++;
Darren Tucker645ab752004-06-25 13:33:20 +10002210 /*
2211 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10002212 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10002213 * line numbers later for error messages
2214 */
2215 if ((cp = strchr(line, '#')) != NULL)
2216 memcpy(cp, "\n", 2);
2217 cp = line + strspn(line, " \t\r");
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002218 if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2219 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002220 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00002221 free(line);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002222 if ((r = sshbuf_put_u8(conf, 0)) != 0)
2223 fatal("%s: buffer error: %s", __func__, ssh_err(r));
Darren Tucker645ab752004-06-25 13:33:20 +10002224 fclose(f);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002225 debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002226}
2227
2228void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002229parse_server_match_config(ServerOptions *options,
2230 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10002231{
Darren Tucker45150472006-07-12 22:34:17 +10002232 ServerOptions mo;
2233
2234 initialize_server_options(&mo);
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002235 parse_server_config(&mo, "reprocess config", cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11002236 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10002237}
2238
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002239int parse_server_match_testspec(struct connection_info *ci, char *spec)
2240{
2241 char *p;
2242
2243 while ((p = strsep(&spec, ",")) && *p != '\0') {
2244 if (strncmp(p, "addr=", 5) == 0) {
2245 ci->address = xstrdup(p + 5);
2246 } else if (strncmp(p, "host=", 5) == 0) {
2247 ci->host = xstrdup(p + 5);
2248 } else if (strncmp(p, "user=", 5) == 0) {
2249 ci->user = xstrdup(p + 5);
2250 } else if (strncmp(p, "laddr=", 6) == 0) {
2251 ci->laddress = xstrdup(p + 6);
djm@openbsd.org68af80e2017-10-25 00:19:47 +00002252 } else if (strncmp(p, "rdomain=", 8) == 0) {
2253 ci->rdomain = xstrdup(p + 8);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002254 } else if (strncmp(p, "lport=", 6) == 0) {
2255 ci->lport = a2port(p + 6);
2256 if (ci->lport == -1) {
2257 fprintf(stderr, "Invalid port '%s' in test mode"
2258 " specification %s\n", p+6, p);
2259 return -1;
2260 }
2261 } else {
2262 fprintf(stderr, "Invalid test mode specification %s\n",
2263 p);
2264 return -1;
2265 }
2266 }
2267 return 0;
2268}
2269
2270/*
Darren Tucker1629c072007-02-19 22:25:37 +11002271 * Copy any supported values that are set.
2272 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002273 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002274 * array values that are not used pre-authentication, because any that we
djm@openbsd.org001aa552018-04-10 00:10:49 +00002275 * do use must be explicitly sent in mm_getpwnamallow().
Darren Tucker1629c072007-02-19 22:25:37 +11002276 */
Darren Tucker45150472006-07-12 22:34:17 +10002277void
Darren Tucker1629c072007-02-19 22:25:37 +11002278copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002279{
Damien Miller534b2cc2013-12-05 14:07:27 +11002280#define M_CP_INTOPT(n) do {\
2281 if (src->n != -1) \
2282 dst->n = src->n; \
2283} while (0)
2284
Darren Tucker1629c072007-02-19 22:25:37 +11002285 M_CP_INTOPT(password_authentication);
2286 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002287 M_CP_INTOPT(pubkey_authentication);
2288 M_CP_INTOPT(kerberos_authentication);
2289 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002290 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002291 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002292 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002293 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002294
2295 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002296 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002297 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002298 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002299 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002300 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002301 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002302 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002303 M_CP_INTOPT(x11_display_offset);
2304 M_CP_INTOPT(x11_forwarding);
2305 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002306 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002307 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002308 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002309 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002310 M_CP_INTOPT(client_alive_count_max);
2311 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002312 M_CP_INTOPT(ip_qos_interactive);
2313 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002314 M_CP_INTOPT(rekey_limit);
2315 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002316 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002317
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002318 /*
2319 * The bind_mask is a mode_t that may be unsigned, so we can't use
2320 * M_CP_INTOPT - it does a signed comparison that causes compiler
2321 * warnings.
2322 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002323 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002324 dst->fwd_opts.streamlocal_bind_mask =
2325 src->fwd_opts.streamlocal_bind_mask;
2326 }
2327
Damien Miller534b2cc2013-12-05 14:07:27 +11002328 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2329#define M_CP_STROPT(n) do {\
2330 if (src->n != NULL && dst->n != src->n) { \
2331 free(dst->n); \
2332 dst->n = src->n; \
2333 } \
2334} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002335#define M_CP_STRARRAYOPT(s, num_s) do {\
2336 u_int i; \
2337 if (src->num_s != 0) { \
2338 for (i = 0; i < dst->num_s; i++) \
2339 free(dst->s[i]); \
2340 free(dst->s); \
2341 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2342 for (i = 0; i < src->num_s; i++) \
2343 dst->s[i] = xstrdup(src->s[i]); \
2344 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002345 } \
2346} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002347
Damien Millerf2e407e2011-05-20 19:04:14 +10002348 /* See comment in servconf.h */
2349 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002350
djm@openbsd.orged085102015-10-29 08:05:01 +00002351 /* Arguments that accept '+...' need to be expanded */
2352 assemble_algorithms(dst);
2353
Damien Millerc2411902011-05-20 19:03:49 +10002354 /*
2355 * The only things that should be below this point are string options
2356 * which are only used after authentication.
2357 */
Damien Miller5d74e582011-05-20 19:03:31 +10002358 if (preauth)
2359 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002360
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002361 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002362 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002363 if (option_clear_or_none(dst->adm_forced_command)) {
2364 free(dst->adm_forced_command);
2365 dst->adm_forced_command = NULL;
2366 }
Damien Miller5d74e582011-05-20 19:03:31 +10002367 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002368 if (option_clear_or_none(dst->chroot_directory)) {
2369 free(dst->chroot_directory);
2370 dst->chroot_directory = NULL;
2371 }
Darren Tucker45150472006-07-12 22:34:17 +10002372}
2373
Darren Tucker1629c072007-02-19 22:25:37 +11002374#undef M_CP_INTOPT
2375#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002376#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002377
Darren Tucker45150472006-07-12 22:34:17 +10002378void
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002379parse_server_config(ServerOptions *options, const char *filename,
2380 struct sshbuf *conf, struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002381{
2382 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002383 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002384
markus@openbsd.orgc3cb7792018-07-09 21:29:36 +00002385 debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
Darren Tucker645ab752004-06-25 13:33:20 +10002386
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002387 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2388 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002389 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002390 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002391 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002392 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002393 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002394 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002395 }
Darren Tuckera627d422013-06-02 07:31:17 +10002396 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002397 if (bad_options > 0)
2398 fatal("%s: terminating, %d bad configuration options",
2399 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002400 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002401}
Darren Tuckere7140f22008-06-10 23:01:51 +10002402
2403static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002404fmt_multistate_int(int val, const struct multistate *m)
2405{
2406 u_int i;
2407
2408 for (i = 0; m[i].key != NULL; i++) {
2409 if (m[i].value == val)
2410 return m[i].key;
2411 }
2412 return "UNKNOWN";
2413}
2414
2415static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002416fmt_intarg(ServerOpCodes code, int val)
2417{
Damien Miller82c55872011-06-23 08:20:30 +10002418 if (val == -1)
2419 return "unset";
2420 switch (code) {
2421 case sAddressFamily:
2422 return fmt_multistate_int(val, multistate_addressfamily);
2423 case sPermitRootLogin:
2424 return fmt_multistate_int(val, multistate_permitrootlogin);
2425 case sGatewayPorts:
2426 return fmt_multistate_int(val, multistate_gatewayports);
2427 case sCompression:
2428 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002429 case sAllowTcpForwarding:
2430 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002431 case sAllowStreamLocalForwarding:
2432 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002433 case sFingerprintHash:
2434 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002435 default:
2436 switch (val) {
2437 case 0:
2438 return "no";
2439 case 1:
2440 return "yes";
2441 default:
2442 return "UNKNOWN";
2443 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002444 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002445}
2446
Darren Tuckere7140f22008-06-10 23:01:51 +10002447static void
2448dump_cfg_int(ServerOpCodes code, int val)
2449{
2450 printf("%s %d\n", lookup_opcode_name(code), val);
2451}
2452
2453static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002454dump_cfg_oct(ServerOpCodes code, int val)
2455{
2456 printf("%s 0%o\n", lookup_opcode_name(code), val);
2457}
2458
2459static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002460dump_cfg_fmtint(ServerOpCodes code, int val)
2461{
2462 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2463}
2464
2465static void
2466dump_cfg_string(ServerOpCodes code, const char *val)
2467{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002468 printf("%s %s\n", lookup_opcode_name(code),
2469 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002470}
2471
2472static void
2473dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2474{
2475 u_int i;
2476
2477 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002478 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2479}
2480
2481static void
2482dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2483{
2484 u_int i;
2485
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002486 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002487 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002488 printf("%s", lookup_opcode_name(code));
2489 for (i = 0; i < count; i++)
2490 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002491 if (code == sAuthenticationMethods && count == 0)
2492 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002493 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002494}
2495
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002496static char *
2497format_listen_addrs(struct listenaddr *la)
Darren Tuckere7140f22008-06-10 23:01:51 +10002498{
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002499 int r;
Darren Tuckere7140f22008-06-10 23:01:51 +10002500 struct addrinfo *ai;
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002501 char addr[NI_MAXHOST], port[NI_MAXSERV];
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002502 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002503
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002504 /*
2505 * ListenAddress must be after Port. add_one_listen_addr pushes
2506 * addresses onto a stack, so to maintain ordering we need to
2507 * print these in reverse order.
2508 */
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002509 for (ai = la->addrs; ai; ai = ai->ai_next) {
2510 if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
Darren Tuckere7140f22008-06-10 23:01:51 +10002511 sizeof(addr), port, sizeof(port),
2512 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002513 error("getnameinfo: %.100s", ssh_gai_strerror(r));
2514 continue;
Darren Tuckere7140f22008-06-10 23:01:51 +10002515 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002516 laddr2 = laddr1;
2517 if (ai->ai_family == AF_INET6) {
2518 xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2519 addr, port,
2520 la->rdomain == NULL ? "" : " rdomain ",
2521 la->rdomain == NULL ? "" : la->rdomain,
2522 laddr2);
2523 } else {
2524 xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2525 addr, port,
2526 la->rdomain == NULL ? "" : " rdomain ",
2527 la->rdomain == NULL ? "" : la->rdomain,
2528 laddr2);
2529 }
2530 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002531 }
djm@openbsd.orgacf559e2017-10-25 00:15:35 +00002532 return laddr1;
2533}
2534
2535void
2536dump_config(ServerOptions *o)
2537{
2538 char *s;
2539 u_int i;
2540
2541 /* these are usually at the top of the config */
2542 for (i = 0; i < o->num_ports; i++)
2543 printf("port %d\n", o->ports[i]);
2544 dump_cfg_fmtint(sAddressFamily, o->address_family);
2545
2546 for (i = 0; i < o->num_listen_addrs; i++) {
2547 s = format_listen_addrs(&o->listen_addrs[i]);
2548 printf("%s", s);
2549 free(s);
2550 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002551
2552 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002553#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002554 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002555#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002556 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002557 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2558 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002559 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002560 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2561 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002562 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002563
2564 /* formatted integer arguments */
2565 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2566 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2567 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002568 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2569 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2570 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002571 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002572#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002573 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2574 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2575 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002576# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002577 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002578# endif
2579#endif
2580#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002581 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2582 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002583#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002584 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2585 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2586 o->kbd_interactive_authentication);
2587 dump_cfg_fmtint(sChallengeResponseAuthentication,
2588 o->challenge_response_authentication);
2589 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002590#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002591 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002592#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002593 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2594 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002595 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002596 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002597 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2598 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2599 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
Darren Tuckere7140f22008-06-10 23:01:51 +10002600 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002601 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002602 dump_cfg_fmtint(sUseDNS, o->use_dns);
2603 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002604 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002605 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002606 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002607 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002608 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002609 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002610
2611 /* string arguments */
2612 dump_cfg_string(sPidFile, o->pid_file);
2613 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002614 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2615 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002616 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002617 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002618 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002619 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2620 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002621 dump_cfg_string(sAuthorizedPrincipalsFile,
2622 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002623 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2624 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002625 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2626 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002627 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2628 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002629 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002630 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002631 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org86e57372018-09-20 03:28:06 +00002632 dump_cfg_string(sCASignatureAlgorithms, o->ca_sign_algorithms ?
2633 o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002634 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2635 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002636 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2637 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002638 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2639 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
djm@openbsd.org35eb33f2017-10-25 00:17:08 +00002640 dump_cfg_string(sRDomain, o->routing_domain);
Darren Tuckere7140f22008-06-10 23:01:51 +10002641
2642 /* string arguments requiring a lookup */
2643 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2644 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2645
2646 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002647 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2648 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002649 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2650 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002651 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002652 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002653 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2654 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2655 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2656 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2657 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
djm@openbsd.org28013752018-06-09 03:03:10 +00002658 dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
Damien Millera6e3f012012-11-04 23:21:40 +11002659 dump_cfg_strarray_oneline(sAuthenticationMethods,
2660 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002661
2662 /* other arguments */
2663 for (i = 0; i < o->num_subsystems; i++)
2664 printf("subsystem %s %s\n", o->subsystem_name[i],
2665 o->subsystem_args[i]);
2666
2667 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2668 o->max_startups_rate, o->max_startups);
2669
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002670 s = NULL;
2671 for (i = 0; tunmode_desc[i].val != -1; i++) {
Darren Tuckere7140f22008-06-10 23:01:51 +10002672 if (tunmode_desc[i].val == o->permit_tun) {
2673 s = tunmode_desc[i].text;
2674 break;
2675 }
djm@openbsd.orgd685e5a2017-10-25 02:10:39 +00002676 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002677 dump_cfg_string(sPermitTunnel, s);
2678
Damien Miller91475862011-05-05 14:14:34 +10002679 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2680 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002681
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002682 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002683 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002684
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002685 printf("permitopen");
2686 if (o->num_permitted_opens == 0)
2687 printf(" any");
2688 else {
2689 for (i = 0; i < o->num_permitted_opens; i++)
2690 printf(" %s", o->permitted_opens[i]);
2691 }
2692 printf("\n");
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002693 printf("permitlisten");
2694 if (o->num_permitted_listens == 0)
djm@openbsd.org115063a2018-06-06 18:22:41 +00002695 printf(" any");
2696 else {
djm@openbsd.org93c06ab2018-06-06 18:23:32 +00002697 for (i = 0; i < o->num_permitted_listens; i++)
2698 printf(" %s", o->permitted_listens[i]);
djm@openbsd.org115063a2018-06-06 18:22:41 +00002699 }
2700 printf("\n");
djm@openbsd.org95344c22018-07-03 10:59:35 +00002701
2702 if (o->permit_user_env_whitelist == NULL) {
2703 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2704 } else {
2705 printf("permituserenvironment %s\n",
2706 o->permit_user_env_whitelist);
2707 }
2708
Darren Tuckere7140f22008-06-10 23:01:51 +10002709}