blob: a96df4f67e6fab5b33b83b66edd2f2ef7d197e04 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002/* $OpenBSD: servconf.c,v 1.314 2017/10/05 15:52:03 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>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100032#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100033#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100034#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100035#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100036#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100037
Damien Millerb84886b2008-05-19 15:05:07 +100038#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100042#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100043#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100045#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000049#include "kex.h"
50#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100051#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100052#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100053#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100054#include "canohost.h"
55#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110056#include "hostfile.h"
57#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000058#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000059#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000060
Damien Miller3dc71ad2009-01-28 16:31:22 +110061static void add_listen_addr(ServerOptions *, char *, int);
62static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110063
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000064/* Use of privilege separation or not */
65extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100066extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068/* Initializes the server options to their default values. */
69
Damien Miller4af51302000-04-16 11:18:38 +100070void
Damien Miller95def091999-11-25 00:26:21 +110071initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072{
Damien Miller95def091999-11-25 00:26:21 +110073 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100076 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110077
78 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110079 options->num_ports = 0;
80 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000081 options->queued_listen_addrs = NULL;
82 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110083 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110084 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110085 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110086 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100087 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100088 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110089 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +000090 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110091 options->ignore_rhosts = -1;
92 options->ignore_user_known_hosts = -1;
93 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000094 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110095 options->x11_forwarding = -1;
96 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110097 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110098 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +100099 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000100 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100102 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100103 options->log_facility = SYSLOG_FACILITY_NOT_SET;
104 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000105 options->hostbased_authentication = -1;
106 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000107 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000108 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100109 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000110 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->kerberos_authentication = -1;
112 options->kerberos_or_local_passwd = -1;
113 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100114 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000115 options->gss_authentication=-1;
116 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000117 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100118 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100119 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000120 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000122 options->permit_user_env = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000123 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000124 options->rekey_limit = -1;
125 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100126 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000127 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000128 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100129 options->num_allow_users = 0;
130 options->num_deny_users = 0;
131 options->num_allow_groups = 0;
132 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000133 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000134 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000135 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000136 options->fwd_opts.gateway_ports = -1;
137 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
138 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000139 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000140 options->max_startups_begin = -1;
141 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000142 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000143 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000144 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000145 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000146 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000147 options->client_alive_interval = -1;
148 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000149 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000150 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100151 options->permit_tun = -1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000152 options->permitted_opens = NULL;
Damien Millere2754432006-07-24 14:06:47 +1000153 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100154 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100155 options->authorized_keys_command = NULL;
156 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100157 options->revoked_keys_file = NULL;
158 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000159 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000160 options->authorized_principals_command = NULL;
161 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100162 options->ip_qos_interactive = -1;
163 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000164 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000165 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000166 options->disable_forwarding = -1;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000167 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000168}
169
djm@openbsd.org161cf412014-12-22 07:55:51 +0000170/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
171static int
172option_clear_or_none(const char *o)
173{
174 return o == NULL || strcasecmp(o, "none") == 0;
175}
176
djm@openbsd.orged085102015-10-29 08:05:01 +0000177static void
178assemble_algorithms(ServerOptions *o)
179{
180 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
181 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
182 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
183 kex_assemble_names(KEX_DEFAULT_PK_ALG,
184 &o->hostkeyalgorithms) != 0 ||
185 kex_assemble_names(KEX_DEFAULT_PK_ALG,
186 &o->hostbased_key_types) != 0 ||
187 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
188 fatal("kex_assemble_names failed");
189}
190
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000191static void
192array_append(const char *file, const int line, const char *directive,
193 char ***array, u_int *lp, const char *s)
194{
195
196 if (*lp >= INT_MAX)
197 fatal("%s line %d: Too many %s entries", file, line, directive);
198
199 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
200 (*array)[*lp] = xstrdup(s);
201 (*lp)++;
202}
203
204void
205servconf_add_hostkey(const char *file, const int line,
206 ServerOptions *options, const char *path)
207{
208 char *apath = derelativise_path(path);
209
210 array_append(file, line, "HostKey",
211 &options->host_key_files, &options->num_host_key_files, apath);
212 free(apath);
213}
214
215void
216servconf_add_hostcert(const char *file, const int line,
217 ServerOptions *options, const char *path)
218{
219 char *apath = derelativise_path(path);
220
221 array_append(file, line, "HostCertificate",
222 &options->host_cert_files, &options->num_host_cert_files, apath);
223 free(apath);
224}
225
Damien Miller4af51302000-04-16 11:18:38 +1000226void
Damien Miller95def091999-11-25 00:26:21 +1100227fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000228{
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000229 u_int i;
djm@openbsd.org161cf412014-12-22 07:55:51 +0000230
Damien Miller726273e2001-11-12 11:40:11 +1100231 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000232 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000233 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100234
235 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100236 if (options->num_host_key_files == 0) {
237 /* fill default hostkeys for protocols */
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000238 servconf_add_hostkey("[default]", 0, options,
239 _PATH_HOST_RSA_KEY_FILE);
240 servconf_add_hostkey("[default]", 0, options,
241 _PATH_HOST_DSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100242#ifdef OPENSSL_HAS_ECC
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000243 servconf_add_hostkey("[default]", 0, options,
244 _PATH_HOST_ECDSA_KEY_FILE);
Damien Millerdd190dd2010-11-11 14:17:02 +1100245#endif
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000246 servconf_add_hostkey("[default]", 0, options,
247 _PATH_HOST_ED25519_KEY_FILE);
Damien Miller0bc1bd82000-11-13 22:57:25 +1100248 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100249 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100250 if (options->num_ports == 0)
251 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000252 if (options->address_family == -1)
253 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100254 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000255 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000256 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000257 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100258 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000259 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000260 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000261 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100263 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100264 if (options->ignore_user_known_hosts == -1)
265 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100266 if (options->print_motd == -1)
267 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000268 if (options->print_lastlog == -1)
269 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100270 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100271 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100272 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100273 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100274 if (options->x11_use_localhost == -1)
275 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000276 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000277 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100278 if (options->permit_tty == -1)
279 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000280 if (options->permit_user_rc == -1)
281 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100282 if (options->strict_modes == -1)
283 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100284 if (options->tcp_keep_alive == -1)
285 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100286 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100287 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100288 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000289 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000290 if (options->hostbased_authentication == -1)
291 options->hostbased_authentication = 0;
292 if (options->hostbased_uses_name_from_packet_only == -1)
293 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100294 if (options->pubkey_authentication == -1)
295 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100296 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000297 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100298 if (options->kerberos_or_local_passwd == -1)
299 options->kerberos_or_local_passwd = 1;
300 if (options->kerberos_ticket_cleanup == -1)
301 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100302 if (options->kerberos_get_afs_token == -1)
303 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000304 if (options->gss_authentication == -1)
305 options->gss_authentication = 0;
306 if (options->gss_cleanup_creds == -1)
307 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000308 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000309 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100310 if (options->password_authentication == -1)
311 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100312 if (options->kbd_interactive_authentication == -1)
313 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000314 if (options->challenge_response_authentication == -1)
315 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100316 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100317 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000318 if (options->permit_user_env == -1)
319 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000320 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000321 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000322 if (options->rekey_limit == -1)
323 options->rekey_limit = 0;
324 if (options->rekey_interval == -1)
325 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100326 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100327 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000328 if (options->allow_streamlocal_forwarding == -1)
329 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000330 if (options->allow_agent_forwarding == -1)
331 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000332 if (options->fwd_opts.gateway_ports == -1)
333 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000334 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100335 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000336 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100337 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000338 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100339 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000340 if (options->max_authtries == -1)
341 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000342 if (options->max_sessions == -1)
343 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000344 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000345 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000346 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100347 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000348 if (options->client_alive_count_max == -1)
349 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000350 if (options->num_authkeys_files == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +0000351 array_append("[default]", 0, "AuthorizedKeysFiles",
352 &options->authorized_keys_files,
353 &options->num_authkeys_files,
354 _PATH_SSH_USER_PERMITTED_KEYS);
355 array_append("[default]", 0, "AuthorizedKeysFiles",
356 &options->authorized_keys_files,
357 &options->num_authkeys_files,
358 _PATH_SSH_USER_PERMITTED_KEYS2);
Damien Millerd8478b62011-05-29 21:39:36 +1000359 }
Damien Millerd27b9472005-12-13 19:29:02 +1100360 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100361 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100362 if (options->ip_qos_interactive == -1)
363 options->ip_qos_interactive = IPTOS_LOWDELAY;
364 if (options->ip_qos_bulk == -1)
365 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000366 if (options->version_addendum == NULL)
367 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000368 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
369 options->fwd_opts.streamlocal_bind_mask = 0177;
370 if (options->fwd_opts.streamlocal_bind_unlink == -1)
371 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000372 if (options->fingerprint_hash == -1)
373 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000374 if (options->disable_forwarding == -1)
375 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000376 if (options->expose_userauth_info == -1)
377 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000378
djm@openbsd.orged085102015-10-29 08:05:01 +0000379 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000380
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000381 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000382 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000383 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000384
djm@openbsd.org161cf412014-12-22 07:55:51 +0000385#define CLEAR_ON_NONE(v) \
386 do { \
387 if (option_clear_or_none(v)) { \
388 free(v); \
389 v = NULL; \
390 } \
391 } while(0)
392 CLEAR_ON_NONE(options->pid_file);
393 CLEAR_ON_NONE(options->xauth_location);
394 CLEAR_ON_NONE(options->banner);
395 CLEAR_ON_NONE(options->trusted_user_ca_keys);
396 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000397 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000398 CLEAR_ON_NONE(options->adm_forced_command);
399 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000400 for (i = 0; i < options->num_host_key_files; i++)
401 CLEAR_ON_NONE(options->host_key_files[i]);
402 for (i = 0; i < options->num_host_cert_files; i++)
403 CLEAR_ON_NONE(options->host_cert_files[i]);
404#undef CLEAR_ON_NONE
405
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000406 /* Similar handling for AuthenticationMethods=any */
407 if (options->num_auth_methods == 1 &&
408 strcmp(options->auth_methods[0], "any") == 0) {
409 free(options->auth_methods[0]);
410 options->auth_methods[0] = NULL;
411 options->num_auth_methods = 0;
412 }
413
Tim Rice40017b02002-07-14 13:36:49 -0700414#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000415 if (use_privsep && options->compression == 1) {
416 error("This platform does not support both privilege "
417 "separation and compression");
418 error("Compression disabled");
419 options->compression = 0;
420 }
421#endif
422
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000423}
424
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000425/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100426typedef enum {
427 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100428 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000429 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100430 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000431 sPort, sHostKeyFile, sLoginGraceTime,
432 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000433 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100434 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100435 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000436 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100437 sPasswordAuthentication, sKbdInteractiveAuthentication,
438 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000439 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100440 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100441 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000442 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000443 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000444 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000445 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
446 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000447 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000448 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000449 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000450 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000451 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
452 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100453 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100454 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100455 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000456 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000457 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000458 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100459 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000460 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000461 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000462 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org8f574952017-06-24 06:34:38 +0000463 sExposeAuthInfo,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000464 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000465} ServerOpCodes;
466
Darren Tucker45150472006-07-12 22:34:17 +1000467#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
468#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
469#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
470
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000471/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100472static struct {
473 const char *name;
474 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000475 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100476} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100477 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000478#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000479 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000480#else
Darren Tucker45150472006-07-12 22:34:17 +1000481 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000482#endif
Darren Tucker45150472006-07-12 22:34:17 +1000483 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100484 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000485 { "port", sPort, SSHCFG_GLOBAL },
486 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
487 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000488 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000489 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000490 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000491 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000492 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100493 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000494 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000495 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000496 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000497 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100498 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000499 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000500 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000501 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000502 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100503 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000504 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000505 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000506#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100507 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000508 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
509 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100510#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000512#else
Darren Tucker45150472006-07-12 22:34:17 +1000513 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100514#endif
515#else
Darren Tucker1629c072007-02-19 22:25:37 +1100516 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000517 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
518 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
519 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000520#endif
Darren Tucker45150472006-07-12 22:34:17 +1000521 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
522 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000523#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100524 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000526 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000527#else
Darren Tucker1629c072007-02-19 22:25:37 +1100528 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000529 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000530 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000531#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100532 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
533 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100534 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000535 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
536 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
537 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
538 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
539 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100540#ifdef DISABLE_LASTLOG
541 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
542#else
Darren Tucker45150472006-07-12 22:34:17 +1000543 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100544#endif
Darren Tucker45150472006-07-12 22:34:17 +1000545 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
546 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000547 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
548 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
549 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000550 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
551 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100552 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000553 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000554 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000555 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000556 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000557 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
558 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
559 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000560 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000561 { "allowusers", sAllowUsers, SSHCFG_ALL },
562 { "denyusers", sDenyUsers, SSHCFG_ALL },
563 { "allowgroups", sAllowGroups, SSHCFG_ALL },
564 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000565 { "ciphers", sCiphers, SSHCFG_GLOBAL },
566 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000567 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000568 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
569 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
570 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000571 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000572 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100573 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000574 { "usedns", sUseDNS, SSHCFG_GLOBAL },
575 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
576 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000577 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
578 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000579 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000580 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000581 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000582 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000583 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100584 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000585 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000586 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000587 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000588 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100589 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100590 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100591 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
592 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000593 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000594 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100595 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100596 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
597 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000598 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
599 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000600 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100601 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000602 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
603 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
604 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000605 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000606 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000607 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000608 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000609};
610
Darren Tuckere7140f22008-06-10 23:01:51 +1000611static struct {
612 int val;
613 char *text;
614} tunmode_desc[] = {
615 { SSH_TUNMODE_NO, "no" },
616 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
617 { SSH_TUNMODE_ETHERNET, "ethernet" },
618 { SSH_TUNMODE_YES, "yes" },
619 { -1, NULL }
620};
621
Damien Miller5428f641999-11-25 11:54:57 +1100622/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000623 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100624 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000625
Damien Miller4af51302000-04-16 11:18:38 +1000626static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100627parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000628 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000629{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000630 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000631
Damien Miller95def091999-11-25 00:26:21 +1100632 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000633 if (strcasecmp(cp, keywords[i].name) == 0) {
634 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100635 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000636 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000637
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000638 error("%s: line %d: Bad configuration option: %s",
639 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100640 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000641}
642
Darren Tucker88b6fb22010-01-13 22:44:29 +1100643char *
644derelativise_path(const char *path)
645{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000646 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100647
djm@openbsd.org161cf412014-12-22 07:55:51 +0000648 if (strcasecmp(path, "none") == 0)
649 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100650 expanded = tilde_expand_filename(path, getuid());
651 if (*expanded == '/')
652 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100653 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100654 fatal("%s: getcwd: %s", __func__, strerror(errno));
655 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000656 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100657 return ret;
658}
659
Ben Lindstrombba81212001-06-25 05:01:22 +0000660static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100661add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100662{
Damien Millereccb9de2005-06-17 12:59:34 +1000663 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100664
Ben Lindstrom19066a12001-04-12 23:39:26 +0000665 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000666 for (i = 0; i < options->num_ports; i++)
667 add_one_listen_addr(options, addr, options->ports[i]);
668 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000669 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000670}
671
Ben Lindstrombba81212001-06-25 05:01:22 +0000672static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100673add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000674{
675 struct addrinfo hints, *ai, *aitop;
676 char strport[NI_MAXSERV];
677 int gaierr;
678
679 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100680 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000681 hints.ai_socktype = SOCK_STREAM;
682 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100683 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000684 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
685 fatal("bad addr or host: %s (%s)",
686 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100687 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000688 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
689 ;
690 ai->ai_next = options->listen_addrs;
691 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100692}
693
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000694/*
695 * Queue a ListenAddress to be processed once we have all of the Ports
696 * and AddressFamily options.
697 */
698static void
699queue_listen_addr(ServerOptions *options, char *addr, int port)
700{
701 options->queued_listen_addrs = xreallocarray(
702 options->queued_listen_addrs, options->num_queued_listens + 1,
703 sizeof(addr));
704 options->queued_listen_ports = xreallocarray(
705 options->queued_listen_ports, options->num_queued_listens + 1,
706 sizeof(port));
707 options->queued_listen_addrs[options->num_queued_listens] =
708 xstrdup(addr);
709 options->queued_listen_ports[options->num_queued_listens] = port;
710 options->num_queued_listens++;
711}
712
713/*
714 * Process queued (text) ListenAddress entries.
715 */
716static void
717process_queued_listen_addrs(ServerOptions *options)
718{
719 u_int i;
720
721 if (options->num_ports == 0)
722 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
723 if (options->address_family == -1)
724 options->address_family = AF_UNSPEC;
725
726 for (i = 0; i < options->num_queued_listens; i++) {
727 add_listen_addr(options, options->queued_listen_addrs[i],
728 options->queued_listen_ports[i]);
729 free(options->queued_listen_addrs[i]);
730 options->queued_listen_addrs[i] = NULL;
731 }
732 free(options->queued_listen_addrs);
733 options->queued_listen_addrs = NULL;
734 free(options->queued_listen_ports);
735 options->queued_listen_ports = NULL;
736 options->num_queued_listens = 0;
737}
738
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000739/*
740 * Inform channels layer of permitopen options from configuration.
741 */
742void
743process_permitopen(struct ssh *ssh, ServerOptions *options)
744{
745 u_int i;
746 int port;
747 char *host, *arg, *oarg;
748
749 channel_clear_adm_permitted_opens(ssh);
750 if (options->num_permitted_opens == 0)
751 return; /* permit any */
752
753 /* handle keywords: "any" / "none" */
754 if (options->num_permitted_opens == 1 &&
755 strcmp(options->permitted_opens[0], "any") == 0)
756 return;
757 if (options->num_permitted_opens == 1 &&
758 strcmp(options->permitted_opens[0], "none") == 0) {
759 channel_disable_adm_local_opens(ssh);
760 return;
761 }
762 /* Otherwise treat it as a list of permitted host:port */
763 for (i = 0; i < options->num_permitted_opens; i++) {
764 oarg = arg = xstrdup(options->permitted_opens[i]);
765 host = hpdelim(&arg);
766 if (host == NULL)
767 fatal("%s: missing host in PermitOpen", __func__);
768 host = cleanhostname(host);
769 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
770 fatal("%s: bad port number in PermitOpen", __func__);
771 /* Send it to channels layer */
772 channel_add_adm_permitted_opens(ssh, host, port);
773 free(oarg);
774 }
775}
776
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000777struct connection_info *
778get_connection_info(int populate, int use_dns)
779{
djm@openbsd.org95767262016-03-07 19:02:43 +0000780 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000781 static struct connection_info ci;
782
783 if (!populate)
784 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000785 ci.host = auth_get_canonical_hostname(ssh, use_dns);
786 ci.address = ssh_remote_ipaddr(ssh);
787 ci.laddress = ssh_local_ipaddr(ssh);
788 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000789 return &ci;
790}
791
Darren Tucker45150472006-07-12 22:34:17 +1000792/*
793 * The strategy for the Match blocks is that the config file is parsed twice.
794 *
795 * The first time is at startup. activep is initialized to 1 and the
796 * directives in the global context are processed and acted on. Hitting a
797 * Match directive unsets activep and the directives inside the block are
798 * checked for syntax only.
799 *
800 * The second time is after a connection has been established but before
801 * authentication. activep is initialized to 2 and global config directives
802 * are ignored since they have already been processed. If the criteria in a
803 * Match block is met, activep is set and the subsequent directives
804 * processed and actioned until EOF or another Match block unsets it. Any
805 * options set are copied into the main server config.
806 *
807 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000808 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000809 *
810 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
811 * Match Address 192.168.0.*
812 * Tag trusted
813 * Match Group wheel
814 * Tag trusted
815 * Match Tag trusted
816 * AllowTcpForwarding yes
817 * GatewayPorts clientspecified
818 * [...]
819 *
820 * - Add a PermittedChannelRequests directive
821 * Match Group shell
822 * PermittedChannelRequests session,forwarded-tcpip
823 */
824
825static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000826match_cfg_line_group(const char *grps, int line, const char *user)
827{
828 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000829 struct passwd *pw;
830
Damien Miller565ca3f2006-08-19 00:23:15 +1000831 if (user == NULL)
832 goto out;
833
834 if ((pw = getpwnam(user)) == NULL) {
835 debug("Can't match group at line %d because user %.100s does "
836 "not exist", line, user);
837 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
838 debug("Can't Match group because user %.100s not in any group "
839 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000840 } else if (ga_match_pattern_list(grps) != 1) {
841 debug("user %.100s does not match group list %.100s at line %d",
842 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000843 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000844 debug("user %.100s matched group list %.100s at line %d", user,
845 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000846 result = 1;
847 }
848out:
849 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000850 return result;
851}
852
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000853/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000854 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100855 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000856 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000857 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000858static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000859match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000860{
Damien Millercf31f382013-10-24 21:02:56 +1100861 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000862 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000863
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000864 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000865 debug3("checking syntax for 'Match %s'", cp);
866 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000867 debug3("checking match for '%s' user %s host %s addr %s "
868 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
869 ci->host ? ci->host : "(null)",
870 ci->address ? ci->address : "(null)",
871 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000872
873 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100874 attributes++;
875 if (strcasecmp(attrib, "all") == 0) {
876 if (attributes != 1 ||
877 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
878 error("'all' cannot be combined with other "
879 "Match attributes");
880 return -1;
881 }
882 *condition = cp;
883 return 1;
884 }
Darren Tucker45150472006-07-12 22:34:17 +1000885 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
886 error("Missing Match criteria for %s", attrib);
887 return -1;
888 }
Darren Tucker45150472006-07-12 22:34:17 +1000889 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000890 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000891 result = 0;
892 continue;
893 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000894 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000895 result = 0;
896 else
897 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000898 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000899 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000900 if (ci == NULL || ci->user == NULL) {
901 result = 0;
902 continue;
903 }
904 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000905 case -1:
906 return -1;
907 case 0:
908 result = 0;
909 }
Darren Tucker45150472006-07-12 22:34:17 +1000910 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000911 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000912 result = 0;
913 continue;
914 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000915 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000916 result = 0;
917 else
918 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000919 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000920 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000921 if (ci == NULL || ci->address == NULL) {
922 result = 0;
923 continue;
924 }
925 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000926 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000927 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000928 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000929 break;
930 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000931 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000932 result = 0;
933 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000934 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000935 return -1;
936 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000937 } else if (strcasecmp(attrib, "localaddress") == 0){
938 if (ci == NULL || ci->laddress == NULL) {
939 result = 0;
940 continue;
941 }
942 switch (addr_match_list(ci->laddress, arg)) {
943 case 1:
944 debug("connection from %.100s matched "
945 "'LocalAddress %.100s' at line %d",
946 ci->laddress, arg, line);
947 break;
948 case 0:
949 case -1:
950 result = 0;
951 break;
952 case -2:
953 return -1;
954 }
955 } else if (strcasecmp(attrib, "localport") == 0) {
956 if ((port = a2port(arg)) == -1) {
957 error("Invalid LocalPort '%s' on Match line",
958 arg);
959 return -1;
960 }
961 if (ci == NULL || ci->lport == 0) {
962 result = 0;
963 continue;
964 }
965 /* TODO support port lists */
966 if (port == ci->lport)
967 debug("connection from %.100s matched "
968 "'LocalPort %d' at line %d",
969 ci->laddress, port, line);
970 else
971 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000972 } else {
973 error("Unsupported Match attribute %s", attrib);
974 return -1;
975 }
976 }
Damien Millercf31f382013-10-24 21:02:56 +1100977 if (attributes == 0) {
978 error("One or more attributes required for Match");
979 return -1;
980 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000981 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000982 debug3("match %sfound", result ? "" : "not ");
983 *condition = cp;
984 return result;
985}
986
Damien Millere2754432006-07-24 14:06:47 +1000987#define WHITESPACE " \t\r\n"
988
Damien Miller33322122011-06-20 14:43:11 +1000989/* Multistate option parsing */
990struct multistate {
991 char *key;
992 int value;
993};
994static const struct multistate multistate_addressfamily[] = {
995 { "inet", AF_INET },
996 { "inet6", AF_INET6 },
997 { "any", AF_UNSPEC },
998 { NULL, -1 }
999};
1000static const struct multistate multistate_permitrootlogin[] = {
1001 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00001002 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +10001003 { "forced-commands-only", PERMIT_FORCED_ONLY },
1004 { "yes", PERMIT_YES },
1005 { "no", PERMIT_NO },
1006 { NULL, -1 }
1007};
1008static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +00001009 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +00001010 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +10001011 { "no", COMP_NONE },
1012 { NULL, -1 }
1013};
1014static const struct multistate multistate_gatewayports[] = {
1015 { "clientspecified", 2 },
1016 { "yes", 1 },
1017 { "no", 0 },
1018 { NULL, -1 }
1019};
Damien Milleraa5b3f82012-12-03 09:50:54 +11001020static const struct multistate multistate_tcpfwd[] = {
1021 { "yes", FORWARD_ALLOW },
1022 { "all", FORWARD_ALLOW },
1023 { "no", FORWARD_DENY },
1024 { "remote", FORWARD_REMOTE },
1025 { "local", FORWARD_LOCAL },
1026 { NULL, -1 }
1027};
Damien Miller33322122011-06-20 14:43:11 +10001028
Ben Lindstromade03f62001-12-06 18:22:17 +00001029int
1030process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001031 const char *filename, int linenum, int *activep,
1032 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +00001033{
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001034 char *cp, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001035 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001036 SyslogFacility *log_facility_ptr;
1037 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +10001039 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001040 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001041 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001042 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001043
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001044 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1045 if ((len = strlen(line)) == 0)
1046 return 0;
1047 for (len--; len > 0; len--) {
1048 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1049 break;
1050 line[len] = '\0';
1051 }
1052
Ben Lindstromade03f62001-12-06 18:22:17 +00001053 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001054 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001055 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001056 /* Ignore leading whitespace */
1057 if (*arg == '\0')
1058 arg = strdelim(&cp);
1059 if (!arg || !*arg || *arg == '#')
1060 return 0;
1061 intptr = NULL;
1062 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001063 opcode = parse_token(arg, filename, linenum, &flags);
1064
1065 if (activep == NULL) { /* We are processing a command line directive */
1066 cmdline = 1;
1067 activep = &cmdline;
1068 }
1069 if (*activep && opcode != sMatch)
1070 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1071 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001072 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001073 fatal("%s line %d: Directive '%s' is not allowed "
1074 "within a Match block", filename, linenum, arg);
1075 } else { /* this is a directive we have already processed */
1076 while (arg)
1077 arg = strdelim(&cp);
1078 return 0;
1079 }
1080 }
1081
Ben Lindstromade03f62001-12-06 18:22:17 +00001082 switch (opcode) {
1083 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001084 case sUsePAM:
1085 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001086 goto parse_flag;
1087
1088 /* Standard Options */
1089 case sBadOption:
1090 return -1;
1091 case sPort:
1092 /* ignore ports from configfile if cmdline specifies ports */
1093 if (options->ports_from_cmdline)
1094 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001095 if (options->num_ports >= MAX_PORTS)
1096 fatal("%s line %d: too many ports.",
1097 filename, linenum);
1098 arg = strdelim(&cp);
1099 if (!arg || *arg == '\0')
1100 fatal("%s line %d: missing port number.",
1101 filename, linenum);
1102 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001103 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001104 fatal("%s line %d: Badly formatted port number.",
1105 filename, linenum);
1106 break;
1107
Ben Lindstromade03f62001-12-06 18:22:17 +00001108 case sLoginGraceTime:
1109 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001110 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001111 arg = strdelim(&cp);
1112 if (!arg || *arg == '\0')
1113 fatal("%s line %d: missing time value.",
1114 filename, linenum);
1115 if ((value = convtime(arg)) == -1)
1116 fatal("%s line %d: invalid time value.",
1117 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001118 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001119 *intptr = value;
1120 break;
1121
Ben Lindstromade03f62001-12-06 18:22:17 +00001122 case sListenAddress:
1123 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001124 if (arg == NULL || *arg == '\0')
1125 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001126 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001127 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1128 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1129 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001130 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001131 break;
1132 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001133 p = hpdelim(&arg);
1134 if (p == NULL)
1135 fatal("%s line %d: bad address:port usage",
1136 filename, linenum);
1137 p = cleanhostname(p);
1138 if (arg == NULL)
1139 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001140 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001141 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001142
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001143 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001144
Ben Lindstromade03f62001-12-06 18:22:17 +00001145 break;
1146
Darren Tucker0f383232005-01-20 10:57:56 +11001147 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001148 intptr = &options->address_family;
1149 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001150 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001151 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001152 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001153 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001154 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001155 value = -1;
1156 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1157 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1158 value = multistate_ptr[i].value;
1159 break;
1160 }
1161 }
1162 if (value == -1)
1163 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001164 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001165 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001166 *intptr = value;
1167 break;
1168
Ben Lindstromade03f62001-12-06 18:22:17 +00001169 case sHostKeyFile:
Ben Lindstromade03f62001-12-06 18:22:17 +00001170 arg = strdelim(&cp);
1171 if (!arg || *arg == '\0')
1172 fatal("%s line %d: missing file name.",
1173 filename, linenum);
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001174 if (*activep)
1175 servconf_add_hostkey(filename, linenum, options, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001176 break;
1177
Damien Miller85b45e02013-07-20 13:21:52 +10001178 case sHostKeyAgent:
1179 charptr = &options->host_key_agent;
1180 arg = strdelim(&cp);
1181 if (!arg || *arg == '\0')
1182 fatal("%s line %d: missing socket name.",
1183 filename, linenum);
1184 if (*activep && *charptr == NULL)
1185 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1186 xstrdup(arg) : derelativise_path(arg);
1187 break;
1188
Damien Miller0a80ca12010-02-27 07:55:05 +11001189 case sHostCertificate:
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001190 arg = strdelim(&cp);
1191 if (!arg || *arg == '\0')
1192 fatal("%s line %d: missing file name.",
1193 filename, linenum);
1194 if (*activep)
1195 servconf_add_hostcert(filename, linenum, options, arg);
1196 break;
Damien Miller0a80ca12010-02-27 07:55:05 +11001197
Ben Lindstromade03f62001-12-06 18:22:17 +00001198 case sPidFile:
1199 charptr = &options->pid_file;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001200 parse_filename:
1201 arg = strdelim(&cp);
1202 if (!arg || *arg == '\0')
1203 fatal("%s line %d: missing file name.",
1204 filename, linenum);
1205 if (*activep && *charptr == NULL) {
1206 *charptr = derelativise_path(arg);
1207 /* increase optional counter */
1208 if (intptr != NULL)
1209 *intptr = *intptr + 1;
1210 }
1211 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001212
1213 case sPermitRootLogin:
1214 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001215 multistate_ptr = multistate_permitrootlogin;
1216 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001217
1218 case sIgnoreRhosts:
1219 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001220 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001221 arg = strdelim(&cp);
1222 if (!arg || *arg == '\0')
1223 fatal("%s line %d: missing yes/no argument.",
1224 filename, linenum);
1225 value = 0; /* silence compiler */
1226 if (strcmp(arg, "yes") == 0)
1227 value = 1;
1228 else if (strcmp(arg, "no") == 0)
1229 value = 0;
1230 else
1231 fatal("%s line %d: Bad yes/no argument: %s",
1232 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001233 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001234 *intptr = value;
1235 break;
1236
1237 case sIgnoreUserKnownHosts:
1238 intptr = &options->ignore_user_known_hosts;
1239 goto parse_flag;
1240
Ben Lindstromade03f62001-12-06 18:22:17 +00001241 case sHostbasedAuthentication:
1242 intptr = &options->hostbased_authentication;
1243 goto parse_flag;
1244
1245 case sHostbasedUsesNameFromPacketOnly:
1246 intptr = &options->hostbased_uses_name_from_packet_only;
1247 goto parse_flag;
1248
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001249 case sHostbasedAcceptedKeyTypes:
1250 charptr = &options->hostbased_key_types;
1251 parse_keytypes:
1252 arg = strdelim(&cp);
1253 if (!arg || *arg == '\0')
1254 fatal("%s line %d: Missing argument.",
1255 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001256 if (*arg != '-' &&
1257 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001258 fatal("%s line %d: Bad key types '%s'.",
1259 filename, linenum, arg ? arg : "<NONE>");
1260 if (*activep && *charptr == NULL)
1261 *charptr = xstrdup(arg);
1262 break;
1263
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001264 case sHostKeyAlgorithms:
1265 charptr = &options->hostkeyalgorithms;
1266 goto parse_keytypes;
1267
Ben Lindstromade03f62001-12-06 18:22:17 +00001268 case sPubkeyAuthentication:
1269 intptr = &options->pubkey_authentication;
1270 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001271
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001272 case sPubkeyAcceptedKeyTypes:
1273 charptr = &options->pubkey_key_types;
1274 goto parse_keytypes;
1275
Ben Lindstromade03f62001-12-06 18:22:17 +00001276 case sKerberosAuthentication:
1277 intptr = &options->kerberos_authentication;
1278 goto parse_flag;
1279
1280 case sKerberosOrLocalPasswd:
1281 intptr = &options->kerberos_or_local_passwd;
1282 goto parse_flag;
1283
1284 case sKerberosTicketCleanup:
1285 intptr = &options->kerberos_ticket_cleanup;
1286 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001287
Darren Tucker22ef5082003-12-31 11:37:34 +11001288 case sKerberosGetAFSToken:
1289 intptr = &options->kerberos_get_afs_token;
1290 goto parse_flag;
1291
Darren Tucker0efd1552003-08-26 11:49:55 +10001292 case sGssAuthentication:
1293 intptr = &options->gss_authentication;
1294 goto parse_flag;
1295
1296 case sGssCleanupCreds:
1297 intptr = &options->gss_cleanup_creds;
1298 goto parse_flag;
1299
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001300 case sGssStrictAcceptor:
1301 intptr = &options->gss_strict_acceptor;
1302 goto parse_flag;
1303
Ben Lindstromade03f62001-12-06 18:22:17 +00001304 case sPasswordAuthentication:
1305 intptr = &options->password_authentication;
1306 goto parse_flag;
1307
1308 case sKbdInteractiveAuthentication:
1309 intptr = &options->kbd_interactive_authentication;
1310 goto parse_flag;
1311
1312 case sChallengeResponseAuthentication:
1313 intptr = &options->challenge_response_authentication;
1314 goto parse_flag;
1315
1316 case sPrintMotd:
1317 intptr = &options->print_motd;
1318 goto parse_flag;
1319
1320 case sPrintLastLog:
1321 intptr = &options->print_lastlog;
1322 goto parse_flag;
1323
1324 case sX11Forwarding:
1325 intptr = &options->x11_forwarding;
1326 goto parse_flag;
1327
1328 case sX11DisplayOffset:
1329 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001330 parse_int:
1331 arg = strdelim(&cp);
1332 if (!arg || *arg == '\0')
1333 fatal("%s line %d: missing integer value.",
1334 filename, linenum);
1335 value = atoi(arg);
1336 if (*activep && *intptr == -1)
1337 *intptr = value;
1338 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001339
Damien Miller95c249f2002-02-05 12:11:34 +11001340 case sX11UseLocalhost:
1341 intptr = &options->x11_use_localhost;
1342 goto parse_flag;
1343
Ben Lindstromade03f62001-12-06 18:22:17 +00001344 case sXAuthLocation:
1345 charptr = &options->xauth_location;
1346 goto parse_filename;
1347
Damien Miller5ff30c62013-10-30 22:21:50 +11001348 case sPermitTTY:
1349 intptr = &options->permit_tty;
1350 goto parse_flag;
1351
Damien Miller72e6b5c2014-07-04 09:00:04 +10001352 case sPermitUserRC:
1353 intptr = &options->permit_user_rc;
1354 goto parse_flag;
1355
Ben Lindstromade03f62001-12-06 18:22:17 +00001356 case sStrictModes:
1357 intptr = &options->strict_modes;
1358 goto parse_flag;
1359
Damien Miller12c150e2003-12-17 16:31:10 +11001360 case sTCPKeepAlive:
1361 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001362 goto parse_flag;
1363
1364 case sEmptyPasswd:
1365 intptr = &options->permit_empty_passwd;
1366 goto parse_flag;
1367
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001368 case sPermitUserEnvironment:
1369 intptr = &options->permit_user_env;
1370 goto parse_flag;
1371
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001372 case sCompression:
1373 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001374 multistate_ptr = multistate_compression;
1375 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001376
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001377 case sRekeyLimit:
1378 arg = strdelim(&cp);
1379 if (!arg || *arg == '\0')
1380 fatal("%.200s line %d: Missing argument.", filename,
1381 linenum);
1382 if (strcmp(arg, "default") == 0) {
1383 val64 = 0;
1384 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001385 if (scan_scaled(arg, &val64) == -1)
1386 fatal("%.200s line %d: Bad number '%s': %s",
1387 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001388 if (val64 != 0 && val64 < 16)
1389 fatal("%.200s line %d: RekeyLimit too small",
1390 filename, linenum);
1391 }
1392 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001393 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001394 if (cp != NULL) { /* optional rekey interval present */
1395 if (strcmp(cp, "none") == 0) {
1396 (void)strdelim(&cp); /* discard */
1397 break;
1398 }
1399 intptr = &options->rekey_interval;
1400 goto parse_time;
1401 }
1402 break;
1403
Ben Lindstromade03f62001-12-06 18:22:17 +00001404 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001405 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001406 multistate_ptr = multistate_gatewayports;
1407 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001408
Damien Miller3a961dc2003-06-03 10:25:48 +10001409 case sUseDNS:
1410 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001411 goto parse_flag;
1412
1413 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001414 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001415 arg = strdelim(&cp);
1416 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001417 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001418 fatal("%.200s line %d: unsupported log facility '%s'",
1419 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001420 if (*log_facility_ptr == -1)
1421 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001422 break;
1423
1424 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001425 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001426 arg = strdelim(&cp);
1427 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001428 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001429 fatal("%.200s line %d: unsupported log level '%s'",
1430 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001431 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001432 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001433 break;
1434
1435 case sAllowTcpForwarding:
1436 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001437 multistate_ptr = multistate_tcpfwd;
1438 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001439
Damien Miller7acefbb2014-07-18 14:11:24 +10001440 case sAllowStreamLocalForwarding:
1441 intptr = &options->allow_streamlocal_forwarding;
1442 multistate_ptr = multistate_tcpfwd;
1443 goto parse_multistate;
1444
Damien Miller4f755cd2008-05-19 14:57:41 +10001445 case sAllowAgentForwarding:
1446 intptr = &options->allow_agent_forwarding;
1447 goto parse_flag;
1448
djm@openbsd.org7844f352016-11-30 03:00:05 +00001449 case sDisableForwarding:
1450 intptr = &options->disable_forwarding;
1451 goto parse_flag;
1452
Ben Lindstromade03f62001-12-06 18:22:17 +00001453 case sAllowUsers:
1454 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001455 if (match_user(NULL, NULL, NULL, arg) == -1)
1456 fatal("%s line %d: invalid AllowUsers pattern: "
1457 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001458 if (!*activep)
1459 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001460 array_append(filename, linenum, "AllowUsers",
1461 &options->allow_users, &options->num_allow_users,
1462 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001463 }
1464 break;
1465
1466 case sDenyUsers:
1467 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.org010359b2016-11-06 05:46:37 +00001468 if (match_user(NULL, NULL, NULL, arg) == -1)
1469 fatal("%s line %d: invalid DenyUsers pattern: "
1470 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001471 if (!*activep)
1472 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001473 array_append(filename, linenum, "DenyUsers",
1474 &options->deny_users, &options->num_deny_users,
1475 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001476 }
1477 break;
1478
1479 case sAllowGroups:
1480 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001481 if (!*activep)
1482 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001483 array_append(filename, linenum, "AllowGroups",
1484 &options->allow_groups, &options->num_allow_groups,
1485 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001486 }
1487 break;
1488
1489 case sDenyGroups:
1490 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Millerc24da772012-06-20 21:53:58 +10001491 if (!*activep)
1492 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001493 array_append(filename, linenum, "DenyGroups",
1494 &options->deny_groups, &options->num_deny_groups,
1495 arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001496 }
1497 break;
1498
1499 case sCiphers:
1500 arg = strdelim(&cp);
1501 if (!arg || *arg == '\0')
1502 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001503 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001504 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1505 filename, linenum, arg ? arg : "<NONE>");
1506 if (options->ciphers == NULL)
1507 options->ciphers = xstrdup(arg);
1508 break;
1509
1510 case sMacs:
1511 arg = strdelim(&cp);
1512 if (!arg || *arg == '\0')
1513 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001514 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001515 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1516 filename, linenum, arg ? arg : "<NONE>");
1517 if (options->macs == NULL)
1518 options->macs = xstrdup(arg);
1519 break;
1520
Damien Millerd5f62bf2010-09-24 22:11:14 +10001521 case sKexAlgorithms:
1522 arg = strdelim(&cp);
1523 if (!arg || *arg == '\0')
1524 fatal("%s line %d: Missing argument.",
1525 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001526 if (*arg != '-' &&
1527 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001528 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1529 filename, linenum, arg ? arg : "<NONE>");
1530 if (options->kex_algorithms == NULL)
1531 options->kex_algorithms = xstrdup(arg);
1532 break;
1533
Ben Lindstromade03f62001-12-06 18:22:17 +00001534 case sSubsystem:
1535 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1536 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001537 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001538 }
1539 arg = strdelim(&cp);
1540 if (!arg || *arg == '\0')
1541 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001542 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001543 if (!*activep) {
1544 arg = strdelim(&cp);
1545 break;
1546 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001547 for (i = 0; i < options->num_subsystems; i++)
1548 if (strcmp(arg, options->subsystem_name[i]) == 0)
1549 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001550 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001551 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1552 arg = strdelim(&cp);
1553 if (!arg || *arg == '\0')
1554 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001555 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001556 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001557
1558 /* Collect arguments (separate to executable) */
1559 p = xstrdup(arg);
1560 len = strlen(p) + 1;
1561 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1562 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001563 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001564 strlcat(p, " ", len);
1565 strlcat(p, arg, len);
1566 }
1567 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001568 options->num_subsystems++;
1569 break;
1570
1571 case sMaxStartups:
1572 arg = strdelim(&cp);
1573 if (!arg || *arg == '\0')
1574 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001575 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001576 if ((n = sscanf(arg, "%d:%d:%d",
1577 &options->max_startups_begin,
1578 &options->max_startups_rate,
1579 &options->max_startups)) == 3) {
1580 if (options->max_startups_begin >
1581 options->max_startups ||
1582 options->max_startups_rate > 100 ||
1583 options->max_startups_rate < 1)
1584 fatal("%s line %d: Illegal MaxStartups spec.",
1585 filename, linenum);
1586 } else if (n != 1)
1587 fatal("%s line %d: Illegal MaxStartups spec.",
1588 filename, linenum);
1589 else
1590 options->max_startups = options->max_startups_begin;
1591 break;
1592
Darren Tucker89413db2004-05-24 10:36:23 +10001593 case sMaxAuthTries:
1594 intptr = &options->max_authtries;
1595 goto parse_int;
1596
Damien Miller7207f642008-05-19 15:34:50 +10001597 case sMaxSessions:
1598 intptr = &options->max_sessions;
1599 goto parse_int;
1600
Ben Lindstromade03f62001-12-06 18:22:17 +00001601 case sBanner:
1602 charptr = &options->banner;
1603 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001604
Ben Lindstromade03f62001-12-06 18:22:17 +00001605 /*
1606 * These options can contain %X options expanded at
1607 * connect time, so that you can specify paths like:
1608 *
1609 * AuthorizedKeysFile /etc/ssh_keys/%u
1610 */
1611 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001612 if (*activep && options->num_authkeys_files == 0) {
1613 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001614 arg = tilde_expand_filename(arg, getuid());
1615 array_append(filename, linenum,
1616 "AuthorizedKeysFile",
1617 &options->authorized_keys_files,
1618 &options->num_authkeys_files, arg);
1619 free(arg);
Damien Millerd8478b62011-05-29 21:39:36 +10001620 }
1621 }
1622 return 0;
1623
Damien Miller30da3442010-05-10 11:58:03 +10001624 case sAuthorizedPrincipalsFile:
1625 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001626 arg = strdelim(&cp);
1627 if (!arg || *arg == '\0')
1628 fatal("%s line %d: missing file name.",
1629 filename, linenum);
1630 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001631 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001632 /* increase optional counter */
1633 if (intptr != NULL)
1634 *intptr = *intptr + 1;
1635 }
1636 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001637
1638 case sClientAliveInterval:
1639 intptr = &options->client_alive_interval;
1640 goto parse_time;
1641
1642 case sClientAliveCountMax:
1643 intptr = &options->client_alive_count_max;
1644 goto parse_int;
1645
Darren Tucker46bc0752004-05-02 22:11:30 +10001646 case sAcceptEnv:
1647 while ((arg = strdelim(&cp)) && *arg != '\0') {
1648 if (strchr(arg, '=') != NULL)
1649 fatal("%s line %d: Invalid environment name.",
1650 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001651 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001652 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001653 array_append(filename, linenum, "AcceptEnv",
1654 &options->accept_env, &options->num_accept_env,
1655 arg);
Darren Tucker46bc0752004-05-02 22:11:30 +10001656 }
1657 break;
1658
Damien Millerd27b9472005-12-13 19:29:02 +11001659 case sPermitTunnel:
1660 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001661 arg = strdelim(&cp);
1662 if (!arg || *arg == '\0')
1663 fatal("%s line %d: Missing yes/point-to-point/"
1664 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001665 value = -1;
1666 for (i = 0; tunmode_desc[i].val != -1; i++)
1667 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1668 value = tunmode_desc[i].val;
1669 break;
1670 }
1671 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001672 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1673 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001674 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001675 *intptr = value;
1676 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001677
Darren Tucker45150472006-07-12 22:34:17 +10001678 case sMatch:
1679 if (cmdline)
1680 fatal("Match directive not supported as a command-line "
1681 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001682 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001683 if (value < 0)
1684 fatal("%s line %d: Bad Match condition", filename,
1685 linenum);
1686 *activep = value;
1687 break;
1688
Damien Miller9b439df2006-07-24 14:04:00 +10001689 case sPermitOpen:
1690 arg = strdelim(&cp);
1691 if (!arg || *arg == '\0')
1692 fatal("%s line %d: missing PermitOpen specification",
1693 filename, linenum);
djm@openbsd.org69bda022017-10-04 18:49:30 +00001694 value = options->num_permitted_opens; /* modified later */
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001695 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
djm@openbsd.org69bda022017-10-04 18:49:30 +00001696 if (*activep && value == 0) {
Damien Millerc6081482012-04-22 11:18:53 +10001697 options->num_permitted_opens = 1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001698 options->permitted_opens = xcalloc(1,
1699 sizeof(*options->permitted_opens));
1700 options->permitted_opens[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001701 }
Damien Millerc6081482012-04-22 11:18:53 +10001702 break;
1703 }
Damien Millera765cf42006-07-24 14:08:13 +10001704 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001705 arg2 = xstrdup(arg);
Damien Millera765cf42006-07-24 14:08:13 +10001706 p = hpdelim(&arg);
1707 if (p == NULL)
1708 fatal("%s line %d: missing host in PermitOpen",
1709 filename, linenum);
1710 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001711 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001712 fatal("%s line %d: bad port number in "
1713 "PermitOpen", filename, linenum);
djm@openbsd.org69bda022017-10-04 18:49:30 +00001714 if (*activep && value == 0) {
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001715 array_append(filename, linenum,
1716 "PermitOpen",
1717 &options->permitted_opens,
1718 &options->num_permitted_opens, arg2);
1719 }
1720 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001721 }
Damien Miller9b439df2006-07-24 14:04:00 +10001722 break;
1723
Damien Millere2754432006-07-24 14:06:47 +10001724 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001725 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001726 fatal("%.200s line %d: Missing argument.", filename,
1727 linenum);
1728 len = strspn(cp, WHITESPACE);
1729 if (*activep && options->adm_forced_command == NULL)
1730 options->adm_forced_command = xstrdup(cp + len);
1731 return 0;
1732
Damien Millerd8cb1f12008-02-10 22:40:12 +11001733 case sChrootDirectory:
1734 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001735
1736 arg = strdelim(&cp);
1737 if (!arg || *arg == '\0')
1738 fatal("%s line %d: missing file name.",
1739 filename, linenum);
1740 if (*activep && *charptr == NULL)
1741 *charptr = xstrdup(arg);
1742 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001743
Damien Miller1aed65e2010-03-04 21:53:35 +11001744 case sTrustedUserCAKeys:
1745 charptr = &options->trusted_user_ca_keys;
1746 goto parse_filename;
1747
1748 case sRevokedKeys:
1749 charptr = &options->revoked_keys_file;
1750 goto parse_filename;
1751
Damien Miller0dac6fb2010-11-20 15:19:38 +11001752 case sIPQoS:
1753 arg = strdelim(&cp);
1754 if ((value = parse_ipqos(arg)) == -1)
1755 fatal("%s line %d: Bad IPQoS value: %s",
1756 filename, linenum, arg);
1757 arg = strdelim(&cp);
1758 if (arg == NULL)
1759 value2 = value;
1760 else if ((value2 = parse_ipqos(arg)) == -1)
1761 fatal("%s line %d: Bad IPQoS value: %s",
1762 filename, linenum, arg);
1763 if (*activep) {
1764 options->ip_qos_interactive = value;
1765 options->ip_qos_bulk = value2;
1766 }
1767 break;
1768
Damien Miller23528812012-04-22 11:24:43 +10001769 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001770 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001771 fatal("%.200s line %d: Missing argument.", filename,
1772 linenum);
1773 len = strspn(cp, WHITESPACE);
1774 if (*activep && options->version_addendum == NULL) {
1775 if (strcasecmp(cp + len, "none") == 0)
1776 options->version_addendum = xstrdup("");
1777 else if (strchr(cp + len, '\r') != NULL)
1778 fatal("%.200s line %d: Invalid argument",
1779 filename, linenum);
1780 else
1781 options->version_addendum = xstrdup(cp + len);
1782 }
1783 return 0;
1784
Damien Miller09d3e122012-10-31 08:58:58 +11001785 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001786 if (cp == NULL)
1787 fatal("%.200s line %d: Missing argument.", filename,
1788 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001789 len = strspn(cp, WHITESPACE);
1790 if (*activep && options->authorized_keys_command == NULL) {
1791 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1792 fatal("%.200s line %d: AuthorizedKeysCommand "
1793 "must be an absolute path",
1794 filename, linenum);
1795 options->authorized_keys_command = xstrdup(cp + len);
1796 }
1797 return 0;
1798
1799 case sAuthorizedKeysCommandUser:
1800 charptr = &options->authorized_keys_command_user;
1801
1802 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001803 if (!arg || *arg == '\0')
1804 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1805 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001806 if (*activep && *charptr == NULL)
1807 *charptr = xstrdup(arg);
1808 break;
1809
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001810 case sAuthorizedPrincipalsCommand:
1811 if (cp == NULL)
1812 fatal("%.200s line %d: Missing argument.", filename,
1813 linenum);
1814 len = strspn(cp, WHITESPACE);
1815 if (*activep &&
1816 options->authorized_principals_command == NULL) {
1817 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1818 fatal("%.200s line %d: "
1819 "AuthorizedPrincipalsCommand must be "
1820 "an absolute path", filename, linenum);
1821 options->authorized_principals_command =
1822 xstrdup(cp + len);
1823 }
1824 return 0;
1825
1826 case sAuthorizedPrincipalsCommandUser:
1827 charptr = &options->authorized_principals_command_user;
1828
1829 arg = strdelim(&cp);
1830 if (!arg || *arg == '\0')
1831 fatal("%s line %d: missing "
1832 "AuthorizedPrincipalsCommandUser argument.",
1833 filename, linenum);
1834 if (*activep && *charptr == NULL)
1835 *charptr = xstrdup(arg);
1836 break;
1837
Damien Millera6e3f012012-11-04 23:21:40 +11001838 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001839 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001840 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001841 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001842 while ((arg = strdelim(&cp)) && *arg != '\0') {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001843 if (strcmp(arg, "any") == 0) {
1844 if (options->num_auth_methods > 0) {
1845 fatal("%s line %d: \"any\" "
1846 "must appear alone in "
1847 "AuthenticationMethods",
1848 filename, linenum);
1849 }
1850 value = 1;
1851 } else if (value) {
1852 fatal("%s line %d: \"any\" must appear "
1853 "alone in AuthenticationMethods",
1854 filename, linenum);
1855 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001856 fatal("%s line %d: invalid "
1857 "authentication method list.",
1858 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001859 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001860 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001861 if (!*activep)
1862 continue;
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00001863 array_append(filename, linenum,
1864 "AuthenticationMethods",
1865 &options->auth_methods,
1866 &options->num_auth_methods, arg);
Damien Millera6e3f012012-11-04 23:21:40 +11001867 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001868 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001869 fatal("%s line %d: no AuthenticationMethods "
1870 "specified", filename, linenum);
1871 }
Damien Millera6e3f012012-11-04 23:21:40 +11001872 }
1873 return 0;
1874
Damien Miller7acefbb2014-07-18 14:11:24 +10001875 case sStreamLocalBindMask:
1876 arg = strdelim(&cp);
1877 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001878 fatal("%s line %d: missing StreamLocalBindMask "
1879 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001880 /* Parse mode in octal format */
1881 value = strtol(arg, &p, 8);
1882 if (arg == p || value < 0 || value > 0777)
1883 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001884 if (*activep)
1885 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001886 break;
1887
1888 case sStreamLocalBindUnlink:
1889 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1890 goto parse_flag;
1891
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001892 case sFingerprintHash:
1893 arg = strdelim(&cp);
1894 if (!arg || *arg == '\0')
1895 fatal("%.200s line %d: Missing argument.",
1896 filename, linenum);
1897 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1898 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1899 filename, linenum, arg);
1900 if (*activep)
1901 options->fingerprint_hash = value;
1902 break;
1903
djm@openbsd.org8f574952017-06-24 06:34:38 +00001904 case sExposeAuthInfo:
1905 intptr = &options->expose_userauth_info;
1906 goto parse_flag;
1907
Ben Lindstromade03f62001-12-06 18:22:17 +00001908 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001909 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001910 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001911 do_log2(opcode == sIgnore ?
1912 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1913 "%s line %d: %s option %s", filename, linenum,
1914 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001915 while (arg)
1916 arg = strdelim(&cp);
1917 break;
1918
Ben Lindstromade03f62001-12-06 18:22:17 +00001919 default:
1920 fatal("%s line %d: Missing handler for opcode %s (%d)",
1921 filename, linenum, arg, opcode);
1922 }
1923 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1924 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1925 filename, linenum, arg);
1926 return 0;
1927}
1928
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001929/* Reads the server configuration file. */
1930
Damien Miller4af51302000-04-16 11:18:38 +10001931void
Darren Tucker645ab752004-06-25 13:33:20 +10001932load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001933{
Damien Miller46cb75a2012-07-31 12:22:37 +10001934 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001935 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001936 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001937
Darren Tucker645ab752004-06-25 13:33:20 +10001938 debug2("%s: filename %s", __func__, filename);
1939 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001940 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001941 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001942 }
Darren Tucker645ab752004-06-25 13:33:20 +10001943 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001944 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001945 lineno++;
1946 if (strlen(line) == sizeof(line) - 1)
1947 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001948 /*
1949 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001950 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001951 * line numbers later for error messages
1952 */
1953 if ((cp = strchr(line, '#')) != NULL)
1954 memcpy(cp, "\n", 2);
1955 cp = line + strspn(line, " \t\r");
1956
1957 buffer_append(conf, cp, strlen(cp));
1958 }
1959 buffer_append(conf, "\0", 1);
1960 fclose(f);
1961 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1962}
1963
1964void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001965parse_server_match_config(ServerOptions *options,
1966 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001967{
Darren Tucker45150472006-07-12 22:34:17 +10001968 ServerOptions mo;
1969
1970 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001971 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001972 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001973}
1974
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001975int parse_server_match_testspec(struct connection_info *ci, char *spec)
1976{
1977 char *p;
1978
1979 while ((p = strsep(&spec, ",")) && *p != '\0') {
1980 if (strncmp(p, "addr=", 5) == 0) {
1981 ci->address = xstrdup(p + 5);
1982 } else if (strncmp(p, "host=", 5) == 0) {
1983 ci->host = xstrdup(p + 5);
1984 } else if (strncmp(p, "user=", 5) == 0) {
1985 ci->user = xstrdup(p + 5);
1986 } else if (strncmp(p, "laddr=", 6) == 0) {
1987 ci->laddress = xstrdup(p + 6);
1988 } else if (strncmp(p, "lport=", 6) == 0) {
1989 ci->lport = a2port(p + 6);
1990 if (ci->lport == -1) {
1991 fprintf(stderr, "Invalid port '%s' in test mode"
1992 " specification %s\n", p+6, p);
1993 return -1;
1994 }
1995 } else {
1996 fprintf(stderr, "Invalid test mode specification %s\n",
1997 p);
1998 return -1;
1999 }
2000 }
2001 return 0;
2002}
2003
2004/*
2005 * returns 1 for a complete spec, 0 for partial spec and -1 for an
2006 * empty spec.
2007 */
2008int server_match_spec_complete(struct connection_info *ci)
2009{
2010 if (ci->user && ci->host && ci->address)
2011 return 1; /* complete */
2012 if (!ci->user && !ci->host && !ci->address)
2013 return -1; /* empty */
2014 return 0; /* partial */
2015}
2016
Darren Tucker1629c072007-02-19 22:25:37 +11002017/*
2018 * Copy any supported values that are set.
2019 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10002020 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11002021 * array values that are not used pre-authentication, because any that we
2022 * do use must be explictly sent in mm_getpwnamallow().
2023 */
Darren Tucker45150472006-07-12 22:34:17 +10002024void
Darren Tucker1629c072007-02-19 22:25:37 +11002025copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002026{
Damien Miller534b2cc2013-12-05 14:07:27 +11002027#define M_CP_INTOPT(n) do {\
2028 if (src->n != -1) \
2029 dst->n = src->n; \
2030} while (0)
2031
Darren Tucker1629c072007-02-19 22:25:37 +11002032 M_CP_INTOPT(password_authentication);
2033 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002034 M_CP_INTOPT(pubkey_authentication);
2035 M_CP_INTOPT(kerberos_authentication);
2036 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002037 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002038 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002039 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002040 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002041
2042 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002043 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002044 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002045 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002046 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002047 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002048 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002049 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002050 M_CP_INTOPT(x11_display_offset);
2051 M_CP_INTOPT(x11_forwarding);
2052 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002053 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002054 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002055 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002056 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002057 M_CP_INTOPT(client_alive_count_max);
2058 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002059 M_CP_INTOPT(ip_qos_interactive);
2060 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002061 M_CP_INTOPT(rekey_limit);
2062 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002063 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002064
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002065 /*
2066 * The bind_mask is a mode_t that may be unsigned, so we can't use
2067 * M_CP_INTOPT - it does a signed comparison that causes compiler
2068 * warnings.
2069 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002070 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002071 dst->fwd_opts.streamlocal_bind_mask =
2072 src->fwd_opts.streamlocal_bind_mask;
2073 }
2074
Damien Miller534b2cc2013-12-05 14:07:27 +11002075 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2076#define M_CP_STROPT(n) do {\
2077 if (src->n != NULL && dst->n != src->n) { \
2078 free(dst->n); \
2079 dst->n = src->n; \
2080 } \
2081} while(0)
djm@openbsd.orgdceabc72017-10-05 15:52:03 +00002082#define M_CP_STRARRAYOPT(s, num_s) do {\
2083 u_int i; \
2084 if (src->num_s != 0) { \
2085 for (i = 0; i < dst->num_s; i++) \
2086 free(dst->s[i]); \
2087 free(dst->s); \
2088 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2089 for (i = 0; i < src->num_s; i++) \
2090 dst->s[i] = xstrdup(src->s[i]); \
2091 dst->num_s = src->num_s; \
djm@openbsd.org66bf74a2017-10-02 19:33:20 +00002092 } \
2093} while(0)
Damien Miller534b2cc2013-12-05 14:07:27 +11002094
Damien Millerf2e407e2011-05-20 19:04:14 +10002095 /* See comment in servconf.h */
2096 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002097
djm@openbsd.orged085102015-10-29 08:05:01 +00002098 /* Arguments that accept '+...' need to be expanded */
2099 assemble_algorithms(dst);
2100
Damien Millerc2411902011-05-20 19:03:49 +10002101 /*
2102 * The only things that should be below this point are string options
2103 * which are only used after authentication.
2104 */
Damien Miller5d74e582011-05-20 19:03:31 +10002105 if (preauth)
2106 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002107
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002108 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002109 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002110 if (option_clear_or_none(dst->adm_forced_command)) {
2111 free(dst->adm_forced_command);
2112 dst->adm_forced_command = NULL;
2113 }
Damien Miller5d74e582011-05-20 19:03:31 +10002114 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002115 if (option_clear_or_none(dst->chroot_directory)) {
2116 free(dst->chroot_directory);
2117 dst->chroot_directory = NULL;
2118 }
Darren Tucker45150472006-07-12 22:34:17 +10002119}
2120
Darren Tucker1629c072007-02-19 22:25:37 +11002121#undef M_CP_INTOPT
2122#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002123#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002124
Darren Tucker45150472006-07-12 22:34:17 +10002125void
2126parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002127 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002128{
2129 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002130 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002131
2132 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2133
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002134 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2135 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002136 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002137 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002138 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002139 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002140 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002141 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002142 }
Darren Tuckera627d422013-06-02 07:31:17 +10002143 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002144 if (bad_options > 0)
2145 fatal("%s: terminating, %d bad configuration options",
2146 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002147 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002148}
Darren Tuckere7140f22008-06-10 23:01:51 +10002149
2150static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002151fmt_multistate_int(int val, const struct multistate *m)
2152{
2153 u_int i;
2154
2155 for (i = 0; m[i].key != NULL; i++) {
2156 if (m[i].value == val)
2157 return m[i].key;
2158 }
2159 return "UNKNOWN";
2160}
2161
2162static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002163fmt_intarg(ServerOpCodes code, int val)
2164{
Damien Miller82c55872011-06-23 08:20:30 +10002165 if (val == -1)
2166 return "unset";
2167 switch (code) {
2168 case sAddressFamily:
2169 return fmt_multistate_int(val, multistate_addressfamily);
2170 case sPermitRootLogin:
2171 return fmt_multistate_int(val, multistate_permitrootlogin);
2172 case sGatewayPorts:
2173 return fmt_multistate_int(val, multistate_gatewayports);
2174 case sCompression:
2175 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002176 case sAllowTcpForwarding:
2177 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002178 case sAllowStreamLocalForwarding:
2179 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002180 case sFingerprintHash:
2181 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002182 default:
2183 switch (val) {
2184 case 0:
2185 return "no";
2186 case 1:
2187 return "yes";
2188 default:
2189 return "UNKNOWN";
2190 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002191 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002192}
2193
2194static const char *
2195lookup_opcode_name(ServerOpCodes code)
2196{
2197 u_int i;
2198
2199 for (i = 0; keywords[i].name != NULL; i++)
2200 if (keywords[i].opcode == code)
2201 return(keywords[i].name);
2202 return "UNKNOWN";
2203}
2204
2205static void
2206dump_cfg_int(ServerOpCodes code, int val)
2207{
2208 printf("%s %d\n", lookup_opcode_name(code), val);
2209}
2210
2211static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002212dump_cfg_oct(ServerOpCodes code, int val)
2213{
2214 printf("%s 0%o\n", lookup_opcode_name(code), val);
2215}
2216
2217static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002218dump_cfg_fmtint(ServerOpCodes code, int val)
2219{
2220 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2221}
2222
2223static void
2224dump_cfg_string(ServerOpCodes code, const char *val)
2225{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002226 printf("%s %s\n", lookup_opcode_name(code),
2227 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002228}
2229
2230static void
2231dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2232{
2233 u_int i;
2234
2235 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002236 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2237}
2238
2239static void
2240dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2241{
2242 u_int i;
2243
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002244 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002245 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002246 printf("%s", lookup_opcode_name(code));
2247 for (i = 0; i < count; i++)
2248 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002249 if (code == sAuthenticationMethods && count == 0)
2250 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002251 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002252}
2253
2254void
2255dump_config(ServerOptions *o)
2256{
2257 u_int i;
2258 int ret;
2259 struct addrinfo *ai;
2260 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002261 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002262
2263 /* these are usually at the top of the config */
2264 for (i = 0; i < o->num_ports; i++)
2265 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002266 dump_cfg_fmtint(sAddressFamily, o->address_family);
2267
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002268 /*
2269 * ListenAddress must be after Port. add_one_listen_addr pushes
2270 * addresses onto a stack, so to maintain ordering we need to
2271 * print these in reverse order.
2272 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002273 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2274 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2275 sizeof(addr), port, sizeof(port),
2276 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2277 error("getnameinfo failed: %.100s",
2278 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2279 strerror(errno));
2280 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002281 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002282 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002283 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2284 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002285 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002286 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2287 addr, port, laddr2);
2288 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002289 }
2290 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002291 printf("%s", laddr1);
2292 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002293
2294 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002295#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002296 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002297#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002298 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002299 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2300 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002301 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002302 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2303 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002304 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002305
2306 /* formatted integer arguments */
2307 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2308 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2309 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002310 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2311 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2312 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002313 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002314#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002315 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2316 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2317 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002318# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002319 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002320# endif
2321#endif
2322#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002323 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2324 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002325#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002326 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2327 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2328 o->kbd_interactive_authentication);
2329 dump_cfg_fmtint(sChallengeResponseAuthentication,
2330 o->challenge_response_authentication);
2331 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002332#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002333 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002334#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002335 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2336 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002337 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002338 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002339 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2340 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2341 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2342 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002343 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002344 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002345 dump_cfg_fmtint(sUseDNS, o->use_dns);
2346 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002347 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002348 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002349 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002350 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002351 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002352 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002353
2354 /* string arguments */
2355 dump_cfg_string(sPidFile, o->pid_file);
2356 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002357 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2358 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002359 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002360 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002361 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002362 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2363 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002364 dump_cfg_string(sAuthorizedPrincipalsFile,
2365 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002366 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2367 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002368 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2369 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002370 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2371 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002372 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002373 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002374 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002375 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2376 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002377 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2378 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002379 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2380 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002381
2382 /* string arguments requiring a lookup */
2383 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2384 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2385
2386 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002387 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2388 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002389 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2390 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002391 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002392 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002393 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2394 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2395 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2396 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2397 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002398 dump_cfg_strarray_oneline(sAuthenticationMethods,
2399 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002400
2401 /* other arguments */
2402 for (i = 0; i < o->num_subsystems; i++)
2403 printf("subsystem %s %s\n", o->subsystem_name[i],
2404 o->subsystem_args[i]);
2405
2406 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2407 o->max_startups_rate, o->max_startups);
2408
2409 for (i = 0; tunmode_desc[i].val != -1; i++)
2410 if (tunmode_desc[i].val == o->permit_tun) {
2411 s = tunmode_desc[i].text;
2412 break;
2413 }
2414 dump_cfg_string(sPermitTunnel, s);
2415
Damien Miller91475862011-05-05 14:14:34 +10002416 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2417 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002418
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002419 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002420 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002421
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002422 printf("permitopen");
2423 if (o->num_permitted_opens == 0)
2424 printf(" any");
2425 else {
2426 for (i = 0; i < o->num_permitted_opens; i++)
2427 printf(" %s", o->permitted_opens[i]);
2428 }
2429 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002430}