blob: 56b831652f5391c2258c5ec4b58aaeb8a48acf4e [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org66705942017-03-14 07:19:07 +00002/* $OpenBSD: servconf.c,v 1.306 2017/03/14 07:19:07 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 },
djm@openbsd.org66705942017-03-14 07:19:07 +0000538 { "useprivilegeseparation", sDeprecated, 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 Lindstromade03f62001-12-06 18:22:17 +00001377 case sAllowUsers:
1378 while ((arg = strdelim(&cp)) && *arg != '\0') {
1379 if (options->num_allow_users >= MAX_ALLOW_USERS)
1380 fatal("%s line %d: too many allow users.",
1381 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001382 if (match_user(NULL, NULL, NULL, arg) == -1)
1383 fatal("%s line %d: invalid AllowUsers pattern: "
1384 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001385 if (!*activep)
1386 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001387 options->allow_users[options->num_allow_users++] =
1388 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001389 }
1390 break;
1391
1392 case sDenyUsers:
1393 while ((arg = strdelim(&cp)) && *arg != '\0') {
1394 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001395 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001396 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001397 if (match_user(NULL, NULL, NULL, arg) == -1)
1398 fatal("%s line %d: invalid DenyUsers pattern: "
1399 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001400 if (!*activep)
1401 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001402 options->deny_users[options->num_deny_users++] =
1403 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001404 }
1405 break;
1406
1407 case sAllowGroups:
1408 while ((arg = strdelim(&cp)) && *arg != '\0') {
1409 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1410 fatal("%s line %d: too many allow groups.",
1411 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001412 if (!*activep)
1413 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001414 options->allow_groups[options->num_allow_groups++] =
1415 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001416 }
1417 break;
1418
1419 case sDenyGroups:
1420 while ((arg = strdelim(&cp)) && *arg != '\0') {
1421 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1422 fatal("%s line %d: too many deny groups.",
1423 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001424 if (!*activep)
1425 continue;
1426 options->deny_groups[options->num_deny_groups++] =
1427 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001428 }
1429 break;
1430
1431 case sCiphers:
1432 arg = strdelim(&cp);
1433 if (!arg || *arg == '\0')
1434 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001435 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001436 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1437 filename, linenum, arg ? arg : "<NONE>");
1438 if (options->ciphers == NULL)
1439 options->ciphers = xstrdup(arg);
1440 break;
1441
1442 case sMacs:
1443 arg = strdelim(&cp);
1444 if (!arg || *arg == '\0')
1445 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001446 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001447 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1448 filename, linenum, arg ? arg : "<NONE>");
1449 if (options->macs == NULL)
1450 options->macs = xstrdup(arg);
1451 break;
1452
Damien Millerd5f62bf2010-09-24 22:11:14 +10001453 case sKexAlgorithms:
1454 arg = strdelim(&cp);
1455 if (!arg || *arg == '\0')
1456 fatal("%s line %d: Missing argument.",
1457 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001458 if (*arg != '-' &&
1459 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001460 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1461 filename, linenum, arg ? arg : "<NONE>");
1462 if (options->kex_algorithms == NULL)
1463 options->kex_algorithms = xstrdup(arg);
1464 break;
1465
Ben Lindstromade03f62001-12-06 18:22:17 +00001466 case sSubsystem:
1467 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1468 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001469 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001470 }
1471 arg = strdelim(&cp);
1472 if (!arg || *arg == '\0')
1473 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001474 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001475 if (!*activep) {
1476 arg = strdelim(&cp);
1477 break;
1478 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001479 for (i = 0; i < options->num_subsystems; i++)
1480 if (strcmp(arg, options->subsystem_name[i]) == 0)
1481 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001482 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001483 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1484 arg = strdelim(&cp);
1485 if (!arg || *arg == '\0')
1486 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001487 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001488 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001489
1490 /* Collect arguments (separate to executable) */
1491 p = xstrdup(arg);
1492 len = strlen(p) + 1;
1493 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1494 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001495 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001496 strlcat(p, " ", len);
1497 strlcat(p, arg, len);
1498 }
1499 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001500 options->num_subsystems++;
1501 break;
1502
1503 case sMaxStartups:
1504 arg = strdelim(&cp);
1505 if (!arg || *arg == '\0')
1506 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001507 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001508 if ((n = sscanf(arg, "%d:%d:%d",
1509 &options->max_startups_begin,
1510 &options->max_startups_rate,
1511 &options->max_startups)) == 3) {
1512 if (options->max_startups_begin >
1513 options->max_startups ||
1514 options->max_startups_rate > 100 ||
1515 options->max_startups_rate < 1)
1516 fatal("%s line %d: Illegal MaxStartups spec.",
1517 filename, linenum);
1518 } else if (n != 1)
1519 fatal("%s line %d: Illegal MaxStartups spec.",
1520 filename, linenum);
1521 else
1522 options->max_startups = options->max_startups_begin;
1523 break;
1524
Darren Tucker89413db2004-05-24 10:36:23 +10001525 case sMaxAuthTries:
1526 intptr = &options->max_authtries;
1527 goto parse_int;
1528
Damien Miller7207f642008-05-19 15:34:50 +10001529 case sMaxSessions:
1530 intptr = &options->max_sessions;
1531 goto parse_int;
1532
Ben Lindstromade03f62001-12-06 18:22:17 +00001533 case sBanner:
1534 charptr = &options->banner;
1535 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001536
Ben Lindstromade03f62001-12-06 18:22:17 +00001537 /*
1538 * These options can contain %X options expanded at
1539 * connect time, so that you can specify paths like:
1540 *
1541 * AuthorizedKeysFile /etc/ssh_keys/%u
1542 */
1543 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001544 if (*activep && options->num_authkeys_files == 0) {
1545 while ((arg = strdelim(&cp)) && *arg != '\0') {
1546 if (options->num_authkeys_files >=
1547 MAX_AUTHKEYS_FILES)
1548 fatal("%s line %d: "
1549 "too many authorized keys files.",
1550 filename, linenum);
1551 options->authorized_keys_files[
1552 options->num_authkeys_files++] =
1553 tilde_expand_filename(arg, getuid());
1554 }
1555 }
1556 return 0;
1557
Damien Miller30da3442010-05-10 11:58:03 +10001558 case sAuthorizedPrincipalsFile:
1559 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001560 arg = strdelim(&cp);
1561 if (!arg || *arg == '\0')
1562 fatal("%s line %d: missing file name.",
1563 filename, linenum);
1564 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001565 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001566 /* increase optional counter */
1567 if (intptr != NULL)
1568 *intptr = *intptr + 1;
1569 }
1570 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001571
1572 case sClientAliveInterval:
1573 intptr = &options->client_alive_interval;
1574 goto parse_time;
1575
1576 case sClientAliveCountMax:
1577 intptr = &options->client_alive_count_max;
1578 goto parse_int;
1579
Darren Tucker46bc0752004-05-02 22:11:30 +10001580 case sAcceptEnv:
1581 while ((arg = strdelim(&cp)) && *arg != '\0') {
1582 if (strchr(arg, '=') != NULL)
1583 fatal("%s line %d: Invalid environment name.",
1584 filename, linenum);
1585 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1586 fatal("%s line %d: too many allow env.",
1587 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001588 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001589 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001590 options->accept_env[options->num_accept_env++] =
1591 xstrdup(arg);
1592 }
1593 break;
1594
Damien Millerd27b9472005-12-13 19:29:02 +11001595 case sPermitTunnel:
1596 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001597 arg = strdelim(&cp);
1598 if (!arg || *arg == '\0')
1599 fatal("%s line %d: Missing yes/point-to-point/"
1600 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001601 value = -1;
1602 for (i = 0; tunmode_desc[i].val != -1; i++)
1603 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1604 value = tunmode_desc[i].val;
1605 break;
1606 }
1607 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001608 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1609 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001610 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001611 *intptr = value;
1612 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001613
Darren Tucker45150472006-07-12 22:34:17 +10001614 case sMatch:
1615 if (cmdline)
1616 fatal("Match directive not supported as a command-line "
1617 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001618 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001619 if (value < 0)
1620 fatal("%s line %d: Bad Match condition", filename,
1621 linenum);
1622 *activep = value;
1623 break;
1624
Damien Miller9b439df2006-07-24 14:04:00 +10001625 case sPermitOpen:
1626 arg = strdelim(&cp);
1627 if (!arg || *arg == '\0')
1628 fatal("%s line %d: missing PermitOpen specification",
1629 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001630 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001631 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001632 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001633 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001634 options->num_permitted_opens = 0;
1635 }
Damien Miller9b439df2006-07-24 14:04:00 +10001636 break;
1637 }
Damien Millerc6081482012-04-22 11:18:53 +10001638 if (strcmp(arg, "none") == 0) {
1639 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001640 options->num_permitted_opens = 1;
1641 channel_disable_adm_local_opens();
1642 }
1643 break;
1644 }
Damien Millera29b95e2007-01-05 16:28:36 +11001645 if (*activep && n == -1)
1646 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001647 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1648 p = hpdelim(&arg);
1649 if (p == NULL)
1650 fatal("%s line %d: missing host in PermitOpen",
1651 filename, linenum);
1652 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001653 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001654 fatal("%s line %d: bad port number in "
1655 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001656 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001657 options->num_permitted_opens =
1658 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001659 }
Damien Miller9b439df2006-07-24 14:04:00 +10001660 break;
1661
Damien Millere2754432006-07-24 14:06:47 +10001662 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001663 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001664 fatal("%.200s line %d: Missing argument.", filename,
1665 linenum);
1666 len = strspn(cp, WHITESPACE);
1667 if (*activep && options->adm_forced_command == NULL)
1668 options->adm_forced_command = xstrdup(cp + len);
1669 return 0;
1670
Damien Millerd8cb1f12008-02-10 22:40:12 +11001671 case sChrootDirectory:
1672 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001673
1674 arg = strdelim(&cp);
1675 if (!arg || *arg == '\0')
1676 fatal("%s line %d: missing file name.",
1677 filename, linenum);
1678 if (*activep && *charptr == NULL)
1679 *charptr = xstrdup(arg);
1680 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001681
Damien Miller1aed65e2010-03-04 21:53:35 +11001682 case sTrustedUserCAKeys:
1683 charptr = &options->trusted_user_ca_keys;
1684 goto parse_filename;
1685
1686 case sRevokedKeys:
1687 charptr = &options->revoked_keys_file;
1688 goto parse_filename;
1689
Damien Miller0dac6fb2010-11-20 15:19:38 +11001690 case sIPQoS:
1691 arg = strdelim(&cp);
1692 if ((value = parse_ipqos(arg)) == -1)
1693 fatal("%s line %d: Bad IPQoS value: %s",
1694 filename, linenum, arg);
1695 arg = strdelim(&cp);
1696 if (arg == NULL)
1697 value2 = value;
1698 else if ((value2 = parse_ipqos(arg)) == -1)
1699 fatal("%s line %d: Bad IPQoS value: %s",
1700 filename, linenum, arg);
1701 if (*activep) {
1702 options->ip_qos_interactive = value;
1703 options->ip_qos_bulk = value2;
1704 }
1705 break;
1706
Damien Miller23528812012-04-22 11:24:43 +10001707 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001708 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001709 fatal("%.200s line %d: Missing argument.", filename,
1710 linenum);
1711 len = strspn(cp, WHITESPACE);
1712 if (*activep && options->version_addendum == NULL) {
1713 if (strcasecmp(cp + len, "none") == 0)
1714 options->version_addendum = xstrdup("");
1715 else if (strchr(cp + len, '\r') != NULL)
1716 fatal("%.200s line %d: Invalid argument",
1717 filename, linenum);
1718 else
1719 options->version_addendum = xstrdup(cp + len);
1720 }
1721 return 0;
1722
Damien Miller09d3e122012-10-31 08:58:58 +11001723 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001724 if (cp == NULL)
1725 fatal("%.200s line %d: Missing argument.", filename,
1726 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001727 len = strspn(cp, WHITESPACE);
1728 if (*activep && options->authorized_keys_command == NULL) {
1729 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1730 fatal("%.200s line %d: AuthorizedKeysCommand "
1731 "must be an absolute path",
1732 filename, linenum);
1733 options->authorized_keys_command = xstrdup(cp + len);
1734 }
1735 return 0;
1736
1737 case sAuthorizedKeysCommandUser:
1738 charptr = &options->authorized_keys_command_user;
1739
1740 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001741 if (!arg || *arg == '\0')
1742 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1743 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001744 if (*activep && *charptr == NULL)
1745 *charptr = xstrdup(arg);
1746 break;
1747
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001748 case sAuthorizedPrincipalsCommand:
1749 if (cp == NULL)
1750 fatal("%.200s line %d: Missing argument.", filename,
1751 linenum);
1752 len = strspn(cp, WHITESPACE);
1753 if (*activep &&
1754 options->authorized_principals_command == NULL) {
1755 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1756 fatal("%.200s line %d: "
1757 "AuthorizedPrincipalsCommand must be "
1758 "an absolute path", filename, linenum);
1759 options->authorized_principals_command =
1760 xstrdup(cp + len);
1761 }
1762 return 0;
1763
1764 case sAuthorizedPrincipalsCommandUser:
1765 charptr = &options->authorized_principals_command_user;
1766
1767 arg = strdelim(&cp);
1768 if (!arg || *arg == '\0')
1769 fatal("%s line %d: missing "
1770 "AuthorizedPrincipalsCommandUser argument.",
1771 filename, linenum);
1772 if (*activep && *charptr == NULL)
1773 *charptr = xstrdup(arg);
1774 break;
1775
Damien Millera6e3f012012-11-04 23:21:40 +11001776 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001777 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001778 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001779 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001780 while ((arg = strdelim(&cp)) && *arg != '\0') {
1781 if (options->num_auth_methods >=
1782 MAX_AUTH_METHODS)
1783 fatal("%s line %d: "
1784 "too many authentication methods.",
1785 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001786 if (strcmp(arg, "any") == 0) {
1787 if (options->num_auth_methods > 0) {
1788 fatal("%s line %d: \"any\" "
1789 "must appear alone in "
1790 "AuthenticationMethods",
1791 filename, linenum);
1792 }
1793 value = 1;
1794 } else if (value) {
1795 fatal("%s line %d: \"any\" must appear "
1796 "alone in AuthenticationMethods",
1797 filename, linenum);
1798 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001799 fatal("%s line %d: invalid "
1800 "authentication method list.",
1801 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001802 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001803 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001804 if (!*activep)
1805 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001806 options->auth_methods[
1807 options->num_auth_methods++] = xstrdup(arg);
1808 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001809 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001810 fatal("%s line %d: no AuthenticationMethods "
1811 "specified", filename, linenum);
1812 }
Damien Millera6e3f012012-11-04 23:21:40 +11001813 }
1814 return 0;
1815
Damien Miller7acefbb2014-07-18 14:11:24 +10001816 case sStreamLocalBindMask:
1817 arg = strdelim(&cp);
1818 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001819 fatal("%s line %d: missing StreamLocalBindMask "
1820 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001821 /* Parse mode in octal format */
1822 value = strtol(arg, &p, 8);
1823 if (arg == p || value < 0 || value > 0777)
1824 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001825 if (*activep)
1826 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001827 break;
1828
1829 case sStreamLocalBindUnlink:
1830 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1831 goto parse_flag;
1832
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001833 case sFingerprintHash:
1834 arg = strdelim(&cp);
1835 if (!arg || *arg == '\0')
1836 fatal("%.200s line %d: Missing argument.",
1837 filename, linenum);
1838 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1839 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1840 filename, linenum, arg);
1841 if (*activep)
1842 options->fingerprint_hash = value;
1843 break;
1844
Ben Lindstromade03f62001-12-06 18:22:17 +00001845 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001846 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001847 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001848 do_log2(opcode == sIgnore ?
1849 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1850 "%s line %d: %s option %s", filename, linenum,
1851 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001852 while (arg)
1853 arg = strdelim(&cp);
1854 break;
1855
Ben Lindstromade03f62001-12-06 18:22:17 +00001856 default:
1857 fatal("%s line %d: Missing handler for opcode %s (%d)",
1858 filename, linenum, arg, opcode);
1859 }
1860 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1861 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1862 filename, linenum, arg);
1863 return 0;
1864}
1865
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001866/* Reads the server configuration file. */
1867
Damien Miller4af51302000-04-16 11:18:38 +10001868void
Darren Tucker645ab752004-06-25 13:33:20 +10001869load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001870{
Damien Miller46cb75a2012-07-31 12:22:37 +10001871 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001872 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001873 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001874
Darren Tucker645ab752004-06-25 13:33:20 +10001875 debug2("%s: filename %s", __func__, filename);
1876 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001877 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001878 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001879 }
Darren Tucker645ab752004-06-25 13:33:20 +10001880 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001881 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001882 lineno++;
1883 if (strlen(line) == sizeof(line) - 1)
1884 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001885 /*
1886 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001887 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001888 * line numbers later for error messages
1889 */
1890 if ((cp = strchr(line, '#')) != NULL)
1891 memcpy(cp, "\n", 2);
1892 cp = line + strspn(line, " \t\r");
1893
1894 buffer_append(conf, cp, strlen(cp));
1895 }
1896 buffer_append(conf, "\0", 1);
1897 fclose(f);
1898 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1899}
1900
1901void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001902parse_server_match_config(ServerOptions *options,
1903 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001904{
Darren Tucker45150472006-07-12 22:34:17 +10001905 ServerOptions mo;
1906
1907 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001908 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001909 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001910}
1911
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001912int parse_server_match_testspec(struct connection_info *ci, char *spec)
1913{
1914 char *p;
1915
1916 while ((p = strsep(&spec, ",")) && *p != '\0') {
1917 if (strncmp(p, "addr=", 5) == 0) {
1918 ci->address = xstrdup(p + 5);
1919 } else if (strncmp(p, "host=", 5) == 0) {
1920 ci->host = xstrdup(p + 5);
1921 } else if (strncmp(p, "user=", 5) == 0) {
1922 ci->user = xstrdup(p + 5);
1923 } else if (strncmp(p, "laddr=", 6) == 0) {
1924 ci->laddress = xstrdup(p + 6);
1925 } else if (strncmp(p, "lport=", 6) == 0) {
1926 ci->lport = a2port(p + 6);
1927 if (ci->lport == -1) {
1928 fprintf(stderr, "Invalid port '%s' in test mode"
1929 " specification %s\n", p+6, p);
1930 return -1;
1931 }
1932 } else {
1933 fprintf(stderr, "Invalid test mode specification %s\n",
1934 p);
1935 return -1;
1936 }
1937 }
1938 return 0;
1939}
1940
1941/*
1942 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1943 * empty spec.
1944 */
1945int server_match_spec_complete(struct connection_info *ci)
1946{
1947 if (ci->user && ci->host && ci->address)
1948 return 1; /* complete */
1949 if (!ci->user && !ci->host && !ci->address)
1950 return -1; /* empty */
1951 return 0; /* partial */
1952}
1953
Darren Tucker1629c072007-02-19 22:25:37 +11001954/*
1955 * Copy any supported values that are set.
1956 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001957 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001958 * array values that are not used pre-authentication, because any that we
1959 * do use must be explictly sent in mm_getpwnamallow().
1960 */
Darren Tucker45150472006-07-12 22:34:17 +10001961void
Darren Tucker1629c072007-02-19 22:25:37 +11001962copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001963{
Damien Miller534b2cc2013-12-05 14:07:27 +11001964#define M_CP_INTOPT(n) do {\
1965 if (src->n != -1) \
1966 dst->n = src->n; \
1967} while (0)
1968
Darren Tucker1629c072007-02-19 22:25:37 +11001969 M_CP_INTOPT(password_authentication);
1970 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11001971 M_CP_INTOPT(pubkey_authentication);
1972 M_CP_INTOPT(kerberos_authentication);
1973 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001974 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001975 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001976 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001977 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001978
1979 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001980 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001981 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00001982 M_CP_INTOPT(disable_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001983 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001984 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001985 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11001986 M_CP_INTOPT(x11_display_offset);
1987 M_CP_INTOPT(x11_forwarding);
1988 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001989 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001990 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001991 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001992 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00001993 M_CP_INTOPT(client_alive_count_max);
1994 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001995 M_CP_INTOPT(ip_qos_interactive);
1996 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001997 M_CP_INTOPT(rekey_limit);
1998 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001999
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002000 /*
2001 * The bind_mask is a mode_t that may be unsigned, so we can't use
2002 * M_CP_INTOPT - it does a signed comparison that causes compiler
2003 * warnings.
2004 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002005 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002006 dst->fwd_opts.streamlocal_bind_mask =
2007 src->fwd_opts.streamlocal_bind_mask;
2008 }
2009
Damien Miller534b2cc2013-12-05 14:07:27 +11002010 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2011#define M_CP_STROPT(n) do {\
2012 if (src->n != NULL && dst->n != src->n) { \
2013 free(dst->n); \
2014 dst->n = src->n; \
2015 } \
2016} while(0)
2017#define M_CP_STRARRAYOPT(n, num_n) do {\
2018 if (src->num_n != 0) { \
2019 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2020 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2021 } \
2022} while(0)
2023
Damien Millerf2e407e2011-05-20 19:04:14 +10002024 /* See comment in servconf.h */
2025 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002026
djm@openbsd.orged085102015-10-29 08:05:01 +00002027 /* Arguments that accept '+...' need to be expanded */
2028 assemble_algorithms(dst);
2029
Damien Millerc2411902011-05-20 19:03:49 +10002030 /*
2031 * The only things that should be below this point are string options
2032 * which are only used after authentication.
2033 */
Damien Miller5d74e582011-05-20 19:03:31 +10002034 if (preauth)
2035 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002036
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002037 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002038 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002039 if (option_clear_or_none(dst->adm_forced_command)) {
2040 free(dst->adm_forced_command);
2041 dst->adm_forced_command = NULL;
2042 }
Damien Miller5d74e582011-05-20 19:03:31 +10002043 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002044 if (option_clear_or_none(dst->chroot_directory)) {
2045 free(dst->chroot_directory);
2046 dst->chroot_directory = NULL;
2047 }
Darren Tucker45150472006-07-12 22:34:17 +10002048}
2049
Darren Tucker1629c072007-02-19 22:25:37 +11002050#undef M_CP_INTOPT
2051#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002052#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002053
Darren Tucker45150472006-07-12 22:34:17 +10002054void
2055parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002056 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002057{
2058 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002059 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002060
2061 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2062
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002063 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2064 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002065 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002066 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002067 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002068 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002069 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002070 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002071 }
Darren Tuckera627d422013-06-02 07:31:17 +10002072 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002073 if (bad_options > 0)
2074 fatal("%s: terminating, %d bad configuration options",
2075 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002076 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002077}
Darren Tuckere7140f22008-06-10 23:01:51 +10002078
2079static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002080fmt_multistate_int(int val, const struct multistate *m)
2081{
2082 u_int i;
2083
2084 for (i = 0; m[i].key != NULL; i++) {
2085 if (m[i].value == val)
2086 return m[i].key;
2087 }
2088 return "UNKNOWN";
2089}
2090
2091static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002092fmt_intarg(ServerOpCodes code, int val)
2093{
Damien Miller82c55872011-06-23 08:20:30 +10002094 if (val == -1)
2095 return "unset";
2096 switch (code) {
2097 case sAddressFamily:
2098 return fmt_multistate_int(val, multistate_addressfamily);
2099 case sPermitRootLogin:
2100 return fmt_multistate_int(val, multistate_permitrootlogin);
2101 case sGatewayPorts:
2102 return fmt_multistate_int(val, multistate_gatewayports);
2103 case sCompression:
2104 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002105 case sAllowTcpForwarding:
2106 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002107 case sAllowStreamLocalForwarding:
2108 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002109 case sFingerprintHash:
2110 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002111 default:
2112 switch (val) {
2113 case 0:
2114 return "no";
2115 case 1:
2116 return "yes";
2117 default:
2118 return "UNKNOWN";
2119 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002120 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002121}
2122
2123static const char *
2124lookup_opcode_name(ServerOpCodes code)
2125{
2126 u_int i;
2127
2128 for (i = 0; keywords[i].name != NULL; i++)
2129 if (keywords[i].opcode == code)
2130 return(keywords[i].name);
2131 return "UNKNOWN";
2132}
2133
2134static void
2135dump_cfg_int(ServerOpCodes code, int val)
2136{
2137 printf("%s %d\n", lookup_opcode_name(code), val);
2138}
2139
2140static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002141dump_cfg_oct(ServerOpCodes code, int val)
2142{
2143 printf("%s 0%o\n", lookup_opcode_name(code), val);
2144}
2145
2146static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002147dump_cfg_fmtint(ServerOpCodes code, int val)
2148{
2149 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2150}
2151
2152static void
2153dump_cfg_string(ServerOpCodes code, const char *val)
2154{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002155 printf("%s %s\n", lookup_opcode_name(code),
2156 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002157}
2158
2159static void
2160dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2161{
2162 u_int i;
2163
2164 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002165 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2166}
2167
2168static void
2169dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2170{
2171 u_int i;
2172
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002173 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002174 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002175 printf("%s", lookup_opcode_name(code));
2176 for (i = 0; i < count; i++)
2177 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002178 if (code == sAuthenticationMethods && count == 0)
2179 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002180 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002181}
2182
2183void
2184dump_config(ServerOptions *o)
2185{
2186 u_int i;
2187 int ret;
2188 struct addrinfo *ai;
2189 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002190 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002191
2192 /* these are usually at the top of the config */
2193 for (i = 0; i < o->num_ports; i++)
2194 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002195 dump_cfg_fmtint(sAddressFamily, o->address_family);
2196
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002197 /*
2198 * ListenAddress must be after Port. add_one_listen_addr pushes
2199 * addresses onto a stack, so to maintain ordering we need to
2200 * print these in reverse order.
2201 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002202 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2203 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2204 sizeof(addr), port, sizeof(port),
2205 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2206 error("getnameinfo failed: %.100s",
2207 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2208 strerror(errno));
2209 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002210 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002211 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002212 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2213 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002214 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002215 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2216 addr, port, laddr2);
2217 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002218 }
2219 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002220 printf("%s", laddr1);
2221 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002222
2223 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002224#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002225 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002226#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002227 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002228 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2229 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002230 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002231 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2232 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002233 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002234
2235 /* formatted integer arguments */
2236 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2237 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2238 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002239 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2240 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2241 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002242 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002243#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002244 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2245 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2246 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002247# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002248 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002249# endif
2250#endif
2251#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002252 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2253 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002254#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002255 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2256 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2257 o->kbd_interactive_authentication);
2258 dump_cfg_fmtint(sChallengeResponseAuthentication,
2259 o->challenge_response_authentication);
2260 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002261#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002262 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002263#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002264 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2265 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002266 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002267 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002268 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2269 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2270 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2271 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002272 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002273 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002274 dump_cfg_fmtint(sUseDNS, o->use_dns);
2275 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002276 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002277 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002278 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002279 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002280 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281
2282 /* string arguments */
2283 dump_cfg_string(sPidFile, o->pid_file);
2284 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002285 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2286 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002287 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002288 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002289 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002290 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2291 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002292 dump_cfg_string(sAuthorizedPrincipalsFile,
2293 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002294 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2295 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002296 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2297 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002298 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2299 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002300 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002301 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002302 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002303 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2304 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002305 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2306 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002307 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2308 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002309
2310 /* string arguments requiring a lookup */
2311 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2312 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2313
2314 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002315 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2316 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002317 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2318 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002319 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002320 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002321 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2322 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2323 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2324 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2325 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002326 dump_cfg_strarray_oneline(sAuthenticationMethods,
2327 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002328
2329 /* other arguments */
2330 for (i = 0; i < o->num_subsystems; i++)
2331 printf("subsystem %s %s\n", o->subsystem_name[i],
2332 o->subsystem_args[i]);
2333
2334 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2335 o->max_startups_rate, o->max_startups);
2336
2337 for (i = 0; tunmode_desc[i].val != -1; i++)
2338 if (tunmode_desc[i].val == o->permit_tun) {
2339 s = tunmode_desc[i].text;
2340 break;
2341 }
2342 dump_cfg_string(sPermitTunnel, s);
2343
Damien Miller91475862011-05-05 14:14:34 +10002344 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2345 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002346
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002347 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002348 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002349
Darren Tuckere7140f22008-06-10 23:01:51 +10002350 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002351}