blob: 2f8e29d4c1a4ed164046b4b85ffdbedbc5fd0bd5 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00002/* $OpenBSD: servconf.c,v 1.304 2017/02/03 23:01:19 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100032#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100033#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100034#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100035#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100036#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100037
Damien Millerb84886b2008-05-19 15:05:07 +100038#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100042#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100043#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100045#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000049#include "kex.h"
50#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100051#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100052#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100053#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100054#include "canohost.h"
55#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110056#include "hostfile.h"
57#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000058#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000059#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000060
Damien Miller3dc71ad2009-01-28 16:31:22 +110061static void add_listen_addr(ServerOptions *, char *, int);
62static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110063
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000064/* Use of privilege separation or not */
65extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100066extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068/* Initializes the server options to their default values. */
69
Damien Miller4af51302000-04-16 11:18:38 +100070void
Damien Miller95def091999-11-25 00:26:21 +110071initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072{
Damien Miller95def091999-11-25 00:26:21 +110073 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100076 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110077
78 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110079 options->num_ports = 0;
80 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000081 options->queued_listen_addrs = NULL;
82 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110083 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110084 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110085 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110086 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100087 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100088 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110089 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +000090 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110091 options->ignore_rhosts = -1;
92 options->ignore_user_known_hosts = -1;
93 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000094 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110095 options->x11_forwarding = -1;
96 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110097 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110098 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +100099 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000100 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100102 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100103 options->log_facility = SYSLOG_FACILITY_NOT_SET;
104 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000105 options->hostbased_authentication = -1;
106 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000107 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000108 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100109 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000110 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->kerberos_authentication = -1;
112 options->kerberos_or_local_passwd = -1;
113 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100114 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000115 options->gss_authentication=-1;
116 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000117 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100118 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100119 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000120 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000122 options->permit_user_env = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000123 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000124 options->rekey_limit = -1;
125 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100126 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000127 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000128 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100129 options->num_allow_users = 0;
130 options->num_deny_users = 0;
131 options->num_allow_groups = 0;
132 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000133 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000134 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000135 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000136 options->fwd_opts.gateway_ports = -1;
137 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
138 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000139 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000140 options->max_startups_begin = -1;
141 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000142 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000143 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000144 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000145 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000146 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000147 options->client_alive_interval = -1;
148 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000149 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000150 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100151 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000152 options->num_permitted_opens = -1;
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;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000167}
168
djm@openbsd.org161cf412014-12-22 07:55:51 +0000169/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
170static int
171option_clear_or_none(const char *o)
172{
173 return o == NULL || strcasecmp(o, "none") == 0;
174}
175
djm@openbsd.orged085102015-10-29 08:05:01 +0000176static void
177assemble_algorithms(ServerOptions *o)
178{
179 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
180 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
181 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
182 kex_assemble_names(KEX_DEFAULT_PK_ALG,
183 &o->hostkeyalgorithms) != 0 ||
184 kex_assemble_names(KEX_DEFAULT_PK_ALG,
185 &o->hostbased_key_types) != 0 ||
186 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
187 fatal("kex_assemble_names failed");
188}
189
Damien Miller4af51302000-04-16 11:18:38 +1000190void
Damien Miller95def091999-11-25 00:26:21 +1100191fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000192{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000193 int i;
194
Damien Miller726273e2001-11-12 11:40:11 +1100195 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000196 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000197 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100198
199 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100200 if (options->num_host_key_files == 0) {
201 /* fill default hostkeys for protocols */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000202 options->host_key_files[options->num_host_key_files++] =
203 _PATH_HOST_RSA_KEY_FILE;
204 options->host_key_files[options->num_host_key_files++] =
205 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100206#ifdef OPENSSL_HAS_ECC
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000207 options->host_key_files[options->num_host_key_files++] =
208 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100209#endif
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000210 options->host_key_files[options->num_host_key_files++] =
211 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100212 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100213 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100214 if (options->num_ports == 0)
215 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000216 if (options->address_family == -1)
217 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100218 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000219 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000220 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000221 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000223 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000224 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000225 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100227 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->ignore_user_known_hosts == -1)
229 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->print_motd == -1)
231 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000232 if (options->print_lastlog == -1)
233 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100235 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100237 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100238 if (options->x11_use_localhost == -1)
239 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000240 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000241 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100242 if (options->permit_tty == -1)
243 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000244 if (options->permit_user_rc == -1)
245 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->strict_modes == -1)
247 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100248 if (options->tcp_keep_alive == -1)
249 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100250 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100251 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100252 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000253 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000254 if (options->hostbased_authentication == -1)
255 options->hostbased_authentication = 0;
256 if (options->hostbased_uses_name_from_packet_only == -1)
257 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100258 if (options->pubkey_authentication == -1)
259 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100260 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000261 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->kerberos_or_local_passwd == -1)
263 options->kerberos_or_local_passwd = 1;
264 if (options->kerberos_ticket_cleanup == -1)
265 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100266 if (options->kerberos_get_afs_token == -1)
267 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000268 if (options->gss_authentication == -1)
269 options->gss_authentication = 0;
270 if (options->gss_cleanup_creds == -1)
271 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000272 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000273 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100274 if (options->password_authentication == -1)
275 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100276 if (options->kbd_interactive_authentication == -1)
277 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000278 if (options->challenge_response_authentication == -1)
279 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100281 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000282 if (options->permit_user_env == -1)
283 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000284 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000285 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000286 if (options->rekey_limit == -1)
287 options->rekey_limit = 0;
288 if (options->rekey_interval == -1)
289 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100290 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100291 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000292 if (options->allow_streamlocal_forwarding == -1)
293 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000294 if (options->allow_agent_forwarding == -1)
295 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000296 if (options->fwd_opts.gateway_ports == -1)
297 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000298 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100299 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000300 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100301 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000302 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100303 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000304 if (options->max_authtries == -1)
305 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000306 if (options->max_sessions == -1)
307 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000308 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000309 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000310 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100311 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000312 if (options->client_alive_count_max == -1)
313 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000314 if (options->num_authkeys_files == 0) {
315 options->authorized_keys_files[options->num_authkeys_files++] =
316 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
317 options->authorized_keys_files[options->num_authkeys_files++] =
318 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
319 }
Damien Millerd27b9472005-12-13 19:29:02 +1100320 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100321 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100322 if (options->ip_qos_interactive == -1)
323 options->ip_qos_interactive = IPTOS_LOWDELAY;
324 if (options->ip_qos_bulk == -1)
325 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000326 if (options->version_addendum == NULL)
327 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000328 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
329 options->fwd_opts.streamlocal_bind_mask = 0177;
330 if (options->fwd_opts.streamlocal_bind_unlink == -1)
331 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000332 if (options->fingerprint_hash == -1)
333 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000334 if (options->disable_forwarding == -1)
335 options->disable_forwarding = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000336
djm@openbsd.orged085102015-10-29 08:05:01 +0000337 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000338
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000339 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000340 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000341 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000342
djm@openbsd.org161cf412014-12-22 07:55:51 +0000343#define CLEAR_ON_NONE(v) \
344 do { \
345 if (option_clear_or_none(v)) { \
346 free(v); \
347 v = NULL; \
348 } \
349 } while(0)
350 CLEAR_ON_NONE(options->pid_file);
351 CLEAR_ON_NONE(options->xauth_location);
352 CLEAR_ON_NONE(options->banner);
353 CLEAR_ON_NONE(options->trusted_user_ca_keys);
354 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000355 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000356 CLEAR_ON_NONE(options->adm_forced_command);
357 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000358 for (i = 0; i < options->num_host_key_files; i++)
359 CLEAR_ON_NONE(options->host_key_files[i]);
360 for (i = 0; i < options->num_host_cert_files; i++)
361 CLEAR_ON_NONE(options->host_cert_files[i]);
362#undef CLEAR_ON_NONE
363
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000364 /* Similar handling for AuthenticationMethods=any */
365 if (options->num_auth_methods == 1 &&
366 strcmp(options->auth_methods[0], "any") == 0) {
367 free(options->auth_methods[0]);
368 options->auth_methods[0] = NULL;
369 options->num_auth_methods = 0;
370 }
371
Tim Rice40017b02002-07-14 13:36:49 -0700372#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000373 if (use_privsep && options->compression == 1) {
374 error("This platform does not support both privilege "
375 "separation and compression");
376 error("Compression disabled");
377 options->compression = 0;
378 }
379#endif
380
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381}
382
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100384typedef enum {
385 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100386 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000387 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100388 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000389 sPort, sHostKeyFile, sLoginGraceTime,
390 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000391 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100392 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100393 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000394 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100395 sPasswordAuthentication, sKbdInteractiveAuthentication,
396 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000397 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100398 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100399 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000400 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000401 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000402 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000403 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
404 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000405 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000406 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000407 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000408 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000409 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
410 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100411 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100412 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100413 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000414 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000415 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000416 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100417 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000418 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000419 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000420 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000421 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422} ServerOpCodes;
423
Darren Tucker45150472006-07-12 22:34:17 +1000424#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
425#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
426#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
427
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000428/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100429static struct {
430 const char *name;
431 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000432 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100433} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100434 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000435#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000436 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000437#else
Darren Tucker45150472006-07-12 22:34:17 +1000438 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000439#endif
Darren Tucker45150472006-07-12 22:34:17 +1000440 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100441 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "port", sPort, SSHCFG_GLOBAL },
443 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
444 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000445 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000447 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000448 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000449 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100450 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
452 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
453 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000454 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100455 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000456 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000457 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000458 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000459 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100460 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000461 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000462 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000463#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000465 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
466 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100467#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000468 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000469#else
Darren Tucker45150472006-07-12 22:34:17 +1000470 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100471#endif
472#else
Darren Tucker1629c072007-02-19 22:25:37 +1100473 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000474 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
475 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
476 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000477#endif
Darren Tucker45150472006-07-12 22:34:17 +1000478 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
479 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000480#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100481 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000482 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000483 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000484#else
Darren Tucker1629c072007-02-19 22:25:37 +1100485 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000487 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000488#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100489 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
490 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100491 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000492 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
493 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
494 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
495 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
496 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100497#ifdef DISABLE_LASTLOG
498 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
499#else
Darren Tucker45150472006-07-12 22:34:17 +1000500 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100501#endif
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
503 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000504 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
505 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
506 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000507 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
508 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100509 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000510 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000511 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000513 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
515 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
516 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000517 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000518 { "allowusers", sAllowUsers, SSHCFG_ALL },
519 { "denyusers", sDenyUsers, SSHCFG_ALL },
520 { "allowgroups", sAllowGroups, SSHCFG_ALL },
521 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "ciphers", sCiphers, SSHCFG_GLOBAL },
523 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000524 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
526 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
527 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000528 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000529 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100530 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000531 { "usedns", sUseDNS, SSHCFG_GLOBAL },
532 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
533 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000534 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
535 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000536 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000537 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000538 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000539 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000540 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100541 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000542 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000543 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000544 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000545 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100546 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100547 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100548 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
549 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000550 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000551 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100552 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100553 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
554 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000555 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
556 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000557 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100558 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000559 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
560 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
561 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000562 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000563 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000564 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000565};
566
Darren Tuckere7140f22008-06-10 23:01:51 +1000567static struct {
568 int val;
569 char *text;
570} tunmode_desc[] = {
571 { SSH_TUNMODE_NO, "no" },
572 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
573 { SSH_TUNMODE_ETHERNET, "ethernet" },
574 { SSH_TUNMODE_YES, "yes" },
575 { -1, NULL }
576};
577
Damien Miller5428f641999-11-25 11:54:57 +1100578/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000579 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100580 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581
Damien Miller4af51302000-04-16 11:18:38 +1000582static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100583parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000584 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000585{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000586 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000587
Damien Miller95def091999-11-25 00:26:21 +1100588 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000589 if (strcasecmp(cp, keywords[i].name) == 0) {
590 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100591 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000592 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000593
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000594 error("%s: line %d: Bad configuration option: %s",
595 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100596 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000597}
598
Darren Tucker88b6fb22010-01-13 22:44:29 +1100599char *
600derelativise_path(const char *path)
601{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000602 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100603
djm@openbsd.org161cf412014-12-22 07:55:51 +0000604 if (strcasecmp(path, "none") == 0)
605 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100606 expanded = tilde_expand_filename(path, getuid());
607 if (*expanded == '/')
608 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100609 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100610 fatal("%s: getcwd: %s", __func__, strerror(errno));
611 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000612 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100613 return ret;
614}
615
Ben Lindstrombba81212001-06-25 05:01:22 +0000616static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100617add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100618{
Damien Millereccb9de2005-06-17 12:59:34 +1000619 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100620
Ben Lindstrom19066a12001-04-12 23:39:26 +0000621 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000622 for (i = 0; i < options->num_ports; i++)
623 add_one_listen_addr(options, addr, options->ports[i]);
624 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000625 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000626}
627
Ben Lindstrombba81212001-06-25 05:01:22 +0000628static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100629add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000630{
631 struct addrinfo hints, *ai, *aitop;
632 char strport[NI_MAXSERV];
633 int gaierr;
634
635 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100636 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000637 hints.ai_socktype = SOCK_STREAM;
638 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100639 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000640 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
641 fatal("bad addr or host: %s (%s)",
642 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100643 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000644 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
645 ;
646 ai->ai_next = options->listen_addrs;
647 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100648}
649
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000650/*
651 * Queue a ListenAddress to be processed once we have all of the Ports
652 * and AddressFamily options.
653 */
654static void
655queue_listen_addr(ServerOptions *options, char *addr, int port)
656{
657 options->queued_listen_addrs = xreallocarray(
658 options->queued_listen_addrs, options->num_queued_listens + 1,
659 sizeof(addr));
660 options->queued_listen_ports = xreallocarray(
661 options->queued_listen_ports, options->num_queued_listens + 1,
662 sizeof(port));
663 options->queued_listen_addrs[options->num_queued_listens] =
664 xstrdup(addr);
665 options->queued_listen_ports[options->num_queued_listens] = port;
666 options->num_queued_listens++;
667}
668
669/*
670 * Process queued (text) ListenAddress entries.
671 */
672static void
673process_queued_listen_addrs(ServerOptions *options)
674{
675 u_int i;
676
677 if (options->num_ports == 0)
678 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
679 if (options->address_family == -1)
680 options->address_family = AF_UNSPEC;
681
682 for (i = 0; i < options->num_queued_listens; i++) {
683 add_listen_addr(options, options->queued_listen_addrs[i],
684 options->queued_listen_ports[i]);
685 free(options->queued_listen_addrs[i]);
686 options->queued_listen_addrs[i] = NULL;
687 }
688 free(options->queued_listen_addrs);
689 options->queued_listen_addrs = NULL;
690 free(options->queued_listen_ports);
691 options->queued_listen_ports = NULL;
692 options->num_queued_listens = 0;
693}
694
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695struct connection_info *
696get_connection_info(int populate, int use_dns)
697{
djm@openbsd.org95767262016-03-07 19:02:43 +0000698 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000699 static struct connection_info ci;
700
701 if (!populate)
702 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000703 ci.host = auth_get_canonical_hostname(ssh, use_dns);
704 ci.address = ssh_remote_ipaddr(ssh);
705 ci.laddress = ssh_local_ipaddr(ssh);
706 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000707 return &ci;
708}
709
Darren Tucker45150472006-07-12 22:34:17 +1000710/*
711 * The strategy for the Match blocks is that the config file is parsed twice.
712 *
713 * The first time is at startup. activep is initialized to 1 and the
714 * directives in the global context are processed and acted on. Hitting a
715 * Match directive unsets activep and the directives inside the block are
716 * checked for syntax only.
717 *
718 * The second time is after a connection has been established but before
719 * authentication. activep is initialized to 2 and global config directives
720 * are ignored since they have already been processed. If the criteria in a
721 * Match block is met, activep is set and the subsequent directives
722 * processed and actioned until EOF or another Match block unsets it. Any
723 * options set are copied into the main server config.
724 *
725 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000726 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000727 *
728 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
729 * Match Address 192.168.0.*
730 * Tag trusted
731 * Match Group wheel
732 * Tag trusted
733 * Match Tag trusted
734 * AllowTcpForwarding yes
735 * GatewayPorts clientspecified
736 * [...]
737 *
738 * - Add a PermittedChannelRequests directive
739 * Match Group shell
740 * PermittedChannelRequests session,forwarded-tcpip
741 */
742
743static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000744match_cfg_line_group(const char *grps, int line, const char *user)
745{
746 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000747 struct passwd *pw;
748
Damien Miller565ca3f2006-08-19 00:23:15 +1000749 if (user == NULL)
750 goto out;
751
752 if ((pw = getpwnam(user)) == NULL) {
753 debug("Can't match group at line %d because user %.100s does "
754 "not exist", line, user);
755 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
756 debug("Can't Match group because user %.100s not in any group "
757 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000758 } else if (ga_match_pattern_list(grps) != 1) {
759 debug("user %.100s does not match group list %.100s at line %d",
760 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000761 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000762 debug("user %.100s matched group list %.100s at line %d", user,
763 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000764 result = 1;
765 }
766out:
767 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000768 return result;
769}
770
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000771/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000772 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100773 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000774 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000775 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000776static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000777match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000778{
Damien Millercf31f382013-10-24 21:02:56 +1100779 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000780 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000781
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000782 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000783 debug3("checking syntax for 'Match %s'", cp);
784 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000785 debug3("checking match for '%s' user %s host %s addr %s "
786 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
787 ci->host ? ci->host : "(null)",
788 ci->address ? ci->address : "(null)",
789 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000790
791 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100792 attributes++;
793 if (strcasecmp(attrib, "all") == 0) {
794 if (attributes != 1 ||
795 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
796 error("'all' cannot be combined with other "
797 "Match attributes");
798 return -1;
799 }
800 *condition = cp;
801 return 1;
802 }
Darren Tucker45150472006-07-12 22:34:17 +1000803 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
804 error("Missing Match criteria for %s", attrib);
805 return -1;
806 }
Darren Tucker45150472006-07-12 22:34:17 +1000807 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000808 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000809 result = 0;
810 continue;
811 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000812 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000813 result = 0;
814 else
815 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000816 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000817 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000818 if (ci == NULL || ci->user == NULL) {
819 result = 0;
820 continue;
821 }
822 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000823 case -1:
824 return -1;
825 case 0:
826 result = 0;
827 }
Darren Tucker45150472006-07-12 22:34:17 +1000828 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000829 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000830 result = 0;
831 continue;
832 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000833 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000834 result = 0;
835 else
836 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000837 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000838 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000839 if (ci == NULL || ci->address == NULL) {
840 result = 0;
841 continue;
842 }
843 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000844 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000845 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000846 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000847 break;
848 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000849 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000850 result = 0;
851 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000852 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000853 return -1;
854 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000855 } else if (strcasecmp(attrib, "localaddress") == 0){
856 if (ci == NULL || ci->laddress == NULL) {
857 result = 0;
858 continue;
859 }
860 switch (addr_match_list(ci->laddress, arg)) {
861 case 1:
862 debug("connection from %.100s matched "
863 "'LocalAddress %.100s' at line %d",
864 ci->laddress, arg, line);
865 break;
866 case 0:
867 case -1:
868 result = 0;
869 break;
870 case -2:
871 return -1;
872 }
873 } else if (strcasecmp(attrib, "localport") == 0) {
874 if ((port = a2port(arg)) == -1) {
875 error("Invalid LocalPort '%s' on Match line",
876 arg);
877 return -1;
878 }
879 if (ci == NULL || ci->lport == 0) {
880 result = 0;
881 continue;
882 }
883 /* TODO support port lists */
884 if (port == ci->lport)
885 debug("connection from %.100s matched "
886 "'LocalPort %d' at line %d",
887 ci->laddress, port, line);
888 else
889 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000890 } else {
891 error("Unsupported Match attribute %s", attrib);
892 return -1;
893 }
894 }
Damien Millercf31f382013-10-24 21:02:56 +1100895 if (attributes == 0) {
896 error("One or more attributes required for Match");
897 return -1;
898 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000899 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000900 debug3("match %sfound", result ? "" : "not ");
901 *condition = cp;
902 return result;
903}
904
Damien Millere2754432006-07-24 14:06:47 +1000905#define WHITESPACE " \t\r\n"
906
Damien Miller33322122011-06-20 14:43:11 +1000907/* Multistate option parsing */
908struct multistate {
909 char *key;
910 int value;
911};
912static const struct multistate multistate_addressfamily[] = {
913 { "inet", AF_INET },
914 { "inet6", AF_INET6 },
915 { "any", AF_UNSPEC },
916 { NULL, -1 }
917};
918static const struct multistate multistate_permitrootlogin[] = {
919 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000920 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000921 { "forced-commands-only", PERMIT_FORCED_ONLY },
922 { "yes", PERMIT_YES },
923 { "no", PERMIT_NO },
924 { NULL, -1 }
925};
926static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +0000927 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +0000928 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +1000929 { "no", COMP_NONE },
930 { NULL, -1 }
931};
932static const struct multistate multistate_gatewayports[] = {
933 { "clientspecified", 2 },
934 { "yes", 1 },
935 { "no", 0 },
936 { NULL, -1 }
937};
Damien Miller69ff1df2011-06-23 08:30:03 +1000938static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000939 { "yes", PRIVSEP_NOSANDBOX },
940 { "sandbox", PRIVSEP_ON },
941 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000942 { "no", PRIVSEP_OFF },
943 { NULL, -1 }
944};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100945static const struct multistate multistate_tcpfwd[] = {
946 { "yes", FORWARD_ALLOW },
947 { "all", FORWARD_ALLOW },
948 { "no", FORWARD_DENY },
949 { "remote", FORWARD_REMOTE },
950 { "local", FORWARD_LOCAL },
951 { NULL, -1 }
952};
Damien Miller33322122011-06-20 14:43:11 +1000953
Ben Lindstromade03f62001-12-06 18:22:17 +0000954int
955process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000956 const char *filename, int linenum, int *activep,
957 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000958{
Darren Tucker09c0f032013-05-16 20:48:57 +1000959 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000960 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100961 SyslogFacility *log_facility_ptr;
962 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000963 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000964 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000965 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000966 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000967 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000968
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +0000969 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
970 if ((len = strlen(line)) == 0)
971 return 0;
972 for (len--; len > 0; len--) {
973 if (strchr(WHITESPACE "\f", line[len]) == NULL)
974 break;
975 line[len] = '\0';
976 }
977
Ben Lindstromade03f62001-12-06 18:22:17 +0000978 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100979 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100980 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000981 /* Ignore leading whitespace */
982 if (*arg == '\0')
983 arg = strdelim(&cp);
984 if (!arg || !*arg || *arg == '#')
985 return 0;
986 intptr = NULL;
987 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000988 opcode = parse_token(arg, filename, linenum, &flags);
989
990 if (activep == NULL) { /* We are processing a command line directive */
991 cmdline = 1;
992 activep = &cmdline;
993 }
994 if (*activep && opcode != sMatch)
995 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
996 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000997 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000998 fatal("%s line %d: Directive '%s' is not allowed "
999 "within a Match block", filename, linenum, arg);
1000 } else { /* this is a directive we have already processed */
1001 while (arg)
1002 arg = strdelim(&cp);
1003 return 0;
1004 }
1005 }
1006
Ben Lindstromade03f62001-12-06 18:22:17 +00001007 switch (opcode) {
1008 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001009 case sUsePAM:
1010 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001011 goto parse_flag;
1012
1013 /* Standard Options */
1014 case sBadOption:
1015 return -1;
1016 case sPort:
1017 /* ignore ports from configfile if cmdline specifies ports */
1018 if (options->ports_from_cmdline)
1019 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001020 if (options->num_ports >= MAX_PORTS)
1021 fatal("%s line %d: too many ports.",
1022 filename, linenum);
1023 arg = strdelim(&cp);
1024 if (!arg || *arg == '\0')
1025 fatal("%s line %d: missing port number.",
1026 filename, linenum);
1027 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001028 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001029 fatal("%s line %d: Badly formatted port number.",
1030 filename, linenum);
1031 break;
1032
Ben Lindstromade03f62001-12-06 18:22:17 +00001033 case sLoginGraceTime:
1034 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001035 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 arg = strdelim(&cp);
1037 if (!arg || *arg == '\0')
1038 fatal("%s line %d: missing time value.",
1039 filename, linenum);
1040 if ((value = convtime(arg)) == -1)
1041 fatal("%s line %d: invalid time value.",
1042 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001043 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 *intptr = value;
1045 break;
1046
Ben Lindstromade03f62001-12-06 18:22:17 +00001047 case sListenAddress:
1048 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001049 if (arg == NULL || *arg == '\0')
1050 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001051 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001052 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1053 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1054 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001055 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001056 break;
1057 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001058 p = hpdelim(&arg);
1059 if (p == NULL)
1060 fatal("%s line %d: bad address:port usage",
1061 filename, linenum);
1062 p = cleanhostname(p);
1063 if (arg == NULL)
1064 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001065 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001066 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001067
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001068 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001069
Ben Lindstromade03f62001-12-06 18:22:17 +00001070 break;
1071
Darren Tucker0f383232005-01-20 10:57:56 +11001072 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001073 intptr = &options->address_family;
1074 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001075 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001076 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001077 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001078 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001079 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001080 value = -1;
1081 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1082 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1083 value = multistate_ptr[i].value;
1084 break;
1085 }
1086 }
1087 if (value == -1)
1088 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001089 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001090 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001091 *intptr = value;
1092 break;
1093
Ben Lindstromade03f62001-12-06 18:22:17 +00001094 case sHostKeyFile:
1095 intptr = &options->num_host_key_files;
1096 if (*intptr >= MAX_HOSTKEYS)
1097 fatal("%s line %d: too many host keys specified (max %d).",
1098 filename, linenum, MAX_HOSTKEYS);
1099 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001100 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001101 arg = strdelim(&cp);
1102 if (!arg || *arg == '\0')
1103 fatal("%s line %d: missing file name.",
1104 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001105 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001106 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001107 /* increase optional counter */
1108 if (intptr != NULL)
1109 *intptr = *intptr + 1;
1110 }
1111 break;
1112
Damien Miller85b45e02013-07-20 13:21:52 +10001113 case sHostKeyAgent:
1114 charptr = &options->host_key_agent;
1115 arg = strdelim(&cp);
1116 if (!arg || *arg == '\0')
1117 fatal("%s line %d: missing socket name.",
1118 filename, linenum);
1119 if (*activep && *charptr == NULL)
1120 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1121 xstrdup(arg) : derelativise_path(arg);
1122 break;
1123
Damien Miller0a80ca12010-02-27 07:55:05 +11001124 case sHostCertificate:
1125 intptr = &options->num_host_cert_files;
1126 if (*intptr >= MAX_HOSTKEYS)
1127 fatal("%s line %d: too many host certificates "
1128 "specified (max %d).", filename, linenum,
1129 MAX_HOSTCERTS);
1130 charptr = &options->host_cert_files[*intptr];
1131 goto parse_filename;
Damien Miller0a80ca12010-02-27 07:55:05 +11001132
Ben Lindstromade03f62001-12-06 18:22:17 +00001133 case sPidFile:
1134 charptr = &options->pid_file;
1135 goto parse_filename;
1136
1137 case sPermitRootLogin:
1138 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001139 multistate_ptr = multistate_permitrootlogin;
1140 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001141
1142 case sIgnoreRhosts:
1143 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001144 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001145 arg = strdelim(&cp);
1146 if (!arg || *arg == '\0')
1147 fatal("%s line %d: missing yes/no argument.",
1148 filename, linenum);
1149 value = 0; /* silence compiler */
1150 if (strcmp(arg, "yes") == 0)
1151 value = 1;
1152 else if (strcmp(arg, "no") == 0)
1153 value = 0;
1154 else
1155 fatal("%s line %d: Bad yes/no argument: %s",
1156 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001157 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001158 *intptr = value;
1159 break;
1160
1161 case sIgnoreUserKnownHosts:
1162 intptr = &options->ignore_user_known_hosts;
1163 goto parse_flag;
1164
Ben Lindstromade03f62001-12-06 18:22:17 +00001165 case sHostbasedAuthentication:
1166 intptr = &options->hostbased_authentication;
1167 goto parse_flag;
1168
1169 case sHostbasedUsesNameFromPacketOnly:
1170 intptr = &options->hostbased_uses_name_from_packet_only;
1171 goto parse_flag;
1172
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001173 case sHostbasedAcceptedKeyTypes:
1174 charptr = &options->hostbased_key_types;
1175 parse_keytypes:
1176 arg = strdelim(&cp);
1177 if (!arg || *arg == '\0')
1178 fatal("%s line %d: Missing argument.",
1179 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001180 if (*arg != '-' &&
1181 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001182 fatal("%s line %d: Bad key types '%s'.",
1183 filename, linenum, arg ? arg : "<NONE>");
1184 if (*activep && *charptr == NULL)
1185 *charptr = xstrdup(arg);
1186 break;
1187
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001188 case sHostKeyAlgorithms:
1189 charptr = &options->hostkeyalgorithms;
1190 goto parse_keytypes;
1191
Ben Lindstromade03f62001-12-06 18:22:17 +00001192 case sPubkeyAuthentication:
1193 intptr = &options->pubkey_authentication;
1194 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001195
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001196 case sPubkeyAcceptedKeyTypes:
1197 charptr = &options->pubkey_key_types;
1198 goto parse_keytypes;
1199
Ben Lindstromade03f62001-12-06 18:22:17 +00001200 case sKerberosAuthentication:
1201 intptr = &options->kerberos_authentication;
1202 goto parse_flag;
1203
1204 case sKerberosOrLocalPasswd:
1205 intptr = &options->kerberos_or_local_passwd;
1206 goto parse_flag;
1207
1208 case sKerberosTicketCleanup:
1209 intptr = &options->kerberos_ticket_cleanup;
1210 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001211
Darren Tucker22ef5082003-12-31 11:37:34 +11001212 case sKerberosGetAFSToken:
1213 intptr = &options->kerberos_get_afs_token;
1214 goto parse_flag;
1215
Darren Tucker0efd1552003-08-26 11:49:55 +10001216 case sGssAuthentication:
1217 intptr = &options->gss_authentication;
1218 goto parse_flag;
1219
1220 case sGssCleanupCreds:
1221 intptr = &options->gss_cleanup_creds;
1222 goto parse_flag;
1223
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001224 case sGssStrictAcceptor:
1225 intptr = &options->gss_strict_acceptor;
1226 goto parse_flag;
1227
Ben Lindstromade03f62001-12-06 18:22:17 +00001228 case sPasswordAuthentication:
1229 intptr = &options->password_authentication;
1230 goto parse_flag;
1231
1232 case sKbdInteractiveAuthentication:
1233 intptr = &options->kbd_interactive_authentication;
1234 goto parse_flag;
1235
1236 case sChallengeResponseAuthentication:
1237 intptr = &options->challenge_response_authentication;
1238 goto parse_flag;
1239
1240 case sPrintMotd:
1241 intptr = &options->print_motd;
1242 goto parse_flag;
1243
1244 case sPrintLastLog:
1245 intptr = &options->print_lastlog;
1246 goto parse_flag;
1247
1248 case sX11Forwarding:
1249 intptr = &options->x11_forwarding;
1250 goto parse_flag;
1251
1252 case sX11DisplayOffset:
1253 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001254 parse_int:
1255 arg = strdelim(&cp);
1256 if (!arg || *arg == '\0')
1257 fatal("%s line %d: missing integer value.",
1258 filename, linenum);
1259 value = atoi(arg);
1260 if (*activep && *intptr == -1)
1261 *intptr = value;
1262 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001263
Damien Miller95c249f2002-02-05 12:11:34 +11001264 case sX11UseLocalhost:
1265 intptr = &options->x11_use_localhost;
1266 goto parse_flag;
1267
Ben Lindstromade03f62001-12-06 18:22:17 +00001268 case sXAuthLocation:
1269 charptr = &options->xauth_location;
1270 goto parse_filename;
1271
Damien Miller5ff30c62013-10-30 22:21:50 +11001272 case sPermitTTY:
1273 intptr = &options->permit_tty;
1274 goto parse_flag;
1275
Damien Miller72e6b5c2014-07-04 09:00:04 +10001276 case sPermitUserRC:
1277 intptr = &options->permit_user_rc;
1278 goto parse_flag;
1279
Ben Lindstromade03f62001-12-06 18:22:17 +00001280 case sStrictModes:
1281 intptr = &options->strict_modes;
1282 goto parse_flag;
1283
Damien Miller12c150e2003-12-17 16:31:10 +11001284 case sTCPKeepAlive:
1285 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001286 goto parse_flag;
1287
1288 case sEmptyPasswd:
1289 intptr = &options->permit_empty_passwd;
1290 goto parse_flag;
1291
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001292 case sPermitUserEnvironment:
1293 intptr = &options->permit_user_env;
1294 goto parse_flag;
1295
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001296 case sCompression:
1297 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001298 multistate_ptr = multistate_compression;
1299 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001300
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001301 case sRekeyLimit:
1302 arg = strdelim(&cp);
1303 if (!arg || *arg == '\0')
1304 fatal("%.200s line %d: Missing argument.", filename,
1305 linenum);
1306 if (strcmp(arg, "default") == 0) {
1307 val64 = 0;
1308 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001309 if (scan_scaled(arg, &val64) == -1)
1310 fatal("%.200s line %d: Bad number '%s': %s",
1311 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001312 if (val64 != 0 && val64 < 16)
1313 fatal("%.200s line %d: RekeyLimit too small",
1314 filename, linenum);
1315 }
1316 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001317 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001318 if (cp != NULL) { /* optional rekey interval present */
1319 if (strcmp(cp, "none") == 0) {
1320 (void)strdelim(&cp); /* discard */
1321 break;
1322 }
1323 intptr = &options->rekey_interval;
1324 goto parse_time;
1325 }
1326 break;
1327
Ben Lindstromade03f62001-12-06 18:22:17 +00001328 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001329 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001330 multistate_ptr = multistate_gatewayports;
1331 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001332
Damien Miller3a961dc2003-06-03 10:25:48 +10001333 case sUseDNS:
1334 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001335 goto parse_flag;
1336
1337 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001338 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001339 arg = strdelim(&cp);
1340 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001341 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001342 fatal("%.200s line %d: unsupported log facility '%s'",
1343 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001344 if (*log_facility_ptr == -1)
1345 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001346 break;
1347
1348 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001349 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001350 arg = strdelim(&cp);
1351 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001352 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 fatal("%.200s line %d: unsupported log level '%s'",
1354 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001355 if (*log_level_ptr == -1)
1356 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001357 break;
1358
1359 case sAllowTcpForwarding:
1360 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001361 multistate_ptr = multistate_tcpfwd;
1362 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001363
Damien Miller7acefbb2014-07-18 14:11:24 +10001364 case sAllowStreamLocalForwarding:
1365 intptr = &options->allow_streamlocal_forwarding;
1366 multistate_ptr = multistate_tcpfwd;
1367 goto parse_multistate;
1368
Damien Miller4f755cd2008-05-19 14:57:41 +10001369 case sAllowAgentForwarding:
1370 intptr = &options->allow_agent_forwarding;
1371 goto parse_flag;
1372
djm@openbsd.org7844f352016-11-30 03:00:05 +00001373 case sDisableForwarding:
1374 intptr = &options->disable_forwarding;
1375 goto parse_flag;
1376
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001377 case sUsePrivilegeSeparation:
1378 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001379 multistate_ptr = multistate_privsep;
1380 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001381
Ben Lindstromade03f62001-12-06 18:22:17 +00001382 case sAllowUsers:
1383 while ((arg = strdelim(&cp)) && *arg != '\0') {
1384 if (options->num_allow_users >= MAX_ALLOW_USERS)
1385 fatal("%s line %d: too many allow users.",
1386 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001387 if (match_user(NULL, NULL, NULL, arg) == -1)
1388 fatal("%s line %d: invalid AllowUsers pattern: "
1389 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001390 if (!*activep)
1391 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001392 options->allow_users[options->num_allow_users++] =
1393 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001394 }
1395 break;
1396
1397 case sDenyUsers:
1398 while ((arg = strdelim(&cp)) && *arg != '\0') {
1399 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001400 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001401 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001402 if (match_user(NULL, NULL, NULL, arg) == -1)
1403 fatal("%s line %d: invalid DenyUsers pattern: "
1404 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001405 if (!*activep)
1406 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001407 options->deny_users[options->num_deny_users++] =
1408 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001409 }
1410 break;
1411
1412 case sAllowGroups:
1413 while ((arg = strdelim(&cp)) && *arg != '\0') {
1414 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1415 fatal("%s line %d: too many allow groups.",
1416 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001417 if (!*activep)
1418 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001419 options->allow_groups[options->num_allow_groups++] =
1420 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001421 }
1422 break;
1423
1424 case sDenyGroups:
1425 while ((arg = strdelim(&cp)) && *arg != '\0') {
1426 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1427 fatal("%s line %d: too many deny groups.",
1428 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001429 if (!*activep)
1430 continue;
1431 options->deny_groups[options->num_deny_groups++] =
1432 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001433 }
1434 break;
1435
1436 case sCiphers:
1437 arg = strdelim(&cp);
1438 if (!arg || *arg == '\0')
1439 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001440 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001441 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1442 filename, linenum, arg ? arg : "<NONE>");
1443 if (options->ciphers == NULL)
1444 options->ciphers = xstrdup(arg);
1445 break;
1446
1447 case sMacs:
1448 arg = strdelim(&cp);
1449 if (!arg || *arg == '\0')
1450 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001451 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001452 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1453 filename, linenum, arg ? arg : "<NONE>");
1454 if (options->macs == NULL)
1455 options->macs = xstrdup(arg);
1456 break;
1457
Damien Millerd5f62bf2010-09-24 22:11:14 +10001458 case sKexAlgorithms:
1459 arg = strdelim(&cp);
1460 if (!arg || *arg == '\0')
1461 fatal("%s line %d: Missing argument.",
1462 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001463 if (*arg != '-' &&
1464 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001465 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1466 filename, linenum, arg ? arg : "<NONE>");
1467 if (options->kex_algorithms == NULL)
1468 options->kex_algorithms = xstrdup(arg);
1469 break;
1470
Ben Lindstromade03f62001-12-06 18:22:17 +00001471 case sSubsystem:
1472 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1473 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001474 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001475 }
1476 arg = strdelim(&cp);
1477 if (!arg || *arg == '\0')
1478 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001479 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001480 if (!*activep) {
1481 arg = strdelim(&cp);
1482 break;
1483 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001484 for (i = 0; i < options->num_subsystems; i++)
1485 if (strcmp(arg, options->subsystem_name[i]) == 0)
1486 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001487 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001488 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1489 arg = strdelim(&cp);
1490 if (!arg || *arg == '\0')
1491 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001492 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001493 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001494
1495 /* Collect arguments (separate to executable) */
1496 p = xstrdup(arg);
1497 len = strlen(p) + 1;
1498 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1499 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001500 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001501 strlcat(p, " ", len);
1502 strlcat(p, arg, len);
1503 }
1504 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001505 options->num_subsystems++;
1506 break;
1507
1508 case sMaxStartups:
1509 arg = strdelim(&cp);
1510 if (!arg || *arg == '\0')
1511 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001512 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001513 if ((n = sscanf(arg, "%d:%d:%d",
1514 &options->max_startups_begin,
1515 &options->max_startups_rate,
1516 &options->max_startups)) == 3) {
1517 if (options->max_startups_begin >
1518 options->max_startups ||
1519 options->max_startups_rate > 100 ||
1520 options->max_startups_rate < 1)
1521 fatal("%s line %d: Illegal MaxStartups spec.",
1522 filename, linenum);
1523 } else if (n != 1)
1524 fatal("%s line %d: Illegal MaxStartups spec.",
1525 filename, linenum);
1526 else
1527 options->max_startups = options->max_startups_begin;
1528 break;
1529
Darren Tucker89413db2004-05-24 10:36:23 +10001530 case sMaxAuthTries:
1531 intptr = &options->max_authtries;
1532 goto parse_int;
1533
Damien Miller7207f642008-05-19 15:34:50 +10001534 case sMaxSessions:
1535 intptr = &options->max_sessions;
1536 goto parse_int;
1537
Ben Lindstromade03f62001-12-06 18:22:17 +00001538 case sBanner:
1539 charptr = &options->banner;
1540 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001541
Ben Lindstromade03f62001-12-06 18:22:17 +00001542 /*
1543 * These options can contain %X options expanded at
1544 * connect time, so that you can specify paths like:
1545 *
1546 * AuthorizedKeysFile /etc/ssh_keys/%u
1547 */
1548 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001549 if (*activep && options->num_authkeys_files == 0) {
1550 while ((arg = strdelim(&cp)) && *arg != '\0') {
1551 if (options->num_authkeys_files >=
1552 MAX_AUTHKEYS_FILES)
1553 fatal("%s line %d: "
1554 "too many authorized keys files.",
1555 filename, linenum);
1556 options->authorized_keys_files[
1557 options->num_authkeys_files++] =
1558 tilde_expand_filename(arg, getuid());
1559 }
1560 }
1561 return 0;
1562
Damien Miller30da3442010-05-10 11:58:03 +10001563 case sAuthorizedPrincipalsFile:
1564 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001565 arg = strdelim(&cp);
1566 if (!arg || *arg == '\0')
1567 fatal("%s line %d: missing file name.",
1568 filename, linenum);
1569 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001570 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001571 /* increase optional counter */
1572 if (intptr != NULL)
1573 *intptr = *intptr + 1;
1574 }
1575 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001576
1577 case sClientAliveInterval:
1578 intptr = &options->client_alive_interval;
1579 goto parse_time;
1580
1581 case sClientAliveCountMax:
1582 intptr = &options->client_alive_count_max;
1583 goto parse_int;
1584
Darren Tucker46bc0752004-05-02 22:11:30 +10001585 case sAcceptEnv:
1586 while ((arg = strdelim(&cp)) && *arg != '\0') {
1587 if (strchr(arg, '=') != NULL)
1588 fatal("%s line %d: Invalid environment name.",
1589 filename, linenum);
1590 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1591 fatal("%s line %d: too many allow env.",
1592 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001593 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001594 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001595 options->accept_env[options->num_accept_env++] =
1596 xstrdup(arg);
1597 }
1598 break;
1599
Damien Millerd27b9472005-12-13 19:29:02 +11001600 case sPermitTunnel:
1601 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001602 arg = strdelim(&cp);
1603 if (!arg || *arg == '\0')
1604 fatal("%s line %d: Missing yes/point-to-point/"
1605 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001606 value = -1;
1607 for (i = 0; tunmode_desc[i].val != -1; i++)
1608 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1609 value = tunmode_desc[i].val;
1610 break;
1611 }
1612 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001613 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1614 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001615 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001616 *intptr = value;
1617 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001618
Darren Tucker45150472006-07-12 22:34:17 +10001619 case sMatch:
1620 if (cmdline)
1621 fatal("Match directive not supported as a command-line "
1622 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001623 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001624 if (value < 0)
1625 fatal("%s line %d: Bad Match condition", filename,
1626 linenum);
1627 *activep = value;
1628 break;
1629
Damien Miller9b439df2006-07-24 14:04:00 +10001630 case sPermitOpen:
1631 arg = strdelim(&cp);
1632 if (!arg || *arg == '\0')
1633 fatal("%s line %d: missing PermitOpen specification",
1634 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001635 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001636 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001637 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001638 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001639 options->num_permitted_opens = 0;
1640 }
Damien Miller9b439df2006-07-24 14:04:00 +10001641 break;
1642 }
Damien Millerc6081482012-04-22 11:18:53 +10001643 if (strcmp(arg, "none") == 0) {
1644 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001645 options->num_permitted_opens = 1;
1646 channel_disable_adm_local_opens();
1647 }
1648 break;
1649 }
Damien Millera29b95e2007-01-05 16:28:36 +11001650 if (*activep && n == -1)
1651 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001652 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1653 p = hpdelim(&arg);
1654 if (p == NULL)
1655 fatal("%s line %d: missing host in PermitOpen",
1656 filename, linenum);
1657 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001658 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001659 fatal("%s line %d: bad port number in "
1660 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001661 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001662 options->num_permitted_opens =
1663 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001664 }
Damien Miller9b439df2006-07-24 14:04:00 +10001665 break;
1666
Damien Millere2754432006-07-24 14:06:47 +10001667 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001668 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001669 fatal("%.200s line %d: Missing argument.", filename,
1670 linenum);
1671 len = strspn(cp, WHITESPACE);
1672 if (*activep && options->adm_forced_command == NULL)
1673 options->adm_forced_command = xstrdup(cp + len);
1674 return 0;
1675
Damien Millerd8cb1f12008-02-10 22:40:12 +11001676 case sChrootDirectory:
1677 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001678
1679 arg = strdelim(&cp);
1680 if (!arg || *arg == '\0')
1681 fatal("%s line %d: missing file name.",
1682 filename, linenum);
1683 if (*activep && *charptr == NULL)
1684 *charptr = xstrdup(arg);
1685 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001686
Damien Miller1aed65e2010-03-04 21:53:35 +11001687 case sTrustedUserCAKeys:
1688 charptr = &options->trusted_user_ca_keys;
1689 goto parse_filename;
1690
1691 case sRevokedKeys:
1692 charptr = &options->revoked_keys_file;
1693 goto parse_filename;
1694
Damien Miller0dac6fb2010-11-20 15:19:38 +11001695 case sIPQoS:
1696 arg = strdelim(&cp);
1697 if ((value = parse_ipqos(arg)) == -1)
1698 fatal("%s line %d: Bad IPQoS value: %s",
1699 filename, linenum, arg);
1700 arg = strdelim(&cp);
1701 if (arg == NULL)
1702 value2 = value;
1703 else if ((value2 = parse_ipqos(arg)) == -1)
1704 fatal("%s line %d: Bad IPQoS value: %s",
1705 filename, linenum, arg);
1706 if (*activep) {
1707 options->ip_qos_interactive = value;
1708 options->ip_qos_bulk = value2;
1709 }
1710 break;
1711
Damien Miller23528812012-04-22 11:24:43 +10001712 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001713 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001714 fatal("%.200s line %d: Missing argument.", filename,
1715 linenum);
1716 len = strspn(cp, WHITESPACE);
1717 if (*activep && options->version_addendum == NULL) {
1718 if (strcasecmp(cp + len, "none") == 0)
1719 options->version_addendum = xstrdup("");
1720 else if (strchr(cp + len, '\r') != NULL)
1721 fatal("%.200s line %d: Invalid argument",
1722 filename, linenum);
1723 else
1724 options->version_addendum = xstrdup(cp + len);
1725 }
1726 return 0;
1727
Damien Miller09d3e122012-10-31 08:58:58 +11001728 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001729 if (cp == NULL)
1730 fatal("%.200s line %d: Missing argument.", filename,
1731 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001732 len = strspn(cp, WHITESPACE);
1733 if (*activep && options->authorized_keys_command == NULL) {
1734 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1735 fatal("%.200s line %d: AuthorizedKeysCommand "
1736 "must be an absolute path",
1737 filename, linenum);
1738 options->authorized_keys_command = xstrdup(cp + len);
1739 }
1740 return 0;
1741
1742 case sAuthorizedKeysCommandUser:
1743 charptr = &options->authorized_keys_command_user;
1744
1745 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001746 if (!arg || *arg == '\0')
1747 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1748 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001749 if (*activep && *charptr == NULL)
1750 *charptr = xstrdup(arg);
1751 break;
1752
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001753 case sAuthorizedPrincipalsCommand:
1754 if (cp == NULL)
1755 fatal("%.200s line %d: Missing argument.", filename,
1756 linenum);
1757 len = strspn(cp, WHITESPACE);
1758 if (*activep &&
1759 options->authorized_principals_command == NULL) {
1760 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1761 fatal("%.200s line %d: "
1762 "AuthorizedPrincipalsCommand must be "
1763 "an absolute path", filename, linenum);
1764 options->authorized_principals_command =
1765 xstrdup(cp + len);
1766 }
1767 return 0;
1768
1769 case sAuthorizedPrincipalsCommandUser:
1770 charptr = &options->authorized_principals_command_user;
1771
1772 arg = strdelim(&cp);
1773 if (!arg || *arg == '\0')
1774 fatal("%s line %d: missing "
1775 "AuthorizedPrincipalsCommandUser argument.",
1776 filename, linenum);
1777 if (*activep && *charptr == NULL)
1778 *charptr = xstrdup(arg);
1779 break;
1780
Damien Millera6e3f012012-11-04 23:21:40 +11001781 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001782 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001783 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001784 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001785 while ((arg = strdelim(&cp)) && *arg != '\0') {
1786 if (options->num_auth_methods >=
1787 MAX_AUTH_METHODS)
1788 fatal("%s line %d: "
1789 "too many authentication methods.",
1790 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001791 if (strcmp(arg, "any") == 0) {
1792 if (options->num_auth_methods > 0) {
1793 fatal("%s line %d: \"any\" "
1794 "must appear alone in "
1795 "AuthenticationMethods",
1796 filename, linenum);
1797 }
1798 value = 1;
1799 } else if (value) {
1800 fatal("%s line %d: \"any\" must appear "
1801 "alone in AuthenticationMethods",
1802 filename, linenum);
1803 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001804 fatal("%s line %d: invalid "
1805 "authentication method list.",
1806 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001807 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001808 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001809 if (!*activep)
1810 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001811 options->auth_methods[
1812 options->num_auth_methods++] = xstrdup(arg);
1813 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001814 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001815 fatal("%s line %d: no AuthenticationMethods "
1816 "specified", filename, linenum);
1817 }
Damien Millera6e3f012012-11-04 23:21:40 +11001818 }
1819 return 0;
1820
Damien Miller7acefbb2014-07-18 14:11:24 +10001821 case sStreamLocalBindMask:
1822 arg = strdelim(&cp);
1823 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001824 fatal("%s line %d: missing StreamLocalBindMask "
1825 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001826 /* Parse mode in octal format */
1827 value = strtol(arg, &p, 8);
1828 if (arg == p || value < 0 || value > 0777)
1829 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001830 if (*activep)
1831 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001832 break;
1833
1834 case sStreamLocalBindUnlink:
1835 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1836 goto parse_flag;
1837
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001838 case sFingerprintHash:
1839 arg = strdelim(&cp);
1840 if (!arg || *arg == '\0')
1841 fatal("%.200s line %d: Missing argument.",
1842 filename, linenum);
1843 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1844 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1845 filename, linenum, arg);
1846 if (*activep)
1847 options->fingerprint_hash = value;
1848 break;
1849
Ben Lindstromade03f62001-12-06 18:22:17 +00001850 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001851 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001852 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001853 do_log2(opcode == sIgnore ?
1854 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1855 "%s line %d: %s option %s", filename, linenum,
1856 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001857 while (arg)
1858 arg = strdelim(&cp);
1859 break;
1860
Ben Lindstromade03f62001-12-06 18:22:17 +00001861 default:
1862 fatal("%s line %d: Missing handler for opcode %s (%d)",
1863 filename, linenum, arg, opcode);
1864 }
1865 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1866 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1867 filename, linenum, arg);
1868 return 0;
1869}
1870
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001871/* Reads the server configuration file. */
1872
Damien Miller4af51302000-04-16 11:18:38 +10001873void
Darren Tucker645ab752004-06-25 13:33:20 +10001874load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001875{
Damien Miller46cb75a2012-07-31 12:22:37 +10001876 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001877 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001878 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001879
Darren Tucker645ab752004-06-25 13:33:20 +10001880 debug2("%s: filename %s", __func__, filename);
1881 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001882 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001883 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001884 }
Darren Tucker645ab752004-06-25 13:33:20 +10001885 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001886 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001887 lineno++;
1888 if (strlen(line) == sizeof(line) - 1)
1889 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001890 /*
1891 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001892 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001893 * line numbers later for error messages
1894 */
1895 if ((cp = strchr(line, '#')) != NULL)
1896 memcpy(cp, "\n", 2);
1897 cp = line + strspn(line, " \t\r");
1898
1899 buffer_append(conf, cp, strlen(cp));
1900 }
1901 buffer_append(conf, "\0", 1);
1902 fclose(f);
1903 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1904}
1905
1906void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001907parse_server_match_config(ServerOptions *options,
1908 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001909{
Darren Tucker45150472006-07-12 22:34:17 +10001910 ServerOptions mo;
1911
1912 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001913 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001914 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001915}
1916
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001917int parse_server_match_testspec(struct connection_info *ci, char *spec)
1918{
1919 char *p;
1920
1921 while ((p = strsep(&spec, ",")) && *p != '\0') {
1922 if (strncmp(p, "addr=", 5) == 0) {
1923 ci->address = xstrdup(p + 5);
1924 } else if (strncmp(p, "host=", 5) == 0) {
1925 ci->host = xstrdup(p + 5);
1926 } else if (strncmp(p, "user=", 5) == 0) {
1927 ci->user = xstrdup(p + 5);
1928 } else if (strncmp(p, "laddr=", 6) == 0) {
1929 ci->laddress = xstrdup(p + 6);
1930 } else if (strncmp(p, "lport=", 6) == 0) {
1931 ci->lport = a2port(p + 6);
1932 if (ci->lport == -1) {
1933 fprintf(stderr, "Invalid port '%s' in test mode"
1934 " specification %s\n", p+6, p);
1935 return -1;
1936 }
1937 } else {
1938 fprintf(stderr, "Invalid test mode specification %s\n",
1939 p);
1940 return -1;
1941 }
1942 }
1943 return 0;
1944}
1945
1946/*
1947 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1948 * empty spec.
1949 */
1950int server_match_spec_complete(struct connection_info *ci)
1951{
1952 if (ci->user && ci->host && ci->address)
1953 return 1; /* complete */
1954 if (!ci->user && !ci->host && !ci->address)
1955 return -1; /* empty */
1956 return 0; /* partial */
1957}
1958
Darren Tucker1629c072007-02-19 22:25:37 +11001959/*
1960 * Copy any supported values that are set.
1961 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001962 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001963 * array values that are not used pre-authentication, because any that we
1964 * do use must be explictly sent in mm_getpwnamallow().
1965 */
Darren Tucker45150472006-07-12 22:34:17 +10001966void
Darren Tucker1629c072007-02-19 22:25:37 +11001967copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001968{
Damien Miller534b2cc2013-12-05 14:07:27 +11001969#define M_CP_INTOPT(n) do {\
1970 if (src->n != -1) \
1971 dst->n = src->n; \
1972} while (0)
1973
Darren Tucker1629c072007-02-19 22:25:37 +11001974 M_CP_INTOPT(password_authentication);
1975 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11001976 M_CP_INTOPT(pubkey_authentication);
1977 M_CP_INTOPT(kerberos_authentication);
1978 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001979 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001980 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001981 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001982 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001983
1984 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001985 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001986 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00001987 M_CP_INTOPT(disable_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001988 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001989 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001990 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11001991 M_CP_INTOPT(x11_display_offset);
1992 M_CP_INTOPT(x11_forwarding);
1993 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001994 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001995 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001996 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001997 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00001998 M_CP_INTOPT(client_alive_count_max);
1999 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002000 M_CP_INTOPT(ip_qos_interactive);
2001 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002002 M_CP_INTOPT(rekey_limit);
2003 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002004
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002005 /*
2006 * The bind_mask is a mode_t that may be unsigned, so we can't use
2007 * M_CP_INTOPT - it does a signed comparison that causes compiler
2008 * warnings.
2009 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002010 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002011 dst->fwd_opts.streamlocal_bind_mask =
2012 src->fwd_opts.streamlocal_bind_mask;
2013 }
2014
Damien Miller534b2cc2013-12-05 14:07:27 +11002015 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2016#define M_CP_STROPT(n) do {\
2017 if (src->n != NULL && dst->n != src->n) { \
2018 free(dst->n); \
2019 dst->n = src->n; \
2020 } \
2021} while(0)
2022#define M_CP_STRARRAYOPT(n, num_n) do {\
2023 if (src->num_n != 0) { \
2024 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2025 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2026 } \
2027} while(0)
2028
Damien Millerf2e407e2011-05-20 19:04:14 +10002029 /* See comment in servconf.h */
2030 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002031
djm@openbsd.orged085102015-10-29 08:05:01 +00002032 /* Arguments that accept '+...' need to be expanded */
2033 assemble_algorithms(dst);
2034
Damien Millerc2411902011-05-20 19:03:49 +10002035 /*
2036 * The only things that should be below this point are string options
2037 * which are only used after authentication.
2038 */
Damien Miller5d74e582011-05-20 19:03:31 +10002039 if (preauth)
2040 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002041
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002042 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002043 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002044 if (option_clear_or_none(dst->adm_forced_command)) {
2045 free(dst->adm_forced_command);
2046 dst->adm_forced_command = NULL;
2047 }
Damien Miller5d74e582011-05-20 19:03:31 +10002048 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002049 if (option_clear_or_none(dst->chroot_directory)) {
2050 free(dst->chroot_directory);
2051 dst->chroot_directory = NULL;
2052 }
Darren Tucker45150472006-07-12 22:34:17 +10002053}
2054
Darren Tucker1629c072007-02-19 22:25:37 +11002055#undef M_CP_INTOPT
2056#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002057#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002058
Darren Tucker45150472006-07-12 22:34:17 +10002059void
2060parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002061 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002062{
2063 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002064 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002065
2066 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2067
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002068 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2069 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002070 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002071 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002072 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002073 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002074 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002075 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002076 }
Darren Tuckera627d422013-06-02 07:31:17 +10002077 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002078 if (bad_options > 0)
2079 fatal("%s: terminating, %d bad configuration options",
2080 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002081 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002082}
Darren Tuckere7140f22008-06-10 23:01:51 +10002083
2084static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002085fmt_multistate_int(int val, const struct multistate *m)
2086{
2087 u_int i;
2088
2089 for (i = 0; m[i].key != NULL; i++) {
2090 if (m[i].value == val)
2091 return m[i].key;
2092 }
2093 return "UNKNOWN";
2094}
2095
2096static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002097fmt_intarg(ServerOpCodes code, int val)
2098{
Damien Miller82c55872011-06-23 08:20:30 +10002099 if (val == -1)
2100 return "unset";
2101 switch (code) {
2102 case sAddressFamily:
2103 return fmt_multistate_int(val, multistate_addressfamily);
2104 case sPermitRootLogin:
2105 return fmt_multistate_int(val, multistate_permitrootlogin);
2106 case sGatewayPorts:
2107 return fmt_multistate_int(val, multistate_gatewayports);
2108 case sCompression:
2109 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002110 case sUsePrivilegeSeparation:
2111 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002112 case sAllowTcpForwarding:
2113 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002114 case sAllowStreamLocalForwarding:
2115 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002116 case sFingerprintHash:
2117 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002118 default:
2119 switch (val) {
2120 case 0:
2121 return "no";
2122 case 1:
2123 return "yes";
2124 default:
2125 return "UNKNOWN";
2126 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002127 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002128}
2129
2130static const char *
2131lookup_opcode_name(ServerOpCodes code)
2132{
2133 u_int i;
2134
2135 for (i = 0; keywords[i].name != NULL; i++)
2136 if (keywords[i].opcode == code)
2137 return(keywords[i].name);
2138 return "UNKNOWN";
2139}
2140
2141static void
2142dump_cfg_int(ServerOpCodes code, int val)
2143{
2144 printf("%s %d\n", lookup_opcode_name(code), val);
2145}
2146
2147static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002148dump_cfg_oct(ServerOpCodes code, int val)
2149{
2150 printf("%s 0%o\n", lookup_opcode_name(code), val);
2151}
2152
2153static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002154dump_cfg_fmtint(ServerOpCodes code, int val)
2155{
2156 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2157}
2158
2159static void
2160dump_cfg_string(ServerOpCodes code, const char *val)
2161{
2162 if (val == NULL)
2163 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002164 printf("%s %s\n", lookup_opcode_name(code),
2165 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002166}
2167
2168static void
2169dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2170{
2171 u_int i;
2172
2173 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002174 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2175}
2176
2177static void
2178dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2179{
2180 u_int i;
2181
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002182 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002183 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002184 printf("%s", lookup_opcode_name(code));
2185 for (i = 0; i < count; i++)
2186 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002187 if (code == sAuthenticationMethods && count == 0)
2188 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002189 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002190}
2191
2192void
2193dump_config(ServerOptions *o)
2194{
2195 u_int i;
2196 int ret;
2197 struct addrinfo *ai;
2198 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002199 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002200
2201 /* these are usually at the top of the config */
2202 for (i = 0; i < o->num_ports; i++)
2203 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002204 dump_cfg_fmtint(sAddressFamily, o->address_family);
2205
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002206 /*
2207 * ListenAddress must be after Port. add_one_listen_addr pushes
2208 * addresses onto a stack, so to maintain ordering we need to
2209 * print these in reverse order.
2210 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002211 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2212 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2213 sizeof(addr), port, sizeof(port),
2214 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2215 error("getnameinfo failed: %.100s",
2216 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2217 strerror(errno));
2218 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002219 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002220 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002221 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2222 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002223 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002224 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2225 addr, port, laddr2);
2226 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002227 }
2228 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002229 printf("%s", laddr1);
2230 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002231
2232 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002233#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002234 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002235#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002236 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002237 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2238 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002239 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002240 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2241 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002242 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002243
2244 /* formatted integer arguments */
2245 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2246 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2247 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002248 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2249 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2250 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002251 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002252#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002253 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2254 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2255 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002256# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002257 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002258# endif
2259#endif
2260#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002261 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2262 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002263#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002264 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2265 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2266 o->kbd_interactive_authentication);
2267 dump_cfg_fmtint(sChallengeResponseAuthentication,
2268 o->challenge_response_authentication);
2269 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002270#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002271 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002272#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002273 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2274 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002275 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002276 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002277 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2278 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2279 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2280 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002282 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002283 dump_cfg_fmtint(sUseDNS, o->use_dns);
2284 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002285 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002286 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002287 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002288 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
Darren Tuckere7140f22008-06-10 23:01:51 +10002289 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002290 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002291
2292 /* string arguments */
2293 dump_cfg_string(sPidFile, o->pid_file);
2294 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002295 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2296 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002297 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002298 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002299 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002300 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2301 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002302 dump_cfg_string(sAuthorizedPrincipalsFile,
2303 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002304 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2305 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002306 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2307 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002308 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2309 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002310 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002311 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002312 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002313 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2314 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002315 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2316 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002317 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2318 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002319
2320 /* string arguments requiring a lookup */
2321 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2322 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2323
2324 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002325 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2326 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002327 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2328 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002329 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002330 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002331 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2332 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2333 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2334 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2335 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002336 dump_cfg_strarray_oneline(sAuthenticationMethods,
2337 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002338
2339 /* other arguments */
2340 for (i = 0; i < o->num_subsystems; i++)
2341 printf("subsystem %s %s\n", o->subsystem_name[i],
2342 o->subsystem_args[i]);
2343
2344 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2345 o->max_startups_rate, o->max_startups);
2346
2347 for (i = 0; tunmode_desc[i].val != -1; i++)
2348 if (tunmode_desc[i].val == o->permit_tun) {
2349 s = tunmode_desc[i].text;
2350 break;
2351 }
2352 dump_cfg_string(sPermitTunnel, s);
2353
Damien Miller91475862011-05-05 14:14:34 +10002354 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2355 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002356
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002357 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002358 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002359
Darren Tuckere7140f22008-06-10 23:01:51 +10002360 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002361}