blob: 018f251cae6d8b169ec87a7767bc2b5d56a5dfa2 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002/* $OpenBSD: servconf.c,v 1.276 2015/07/10 06:21:53 markus 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->server_key_bits = -1;
90 options->login_grace_time = -1;
91 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000092 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110093 options->ignore_rhosts = -1;
94 options->ignore_user_known_hosts = -1;
95 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000096 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110097 options->x11_forwarding = -1;
98 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110099 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100100 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000101 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000102 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100104 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100105 options->log_facility = SYSLOG_FACILITY_NOT_SET;
106 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000108 options->hostbased_authentication = -1;
109 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000110 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000111 options->hostkeyalgorithms = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100113 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000114 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100115 options->kerberos_authentication = -1;
116 options->kerberos_or_local_passwd = -1;
117 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100118 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000119 options->gss_authentication=-1;
120 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000121 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100122 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100123 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000124 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100125 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000126 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100127 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000128 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000129 options->rekey_limit = -1;
130 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100131 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000132 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000133 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100134 options->num_allow_users = 0;
135 options->num_deny_users = 0;
136 options->num_allow_groups = 0;
137 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000138 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000139 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000140 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000141 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller7acefbb2014-07-18 14:11:24 +1000142 options->fwd_opts.gateway_ports = -1;
143 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
144 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000145 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000146 options->max_startups_begin = -1;
147 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000148 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000149 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000150 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000151 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000152 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000153 options->client_alive_interval = -1;
154 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000155 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000156 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100157 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000158 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000159 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100160 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100161 options->authorized_keys_command = NULL;
162 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100163 options->revoked_keys_file = NULL;
164 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000165 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000166 options->authorized_principals_command = NULL;
167 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100168 options->ip_qos_interactive = -1;
169 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000170 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000171 options->fingerprint_hash = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000172}
173
djm@openbsd.org161cf412014-12-22 07:55:51 +0000174/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
175static int
176option_clear_or_none(const char *o)
177{
178 return o == NULL || strcasecmp(o, "none") == 0;
179}
180
Damien Miller4af51302000-04-16 11:18:38 +1000181void
Damien Miller95def091999-11-25 00:26:21 +1100182fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000183{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000184 int i;
185
Damien Miller726273e2001-11-12 11:40:11 +1100186 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000187 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000188 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100189
190 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100191 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100192 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100193 if (options->num_host_key_files == 0) {
194 /* fill default hostkeys for protocols */
195 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100196 options->host_key_files[options->num_host_key_files++] =
197 _PATH_HOST_KEY_FILE;
198 if (options->protocol & SSH_PROTO_2) {
199 options->host_key_files[options->num_host_key_files++] =
200 _PATH_HOST_RSA_KEY_FILE;
201 options->host_key_files[options->num_host_key_files++] =
202 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100203#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000204 options->host_key_files[options->num_host_key_files++] =
205 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100206#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100207 options->host_key_files[options->num_host_key_files++] =
208 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100209 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100210 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100211 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100212 if (options->num_ports == 0)
213 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000214 if (options->address_family == -1)
215 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100216 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000217 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000218 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000219 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000221 options->server_key_bits = 1024;
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;
Damien Miller95def091999-11-25 00:26:21 +1100224 if (options->key_regeneration_time == -1)
225 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000226 if (options->permit_root_login == PERMIT_NOT_SET)
djm@openbsd.org868109b2015-07-01 02:39:06 +0000227 options->permit_root_login = PERMIT_NO;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100229 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->ignore_user_known_hosts == -1)
231 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100232 if (options->print_motd == -1)
233 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000234 if (options->print_lastlog == -1)
235 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100237 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100238 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100239 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100240 if (options->x11_use_localhost == -1)
241 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000242 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000243 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100244 if (options->permit_tty == -1)
245 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000246 if (options->permit_user_rc == -1)
247 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100248 if (options->strict_modes == -1)
249 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100250 if (options->tcp_keep_alive == -1)
251 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100252 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100253 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100254 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000255 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100256 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100257 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000258 if (options->hostbased_authentication == -1)
259 options->hostbased_authentication = 0;
260 if (options->hostbased_uses_name_from_packet_only == -1)
261 options->hostbased_uses_name_from_packet_only = 0;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000262 if (options->hostbased_key_types == NULL)
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000263 options->hostbased_key_types = xstrdup(KEX_DEFAULT_PK_ALG);
264 if (options->hostkeyalgorithms == NULL)
265 options->hostkeyalgorithms = xstrdup(KEX_DEFAULT_PK_ALG);
Damien Miller95def091999-11-25 00:26:21 +1100266 if (options->rsa_authentication == -1)
267 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100268 if (options->pubkey_authentication == -1)
269 options->pubkey_authentication = 1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000270 if (options->pubkey_key_types == NULL)
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000271 options->pubkey_key_types = xstrdup(KEX_DEFAULT_PK_ALG);
Damien Miller95def091999-11-25 00:26:21 +1100272 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000273 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100274 if (options->kerberos_or_local_passwd == -1)
275 options->kerberos_or_local_passwd = 1;
276 if (options->kerberos_ticket_cleanup == -1)
277 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100278 if (options->kerberos_get_afs_token == -1)
279 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000280 if (options->gss_authentication == -1)
281 options->gss_authentication = 0;
282 if (options->gss_cleanup_creds == -1)
283 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000284 if (options->gss_strict_acceptor == -1)
285 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100286 if (options->password_authentication == -1)
287 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100288 if (options->kbd_interactive_authentication == -1)
289 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000290 if (options->challenge_response_authentication == -1)
291 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100292 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100293 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000294 if (options->permit_user_env == -1)
295 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100296 if (options->use_login == -1)
297 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000298 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000299 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000300 if (options->rekey_limit == -1)
301 options->rekey_limit = 0;
302 if (options->rekey_interval == -1)
303 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100304 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100305 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000306 if (options->allow_streamlocal_forwarding == -1)
307 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000308 if (options->allow_agent_forwarding == -1)
309 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000310 if (options->fwd_opts.gateway_ports == -1)
311 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000312 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100313 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000314 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100315 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000316 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100317 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000318 if (options->max_authtries == -1)
319 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000320 if (options->max_sessions == -1)
321 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000322 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000323 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000324 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100325 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000326 if (options->client_alive_count_max == -1)
327 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000328 if (options->num_authkeys_files == 0) {
329 options->authorized_keys_files[options->num_authkeys_files++] =
330 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
331 options->authorized_keys_files[options->num_authkeys_files++] =
332 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
333 }
Damien Millerd27b9472005-12-13 19:29:02 +1100334 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100335 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100336 if (options->ip_qos_interactive == -1)
337 options->ip_qos_interactive = IPTOS_LOWDELAY;
338 if (options->ip_qos_bulk == -1)
339 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000340 if (options->version_addendum == NULL)
341 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000342 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
343 options->fwd_opts.streamlocal_bind_mask = 0177;
344 if (options->fwd_opts.streamlocal_bind_unlink == -1)
345 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000346 if (options->fingerprint_hash == -1)
347 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
Ben Lindstromfb62a692002-06-06 19:47:11 +0000348 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000349 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000350 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000351
djm@openbsd.org161cf412014-12-22 07:55:51 +0000352#define CLEAR_ON_NONE(v) \
353 do { \
354 if (option_clear_or_none(v)) { \
355 free(v); \
356 v = NULL; \
357 } \
358 } while(0)
359 CLEAR_ON_NONE(options->pid_file);
360 CLEAR_ON_NONE(options->xauth_location);
361 CLEAR_ON_NONE(options->banner);
362 CLEAR_ON_NONE(options->trusted_user_ca_keys);
363 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000364 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000365 for (i = 0; i < options->num_host_key_files; i++)
366 CLEAR_ON_NONE(options->host_key_files[i]);
367 for (i = 0; i < options->num_host_cert_files; i++)
368 CLEAR_ON_NONE(options->host_cert_files[i]);
369#undef CLEAR_ON_NONE
370
Tim Rice40017b02002-07-14 13:36:49 -0700371#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000372 if (use_privsep && options->compression == 1) {
373 error("This platform does not support both privilege "
374 "separation and compression");
375 error("Compression disabled");
376 options->compression = 0;
377 }
378#endif
379
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000380}
381
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000382/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100383typedef enum {
384 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100385 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000386 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100387 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000388 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
389 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000390 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100391 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100392 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000393 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100394 sPasswordAuthentication, sKbdInteractiveAuthentication,
395 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000396 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100397 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100398 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000399 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000400 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000401 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000402 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
403 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000404 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000405 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000406 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000407 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000408 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
409 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100410 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100411 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100412 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000413 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000414 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000415 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100416 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000417 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000418 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000419 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000420 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000421} ServerOpCodes;
422
Darren Tucker45150472006-07-12 22:34:17 +1000423#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
424#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
425#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
426
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000427/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100428static struct {
429 const char *name;
430 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000431 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100432} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100433 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000434#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000435 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000436#else
Darren Tucker45150472006-07-12 22:34:17 +1000437 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000438#endif
Darren Tucker45150472006-07-12 22:34:17 +1000439 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100440 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000441 { "port", sPort, SSHCFG_GLOBAL },
442 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
443 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000444 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000445 { "pidfile", sPidFile, SSHCFG_GLOBAL },
446 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
447 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
448 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100449 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000450 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
451 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
452 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100453 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
454 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000455 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000456 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000457 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100458 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
459 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000460 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000461 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000462#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100463 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000464 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
465 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100466#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000467 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000468#else
Darren Tucker45150472006-07-12 22:34:17 +1000469 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100470#endif
471#else
Darren Tucker1629c072007-02-19 22:25:37 +1100472 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000473 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
474 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
475 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000476#endif
Darren Tucker45150472006-07-12 22:34:17 +1000477 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
478 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000479#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100480 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000481 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000482 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000483#else
Darren Tucker1629c072007-02-19 22:25:37 +1100484 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000485 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000486 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000487#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100488 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
489 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100490 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000491 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
492 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
493 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
494 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
495 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
496 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
497 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
498 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000499 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
500 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
501 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
503 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100504 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000505 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
506 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
507 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000508 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000509 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
510 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
511 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000512 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000513 { "allowusers", sAllowUsers, SSHCFG_ALL },
514 { "denyusers", sDenyUsers, SSHCFG_ALL },
515 { "allowgroups", sAllowGroups, SSHCFG_ALL },
516 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000517 { "ciphers", sCiphers, SSHCFG_GLOBAL },
518 { "macs", sMacs, SSHCFG_GLOBAL },
519 { "protocol", sProtocol, SSHCFG_GLOBAL },
520 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
521 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
522 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000523 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000524 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100525 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000526 { "usedns", sUseDNS, SSHCFG_GLOBAL },
527 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
528 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
529 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
530 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000531 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000532 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000533 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000534 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000535 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100536 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000537 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000538 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000539 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000540 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100541 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100542 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100543 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
544 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000545 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000546 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100547 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100548 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
549 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000550 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
551 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000552 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100553 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000554 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
555 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
556 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000557 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000558 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000559};
560
Darren Tuckere7140f22008-06-10 23:01:51 +1000561static struct {
562 int val;
563 char *text;
564} tunmode_desc[] = {
565 { SSH_TUNMODE_NO, "no" },
566 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
567 { SSH_TUNMODE_ETHERNET, "ethernet" },
568 { SSH_TUNMODE_YES, "yes" },
569 { -1, NULL }
570};
571
Damien Miller5428f641999-11-25 11:54:57 +1100572/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000573 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100574 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000575
Damien Miller4af51302000-04-16 11:18:38 +1000576static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100577parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000578 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000579{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000580 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581
Damien Miller95def091999-11-25 00:26:21 +1100582 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000583 if (strcasecmp(cp, keywords[i].name) == 0) {
584 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100585 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000586 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000587
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000588 error("%s: line %d: Bad configuration option: %s",
589 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100590 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000591}
592
Darren Tucker88b6fb22010-01-13 22:44:29 +1100593char *
594derelativise_path(const char *path)
595{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000596 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100597
djm@openbsd.org161cf412014-12-22 07:55:51 +0000598 if (strcasecmp(path, "none") == 0)
599 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100600 expanded = tilde_expand_filename(path, getuid());
601 if (*expanded == '/')
602 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100603 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100604 fatal("%s: getcwd: %s", __func__, strerror(errno));
605 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000606 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100607 return ret;
608}
609
Ben Lindstrombba81212001-06-25 05:01:22 +0000610static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100611add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100612{
Damien Millereccb9de2005-06-17 12:59:34 +1000613 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100614
Ben Lindstrom19066a12001-04-12 23:39:26 +0000615 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000616 for (i = 0; i < options->num_ports; i++)
617 add_one_listen_addr(options, addr, options->ports[i]);
618 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000619 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000620}
621
Ben Lindstrombba81212001-06-25 05:01:22 +0000622static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100623add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000624{
625 struct addrinfo hints, *ai, *aitop;
626 char strport[NI_MAXSERV];
627 int gaierr;
628
629 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100630 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000631 hints.ai_socktype = SOCK_STREAM;
632 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100633 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000634 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
635 fatal("bad addr or host: %s (%s)",
636 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100637 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000638 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
639 ;
640 ai->ai_next = options->listen_addrs;
641 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100642}
643
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000644/*
645 * Queue a ListenAddress to be processed once we have all of the Ports
646 * and AddressFamily options.
647 */
648static void
649queue_listen_addr(ServerOptions *options, char *addr, int port)
650{
651 options->queued_listen_addrs = xreallocarray(
652 options->queued_listen_addrs, options->num_queued_listens + 1,
653 sizeof(addr));
654 options->queued_listen_ports = xreallocarray(
655 options->queued_listen_ports, options->num_queued_listens + 1,
656 sizeof(port));
657 options->queued_listen_addrs[options->num_queued_listens] =
658 xstrdup(addr);
659 options->queued_listen_ports[options->num_queued_listens] = port;
660 options->num_queued_listens++;
661}
662
663/*
664 * Process queued (text) ListenAddress entries.
665 */
666static void
667process_queued_listen_addrs(ServerOptions *options)
668{
669 u_int i;
670
671 if (options->num_ports == 0)
672 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
673 if (options->address_family == -1)
674 options->address_family = AF_UNSPEC;
675
676 for (i = 0; i < options->num_queued_listens; i++) {
677 add_listen_addr(options, options->queued_listen_addrs[i],
678 options->queued_listen_ports[i]);
679 free(options->queued_listen_addrs[i]);
680 options->queued_listen_addrs[i] = NULL;
681 }
682 free(options->queued_listen_addrs);
683 options->queued_listen_addrs = NULL;
684 free(options->queued_listen_ports);
685 options->queued_listen_ports = NULL;
686 options->num_queued_listens = 0;
687}
688
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000689struct connection_info *
690get_connection_info(int populate, int use_dns)
691{
692 static struct connection_info ci;
693
694 if (!populate)
695 return &ci;
696 ci.host = get_canonical_hostname(use_dns);
697 ci.address = get_remote_ipaddr();
698 ci.laddress = get_local_ipaddr(packet_get_connection_in());
699 ci.lport = get_local_port();
700 return &ci;
701}
702
Darren Tucker45150472006-07-12 22:34:17 +1000703/*
704 * The strategy for the Match blocks is that the config file is parsed twice.
705 *
706 * The first time is at startup. activep is initialized to 1 and the
707 * directives in the global context are processed and acted on. Hitting a
708 * Match directive unsets activep and the directives inside the block are
709 * checked for syntax only.
710 *
711 * The second time is after a connection has been established but before
712 * authentication. activep is initialized to 2 and global config directives
713 * are ignored since they have already been processed. If the criteria in a
714 * Match block is met, activep is set and the subsequent directives
715 * processed and actioned until EOF or another Match block unsets it. Any
716 * options set are copied into the main server config.
717 *
718 * Potential additions/improvements:
719 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
720 *
721 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
722 * Match Address 192.168.0.*
723 * Tag trusted
724 * Match Group wheel
725 * Tag trusted
726 * Match Tag trusted
727 * AllowTcpForwarding yes
728 * GatewayPorts clientspecified
729 * [...]
730 *
731 * - Add a PermittedChannelRequests directive
732 * Match Group shell
733 * PermittedChannelRequests session,forwarded-tcpip
734 */
735
736static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000737match_cfg_line_group(const char *grps, int line, const char *user)
738{
739 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000740 struct passwd *pw;
741
Damien Miller565ca3f2006-08-19 00:23:15 +1000742 if (user == NULL)
743 goto out;
744
745 if ((pw = getpwnam(user)) == NULL) {
746 debug("Can't match group at line %d because user %.100s does "
747 "not exist", line, user);
748 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
749 debug("Can't Match group because user %.100s not in any group "
750 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000751 } else if (ga_match_pattern_list(grps) != 1) {
752 debug("user %.100s does not match group list %.100s at line %d",
753 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000754 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000755 debug("user %.100s matched group list %.100s at line %d", user,
756 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000757 result = 1;
758 }
759out:
760 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000761 return result;
762}
763
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000764/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000765 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100766 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000767 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000768 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000769static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000770match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000771{
Damien Millercf31f382013-10-24 21:02:56 +1100772 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000773 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000774
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000775 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000776 debug3("checking syntax for 'Match %s'", cp);
777 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000778 debug3("checking match for '%s' user %s host %s addr %s "
779 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
780 ci->host ? ci->host : "(null)",
781 ci->address ? ci->address : "(null)",
782 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000783
784 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100785 attributes++;
786 if (strcasecmp(attrib, "all") == 0) {
787 if (attributes != 1 ||
788 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
789 error("'all' cannot be combined with other "
790 "Match attributes");
791 return -1;
792 }
793 *condition = cp;
794 return 1;
795 }
Darren Tucker45150472006-07-12 22:34:17 +1000796 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
797 error("Missing Match criteria for %s", attrib);
798 return -1;
799 }
Darren Tucker45150472006-07-12 22:34:17 +1000800 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000801 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000802 result = 0;
803 continue;
804 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000805 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000806 result = 0;
807 else
808 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000809 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000810 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000811 if (ci == NULL || ci->user == NULL) {
812 result = 0;
813 continue;
814 }
815 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000816 case -1:
817 return -1;
818 case 0:
819 result = 0;
820 }
Darren Tucker45150472006-07-12 22:34:17 +1000821 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000822 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000823 result = 0;
824 continue;
825 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000826 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000827 result = 0;
828 else
829 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000830 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000831 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000832 if (ci == NULL || ci->address == NULL) {
833 result = 0;
834 continue;
835 }
836 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000837 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000838 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000839 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000840 break;
841 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000842 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000843 result = 0;
844 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000845 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000846 return -1;
847 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000848 } else if (strcasecmp(attrib, "localaddress") == 0){
849 if (ci == NULL || ci->laddress == NULL) {
850 result = 0;
851 continue;
852 }
853 switch (addr_match_list(ci->laddress, arg)) {
854 case 1:
855 debug("connection from %.100s matched "
856 "'LocalAddress %.100s' at line %d",
857 ci->laddress, arg, line);
858 break;
859 case 0:
860 case -1:
861 result = 0;
862 break;
863 case -2:
864 return -1;
865 }
866 } else if (strcasecmp(attrib, "localport") == 0) {
867 if ((port = a2port(arg)) == -1) {
868 error("Invalid LocalPort '%s' on Match line",
869 arg);
870 return -1;
871 }
872 if (ci == NULL || ci->lport == 0) {
873 result = 0;
874 continue;
875 }
876 /* TODO support port lists */
877 if (port == ci->lport)
878 debug("connection from %.100s matched "
879 "'LocalPort %d' at line %d",
880 ci->laddress, port, line);
881 else
882 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000883 } else {
884 error("Unsupported Match attribute %s", attrib);
885 return -1;
886 }
887 }
Damien Millercf31f382013-10-24 21:02:56 +1100888 if (attributes == 0) {
889 error("One or more attributes required for Match");
890 return -1;
891 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000892 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000893 debug3("match %sfound", result ? "" : "not ");
894 *condition = cp;
895 return result;
896}
897
Damien Millere2754432006-07-24 14:06:47 +1000898#define WHITESPACE " \t\r\n"
899
Damien Miller33322122011-06-20 14:43:11 +1000900/* Multistate option parsing */
901struct multistate {
902 char *key;
903 int value;
904};
905static const struct multistate multistate_addressfamily[] = {
906 { "inet", AF_INET },
907 { "inet6", AF_INET6 },
908 { "any", AF_UNSPEC },
909 { NULL, -1 }
910};
911static const struct multistate multistate_permitrootlogin[] = {
912 { "without-password", PERMIT_NO_PASSWD },
913 { "forced-commands-only", PERMIT_FORCED_ONLY },
914 { "yes", PERMIT_YES },
915 { "no", PERMIT_NO },
916 { NULL, -1 }
917};
918static const struct multistate multistate_compression[] = {
919 { "delayed", COMP_DELAYED },
920 { "yes", COMP_ZLIB },
921 { "no", COMP_NONE },
922 { NULL, -1 }
923};
924static const struct multistate multistate_gatewayports[] = {
925 { "clientspecified", 2 },
926 { "yes", 1 },
927 { "no", 0 },
928 { NULL, -1 }
929};
Damien Miller69ff1df2011-06-23 08:30:03 +1000930static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000931 { "yes", PRIVSEP_NOSANDBOX },
932 { "sandbox", PRIVSEP_ON },
933 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000934 { "no", PRIVSEP_OFF },
935 { NULL, -1 }
936};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100937static const struct multistate multistate_tcpfwd[] = {
938 { "yes", FORWARD_ALLOW },
939 { "all", FORWARD_ALLOW },
940 { "no", FORWARD_DENY },
941 { "remote", FORWARD_REMOTE },
942 { "local", FORWARD_LOCAL },
943 { NULL, -1 }
944};
Damien Miller33322122011-06-20 14:43:11 +1000945
Ben Lindstromade03f62001-12-06 18:22:17 +0000946int
947process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000948 const char *filename, int linenum, int *activep,
949 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000950{
Darren Tucker09c0f032013-05-16 20:48:57 +1000951 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000952 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100953 SyslogFacility *log_facility_ptr;
954 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000955 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000956 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000957 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000958 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000959 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000960
961 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100962 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100963 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000964 /* Ignore leading whitespace */
965 if (*arg == '\0')
966 arg = strdelim(&cp);
967 if (!arg || !*arg || *arg == '#')
968 return 0;
969 intptr = NULL;
970 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000971 opcode = parse_token(arg, filename, linenum, &flags);
972
973 if (activep == NULL) { /* We are processing a command line directive */
974 cmdline = 1;
975 activep = &cmdline;
976 }
977 if (*activep && opcode != sMatch)
978 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
979 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000980 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000981 fatal("%s line %d: Directive '%s' is not allowed "
982 "within a Match block", filename, linenum, arg);
983 } else { /* this is a directive we have already processed */
984 while (arg)
985 arg = strdelim(&cp);
986 return 0;
987 }
988 }
989
Ben Lindstromade03f62001-12-06 18:22:17 +0000990 switch (opcode) {
991 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000992 case sUsePAM:
993 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000994 goto parse_flag;
995
996 /* Standard Options */
997 case sBadOption:
998 return -1;
999 case sPort:
1000 /* ignore ports from configfile if cmdline specifies ports */
1001 if (options->ports_from_cmdline)
1002 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001003 if (options->num_ports >= MAX_PORTS)
1004 fatal("%s line %d: too many ports.",
1005 filename, linenum);
1006 arg = strdelim(&cp);
1007 if (!arg || *arg == '\0')
1008 fatal("%s line %d: missing port number.",
1009 filename, linenum);
1010 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001011 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001012 fatal("%s line %d: Badly formatted port number.",
1013 filename, linenum);
1014 break;
1015
1016 case sServerKeyBits:
1017 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001018 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001019 arg = strdelim(&cp);
1020 if (!arg || *arg == '\0')
1021 fatal("%s line %d: missing integer value.",
1022 filename, linenum);
1023 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001024 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001025 *intptr = value;
1026 break;
1027
1028 case sLoginGraceTime:
1029 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001030 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001031 arg = strdelim(&cp);
1032 if (!arg || *arg == '\0')
1033 fatal("%s line %d: missing time value.",
1034 filename, linenum);
1035 if ((value = convtime(arg)) == -1)
1036 fatal("%s line %d: invalid time value.",
1037 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001038 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001039 *intptr = value;
1040 break;
1041
1042 case sKeyRegenerationTime:
1043 intptr = &options->key_regeneration_time;
1044 goto parse_time;
1045
1046 case sListenAddress:
1047 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001048 if (arg == NULL || *arg == '\0')
1049 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001050 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001051 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1052 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1053 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001054 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001055 break;
1056 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001057 p = hpdelim(&arg);
1058 if (p == NULL)
1059 fatal("%s line %d: bad address:port usage",
1060 filename, linenum);
1061 p = cleanhostname(p);
1062 if (arg == NULL)
1063 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001064 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001065 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001066
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001067 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001068
Ben Lindstromade03f62001-12-06 18:22:17 +00001069 break;
1070
Darren Tucker0f383232005-01-20 10:57:56 +11001071 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001072 intptr = &options->address_family;
1073 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001074 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001075 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001076 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001077 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001078 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001079 value = -1;
1080 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1081 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1082 value = multistate_ptr[i].value;
1083 break;
1084 }
1085 }
1086 if (value == -1)
1087 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001088 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001089 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001090 *intptr = value;
1091 break;
1092
Ben Lindstromade03f62001-12-06 18:22:17 +00001093 case sHostKeyFile:
1094 intptr = &options->num_host_key_files;
1095 if (*intptr >= MAX_HOSTKEYS)
1096 fatal("%s line %d: too many host keys specified (max %d).",
1097 filename, linenum, MAX_HOSTKEYS);
1098 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001099 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001100 arg = strdelim(&cp);
1101 if (!arg || *arg == '\0')
1102 fatal("%s line %d: missing file name.",
1103 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001104 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001105 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001106 /* increase optional counter */
1107 if (intptr != NULL)
1108 *intptr = *intptr + 1;
1109 }
1110 break;
1111
Damien Miller85b45e02013-07-20 13:21:52 +10001112 case sHostKeyAgent:
1113 charptr = &options->host_key_agent;
1114 arg = strdelim(&cp);
1115 if (!arg || *arg == '\0')
1116 fatal("%s line %d: missing socket name.",
1117 filename, linenum);
1118 if (*activep && *charptr == NULL)
1119 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1120 xstrdup(arg) : derelativise_path(arg);
1121 break;
1122
Damien Miller0a80ca12010-02-27 07:55:05 +11001123 case sHostCertificate:
1124 intptr = &options->num_host_cert_files;
1125 if (*intptr >= MAX_HOSTKEYS)
1126 fatal("%s line %d: too many host certificates "
1127 "specified (max %d).", filename, linenum,
1128 MAX_HOSTCERTS);
1129 charptr = &options->host_cert_files[*intptr];
1130 goto parse_filename;
1131 break;
1132
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 sRhostsRSAAuthentication:
1166 intptr = &options->rhosts_rsa_authentication;
1167 goto parse_flag;
1168
1169 case sHostbasedAuthentication:
1170 intptr = &options->hostbased_authentication;
1171 goto parse_flag;
1172
1173 case sHostbasedUsesNameFromPacketOnly:
1174 intptr = &options->hostbased_uses_name_from_packet_only;
1175 goto parse_flag;
1176
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001177 case sHostbasedAcceptedKeyTypes:
1178 charptr = &options->hostbased_key_types;
1179 parse_keytypes:
1180 arg = strdelim(&cp);
1181 if (!arg || *arg == '\0')
1182 fatal("%s line %d: Missing argument.",
1183 filename, linenum);
1184 if (!sshkey_names_valid2(arg, 1))
1185 fatal("%s line %d: Bad key types '%s'.",
1186 filename, linenum, arg ? arg : "<NONE>");
1187 if (*activep && *charptr == NULL)
1188 *charptr = xstrdup(arg);
1189 break;
1190
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001191 case sHostKeyAlgorithms:
1192 charptr = &options->hostkeyalgorithms;
1193 goto parse_keytypes;
1194
Ben Lindstromade03f62001-12-06 18:22:17 +00001195 case sRSAAuthentication:
1196 intptr = &options->rsa_authentication;
1197 goto parse_flag;
1198
1199 case sPubkeyAuthentication:
1200 intptr = &options->pubkey_authentication;
1201 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001202
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001203 case sPubkeyAcceptedKeyTypes:
1204 charptr = &options->pubkey_key_types;
1205 goto parse_keytypes;
1206
Ben Lindstromade03f62001-12-06 18:22:17 +00001207 case sKerberosAuthentication:
1208 intptr = &options->kerberos_authentication;
1209 goto parse_flag;
1210
1211 case sKerberosOrLocalPasswd:
1212 intptr = &options->kerberos_or_local_passwd;
1213 goto parse_flag;
1214
1215 case sKerberosTicketCleanup:
1216 intptr = &options->kerberos_ticket_cleanup;
1217 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001218
Darren Tucker22ef5082003-12-31 11:37:34 +11001219 case sKerberosGetAFSToken:
1220 intptr = &options->kerberos_get_afs_token;
1221 goto parse_flag;
1222
Darren Tucker0efd1552003-08-26 11:49:55 +10001223 case sGssAuthentication:
1224 intptr = &options->gss_authentication;
1225 goto parse_flag;
1226
1227 case sGssCleanupCreds:
1228 intptr = &options->gss_cleanup_creds;
1229 goto parse_flag;
1230
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001231 case sGssStrictAcceptor:
1232 intptr = &options->gss_strict_acceptor;
1233 goto parse_flag;
1234
Ben Lindstromade03f62001-12-06 18:22:17 +00001235 case sPasswordAuthentication:
1236 intptr = &options->password_authentication;
1237 goto parse_flag;
1238
1239 case sKbdInteractiveAuthentication:
1240 intptr = &options->kbd_interactive_authentication;
1241 goto parse_flag;
1242
1243 case sChallengeResponseAuthentication:
1244 intptr = &options->challenge_response_authentication;
1245 goto parse_flag;
1246
1247 case sPrintMotd:
1248 intptr = &options->print_motd;
1249 goto parse_flag;
1250
1251 case sPrintLastLog:
1252 intptr = &options->print_lastlog;
1253 goto parse_flag;
1254
1255 case sX11Forwarding:
1256 intptr = &options->x11_forwarding;
1257 goto parse_flag;
1258
1259 case sX11DisplayOffset:
1260 intptr = &options->x11_display_offset;
1261 goto parse_int;
1262
Damien Miller95c249f2002-02-05 12:11:34 +11001263 case sX11UseLocalhost:
1264 intptr = &options->x11_use_localhost;
1265 goto parse_flag;
1266
Ben Lindstromade03f62001-12-06 18:22:17 +00001267 case sXAuthLocation:
1268 charptr = &options->xauth_location;
1269 goto parse_filename;
1270
Damien Miller5ff30c62013-10-30 22:21:50 +11001271 case sPermitTTY:
1272 intptr = &options->permit_tty;
1273 goto parse_flag;
1274
Damien Miller72e6b5c2014-07-04 09:00:04 +10001275 case sPermitUserRC:
1276 intptr = &options->permit_user_rc;
1277 goto parse_flag;
1278
Ben Lindstromade03f62001-12-06 18:22:17 +00001279 case sStrictModes:
1280 intptr = &options->strict_modes;
1281 goto parse_flag;
1282
Damien Miller12c150e2003-12-17 16:31:10 +11001283 case sTCPKeepAlive:
1284 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001285 goto parse_flag;
1286
1287 case sEmptyPasswd:
1288 intptr = &options->permit_empty_passwd;
1289 goto parse_flag;
1290
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001291 case sPermitUserEnvironment:
1292 intptr = &options->permit_user_env;
1293 goto parse_flag;
1294
Ben Lindstromade03f62001-12-06 18:22:17 +00001295 case sUseLogin:
1296 intptr = &options->use_login;
1297 goto parse_flag;
1298
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001299 case sCompression:
1300 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001301 multistate_ptr = multistate_compression;
1302 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001303
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001304 case sRekeyLimit:
1305 arg = strdelim(&cp);
1306 if (!arg || *arg == '\0')
1307 fatal("%.200s line %d: Missing argument.", filename,
1308 linenum);
1309 if (strcmp(arg, "default") == 0) {
1310 val64 = 0;
1311 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001312 if (scan_scaled(arg, &val64) == -1)
1313 fatal("%.200s line %d: Bad number '%s': %s",
1314 filename, linenum, arg, strerror(errno));
1315 /* check for too-large or too-small limits */
1316 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001317 fatal("%.200s line %d: RekeyLimit too large",
1318 filename, linenum);
1319 if (val64 != 0 && val64 < 16)
1320 fatal("%.200s line %d: RekeyLimit too small",
1321 filename, linenum);
1322 }
1323 if (*activep && options->rekey_limit == -1)
1324 options->rekey_limit = (u_int32_t)val64;
1325 if (cp != NULL) { /* optional rekey interval present */
1326 if (strcmp(cp, "none") == 0) {
1327 (void)strdelim(&cp); /* discard */
1328 break;
1329 }
1330 intptr = &options->rekey_interval;
1331 goto parse_time;
1332 }
1333 break;
1334
Ben Lindstromade03f62001-12-06 18:22:17 +00001335 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001336 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001337 multistate_ptr = multistate_gatewayports;
1338 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001339
Damien Miller3a961dc2003-06-03 10:25:48 +10001340 case sUseDNS:
1341 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001342 goto parse_flag;
1343
1344 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001345 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001346 arg = strdelim(&cp);
1347 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001348 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001349 fatal("%.200s line %d: unsupported log facility '%s'",
1350 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001351 if (*log_facility_ptr == -1)
1352 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 break;
1354
1355 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001356 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001357 arg = strdelim(&cp);
1358 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001359 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001360 fatal("%.200s line %d: unsupported log level '%s'",
1361 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001362 if (*log_level_ptr == -1)
1363 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 break;
1365
1366 case sAllowTcpForwarding:
1367 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001368 multistate_ptr = multistate_tcpfwd;
1369 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001370
Damien Miller7acefbb2014-07-18 14:11:24 +10001371 case sAllowStreamLocalForwarding:
1372 intptr = &options->allow_streamlocal_forwarding;
1373 multistate_ptr = multistate_tcpfwd;
1374 goto parse_multistate;
1375
Damien Miller4f755cd2008-05-19 14:57:41 +10001376 case sAllowAgentForwarding:
1377 intptr = &options->allow_agent_forwarding;
1378 goto parse_flag;
1379
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001380 case sUsePrivilegeSeparation:
1381 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001382 multistate_ptr = multistate_privsep;
1383 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001384
Ben Lindstromade03f62001-12-06 18:22:17 +00001385 case sAllowUsers:
1386 while ((arg = strdelim(&cp)) && *arg != '\0') {
1387 if (options->num_allow_users >= MAX_ALLOW_USERS)
1388 fatal("%s line %d: too many allow users.",
1389 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001390 if (!*activep)
1391 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001392 options->allow_users[options->num_allow_users++] =
1393 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001394 }
1395 break;
1396
1397 case sDenyUsers:
1398 while ((arg = strdelim(&cp)) && *arg != '\0') {
1399 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001400 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001401 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001402 if (!*activep)
1403 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001404 options->deny_users[options->num_deny_users++] =
1405 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001406 }
1407 break;
1408
1409 case sAllowGroups:
1410 while ((arg = strdelim(&cp)) && *arg != '\0') {
1411 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1412 fatal("%s line %d: too many allow groups.",
1413 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001414 if (!*activep)
1415 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001416 options->allow_groups[options->num_allow_groups++] =
1417 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001418 }
1419 break;
1420
1421 case sDenyGroups:
1422 while ((arg = strdelim(&cp)) && *arg != '\0') {
1423 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1424 fatal("%s line %d: too many deny groups.",
1425 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001426 if (!*activep)
1427 continue;
1428 options->deny_groups[options->num_deny_groups++] =
1429 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001430 }
1431 break;
1432
1433 case sCiphers:
1434 arg = strdelim(&cp);
1435 if (!arg || *arg == '\0')
1436 fatal("%s line %d: Missing argument.", filename, linenum);
1437 if (!ciphers_valid(arg))
1438 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1439 filename, linenum, arg ? arg : "<NONE>");
1440 if (options->ciphers == NULL)
1441 options->ciphers = xstrdup(arg);
1442 break;
1443
1444 case sMacs:
1445 arg = strdelim(&cp);
1446 if (!arg || *arg == '\0')
1447 fatal("%s line %d: Missing argument.", filename, linenum);
1448 if (!mac_valid(arg))
1449 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1450 filename, linenum, arg ? arg : "<NONE>");
1451 if (options->macs == NULL)
1452 options->macs = xstrdup(arg);
1453 break;
1454
Damien Millerd5f62bf2010-09-24 22:11:14 +10001455 case sKexAlgorithms:
1456 arg = strdelim(&cp);
1457 if (!arg || *arg == '\0')
1458 fatal("%s line %d: Missing argument.",
1459 filename, linenum);
1460 if (!kex_names_valid(arg))
1461 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1462 filename, linenum, arg ? arg : "<NONE>");
1463 if (options->kex_algorithms == NULL)
1464 options->kex_algorithms = xstrdup(arg);
1465 break;
1466
Ben Lindstromade03f62001-12-06 18:22:17 +00001467 case sProtocol:
1468 intptr = &options->protocol;
1469 arg = strdelim(&cp);
1470 if (!arg || *arg == '\0')
1471 fatal("%s line %d: Missing argument.", filename, linenum);
1472 value = proto_spec(arg);
1473 if (value == SSH_PROTO_UNKNOWN)
1474 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001475 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001476 if (*intptr == SSH_PROTO_UNKNOWN)
1477 *intptr = value;
1478 break;
1479
1480 case sSubsystem:
1481 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1482 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001483 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001484 }
1485 arg = strdelim(&cp);
1486 if (!arg || *arg == '\0')
1487 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001488 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001489 if (!*activep) {
1490 arg = strdelim(&cp);
1491 break;
1492 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001493 for (i = 0; i < options->num_subsystems; i++)
1494 if (strcmp(arg, options->subsystem_name[i]) == 0)
1495 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001496 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001497 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1498 arg = strdelim(&cp);
1499 if (!arg || *arg == '\0')
1500 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001501 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001502 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001503
1504 /* Collect arguments (separate to executable) */
1505 p = xstrdup(arg);
1506 len = strlen(p) + 1;
1507 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1508 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001509 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001510 strlcat(p, " ", len);
1511 strlcat(p, arg, len);
1512 }
1513 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001514 options->num_subsystems++;
1515 break;
1516
1517 case sMaxStartups:
1518 arg = strdelim(&cp);
1519 if (!arg || *arg == '\0')
1520 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001521 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001522 if ((n = sscanf(arg, "%d:%d:%d",
1523 &options->max_startups_begin,
1524 &options->max_startups_rate,
1525 &options->max_startups)) == 3) {
1526 if (options->max_startups_begin >
1527 options->max_startups ||
1528 options->max_startups_rate > 100 ||
1529 options->max_startups_rate < 1)
1530 fatal("%s line %d: Illegal MaxStartups spec.",
1531 filename, linenum);
1532 } else if (n != 1)
1533 fatal("%s line %d: Illegal MaxStartups spec.",
1534 filename, linenum);
1535 else
1536 options->max_startups = options->max_startups_begin;
1537 break;
1538
Darren Tucker89413db2004-05-24 10:36:23 +10001539 case sMaxAuthTries:
1540 intptr = &options->max_authtries;
1541 goto parse_int;
1542
Damien Miller7207f642008-05-19 15:34:50 +10001543 case sMaxSessions:
1544 intptr = &options->max_sessions;
1545 goto parse_int;
1546
Ben Lindstromade03f62001-12-06 18:22:17 +00001547 case sBanner:
1548 charptr = &options->banner;
1549 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001550
Ben Lindstromade03f62001-12-06 18:22:17 +00001551 /*
1552 * These options can contain %X options expanded at
1553 * connect time, so that you can specify paths like:
1554 *
1555 * AuthorizedKeysFile /etc/ssh_keys/%u
1556 */
1557 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001558 if (*activep && options->num_authkeys_files == 0) {
1559 while ((arg = strdelim(&cp)) && *arg != '\0') {
1560 if (options->num_authkeys_files >=
1561 MAX_AUTHKEYS_FILES)
1562 fatal("%s line %d: "
1563 "too many authorized keys files.",
1564 filename, linenum);
1565 options->authorized_keys_files[
1566 options->num_authkeys_files++] =
1567 tilde_expand_filename(arg, getuid());
1568 }
1569 }
1570 return 0;
1571
Damien Miller30da3442010-05-10 11:58:03 +10001572 case sAuthorizedPrincipalsFile:
1573 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001574 arg = strdelim(&cp);
1575 if (!arg || *arg == '\0')
1576 fatal("%s line %d: missing file name.",
1577 filename, linenum);
1578 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001579 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001580 /* increase optional counter */
1581 if (intptr != NULL)
1582 *intptr = *intptr + 1;
1583 }
1584 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001585
1586 case sClientAliveInterval:
1587 intptr = &options->client_alive_interval;
1588 goto parse_time;
1589
1590 case sClientAliveCountMax:
1591 intptr = &options->client_alive_count_max;
1592 goto parse_int;
1593
Darren Tucker46bc0752004-05-02 22:11:30 +10001594 case sAcceptEnv:
1595 while ((arg = strdelim(&cp)) && *arg != '\0') {
1596 if (strchr(arg, '=') != NULL)
1597 fatal("%s line %d: Invalid environment name.",
1598 filename, linenum);
1599 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1600 fatal("%s line %d: too many allow env.",
1601 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001602 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001603 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001604 options->accept_env[options->num_accept_env++] =
1605 xstrdup(arg);
1606 }
1607 break;
1608
Damien Millerd27b9472005-12-13 19:29:02 +11001609 case sPermitTunnel:
1610 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001611 arg = strdelim(&cp);
1612 if (!arg || *arg == '\0')
1613 fatal("%s line %d: Missing yes/point-to-point/"
1614 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001615 value = -1;
1616 for (i = 0; tunmode_desc[i].val != -1; i++)
1617 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1618 value = tunmode_desc[i].val;
1619 break;
1620 }
1621 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001622 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1623 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001624 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001625 *intptr = value;
1626 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001627
Darren Tucker45150472006-07-12 22:34:17 +10001628 case sMatch:
1629 if (cmdline)
1630 fatal("Match directive not supported as a command-line "
1631 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001632 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001633 if (value < 0)
1634 fatal("%s line %d: Bad Match condition", filename,
1635 linenum);
1636 *activep = value;
1637 break;
1638
Damien Miller9b439df2006-07-24 14:04:00 +10001639 case sPermitOpen:
1640 arg = strdelim(&cp);
1641 if (!arg || *arg == '\0')
1642 fatal("%s line %d: missing PermitOpen specification",
1643 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001644 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001645 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001646 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001647 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001648 options->num_permitted_opens = 0;
1649 }
Damien Miller9b439df2006-07-24 14:04:00 +10001650 break;
1651 }
Damien Millerc6081482012-04-22 11:18:53 +10001652 if (strcmp(arg, "none") == 0) {
1653 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001654 options->num_permitted_opens = 1;
1655 channel_disable_adm_local_opens();
1656 }
1657 break;
1658 }
Damien Millera29b95e2007-01-05 16:28:36 +11001659 if (*activep && n == -1)
1660 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001661 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1662 p = hpdelim(&arg);
1663 if (p == NULL)
1664 fatal("%s line %d: missing host in PermitOpen",
1665 filename, linenum);
1666 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001667 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001668 fatal("%s line %d: bad port number in "
1669 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001670 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001671 options->num_permitted_opens =
1672 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001673 }
Damien Miller9b439df2006-07-24 14:04:00 +10001674 break;
1675
Damien Millere2754432006-07-24 14:06:47 +10001676 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001677 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001678 fatal("%.200s line %d: Missing argument.", filename,
1679 linenum);
1680 len = strspn(cp, WHITESPACE);
1681 if (*activep && options->adm_forced_command == NULL)
1682 options->adm_forced_command = xstrdup(cp + len);
1683 return 0;
1684
Damien Millerd8cb1f12008-02-10 22:40:12 +11001685 case sChrootDirectory:
1686 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001687
1688 arg = strdelim(&cp);
1689 if (!arg || *arg == '\0')
1690 fatal("%s line %d: missing file name.",
1691 filename, linenum);
1692 if (*activep && *charptr == NULL)
1693 *charptr = xstrdup(arg);
1694 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001695
Damien Miller1aed65e2010-03-04 21:53:35 +11001696 case sTrustedUserCAKeys:
1697 charptr = &options->trusted_user_ca_keys;
1698 goto parse_filename;
1699
1700 case sRevokedKeys:
1701 charptr = &options->revoked_keys_file;
1702 goto parse_filename;
1703
Damien Miller0dac6fb2010-11-20 15:19:38 +11001704 case sIPQoS:
1705 arg = strdelim(&cp);
1706 if ((value = parse_ipqos(arg)) == -1)
1707 fatal("%s line %d: Bad IPQoS value: %s",
1708 filename, linenum, arg);
1709 arg = strdelim(&cp);
1710 if (arg == NULL)
1711 value2 = value;
1712 else if ((value2 = parse_ipqos(arg)) == -1)
1713 fatal("%s line %d: Bad IPQoS value: %s",
1714 filename, linenum, arg);
1715 if (*activep) {
1716 options->ip_qos_interactive = value;
1717 options->ip_qos_bulk = value2;
1718 }
1719 break;
1720
Damien Miller23528812012-04-22 11:24:43 +10001721 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001722 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001723 fatal("%.200s line %d: Missing argument.", filename,
1724 linenum);
1725 len = strspn(cp, WHITESPACE);
1726 if (*activep && options->version_addendum == NULL) {
1727 if (strcasecmp(cp + len, "none") == 0)
1728 options->version_addendum = xstrdup("");
1729 else if (strchr(cp + len, '\r') != NULL)
1730 fatal("%.200s line %d: Invalid argument",
1731 filename, linenum);
1732 else
1733 options->version_addendum = xstrdup(cp + len);
1734 }
1735 return 0;
1736
Damien Miller09d3e122012-10-31 08:58:58 +11001737 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001738 if (cp == NULL)
1739 fatal("%.200s line %d: Missing argument.", filename,
1740 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001741 len = strspn(cp, WHITESPACE);
1742 if (*activep && options->authorized_keys_command == NULL) {
1743 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1744 fatal("%.200s line %d: AuthorizedKeysCommand "
1745 "must be an absolute path",
1746 filename, linenum);
1747 options->authorized_keys_command = xstrdup(cp + len);
1748 }
1749 return 0;
1750
1751 case sAuthorizedKeysCommandUser:
1752 charptr = &options->authorized_keys_command_user;
1753
1754 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001755 if (!arg || *arg == '\0')
1756 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1757 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001758 if (*activep && *charptr == NULL)
1759 *charptr = xstrdup(arg);
1760 break;
1761
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001762 case sAuthorizedPrincipalsCommand:
1763 if (cp == NULL)
1764 fatal("%.200s line %d: Missing argument.", filename,
1765 linenum);
1766 len = strspn(cp, WHITESPACE);
1767 if (*activep &&
1768 options->authorized_principals_command == NULL) {
1769 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1770 fatal("%.200s line %d: "
1771 "AuthorizedPrincipalsCommand must be "
1772 "an absolute path", filename, linenum);
1773 options->authorized_principals_command =
1774 xstrdup(cp + len);
1775 }
1776 return 0;
1777
1778 case sAuthorizedPrincipalsCommandUser:
1779 charptr = &options->authorized_principals_command_user;
1780
1781 arg = strdelim(&cp);
1782 if (!arg || *arg == '\0')
1783 fatal("%s line %d: missing "
1784 "AuthorizedPrincipalsCommandUser argument.",
1785 filename, linenum);
1786 if (*activep && *charptr == NULL)
1787 *charptr = xstrdup(arg);
1788 break;
1789
Damien Millera6e3f012012-11-04 23:21:40 +11001790 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001791 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001792 while ((arg = strdelim(&cp)) && *arg != '\0') {
1793 if (options->num_auth_methods >=
1794 MAX_AUTH_METHODS)
1795 fatal("%s line %d: "
1796 "too many authentication methods.",
1797 filename, linenum);
1798 if (auth2_methods_valid(arg, 0) != 0)
1799 fatal("%s line %d: invalid "
1800 "authentication method list.",
1801 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001802 if (!*activep)
1803 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001804 options->auth_methods[
1805 options->num_auth_methods++] = xstrdup(arg);
1806 }
1807 }
1808 return 0;
1809
Damien Miller7acefbb2014-07-18 14:11:24 +10001810 case sStreamLocalBindMask:
1811 arg = strdelim(&cp);
1812 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001813 fatal("%s line %d: missing StreamLocalBindMask "
1814 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001815 /* Parse mode in octal format */
1816 value = strtol(arg, &p, 8);
1817 if (arg == p || value < 0 || value > 0777)
1818 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001819 if (*activep)
1820 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001821 break;
1822
1823 case sStreamLocalBindUnlink:
1824 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1825 goto parse_flag;
1826
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001827 case sFingerprintHash:
1828 arg = strdelim(&cp);
1829 if (!arg || *arg == '\0')
1830 fatal("%.200s line %d: Missing argument.",
1831 filename, linenum);
1832 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1833 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1834 filename, linenum, arg);
1835 if (*activep)
1836 options->fingerprint_hash = value;
1837 break;
1838
Ben Lindstromade03f62001-12-06 18:22:17 +00001839 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001840 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001841 filename, linenum, arg);
1842 while (arg)
1843 arg = strdelim(&cp);
1844 break;
1845
Damien Millerf9b3feb2003-05-16 11:38:32 +10001846 case sUnsupported:
1847 logit("%s line %d: Unsupported option %s",
1848 filename, linenum, arg);
1849 while (arg)
1850 arg = strdelim(&cp);
1851 break;
1852
Ben Lindstromade03f62001-12-06 18:22:17 +00001853 default:
1854 fatal("%s line %d: Missing handler for opcode %s (%d)",
1855 filename, linenum, arg, opcode);
1856 }
1857 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1858 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1859 filename, linenum, arg);
1860 return 0;
1861}
1862
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001863/* Reads the server configuration file. */
1864
Damien Miller4af51302000-04-16 11:18:38 +10001865void
Darren Tucker645ab752004-06-25 13:33:20 +10001866load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001867{
Damien Miller46cb75a2012-07-31 12:22:37 +10001868 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001869 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001870 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001871
Darren Tucker645ab752004-06-25 13:33:20 +10001872 debug2("%s: filename %s", __func__, filename);
1873 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001874 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001875 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001876 }
Darren Tucker645ab752004-06-25 13:33:20 +10001877 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001878 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001879 lineno++;
1880 if (strlen(line) == sizeof(line) - 1)
1881 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001882 /*
1883 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001884 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001885 * line numbers later for error messages
1886 */
1887 if ((cp = strchr(line, '#')) != NULL)
1888 memcpy(cp, "\n", 2);
1889 cp = line + strspn(line, " \t\r");
1890
1891 buffer_append(conf, cp, strlen(cp));
1892 }
1893 buffer_append(conf, "\0", 1);
1894 fclose(f);
1895 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1896}
1897
1898void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001899parse_server_match_config(ServerOptions *options,
1900 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001901{
Darren Tucker45150472006-07-12 22:34:17 +10001902 ServerOptions mo;
1903
1904 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001905 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001906 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001907}
1908
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001909int parse_server_match_testspec(struct connection_info *ci, char *spec)
1910{
1911 char *p;
1912
1913 while ((p = strsep(&spec, ",")) && *p != '\0') {
1914 if (strncmp(p, "addr=", 5) == 0) {
1915 ci->address = xstrdup(p + 5);
1916 } else if (strncmp(p, "host=", 5) == 0) {
1917 ci->host = xstrdup(p + 5);
1918 } else if (strncmp(p, "user=", 5) == 0) {
1919 ci->user = xstrdup(p + 5);
1920 } else if (strncmp(p, "laddr=", 6) == 0) {
1921 ci->laddress = xstrdup(p + 6);
1922 } else if (strncmp(p, "lport=", 6) == 0) {
1923 ci->lport = a2port(p + 6);
1924 if (ci->lport == -1) {
1925 fprintf(stderr, "Invalid port '%s' in test mode"
1926 " specification %s\n", p+6, p);
1927 return -1;
1928 }
1929 } else {
1930 fprintf(stderr, "Invalid test mode specification %s\n",
1931 p);
1932 return -1;
1933 }
1934 }
1935 return 0;
1936}
1937
1938/*
1939 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1940 * empty spec.
1941 */
1942int server_match_spec_complete(struct connection_info *ci)
1943{
1944 if (ci->user && ci->host && ci->address)
1945 return 1; /* complete */
1946 if (!ci->user && !ci->host && !ci->address)
1947 return -1; /* empty */
1948 return 0; /* partial */
1949}
1950
Darren Tucker1629c072007-02-19 22:25:37 +11001951/*
1952 * Copy any supported values that are set.
1953 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001954 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001955 * array values that are not used pre-authentication, because any that we
1956 * do use must be explictly sent in mm_getpwnamallow().
1957 */
Darren Tucker45150472006-07-12 22:34:17 +10001958void
Darren Tucker1629c072007-02-19 22:25:37 +11001959copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001960{
Damien Miller534b2cc2013-12-05 14:07:27 +11001961#define M_CP_INTOPT(n) do {\
1962 if (src->n != -1) \
1963 dst->n = src->n; \
1964} while (0)
1965
Darren Tucker1629c072007-02-19 22:25:37 +11001966 M_CP_INTOPT(password_authentication);
1967 M_CP_INTOPT(gss_authentication);
1968 M_CP_INTOPT(rsa_authentication);
1969 M_CP_INTOPT(pubkey_authentication);
1970 M_CP_INTOPT(kerberos_authentication);
1971 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001972 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001973 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001974 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001975 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001976
1977 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001978 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001979 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001980 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001981 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001982 M_CP_INTOPT(x11_display_offset);
1983 M_CP_INTOPT(x11_forwarding);
1984 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001985 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001986 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001987 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001988 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001989 M_CP_INTOPT(ip_qos_interactive);
1990 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001991 M_CP_INTOPT(rekey_limit);
1992 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001993
Damien Miller534b2cc2013-12-05 14:07:27 +11001994 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1995#define M_CP_STROPT(n) do {\
1996 if (src->n != NULL && dst->n != src->n) { \
1997 free(dst->n); \
1998 dst->n = src->n; \
1999 } \
2000} while(0)
2001#define M_CP_STRARRAYOPT(n, num_n) do {\
2002 if (src->num_n != 0) { \
2003 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2004 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2005 } \
2006} while(0)
2007
Damien Millerf2e407e2011-05-20 19:04:14 +10002008 /* See comment in servconf.h */
2009 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002010
Damien Millerc2411902011-05-20 19:03:49 +10002011 /*
2012 * The only things that should be below this point are string options
2013 * which are only used after authentication.
2014 */
Damien Miller5d74e582011-05-20 19:03:31 +10002015 if (preauth)
2016 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002017
Damien Miller5d74e582011-05-20 19:03:31 +10002018 M_CP_STROPT(adm_forced_command);
2019 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10002020}
2021
Darren Tucker1629c072007-02-19 22:25:37 +11002022#undef M_CP_INTOPT
2023#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002024#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002025
Darren Tucker45150472006-07-12 22:34:17 +10002026void
2027parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002028 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002029{
2030 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002031 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002032
2033 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2034
Darren Tucker9fbac712004-08-12 22:41:44 +10002035 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002036 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002037 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002038 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002039 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002040 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002041 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002042 }
Darren Tuckera627d422013-06-02 07:31:17 +10002043 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002044 if (bad_options > 0)
2045 fatal("%s: terminating, %d bad configuration options",
2046 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002047 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002048}
Darren Tuckere7140f22008-06-10 23:01:51 +10002049
2050static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002051fmt_multistate_int(int val, const struct multistate *m)
2052{
2053 u_int i;
2054
2055 for (i = 0; m[i].key != NULL; i++) {
2056 if (m[i].value == val)
2057 return m[i].key;
2058 }
2059 return "UNKNOWN";
2060}
2061
2062static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002063fmt_intarg(ServerOpCodes code, int val)
2064{
Damien Miller82c55872011-06-23 08:20:30 +10002065 if (val == -1)
2066 return "unset";
2067 switch (code) {
2068 case sAddressFamily:
2069 return fmt_multistate_int(val, multistate_addressfamily);
2070 case sPermitRootLogin:
2071 return fmt_multistate_int(val, multistate_permitrootlogin);
2072 case sGatewayPorts:
2073 return fmt_multistate_int(val, multistate_gatewayports);
2074 case sCompression:
2075 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002076 case sUsePrivilegeSeparation:
2077 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002078 case sAllowTcpForwarding:
2079 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002080 case sAllowStreamLocalForwarding:
2081 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002082 case sFingerprintHash:
2083 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002084 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002085 switch (val) {
2086 case SSH_PROTO_1:
2087 return "1";
2088 case SSH_PROTO_2:
2089 return "2";
2090 case (SSH_PROTO_1|SSH_PROTO_2):
2091 return "2,1";
2092 default:
2093 return "UNKNOWN";
2094 }
Damien Miller82c55872011-06-23 08:20:30 +10002095 default:
2096 switch (val) {
2097 case 0:
2098 return "no";
2099 case 1:
2100 return "yes";
2101 default:
2102 return "UNKNOWN";
2103 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002104 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002105}
2106
2107static const char *
2108lookup_opcode_name(ServerOpCodes code)
2109{
2110 u_int i;
2111
2112 for (i = 0; keywords[i].name != NULL; i++)
2113 if (keywords[i].opcode == code)
2114 return(keywords[i].name);
2115 return "UNKNOWN";
2116}
2117
2118static void
2119dump_cfg_int(ServerOpCodes code, int val)
2120{
2121 printf("%s %d\n", lookup_opcode_name(code), val);
2122}
2123
2124static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002125dump_cfg_oct(ServerOpCodes code, int val)
2126{
2127 printf("%s 0%o\n", lookup_opcode_name(code), val);
2128}
2129
2130static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002131dump_cfg_fmtint(ServerOpCodes code, int val)
2132{
2133 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2134}
2135
2136static void
2137dump_cfg_string(ServerOpCodes code, const char *val)
2138{
2139 if (val == NULL)
2140 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002141 printf("%s %s\n", lookup_opcode_name(code),
2142 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002143}
2144
2145static void
2146dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2147{
2148 u_int i;
2149
2150 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002151 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2152}
2153
2154static void
2155dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2156{
2157 u_int i;
2158
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002159 if (count <= 0)
2160 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002161 printf("%s", lookup_opcode_name(code));
2162 for (i = 0; i < count; i++)
2163 printf(" %s", vals[i]);
2164 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002165}
2166
2167void
2168dump_config(ServerOptions *o)
2169{
2170 u_int i;
2171 int ret;
2172 struct addrinfo *ai;
2173 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002174 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002175
2176 /* these are usually at the top of the config */
2177 for (i = 0; i < o->num_ports; i++)
2178 printf("port %d\n", o->ports[i]);
2179 dump_cfg_fmtint(sProtocol, o->protocol);
2180 dump_cfg_fmtint(sAddressFamily, o->address_family);
2181
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002182 /*
2183 * ListenAddress must be after Port. add_one_listen_addr pushes
2184 * addresses onto a stack, so to maintain ordering we need to
2185 * print these in reverse order.
2186 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002187 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2188 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2189 sizeof(addr), port, sizeof(port),
2190 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2191 error("getnameinfo failed: %.100s",
2192 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2193 strerror(errno));
2194 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002195 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002196 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002197 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2198 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002199 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002200 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2201 addr, port, laddr2);
2202 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002203 }
2204 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002205 printf("%s", laddr1);
2206 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002207
2208 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002209#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002210 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002211#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002212 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2213 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2214 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2215 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2216 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002217 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002218 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2219 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002220 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002221
2222 /* formatted integer arguments */
2223 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2224 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2225 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2226 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2227 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2228 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2229 o->hostbased_uses_name_from_packet_only);
2230 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2231 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002232#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002233 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2234 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2235 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002236# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002237 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002238# endif
2239#endif
2240#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002241 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2242 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002243#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002244 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2245 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2246 o->kbd_interactive_authentication);
2247 dump_cfg_fmtint(sChallengeResponseAuthentication,
2248 o->challenge_response_authentication);
2249 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2250 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2251 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2252 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002253 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002254 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002255 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2256 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2257 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2258 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2259 dump_cfg_fmtint(sUseLogin, o->use_login);
2260 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002261 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002262 dump_cfg_fmtint(sUseDNS, o->use_dns);
2263 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002264 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002265 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002266 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002267 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002268
2269 /* string arguments */
2270 dump_cfg_string(sPidFile, o->pid_file);
2271 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002272 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2273 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002274 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002275 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002276 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002277 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2278 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002279 dump_cfg_string(sAuthorizedPrincipalsFile,
2280 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002281 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2282 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002283 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2284 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002285 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2286 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002287 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002288 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002289 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002290 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2291 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002292 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2293 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002294 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2295 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002296
2297 /* string arguments requiring a lookup */
2298 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2299 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2300
2301 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002302 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2303 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002304 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2305 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002306 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002307 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002308 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2309 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2310 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2311 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2312 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002313 dump_cfg_strarray_oneline(sAuthenticationMethods,
2314 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002315
2316 /* other arguments */
2317 for (i = 0; i < o->num_subsystems; i++)
2318 printf("subsystem %s %s\n", o->subsystem_name[i],
2319 o->subsystem_args[i]);
2320
2321 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2322 o->max_startups_rate, o->max_startups);
2323
2324 for (i = 0; tunmode_desc[i].val != -1; i++)
2325 if (tunmode_desc[i].val == o->permit_tun) {
2326 s = tunmode_desc[i].text;
2327 break;
2328 }
2329 dump_cfg_string(sPermitTunnel, s);
2330
Damien Miller91475862011-05-05 14:14:34 +10002331 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2332 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002333
Damien Millera6d6c1f2013-08-21 02:40:01 +10002334 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2335 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002336
Darren Tuckere7140f22008-06-10 23:01:51 +10002337 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002338}