blob: 16436512e0f67642257e2f56235fceac9b241f24 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00002/* $OpenBSD: servconf.c,v 1.311 2017/09/18 09:41:52 dtucker 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
Damien Miller4af51302000-04-16 11:18:38 +1000191void
Damien Miller95def091999-11-25 00:26:21 +1100192fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000193{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000194 int i;
195
Damien Miller726273e2001-11-12 11:40:11 +1100196 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000197 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000198 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100199
200 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100201 if (options->num_host_key_files == 0) {
202 /* fill default hostkeys for protocols */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000203 options->host_key_files[options->num_host_key_files++] =
204 _PATH_HOST_RSA_KEY_FILE;
205 options->host_key_files[options->num_host_key_files++] =
206 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100207#ifdef OPENSSL_HAS_ECC
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000208 options->host_key_files[options->num_host_key_files++] =
209 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100210#endif
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000211 options->host_key_files[options->num_host_key_files++] =
212 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100213 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100214 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100215 if (options->num_ports == 0)
216 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000217 if (options->address_family == -1)
218 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100219 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000220 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000221 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000222 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100223 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000224 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000225 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000226 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100227 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100228 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->ignore_user_known_hosts == -1)
230 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100231 if (options->print_motd == -1)
232 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000233 if (options->print_lastlog == -1)
234 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100235 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100236 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100237 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100238 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100239 if (options->x11_use_localhost == -1)
240 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000241 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000242 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100243 if (options->permit_tty == -1)
244 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000245 if (options->permit_user_rc == -1)
246 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100247 if (options->strict_modes == -1)
248 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100249 if (options->tcp_keep_alive == -1)
250 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100251 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100252 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100253 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000254 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000255 if (options->hostbased_authentication == -1)
256 options->hostbased_authentication = 0;
257 if (options->hostbased_uses_name_from_packet_only == -1)
258 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100259 if (options->pubkey_authentication == -1)
260 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100261 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000262 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100263 if (options->kerberos_or_local_passwd == -1)
264 options->kerberos_or_local_passwd = 1;
265 if (options->kerberos_ticket_cleanup == -1)
266 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100267 if (options->kerberos_get_afs_token == -1)
268 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000269 if (options->gss_authentication == -1)
270 options->gss_authentication = 0;
271 if (options->gss_cleanup_creds == -1)
272 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000273 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000274 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100275 if (options->password_authentication == -1)
276 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100277 if (options->kbd_interactive_authentication == -1)
278 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000279 if (options->challenge_response_authentication == -1)
280 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100281 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100282 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000283 if (options->permit_user_env == -1)
284 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000285 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000286 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000287 if (options->rekey_limit == -1)
288 options->rekey_limit = 0;
289 if (options->rekey_interval == -1)
290 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100291 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100292 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000293 if (options->allow_streamlocal_forwarding == -1)
294 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000295 if (options->allow_agent_forwarding == -1)
296 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000297 if (options->fwd_opts.gateway_ports == -1)
298 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000299 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100300 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000301 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100302 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000303 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100304 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000305 if (options->max_authtries == -1)
306 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000307 if (options->max_sessions == -1)
308 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000309 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000310 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000311 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100312 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000313 if (options->client_alive_count_max == -1)
314 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000315 if (options->num_authkeys_files == 0) {
316 options->authorized_keys_files[options->num_authkeys_files++] =
317 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
318 options->authorized_keys_files[options->num_authkeys_files++] =
319 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
320 }
Damien Millerd27b9472005-12-13 19:29:02 +1100321 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100322 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100323 if (options->ip_qos_interactive == -1)
324 options->ip_qos_interactive = IPTOS_LOWDELAY;
325 if (options->ip_qos_bulk == -1)
326 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000327 if (options->version_addendum == NULL)
328 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000329 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
330 options->fwd_opts.streamlocal_bind_mask = 0177;
331 if (options->fwd_opts.streamlocal_bind_unlink == -1)
332 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000333 if (options->fingerprint_hash == -1)
334 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000335 if (options->disable_forwarding == -1)
336 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000337 if (options->expose_userauth_info == -1)
338 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000339
djm@openbsd.orged085102015-10-29 08:05:01 +0000340 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000341
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000342 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000343 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000344 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000345
djm@openbsd.org161cf412014-12-22 07:55:51 +0000346#define CLEAR_ON_NONE(v) \
347 do { \
348 if (option_clear_or_none(v)) { \
349 free(v); \
350 v = NULL; \
351 } \
352 } while(0)
353 CLEAR_ON_NONE(options->pid_file);
354 CLEAR_ON_NONE(options->xauth_location);
355 CLEAR_ON_NONE(options->banner);
356 CLEAR_ON_NONE(options->trusted_user_ca_keys);
357 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000358 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000359 CLEAR_ON_NONE(options->adm_forced_command);
360 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000361 for (i = 0; i < options->num_host_key_files; i++)
362 CLEAR_ON_NONE(options->host_key_files[i]);
363 for (i = 0; i < options->num_host_cert_files; i++)
364 CLEAR_ON_NONE(options->host_cert_files[i]);
365#undef CLEAR_ON_NONE
366
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000367 /* Similar handling for AuthenticationMethods=any */
368 if (options->num_auth_methods == 1 &&
369 strcmp(options->auth_methods[0], "any") == 0) {
370 free(options->auth_methods[0]);
371 options->auth_methods[0] = NULL;
372 options->num_auth_methods = 0;
373 }
374
Tim Rice40017b02002-07-14 13:36:49 -0700375#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000376 if (use_privsep && options->compression == 1) {
377 error("This platform does not support both privilege "
378 "separation and compression");
379 error("Compression disabled");
380 options->compression = 0;
381 }
382#endif
383
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000384}
385
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000386/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100387typedef enum {
388 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100389 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000390 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100391 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000392 sPort, sHostKeyFile, sLoginGraceTime,
393 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000394 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100395 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100396 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000397 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100398 sPasswordAuthentication, sKbdInteractiveAuthentication,
399 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000400 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100401 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100402 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000403 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000404 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000405 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000406 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
407 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000408 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000409 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000410 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000411 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000412 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
413 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100414 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100415 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100416 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000417 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000418 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000419 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100420 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000421 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000422 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000423 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org8f574952017-06-24 06:34:38 +0000424 sExposeAuthInfo,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000425 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000426} ServerOpCodes;
427
Darren Tucker45150472006-07-12 22:34:17 +1000428#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
429#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
430#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
431
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000432/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100433static struct {
434 const char *name;
435 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000436 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100437} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100438 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000439#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000440 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000441#else
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000443#endif
Darren Tucker45150472006-07-12 22:34:17 +1000444 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100445 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "port", sPort, SSHCFG_GLOBAL },
447 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
448 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000449 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000450 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000451 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000452 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000453 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100454 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000455 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000456 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000457 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000458 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100459 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000460 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000461 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000462 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000463 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000465 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000466 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000467#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100468 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000469 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
470 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100471#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000472 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000473#else
Darren Tucker45150472006-07-12 22:34:17 +1000474 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100475#endif
476#else
Darren Tucker1629c072007-02-19 22:25:37 +1100477 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000478 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
479 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
480 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000481#endif
Darren Tucker45150472006-07-12 22:34:17 +1000482 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
483 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000484#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100485 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000487 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000488#else
Darren Tucker1629c072007-02-19 22:25:37 +1100489 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000490 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000491 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000492#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100493 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
494 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100495 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000496 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
497 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
498 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
499 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
500 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100501#ifdef DISABLE_LASTLOG
502 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
503#else
Darren Tucker45150472006-07-12 22:34:17 +1000504 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100505#endif
Darren Tucker45150472006-07-12 22:34:17 +1000506 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
507 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000508 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
509 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
510 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
512 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100513 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000515 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000516 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000517 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000518 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
519 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
520 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000521 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000522 { "allowusers", sAllowUsers, SSHCFG_ALL },
523 { "denyusers", sDenyUsers, SSHCFG_ALL },
524 { "allowgroups", sAllowGroups, SSHCFG_ALL },
525 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000526 { "ciphers", sCiphers, SSHCFG_GLOBAL },
527 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000528 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000529 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
530 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
531 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000532 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000533 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100534 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000535 { "usedns", sUseDNS, SSHCFG_GLOBAL },
536 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
537 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000538 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
539 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000540 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000541 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000542 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000543 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000544 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100545 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000546 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000547 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000548 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000549 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100550 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100551 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100552 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
553 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000554 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000555 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100556 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100557 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
558 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000559 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
560 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000561 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100562 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000563 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
564 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
565 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000566 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000567 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000568 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000569 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000570};
571
Darren Tuckere7140f22008-06-10 23:01:51 +1000572static struct {
573 int val;
574 char *text;
575} tunmode_desc[] = {
576 { SSH_TUNMODE_NO, "no" },
577 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
578 { SSH_TUNMODE_ETHERNET, "ethernet" },
579 { SSH_TUNMODE_YES, "yes" },
580 { -1, NULL }
581};
582
Damien Miller5428f641999-11-25 11:54:57 +1100583/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000584 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100585 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000586
Damien Miller4af51302000-04-16 11:18:38 +1000587static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100588parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000589 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000590{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000591 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000592
Damien Miller95def091999-11-25 00:26:21 +1100593 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000594 if (strcasecmp(cp, keywords[i].name) == 0) {
595 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100596 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000597 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000598
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000599 error("%s: line %d: Bad configuration option: %s",
600 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100601 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000602}
603
Darren Tucker88b6fb22010-01-13 22:44:29 +1100604char *
605derelativise_path(const char *path)
606{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000607 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100608
djm@openbsd.org161cf412014-12-22 07:55:51 +0000609 if (strcasecmp(path, "none") == 0)
610 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100611 expanded = tilde_expand_filename(path, getuid());
612 if (*expanded == '/')
613 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100614 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100615 fatal("%s: getcwd: %s", __func__, strerror(errno));
616 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000617 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100618 return ret;
619}
620
Ben Lindstrombba81212001-06-25 05:01:22 +0000621static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100622add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100623{
Damien Millereccb9de2005-06-17 12:59:34 +1000624 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100625
Ben Lindstrom19066a12001-04-12 23:39:26 +0000626 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000627 for (i = 0; i < options->num_ports; i++)
628 add_one_listen_addr(options, addr, options->ports[i]);
629 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000630 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000631}
632
Ben Lindstrombba81212001-06-25 05:01:22 +0000633static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100634add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000635{
636 struct addrinfo hints, *ai, *aitop;
637 char strport[NI_MAXSERV];
638 int gaierr;
639
640 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100641 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000642 hints.ai_socktype = SOCK_STREAM;
643 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100644 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000645 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
646 fatal("bad addr or host: %s (%s)",
647 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100648 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000649 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
650 ;
651 ai->ai_next = options->listen_addrs;
652 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100653}
654
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000655/*
656 * Queue a ListenAddress to be processed once we have all of the Ports
657 * and AddressFamily options.
658 */
659static void
660queue_listen_addr(ServerOptions *options, char *addr, int port)
661{
662 options->queued_listen_addrs = xreallocarray(
663 options->queued_listen_addrs, options->num_queued_listens + 1,
664 sizeof(addr));
665 options->queued_listen_ports = xreallocarray(
666 options->queued_listen_ports, options->num_queued_listens + 1,
667 sizeof(port));
668 options->queued_listen_addrs[options->num_queued_listens] =
669 xstrdup(addr);
670 options->queued_listen_ports[options->num_queued_listens] = port;
671 options->num_queued_listens++;
672}
673
674/*
675 * Process queued (text) ListenAddress entries.
676 */
677static void
678process_queued_listen_addrs(ServerOptions *options)
679{
680 u_int i;
681
682 if (options->num_ports == 0)
683 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
684 if (options->address_family == -1)
685 options->address_family = AF_UNSPEC;
686
687 for (i = 0; i < options->num_queued_listens; i++) {
688 add_listen_addr(options, options->queued_listen_addrs[i],
689 options->queued_listen_ports[i]);
690 free(options->queued_listen_addrs[i]);
691 options->queued_listen_addrs[i] = NULL;
692 }
693 free(options->queued_listen_addrs);
694 options->queued_listen_addrs = NULL;
695 free(options->queued_listen_ports);
696 options->queued_listen_ports = NULL;
697 options->num_queued_listens = 0;
698}
699
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000700/*
701 * Inform channels layer of permitopen options from configuration.
702 */
703void
704process_permitopen(struct ssh *ssh, ServerOptions *options)
705{
706 u_int i;
707 int port;
708 char *host, *arg, *oarg;
709
710 channel_clear_adm_permitted_opens(ssh);
711 if (options->num_permitted_opens == 0)
712 return; /* permit any */
713
714 /* handle keywords: "any" / "none" */
715 if (options->num_permitted_opens == 1 &&
716 strcmp(options->permitted_opens[0], "any") == 0)
717 return;
718 if (options->num_permitted_opens == 1 &&
719 strcmp(options->permitted_opens[0], "none") == 0) {
720 channel_disable_adm_local_opens(ssh);
721 return;
722 }
723 /* Otherwise treat it as a list of permitted host:port */
724 for (i = 0; i < options->num_permitted_opens; i++) {
725 oarg = arg = xstrdup(options->permitted_opens[i]);
726 host = hpdelim(&arg);
727 if (host == NULL)
728 fatal("%s: missing host in PermitOpen", __func__);
729 host = cleanhostname(host);
730 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
731 fatal("%s: bad port number in PermitOpen", __func__);
732 /* Send it to channels layer */
733 channel_add_adm_permitted_opens(ssh, host, port);
734 free(oarg);
735 }
736}
737
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000738struct connection_info *
739get_connection_info(int populate, int use_dns)
740{
djm@openbsd.org95767262016-03-07 19:02:43 +0000741 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000742 static struct connection_info ci;
743
744 if (!populate)
745 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000746 ci.host = auth_get_canonical_hostname(ssh, use_dns);
747 ci.address = ssh_remote_ipaddr(ssh);
748 ci.laddress = ssh_local_ipaddr(ssh);
749 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000750 return &ci;
751}
752
Darren Tucker45150472006-07-12 22:34:17 +1000753/*
754 * The strategy for the Match blocks is that the config file is parsed twice.
755 *
756 * The first time is at startup. activep is initialized to 1 and the
757 * directives in the global context are processed and acted on. Hitting a
758 * Match directive unsets activep and the directives inside the block are
759 * checked for syntax only.
760 *
761 * The second time is after a connection has been established but before
762 * authentication. activep is initialized to 2 and global config directives
763 * are ignored since they have already been processed. If the criteria in a
764 * Match block is met, activep is set and the subsequent directives
765 * processed and actioned until EOF or another Match block unsets it. Any
766 * options set are copied into the main server config.
767 *
768 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000769 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000770 *
771 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
772 * Match Address 192.168.0.*
773 * Tag trusted
774 * Match Group wheel
775 * Tag trusted
776 * Match Tag trusted
777 * AllowTcpForwarding yes
778 * GatewayPorts clientspecified
779 * [...]
780 *
781 * - Add a PermittedChannelRequests directive
782 * Match Group shell
783 * PermittedChannelRequests session,forwarded-tcpip
784 */
785
786static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000787match_cfg_line_group(const char *grps, int line, const char *user)
788{
789 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000790 struct passwd *pw;
791
Damien Miller565ca3f2006-08-19 00:23:15 +1000792 if (user == NULL)
793 goto out;
794
795 if ((pw = getpwnam(user)) == NULL) {
796 debug("Can't match group at line %d because user %.100s does "
797 "not exist", line, user);
798 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
799 debug("Can't Match group because user %.100s not in any group "
800 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000801 } else if (ga_match_pattern_list(grps) != 1) {
802 debug("user %.100s does not match group list %.100s at line %d",
803 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000804 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000805 debug("user %.100s matched group list %.100s at line %d", user,
806 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000807 result = 1;
808 }
809out:
810 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000811 return result;
812}
813
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000814/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000815 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100816 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000817 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000818 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000819static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000820match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000821{
Damien Millercf31f382013-10-24 21:02:56 +1100822 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000823 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000824
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000825 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000826 debug3("checking syntax for 'Match %s'", cp);
827 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000828 debug3("checking match for '%s' user %s host %s addr %s "
829 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
830 ci->host ? ci->host : "(null)",
831 ci->address ? ci->address : "(null)",
832 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000833
834 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100835 attributes++;
836 if (strcasecmp(attrib, "all") == 0) {
837 if (attributes != 1 ||
838 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
839 error("'all' cannot be combined with other "
840 "Match attributes");
841 return -1;
842 }
843 *condition = cp;
844 return 1;
845 }
Darren Tucker45150472006-07-12 22:34:17 +1000846 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
847 error("Missing Match criteria for %s", attrib);
848 return -1;
849 }
Darren Tucker45150472006-07-12 22:34:17 +1000850 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000851 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000852 result = 0;
853 continue;
854 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000855 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000856 result = 0;
857 else
858 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000859 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000860 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000861 if (ci == NULL || ci->user == NULL) {
862 result = 0;
863 continue;
864 }
865 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000866 case -1:
867 return -1;
868 case 0:
869 result = 0;
870 }
Darren Tucker45150472006-07-12 22:34:17 +1000871 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000872 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000873 result = 0;
874 continue;
875 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000876 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000877 result = 0;
878 else
879 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000880 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000881 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000882 if (ci == NULL || ci->address == NULL) {
883 result = 0;
884 continue;
885 }
886 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000887 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000888 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000889 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000890 break;
891 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000892 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000893 result = 0;
894 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000895 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000896 return -1;
897 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000898 } else if (strcasecmp(attrib, "localaddress") == 0){
899 if (ci == NULL || ci->laddress == NULL) {
900 result = 0;
901 continue;
902 }
903 switch (addr_match_list(ci->laddress, arg)) {
904 case 1:
905 debug("connection from %.100s matched "
906 "'LocalAddress %.100s' at line %d",
907 ci->laddress, arg, line);
908 break;
909 case 0:
910 case -1:
911 result = 0;
912 break;
913 case -2:
914 return -1;
915 }
916 } else if (strcasecmp(attrib, "localport") == 0) {
917 if ((port = a2port(arg)) == -1) {
918 error("Invalid LocalPort '%s' on Match line",
919 arg);
920 return -1;
921 }
922 if (ci == NULL || ci->lport == 0) {
923 result = 0;
924 continue;
925 }
926 /* TODO support port lists */
927 if (port == ci->lport)
928 debug("connection from %.100s matched "
929 "'LocalPort %d' at line %d",
930 ci->laddress, port, line);
931 else
932 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000933 } else {
934 error("Unsupported Match attribute %s", attrib);
935 return -1;
936 }
937 }
Damien Millercf31f382013-10-24 21:02:56 +1100938 if (attributes == 0) {
939 error("One or more attributes required for Match");
940 return -1;
941 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000942 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000943 debug3("match %sfound", result ? "" : "not ");
944 *condition = cp;
945 return result;
946}
947
Damien Millere2754432006-07-24 14:06:47 +1000948#define WHITESPACE " \t\r\n"
949
Damien Miller33322122011-06-20 14:43:11 +1000950/* Multistate option parsing */
951struct multistate {
952 char *key;
953 int value;
954};
955static const struct multistate multistate_addressfamily[] = {
956 { "inet", AF_INET },
957 { "inet6", AF_INET6 },
958 { "any", AF_UNSPEC },
959 { NULL, -1 }
960};
961static const struct multistate multistate_permitrootlogin[] = {
962 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000963 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000964 { "forced-commands-only", PERMIT_FORCED_ONLY },
965 { "yes", PERMIT_YES },
966 { "no", PERMIT_NO },
967 { NULL, -1 }
968};
969static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +0000970 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +0000971 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +1000972 { "no", COMP_NONE },
973 { NULL, -1 }
974};
975static const struct multistate multistate_gatewayports[] = {
976 { "clientspecified", 2 },
977 { "yes", 1 },
978 { "no", 0 },
979 { NULL, -1 }
980};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100981static const struct multistate multistate_tcpfwd[] = {
982 { "yes", FORWARD_ALLOW },
983 { "all", FORWARD_ALLOW },
984 { "no", FORWARD_DENY },
985 { "remote", FORWARD_REMOTE },
986 { "local", FORWARD_LOCAL },
987 { NULL, -1 }
988};
Damien Miller33322122011-06-20 14:43:11 +1000989
Ben Lindstromade03f62001-12-06 18:22:17 +0000990int
991process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000992 const char *filename, int linenum, int *activep,
993 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000994{
djm@openbsd.orgdbee4112017-09-12 06:32:07 +0000995 char *cp, **charptr, *arg, *arg2, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000996 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100997 SyslogFacility *log_facility_ptr;
998 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000999 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +10001000 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +10001001 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +10001002 long long val64;
Damien Miller33322122011-06-20 14:43:11 +10001003 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +00001004
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00001005 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1006 if ((len = strlen(line)) == 0)
1007 return 0;
1008 for (len--; len > 0; len--) {
1009 if (strchr(WHITESPACE "\f", line[len]) == NULL)
1010 break;
1011 line[len] = '\0';
1012 }
1013
Ben Lindstromade03f62001-12-06 18:22:17 +00001014 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +11001015 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +11001016 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001017 /* Ignore leading whitespace */
1018 if (*arg == '\0')
1019 arg = strdelim(&cp);
1020 if (!arg || !*arg || *arg == '#')
1021 return 0;
1022 intptr = NULL;
1023 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +10001024 opcode = parse_token(arg, filename, linenum, &flags);
1025
1026 if (activep == NULL) { /* We are processing a command line directive */
1027 cmdline = 1;
1028 activep = &cmdline;
1029 }
1030 if (*activep && opcode != sMatch)
1031 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1032 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001033 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001034 fatal("%s line %d: Directive '%s' is not allowed "
1035 "within a Match block", filename, linenum, arg);
1036 } else { /* this is a directive we have already processed */
1037 while (arg)
1038 arg = strdelim(&cp);
1039 return 0;
1040 }
1041 }
1042
Ben Lindstromade03f62001-12-06 18:22:17 +00001043 switch (opcode) {
1044 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001045 case sUsePAM:
1046 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001047 goto parse_flag;
1048
1049 /* Standard Options */
1050 case sBadOption:
1051 return -1;
1052 case sPort:
1053 /* ignore ports from configfile if cmdline specifies ports */
1054 if (options->ports_from_cmdline)
1055 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001056 if (options->num_ports >= MAX_PORTS)
1057 fatal("%s line %d: too many ports.",
1058 filename, linenum);
1059 arg = strdelim(&cp);
1060 if (!arg || *arg == '\0')
1061 fatal("%s line %d: missing port number.",
1062 filename, linenum);
1063 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001064 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001065 fatal("%s line %d: Badly formatted port number.",
1066 filename, linenum);
1067 break;
1068
Ben Lindstromade03f62001-12-06 18:22:17 +00001069 case sLoginGraceTime:
1070 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001071 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001072 arg = strdelim(&cp);
1073 if (!arg || *arg == '\0')
1074 fatal("%s line %d: missing time value.",
1075 filename, linenum);
1076 if ((value = convtime(arg)) == -1)
1077 fatal("%s line %d: invalid time value.",
1078 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001079 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001080 *intptr = value;
1081 break;
1082
Ben Lindstromade03f62001-12-06 18:22:17 +00001083 case sListenAddress:
1084 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001085 if (arg == NULL || *arg == '\0')
1086 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001087 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001088 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1089 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1090 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001091 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001092 break;
1093 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001094 p = hpdelim(&arg);
1095 if (p == NULL)
1096 fatal("%s line %d: bad address:port usage",
1097 filename, linenum);
1098 p = cleanhostname(p);
1099 if (arg == NULL)
1100 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001101 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001102 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001103
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001104 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001105
Ben Lindstromade03f62001-12-06 18:22:17 +00001106 break;
1107
Darren Tucker0f383232005-01-20 10:57:56 +11001108 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001109 intptr = &options->address_family;
1110 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001111 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001112 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001113 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001114 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001115 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001116 value = -1;
1117 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1118 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1119 value = multistate_ptr[i].value;
1120 break;
1121 }
1122 }
1123 if (value == -1)
1124 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001125 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001126 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001127 *intptr = value;
1128 break;
1129
Ben Lindstromade03f62001-12-06 18:22:17 +00001130 case sHostKeyFile:
1131 intptr = &options->num_host_key_files;
1132 if (*intptr >= MAX_HOSTKEYS)
1133 fatal("%s line %d: too many host keys specified (max %d).",
1134 filename, linenum, MAX_HOSTKEYS);
1135 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001136 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001137 arg = strdelim(&cp);
1138 if (!arg || *arg == '\0')
1139 fatal("%s line %d: missing file name.",
1140 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001141 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001142 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001143 /* increase optional counter */
1144 if (intptr != NULL)
1145 *intptr = *intptr + 1;
1146 }
1147 break;
1148
Damien Miller85b45e02013-07-20 13:21:52 +10001149 case sHostKeyAgent:
1150 charptr = &options->host_key_agent;
1151 arg = strdelim(&cp);
1152 if (!arg || *arg == '\0')
1153 fatal("%s line %d: missing socket name.",
1154 filename, linenum);
1155 if (*activep && *charptr == NULL)
1156 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1157 xstrdup(arg) : derelativise_path(arg);
1158 break;
1159
Damien Miller0a80ca12010-02-27 07:55:05 +11001160 case sHostCertificate:
1161 intptr = &options->num_host_cert_files;
1162 if (*intptr >= MAX_HOSTKEYS)
1163 fatal("%s line %d: too many host certificates "
1164 "specified (max %d).", filename, linenum,
1165 MAX_HOSTCERTS);
1166 charptr = &options->host_cert_files[*intptr];
1167 goto parse_filename;
Damien Miller0a80ca12010-02-27 07:55:05 +11001168
Ben Lindstromade03f62001-12-06 18:22:17 +00001169 case sPidFile:
1170 charptr = &options->pid_file;
1171 goto parse_filename;
1172
1173 case sPermitRootLogin:
1174 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001175 multistate_ptr = multistate_permitrootlogin;
1176 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001177
1178 case sIgnoreRhosts:
1179 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001180 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001181 arg = strdelim(&cp);
1182 if (!arg || *arg == '\0')
1183 fatal("%s line %d: missing yes/no argument.",
1184 filename, linenum);
1185 value = 0; /* silence compiler */
1186 if (strcmp(arg, "yes") == 0)
1187 value = 1;
1188 else if (strcmp(arg, "no") == 0)
1189 value = 0;
1190 else
1191 fatal("%s line %d: Bad yes/no argument: %s",
1192 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001193 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001194 *intptr = value;
1195 break;
1196
1197 case sIgnoreUserKnownHosts:
1198 intptr = &options->ignore_user_known_hosts;
1199 goto parse_flag;
1200
Ben Lindstromade03f62001-12-06 18:22:17 +00001201 case sHostbasedAuthentication:
1202 intptr = &options->hostbased_authentication;
1203 goto parse_flag;
1204
1205 case sHostbasedUsesNameFromPacketOnly:
1206 intptr = &options->hostbased_uses_name_from_packet_only;
1207 goto parse_flag;
1208
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001209 case sHostbasedAcceptedKeyTypes:
1210 charptr = &options->hostbased_key_types;
1211 parse_keytypes:
1212 arg = strdelim(&cp);
1213 if (!arg || *arg == '\0')
1214 fatal("%s line %d: Missing argument.",
1215 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001216 if (*arg != '-' &&
1217 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001218 fatal("%s line %d: Bad key types '%s'.",
1219 filename, linenum, arg ? arg : "<NONE>");
1220 if (*activep && *charptr == NULL)
1221 *charptr = xstrdup(arg);
1222 break;
1223
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001224 case sHostKeyAlgorithms:
1225 charptr = &options->hostkeyalgorithms;
1226 goto parse_keytypes;
1227
Ben Lindstromade03f62001-12-06 18:22:17 +00001228 case sPubkeyAuthentication:
1229 intptr = &options->pubkey_authentication;
1230 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001231
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001232 case sPubkeyAcceptedKeyTypes:
1233 charptr = &options->pubkey_key_types;
1234 goto parse_keytypes;
1235
Ben Lindstromade03f62001-12-06 18:22:17 +00001236 case sKerberosAuthentication:
1237 intptr = &options->kerberos_authentication;
1238 goto parse_flag;
1239
1240 case sKerberosOrLocalPasswd:
1241 intptr = &options->kerberos_or_local_passwd;
1242 goto parse_flag;
1243
1244 case sKerberosTicketCleanup:
1245 intptr = &options->kerberos_ticket_cleanup;
1246 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001247
Darren Tucker22ef5082003-12-31 11:37:34 +11001248 case sKerberosGetAFSToken:
1249 intptr = &options->kerberos_get_afs_token;
1250 goto parse_flag;
1251
Darren Tucker0efd1552003-08-26 11:49:55 +10001252 case sGssAuthentication:
1253 intptr = &options->gss_authentication;
1254 goto parse_flag;
1255
1256 case sGssCleanupCreds:
1257 intptr = &options->gss_cleanup_creds;
1258 goto parse_flag;
1259
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001260 case sGssStrictAcceptor:
1261 intptr = &options->gss_strict_acceptor;
1262 goto parse_flag;
1263
Ben Lindstromade03f62001-12-06 18:22:17 +00001264 case sPasswordAuthentication:
1265 intptr = &options->password_authentication;
1266 goto parse_flag;
1267
1268 case sKbdInteractiveAuthentication:
1269 intptr = &options->kbd_interactive_authentication;
1270 goto parse_flag;
1271
1272 case sChallengeResponseAuthentication:
1273 intptr = &options->challenge_response_authentication;
1274 goto parse_flag;
1275
1276 case sPrintMotd:
1277 intptr = &options->print_motd;
1278 goto parse_flag;
1279
1280 case sPrintLastLog:
1281 intptr = &options->print_lastlog;
1282 goto parse_flag;
1283
1284 case sX11Forwarding:
1285 intptr = &options->x11_forwarding;
1286 goto parse_flag;
1287
1288 case sX11DisplayOffset:
1289 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001290 parse_int:
1291 arg = strdelim(&cp);
1292 if (!arg || *arg == '\0')
1293 fatal("%s line %d: missing integer value.",
1294 filename, linenum);
1295 value = atoi(arg);
1296 if (*activep && *intptr == -1)
1297 *intptr = value;
1298 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001299
Damien Miller95c249f2002-02-05 12:11:34 +11001300 case sX11UseLocalhost:
1301 intptr = &options->x11_use_localhost;
1302 goto parse_flag;
1303
Ben Lindstromade03f62001-12-06 18:22:17 +00001304 case sXAuthLocation:
1305 charptr = &options->xauth_location;
1306 goto parse_filename;
1307
Damien Miller5ff30c62013-10-30 22:21:50 +11001308 case sPermitTTY:
1309 intptr = &options->permit_tty;
1310 goto parse_flag;
1311
Damien Miller72e6b5c2014-07-04 09:00:04 +10001312 case sPermitUserRC:
1313 intptr = &options->permit_user_rc;
1314 goto parse_flag;
1315
Ben Lindstromade03f62001-12-06 18:22:17 +00001316 case sStrictModes:
1317 intptr = &options->strict_modes;
1318 goto parse_flag;
1319
Damien Miller12c150e2003-12-17 16:31:10 +11001320 case sTCPKeepAlive:
1321 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001322 goto parse_flag;
1323
1324 case sEmptyPasswd:
1325 intptr = &options->permit_empty_passwd;
1326 goto parse_flag;
1327
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001328 case sPermitUserEnvironment:
1329 intptr = &options->permit_user_env;
1330 goto parse_flag;
1331
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001332 case sCompression:
1333 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001334 multistate_ptr = multistate_compression;
1335 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001336
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001337 case sRekeyLimit:
1338 arg = strdelim(&cp);
1339 if (!arg || *arg == '\0')
1340 fatal("%.200s line %d: Missing argument.", filename,
1341 linenum);
1342 if (strcmp(arg, "default") == 0) {
1343 val64 = 0;
1344 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001345 if (scan_scaled(arg, &val64) == -1)
1346 fatal("%.200s line %d: Bad number '%s': %s",
1347 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001348 if (val64 != 0 && val64 < 16)
1349 fatal("%.200s line %d: RekeyLimit too small",
1350 filename, linenum);
1351 }
1352 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001353 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001354 if (cp != NULL) { /* optional rekey interval present */
1355 if (strcmp(cp, "none") == 0) {
1356 (void)strdelim(&cp); /* discard */
1357 break;
1358 }
1359 intptr = &options->rekey_interval;
1360 goto parse_time;
1361 }
1362 break;
1363
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001365 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001366 multistate_ptr = multistate_gatewayports;
1367 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001368
Damien Miller3a961dc2003-06-03 10:25:48 +10001369 case sUseDNS:
1370 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 goto parse_flag;
1372
1373 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001374 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001375 arg = strdelim(&cp);
1376 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001377 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001378 fatal("%.200s line %d: unsupported log facility '%s'",
1379 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001380 if (*log_facility_ptr == -1)
1381 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001382 break;
1383
1384 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001385 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001386 arg = strdelim(&cp);
1387 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001388 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001389 fatal("%.200s line %d: unsupported log level '%s'",
1390 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001391 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001392 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001393 break;
1394
1395 case sAllowTcpForwarding:
1396 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001397 multistate_ptr = multistate_tcpfwd;
1398 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001399
Damien Miller7acefbb2014-07-18 14:11:24 +10001400 case sAllowStreamLocalForwarding:
1401 intptr = &options->allow_streamlocal_forwarding;
1402 multistate_ptr = multistate_tcpfwd;
1403 goto parse_multistate;
1404
Damien Miller4f755cd2008-05-19 14:57:41 +10001405 case sAllowAgentForwarding:
1406 intptr = &options->allow_agent_forwarding;
1407 goto parse_flag;
1408
djm@openbsd.org7844f352016-11-30 03:00:05 +00001409 case sDisableForwarding:
1410 intptr = &options->disable_forwarding;
1411 goto parse_flag;
1412
Ben Lindstromade03f62001-12-06 18:22:17 +00001413 case sAllowUsers:
1414 while ((arg = strdelim(&cp)) && *arg != '\0') {
1415 if (options->num_allow_users >= MAX_ALLOW_USERS)
1416 fatal("%s line %d: too many allow users.",
1417 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001418 if (match_user(NULL, NULL, NULL, arg) == -1)
1419 fatal("%s line %d: invalid AllowUsers pattern: "
1420 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001421 if (!*activep)
1422 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001423 options->allow_users[options->num_allow_users++] =
1424 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001425 }
1426 break;
1427
1428 case sDenyUsers:
1429 while ((arg = strdelim(&cp)) && *arg != '\0') {
1430 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001431 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001432 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001433 if (match_user(NULL, NULL, NULL, arg) == -1)
1434 fatal("%s line %d: invalid DenyUsers pattern: "
1435 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001436 if (!*activep)
1437 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001438 options->deny_users[options->num_deny_users++] =
1439 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001440 }
1441 break;
1442
1443 case sAllowGroups:
1444 while ((arg = strdelim(&cp)) && *arg != '\0') {
1445 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1446 fatal("%s line %d: too many allow groups.",
1447 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001448 if (!*activep)
1449 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001450 options->allow_groups[options->num_allow_groups++] =
1451 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001452 }
1453 break;
1454
1455 case sDenyGroups:
1456 while ((arg = strdelim(&cp)) && *arg != '\0') {
1457 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1458 fatal("%s line %d: too many deny groups.",
1459 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001460 if (!*activep)
1461 continue;
1462 options->deny_groups[options->num_deny_groups++] =
1463 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001464 }
1465 break;
1466
1467 case sCiphers:
1468 arg = strdelim(&cp);
1469 if (!arg || *arg == '\0')
1470 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001471 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001472 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1473 filename, linenum, arg ? arg : "<NONE>");
1474 if (options->ciphers == NULL)
1475 options->ciphers = xstrdup(arg);
1476 break;
1477
1478 case sMacs:
1479 arg = strdelim(&cp);
1480 if (!arg || *arg == '\0')
1481 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001482 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001483 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1484 filename, linenum, arg ? arg : "<NONE>");
1485 if (options->macs == NULL)
1486 options->macs = xstrdup(arg);
1487 break;
1488
Damien Millerd5f62bf2010-09-24 22:11:14 +10001489 case sKexAlgorithms:
1490 arg = strdelim(&cp);
1491 if (!arg || *arg == '\0')
1492 fatal("%s line %d: Missing argument.",
1493 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001494 if (*arg != '-' &&
1495 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001496 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1497 filename, linenum, arg ? arg : "<NONE>");
1498 if (options->kex_algorithms == NULL)
1499 options->kex_algorithms = xstrdup(arg);
1500 break;
1501
Ben Lindstromade03f62001-12-06 18:22:17 +00001502 case sSubsystem:
1503 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1504 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001505 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001506 }
1507 arg = strdelim(&cp);
1508 if (!arg || *arg == '\0')
1509 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001510 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001511 if (!*activep) {
1512 arg = strdelim(&cp);
1513 break;
1514 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001515 for (i = 0; i < options->num_subsystems; i++)
1516 if (strcmp(arg, options->subsystem_name[i]) == 0)
1517 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001518 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001519 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1520 arg = strdelim(&cp);
1521 if (!arg || *arg == '\0')
1522 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001523 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001524 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001525
1526 /* Collect arguments (separate to executable) */
1527 p = xstrdup(arg);
1528 len = strlen(p) + 1;
1529 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1530 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001531 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001532 strlcat(p, " ", len);
1533 strlcat(p, arg, len);
1534 }
1535 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001536 options->num_subsystems++;
1537 break;
1538
1539 case sMaxStartups:
1540 arg = strdelim(&cp);
1541 if (!arg || *arg == '\0')
1542 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001543 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001544 if ((n = sscanf(arg, "%d:%d:%d",
1545 &options->max_startups_begin,
1546 &options->max_startups_rate,
1547 &options->max_startups)) == 3) {
1548 if (options->max_startups_begin >
1549 options->max_startups ||
1550 options->max_startups_rate > 100 ||
1551 options->max_startups_rate < 1)
1552 fatal("%s line %d: Illegal MaxStartups spec.",
1553 filename, linenum);
1554 } else if (n != 1)
1555 fatal("%s line %d: Illegal MaxStartups spec.",
1556 filename, linenum);
1557 else
1558 options->max_startups = options->max_startups_begin;
1559 break;
1560
Darren Tucker89413db2004-05-24 10:36:23 +10001561 case sMaxAuthTries:
1562 intptr = &options->max_authtries;
1563 goto parse_int;
1564
Damien Miller7207f642008-05-19 15:34:50 +10001565 case sMaxSessions:
1566 intptr = &options->max_sessions;
1567 goto parse_int;
1568
Ben Lindstromade03f62001-12-06 18:22:17 +00001569 case sBanner:
1570 charptr = &options->banner;
1571 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001572
Ben Lindstromade03f62001-12-06 18:22:17 +00001573 /*
1574 * These options can contain %X options expanded at
1575 * connect time, so that you can specify paths like:
1576 *
1577 * AuthorizedKeysFile /etc/ssh_keys/%u
1578 */
1579 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001580 if (*activep && options->num_authkeys_files == 0) {
1581 while ((arg = strdelim(&cp)) && *arg != '\0') {
1582 if (options->num_authkeys_files >=
1583 MAX_AUTHKEYS_FILES)
1584 fatal("%s line %d: "
1585 "too many authorized keys files.",
1586 filename, linenum);
1587 options->authorized_keys_files[
1588 options->num_authkeys_files++] =
1589 tilde_expand_filename(arg, getuid());
1590 }
1591 }
1592 return 0;
1593
Damien Miller30da3442010-05-10 11:58:03 +10001594 case sAuthorizedPrincipalsFile:
1595 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001596 arg = strdelim(&cp);
1597 if (!arg || *arg == '\0')
1598 fatal("%s line %d: missing file name.",
1599 filename, linenum);
1600 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001601 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001602 /* increase optional counter */
1603 if (intptr != NULL)
1604 *intptr = *intptr + 1;
1605 }
1606 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001607
1608 case sClientAliveInterval:
1609 intptr = &options->client_alive_interval;
1610 goto parse_time;
1611
1612 case sClientAliveCountMax:
1613 intptr = &options->client_alive_count_max;
1614 goto parse_int;
1615
Darren Tucker46bc0752004-05-02 22:11:30 +10001616 case sAcceptEnv:
1617 while ((arg = strdelim(&cp)) && *arg != '\0') {
1618 if (strchr(arg, '=') != NULL)
1619 fatal("%s line %d: Invalid environment name.",
1620 filename, linenum);
1621 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1622 fatal("%s line %d: too many allow env.",
1623 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001624 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001625 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001626 options->accept_env[options->num_accept_env++] =
1627 xstrdup(arg);
1628 }
1629 break;
1630
Damien Millerd27b9472005-12-13 19:29:02 +11001631 case sPermitTunnel:
1632 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001633 arg = strdelim(&cp);
1634 if (!arg || *arg == '\0')
1635 fatal("%s line %d: Missing yes/point-to-point/"
1636 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001637 value = -1;
1638 for (i = 0; tunmode_desc[i].val != -1; i++)
1639 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1640 value = tunmode_desc[i].val;
1641 break;
1642 }
1643 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001644 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1645 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001646 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001647 *intptr = value;
1648 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001649
Darren Tucker45150472006-07-12 22:34:17 +10001650 case sMatch:
1651 if (cmdline)
1652 fatal("Match directive not supported as a command-line "
1653 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001654 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001655 if (value < 0)
1656 fatal("%s line %d: Bad Match condition", filename,
1657 linenum);
1658 *activep = value;
1659 break;
1660
Damien Miller9b439df2006-07-24 14:04:00 +10001661 case sPermitOpen:
1662 arg = strdelim(&cp);
1663 if (!arg || *arg == '\0')
1664 fatal("%s line %d: missing PermitOpen specification",
1665 filename, linenum);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001666 i = options->num_permitted_opens; /* modified later */
1667 if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001668 if (*activep && i == 0) {
Damien Millerc6081482012-04-22 11:18:53 +10001669 options->num_permitted_opens = 1;
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001670 options->permitted_opens = xcalloc(1,
1671 sizeof(*options->permitted_opens));
1672 options->permitted_opens[0] = xstrdup(arg);
dtucker@openbsd.org30484e52017-09-18 09:41:52 +00001673 }
Damien Millerc6081482012-04-22 11:18:53 +10001674 break;
1675 }
Damien Millera765cf42006-07-24 14:08:13 +10001676 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001677 arg2 = xstrdup(arg);
Damien Millera765cf42006-07-24 14:08:13 +10001678 p = hpdelim(&arg);
1679 if (p == NULL)
1680 fatal("%s line %d: missing host in PermitOpen",
1681 filename, linenum);
1682 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001683 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001684 fatal("%s line %d: bad port number in "
1685 "PermitOpen", filename, linenum);
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00001686 if (*activep && i == 0) {
1687 options->permitted_opens = xrecallocarray(
1688 options->permitted_opens,
1689 options->num_permitted_opens,
1690 options->num_permitted_opens + 1,
1691 sizeof(*options->permitted_opens));
1692 i = options->num_permitted_opens++;
1693 options->permitted_opens[i] = arg2;
1694 } else
1695 free(arg2);
Damien Millera765cf42006-07-24 14:08:13 +10001696 }
Damien Miller9b439df2006-07-24 14:04:00 +10001697 break;
1698
Damien Millere2754432006-07-24 14:06:47 +10001699 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001700 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001701 fatal("%.200s line %d: Missing argument.", filename,
1702 linenum);
1703 len = strspn(cp, WHITESPACE);
1704 if (*activep && options->adm_forced_command == NULL)
1705 options->adm_forced_command = xstrdup(cp + len);
1706 return 0;
1707
Damien Millerd8cb1f12008-02-10 22:40:12 +11001708 case sChrootDirectory:
1709 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001710
1711 arg = strdelim(&cp);
1712 if (!arg || *arg == '\0')
1713 fatal("%s line %d: missing file name.",
1714 filename, linenum);
1715 if (*activep && *charptr == NULL)
1716 *charptr = xstrdup(arg);
1717 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001718
Damien Miller1aed65e2010-03-04 21:53:35 +11001719 case sTrustedUserCAKeys:
1720 charptr = &options->trusted_user_ca_keys;
1721 goto parse_filename;
1722
1723 case sRevokedKeys:
1724 charptr = &options->revoked_keys_file;
1725 goto parse_filename;
1726
Damien Miller0dac6fb2010-11-20 15:19:38 +11001727 case sIPQoS:
1728 arg = strdelim(&cp);
1729 if ((value = parse_ipqos(arg)) == -1)
1730 fatal("%s line %d: Bad IPQoS value: %s",
1731 filename, linenum, arg);
1732 arg = strdelim(&cp);
1733 if (arg == NULL)
1734 value2 = value;
1735 else if ((value2 = parse_ipqos(arg)) == -1)
1736 fatal("%s line %d: Bad IPQoS value: %s",
1737 filename, linenum, arg);
1738 if (*activep) {
1739 options->ip_qos_interactive = value;
1740 options->ip_qos_bulk = value2;
1741 }
1742 break;
1743
Damien Miller23528812012-04-22 11:24:43 +10001744 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001745 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001746 fatal("%.200s line %d: Missing argument.", filename,
1747 linenum);
1748 len = strspn(cp, WHITESPACE);
1749 if (*activep && options->version_addendum == NULL) {
1750 if (strcasecmp(cp + len, "none") == 0)
1751 options->version_addendum = xstrdup("");
1752 else if (strchr(cp + len, '\r') != NULL)
1753 fatal("%.200s line %d: Invalid argument",
1754 filename, linenum);
1755 else
1756 options->version_addendum = xstrdup(cp + len);
1757 }
1758 return 0;
1759
Damien Miller09d3e122012-10-31 08:58:58 +11001760 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001761 if (cp == NULL)
1762 fatal("%.200s line %d: Missing argument.", filename,
1763 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001764 len = strspn(cp, WHITESPACE);
1765 if (*activep && options->authorized_keys_command == NULL) {
1766 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1767 fatal("%.200s line %d: AuthorizedKeysCommand "
1768 "must be an absolute path",
1769 filename, linenum);
1770 options->authorized_keys_command = xstrdup(cp + len);
1771 }
1772 return 0;
1773
1774 case sAuthorizedKeysCommandUser:
1775 charptr = &options->authorized_keys_command_user;
1776
1777 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001778 if (!arg || *arg == '\0')
1779 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1780 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001781 if (*activep && *charptr == NULL)
1782 *charptr = xstrdup(arg);
1783 break;
1784
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001785 case sAuthorizedPrincipalsCommand:
1786 if (cp == NULL)
1787 fatal("%.200s line %d: Missing argument.", filename,
1788 linenum);
1789 len = strspn(cp, WHITESPACE);
1790 if (*activep &&
1791 options->authorized_principals_command == NULL) {
1792 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1793 fatal("%.200s line %d: "
1794 "AuthorizedPrincipalsCommand must be "
1795 "an absolute path", filename, linenum);
1796 options->authorized_principals_command =
1797 xstrdup(cp + len);
1798 }
1799 return 0;
1800
1801 case sAuthorizedPrincipalsCommandUser:
1802 charptr = &options->authorized_principals_command_user;
1803
1804 arg = strdelim(&cp);
1805 if (!arg || *arg == '\0')
1806 fatal("%s line %d: missing "
1807 "AuthorizedPrincipalsCommandUser argument.",
1808 filename, linenum);
1809 if (*activep && *charptr == NULL)
1810 *charptr = xstrdup(arg);
1811 break;
1812
Damien Millera6e3f012012-11-04 23:21:40 +11001813 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001814 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001815 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001816 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001817 while ((arg = strdelim(&cp)) && *arg != '\0') {
1818 if (options->num_auth_methods >=
1819 MAX_AUTH_METHODS)
1820 fatal("%s line %d: "
1821 "too many authentication methods.",
1822 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001823 if (strcmp(arg, "any") == 0) {
1824 if (options->num_auth_methods > 0) {
1825 fatal("%s line %d: \"any\" "
1826 "must appear alone in "
1827 "AuthenticationMethods",
1828 filename, linenum);
1829 }
1830 value = 1;
1831 } else if (value) {
1832 fatal("%s line %d: \"any\" must appear "
1833 "alone in AuthenticationMethods",
1834 filename, linenum);
1835 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001836 fatal("%s line %d: invalid "
1837 "authentication method list.",
1838 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001839 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001840 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001841 if (!*activep)
1842 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001843 options->auth_methods[
1844 options->num_auth_methods++] = xstrdup(arg);
1845 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001846 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001847 fatal("%s line %d: no AuthenticationMethods "
1848 "specified", filename, linenum);
1849 }
Damien Millera6e3f012012-11-04 23:21:40 +11001850 }
1851 return 0;
1852
Damien Miller7acefbb2014-07-18 14:11:24 +10001853 case sStreamLocalBindMask:
1854 arg = strdelim(&cp);
1855 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001856 fatal("%s line %d: missing StreamLocalBindMask "
1857 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001858 /* Parse mode in octal format */
1859 value = strtol(arg, &p, 8);
1860 if (arg == p || value < 0 || value > 0777)
1861 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001862 if (*activep)
1863 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001864 break;
1865
1866 case sStreamLocalBindUnlink:
1867 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1868 goto parse_flag;
1869
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001870 case sFingerprintHash:
1871 arg = strdelim(&cp);
1872 if (!arg || *arg == '\0')
1873 fatal("%.200s line %d: Missing argument.",
1874 filename, linenum);
1875 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1876 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1877 filename, linenum, arg);
1878 if (*activep)
1879 options->fingerprint_hash = value;
1880 break;
1881
djm@openbsd.org8f574952017-06-24 06:34:38 +00001882 case sExposeAuthInfo:
1883 intptr = &options->expose_userauth_info;
1884 goto parse_flag;
1885
Ben Lindstromade03f62001-12-06 18:22:17 +00001886 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001887 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001888 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001889 do_log2(opcode == sIgnore ?
1890 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1891 "%s line %d: %s option %s", filename, linenum,
1892 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001893 while (arg)
1894 arg = strdelim(&cp);
1895 break;
1896
Ben Lindstromade03f62001-12-06 18:22:17 +00001897 default:
1898 fatal("%s line %d: Missing handler for opcode %s (%d)",
1899 filename, linenum, arg, opcode);
1900 }
1901 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1902 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1903 filename, linenum, arg);
1904 return 0;
1905}
1906
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001907/* Reads the server configuration file. */
1908
Damien Miller4af51302000-04-16 11:18:38 +10001909void
Darren Tucker645ab752004-06-25 13:33:20 +10001910load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001911{
Damien Miller46cb75a2012-07-31 12:22:37 +10001912 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001913 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001914 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001915
Darren Tucker645ab752004-06-25 13:33:20 +10001916 debug2("%s: filename %s", __func__, filename);
1917 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001918 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001919 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001920 }
Darren Tucker645ab752004-06-25 13:33:20 +10001921 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001922 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001923 lineno++;
1924 if (strlen(line) == sizeof(line) - 1)
1925 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001926 /*
1927 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001928 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001929 * line numbers later for error messages
1930 */
1931 if ((cp = strchr(line, '#')) != NULL)
1932 memcpy(cp, "\n", 2);
1933 cp = line + strspn(line, " \t\r");
1934
1935 buffer_append(conf, cp, strlen(cp));
1936 }
1937 buffer_append(conf, "\0", 1);
1938 fclose(f);
1939 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1940}
1941
1942void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001943parse_server_match_config(ServerOptions *options,
1944 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001945{
Darren Tucker45150472006-07-12 22:34:17 +10001946 ServerOptions mo;
1947
1948 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001949 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001950 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001951}
1952
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001953int parse_server_match_testspec(struct connection_info *ci, char *spec)
1954{
1955 char *p;
1956
1957 while ((p = strsep(&spec, ",")) && *p != '\0') {
1958 if (strncmp(p, "addr=", 5) == 0) {
1959 ci->address = xstrdup(p + 5);
1960 } else if (strncmp(p, "host=", 5) == 0) {
1961 ci->host = xstrdup(p + 5);
1962 } else if (strncmp(p, "user=", 5) == 0) {
1963 ci->user = xstrdup(p + 5);
1964 } else if (strncmp(p, "laddr=", 6) == 0) {
1965 ci->laddress = xstrdup(p + 6);
1966 } else if (strncmp(p, "lport=", 6) == 0) {
1967 ci->lport = a2port(p + 6);
1968 if (ci->lport == -1) {
1969 fprintf(stderr, "Invalid port '%s' in test mode"
1970 " specification %s\n", p+6, p);
1971 return -1;
1972 }
1973 } else {
1974 fprintf(stderr, "Invalid test mode specification %s\n",
1975 p);
1976 return -1;
1977 }
1978 }
1979 return 0;
1980}
1981
1982/*
1983 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1984 * empty spec.
1985 */
1986int server_match_spec_complete(struct connection_info *ci)
1987{
1988 if (ci->user && ci->host && ci->address)
1989 return 1; /* complete */
1990 if (!ci->user && !ci->host && !ci->address)
1991 return -1; /* empty */
1992 return 0; /* partial */
1993}
1994
Darren Tucker1629c072007-02-19 22:25:37 +11001995/*
1996 * Copy any supported values that are set.
1997 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001998 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001999 * array values that are not used pre-authentication, because any that we
2000 * do use must be explictly sent in mm_getpwnamallow().
2001 */
Darren Tucker45150472006-07-12 22:34:17 +10002002void
Darren Tucker1629c072007-02-19 22:25:37 +11002003copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002004{
Damien Miller534b2cc2013-12-05 14:07:27 +11002005#define M_CP_INTOPT(n) do {\
2006 if (src->n != -1) \
2007 dst->n = src->n; \
2008} while (0)
2009
Darren Tucker1629c072007-02-19 22:25:37 +11002010 M_CP_INTOPT(password_authentication);
2011 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11002012 M_CP_INTOPT(pubkey_authentication);
2013 M_CP_INTOPT(kerberos_authentication);
2014 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002015 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002016 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002017 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002018 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002019
2020 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002021 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002022 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002023 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002024 M_CP_INTOPT(expose_userauth_info);
Damien Millerab6de352010-06-26 09:38:45 +10002025 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002026 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002027 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002028 M_CP_INTOPT(x11_display_offset);
2029 M_CP_INTOPT(x11_forwarding);
2030 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002031 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002032 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002033 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002034 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00002035 M_CP_INTOPT(client_alive_count_max);
2036 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002037 M_CP_INTOPT(ip_qos_interactive);
2038 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002039 M_CP_INTOPT(rekey_limit);
2040 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002041 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002042
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002043 /*
2044 * The bind_mask is a mode_t that may be unsigned, so we can't use
2045 * M_CP_INTOPT - it does a signed comparison that causes compiler
2046 * warnings.
2047 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002048 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002049 dst->fwd_opts.streamlocal_bind_mask =
2050 src->fwd_opts.streamlocal_bind_mask;
2051 }
2052
Damien Miller534b2cc2013-12-05 14:07:27 +11002053 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2054#define M_CP_STROPT(n) do {\
2055 if (src->n != NULL && dst->n != src->n) { \
2056 free(dst->n); \
2057 dst->n = src->n; \
2058 } \
2059} while(0)
2060#define M_CP_STRARRAYOPT(n, num_n) do {\
2061 if (src->num_n != 0) { \
2062 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2063 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2064 } \
2065} while(0)
2066
Damien Millerf2e407e2011-05-20 19:04:14 +10002067 /* See comment in servconf.h */
2068 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002069
djm@openbsd.orged085102015-10-29 08:05:01 +00002070 /* Arguments that accept '+...' need to be expanded */
2071 assemble_algorithms(dst);
2072
Damien Millerc2411902011-05-20 19:03:49 +10002073 /*
2074 * The only things that should be below this point are string options
2075 * which are only used after authentication.
2076 */
Damien Miller5d74e582011-05-20 19:03:31 +10002077 if (preauth)
2078 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002079
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002080 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002081 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002082 if (option_clear_or_none(dst->adm_forced_command)) {
2083 free(dst->adm_forced_command);
2084 dst->adm_forced_command = NULL;
2085 }
Damien Miller5d74e582011-05-20 19:03:31 +10002086 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002087 if (option_clear_or_none(dst->chroot_directory)) {
2088 free(dst->chroot_directory);
2089 dst->chroot_directory = NULL;
2090 }
Darren Tucker45150472006-07-12 22:34:17 +10002091}
2092
Darren Tucker1629c072007-02-19 22:25:37 +11002093#undef M_CP_INTOPT
2094#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002095#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002096
Darren Tucker45150472006-07-12 22:34:17 +10002097void
2098parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002099 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002100{
2101 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002102 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002103
2104 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2105
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002106 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2107 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002108 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002109 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002110 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002111 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002112 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002113 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002114 }
Darren Tuckera627d422013-06-02 07:31:17 +10002115 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002116 if (bad_options > 0)
2117 fatal("%s: terminating, %d bad configuration options",
2118 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002119 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002120}
Darren Tuckere7140f22008-06-10 23:01:51 +10002121
2122static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002123fmt_multistate_int(int val, const struct multistate *m)
2124{
2125 u_int i;
2126
2127 for (i = 0; m[i].key != NULL; i++) {
2128 if (m[i].value == val)
2129 return m[i].key;
2130 }
2131 return "UNKNOWN";
2132}
2133
2134static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002135fmt_intarg(ServerOpCodes code, int val)
2136{
Damien Miller82c55872011-06-23 08:20:30 +10002137 if (val == -1)
2138 return "unset";
2139 switch (code) {
2140 case sAddressFamily:
2141 return fmt_multistate_int(val, multistate_addressfamily);
2142 case sPermitRootLogin:
2143 return fmt_multistate_int(val, multistate_permitrootlogin);
2144 case sGatewayPorts:
2145 return fmt_multistate_int(val, multistate_gatewayports);
2146 case sCompression:
2147 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002148 case sAllowTcpForwarding:
2149 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002150 case sAllowStreamLocalForwarding:
2151 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002152 case sFingerprintHash:
2153 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002154 default:
2155 switch (val) {
2156 case 0:
2157 return "no";
2158 case 1:
2159 return "yes";
2160 default:
2161 return "UNKNOWN";
2162 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002163 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002164}
2165
2166static const char *
2167lookup_opcode_name(ServerOpCodes code)
2168{
2169 u_int i;
2170
2171 for (i = 0; keywords[i].name != NULL; i++)
2172 if (keywords[i].opcode == code)
2173 return(keywords[i].name);
2174 return "UNKNOWN";
2175}
2176
2177static void
2178dump_cfg_int(ServerOpCodes code, int val)
2179{
2180 printf("%s %d\n", lookup_opcode_name(code), val);
2181}
2182
2183static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002184dump_cfg_oct(ServerOpCodes code, int val)
2185{
2186 printf("%s 0%o\n", lookup_opcode_name(code), val);
2187}
2188
2189static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002190dump_cfg_fmtint(ServerOpCodes code, int val)
2191{
2192 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2193}
2194
2195static void
2196dump_cfg_string(ServerOpCodes code, const char *val)
2197{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002198 printf("%s %s\n", lookup_opcode_name(code),
2199 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002200}
2201
2202static void
2203dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2204{
2205 u_int i;
2206
2207 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002208 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2209}
2210
2211static void
2212dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2213{
2214 u_int i;
2215
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002216 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002217 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002218 printf("%s", lookup_opcode_name(code));
2219 for (i = 0; i < count; i++)
2220 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002221 if (code == sAuthenticationMethods && count == 0)
2222 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002223 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002224}
2225
2226void
2227dump_config(ServerOptions *o)
2228{
2229 u_int i;
2230 int ret;
2231 struct addrinfo *ai;
2232 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002233 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002234
2235 /* these are usually at the top of the config */
2236 for (i = 0; i < o->num_ports; i++)
2237 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002238 dump_cfg_fmtint(sAddressFamily, o->address_family);
2239
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002240 /*
2241 * ListenAddress must be after Port. add_one_listen_addr pushes
2242 * addresses onto a stack, so to maintain ordering we need to
2243 * print these in reverse order.
2244 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002245 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2246 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2247 sizeof(addr), port, sizeof(port),
2248 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2249 error("getnameinfo failed: %.100s",
2250 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2251 strerror(errno));
2252 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002253 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002254 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002255 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2256 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002257 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002258 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2259 addr, port, laddr2);
2260 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002261 }
2262 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002263 printf("%s", laddr1);
2264 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002265
2266 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002267#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002268 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002269#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002270 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002271 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2272 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002273 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002274 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2275 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002276 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002277
2278 /* formatted integer arguments */
2279 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2280 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2281 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002282 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2283 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2284 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002285 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002286#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002287 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2288 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2289 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002290# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002291 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002292# endif
2293#endif
2294#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002295 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2296 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002297#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002298 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2299 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2300 o->kbd_interactive_authentication);
2301 dump_cfg_fmtint(sChallengeResponseAuthentication,
2302 o->challenge_response_authentication);
2303 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002304#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002305 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002306#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002307 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2308 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002309 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002310 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002311 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2312 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2313 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2314 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002315 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002316 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002317 dump_cfg_fmtint(sUseDNS, o->use_dns);
2318 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002319 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002320 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002321 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002322 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002323 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002324 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002325
2326 /* string arguments */
2327 dump_cfg_string(sPidFile, o->pid_file);
2328 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002329 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2330 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002331 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002332 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002333 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002334 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2335 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002336 dump_cfg_string(sAuthorizedPrincipalsFile,
2337 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002338 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2339 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002340 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2341 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002342 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2343 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002344 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002345 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002346 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002347 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2348 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002349 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2350 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002351 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2352 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002353
2354 /* string arguments requiring a lookup */
2355 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2356 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2357
2358 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002359 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2360 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002361 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2362 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002363 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002364 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002365 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2366 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2367 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2368 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2369 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002370 dump_cfg_strarray_oneline(sAuthenticationMethods,
2371 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002372
2373 /* other arguments */
2374 for (i = 0; i < o->num_subsystems; i++)
2375 printf("subsystem %s %s\n", o->subsystem_name[i],
2376 o->subsystem_args[i]);
2377
2378 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2379 o->max_startups_rate, o->max_startups);
2380
2381 for (i = 0; tunmode_desc[i].val != -1; i++)
2382 if (tunmode_desc[i].val == o->permit_tun) {
2383 s = tunmode_desc[i].text;
2384 break;
2385 }
2386 dump_cfg_string(sPermitTunnel, s);
2387
Damien Miller91475862011-05-05 14:14:34 +10002388 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2389 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002390
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002391 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002392 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002393
djm@openbsd.orgdbee4112017-09-12 06:32:07 +00002394 printf("permitopen");
2395 if (o->num_permitted_opens == 0)
2396 printf(" any");
2397 else {
2398 for (i = 0; i < o->num_permitted_opens; i++)
2399 printf(" %s", o->permitted_opens[i]);
2400 }
2401 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002402}