blob: f06e1748f94fbd08230a6619fe50a29b3a683f50 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
chris@openbsd.org3d5728a2015-07-31 15:38:09 +00002/* $OpenBSD: servconf.c,v 1.279 2015/07/31 15:38:09 chris 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;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +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)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000227 options->permit_root_login = PERMIT_NO_PASSWD;
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;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000262 if (options->hostkeyalgorithms == NULL)
263 options->hostkeyalgorithms = xstrdup(KEX_DEFAULT_PK_ALG);
Damien Miller95def091999-11-25 00:26:21 +1100264 if (options->rsa_authentication == -1)
265 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100266 if (options->pubkey_authentication == -1)
267 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100268 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000269 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100270 if (options->kerberos_or_local_passwd == -1)
271 options->kerberos_or_local_passwd = 1;
272 if (options->kerberos_ticket_cleanup == -1)
273 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100274 if (options->kerberos_get_afs_token == -1)
275 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000276 if (options->gss_authentication == -1)
277 options->gss_authentication = 0;
278 if (options->gss_cleanup_creds == -1)
279 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000280 if (options->gss_strict_acceptor == -1)
281 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100282 if (options->password_authentication == -1)
283 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100284 if (options->kbd_interactive_authentication == -1)
285 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000286 if (options->challenge_response_authentication == -1)
287 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100288 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100289 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000290 if (options->permit_user_env == -1)
291 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100292 if (options->use_login == -1)
293 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000294 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000295 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000296 if (options->rekey_limit == -1)
297 options->rekey_limit = 0;
298 if (options->rekey_interval == -1)
299 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100300 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100301 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000302 if (options->allow_streamlocal_forwarding == -1)
303 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000304 if (options->allow_agent_forwarding == -1)
305 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000306 if (options->fwd_opts.gateway_ports == -1)
307 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000308 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100309 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000310 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100311 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000312 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100313 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000314 if (options->max_authtries == -1)
315 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000316 if (options->max_sessions == -1)
317 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000318 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000319 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000320 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100321 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000322 if (options->client_alive_count_max == -1)
323 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000324 if (options->num_authkeys_files == 0) {
325 options->authorized_keys_files[options->num_authkeys_files++] =
326 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
327 options->authorized_keys_files[options->num_authkeys_files++] =
328 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
329 }
Damien Millerd27b9472005-12-13 19:29:02 +1100330 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100331 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100332 if (options->ip_qos_interactive == -1)
333 options->ip_qos_interactive = IPTOS_LOWDELAY;
334 if (options->ip_qos_bulk == -1)
335 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000336 if (options->version_addendum == NULL)
337 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000338 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
339 options->fwd_opts.streamlocal_bind_mask = 0177;
340 if (options->fwd_opts.streamlocal_bind_unlink == -1)
341 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000342 if (options->fingerprint_hash == -1)
343 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000344
345 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &options->ciphers) != 0 ||
346 kex_assemble_names(KEX_SERVER_MAC, &options->macs) != 0 ||
347 kex_assemble_names(KEX_SERVER_KEX, &options->kex_algorithms) != 0 ||
348 kex_assemble_names(KEX_DEFAULT_PK_ALG,
349 &options->hostbased_key_types) != 0 ||
350 kex_assemble_names(KEX_DEFAULT_PK_ALG,
351 &options->pubkey_key_types) != 0)
352 fatal("%s: kex_assemble_names failed", __func__);
353
Ben Lindstromfb62a692002-06-06 19:47:11 +0000354 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000355 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000356 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000357
djm@openbsd.org161cf412014-12-22 07:55:51 +0000358#define CLEAR_ON_NONE(v) \
359 do { \
360 if (option_clear_or_none(v)) { \
361 free(v); \
362 v = NULL; \
363 } \
364 } while(0)
365 CLEAR_ON_NONE(options->pid_file);
366 CLEAR_ON_NONE(options->xauth_location);
367 CLEAR_ON_NONE(options->banner);
368 CLEAR_ON_NONE(options->trusted_user_ca_keys);
369 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000370 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000371 for (i = 0; i < options->num_host_key_files; i++)
372 CLEAR_ON_NONE(options->host_key_files[i]);
373 for (i = 0; i < options->num_host_cert_files; i++)
374 CLEAR_ON_NONE(options->host_cert_files[i]);
375#undef CLEAR_ON_NONE
376
Tim Rice40017b02002-07-14 13:36:49 -0700377#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000378 if (use_privsep && options->compression == 1) {
379 error("This platform does not support both privilege "
380 "separation and compression");
381 error("Compression disabled");
382 options->compression = 0;
383 }
384#endif
385
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000386}
387
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000388/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100389typedef enum {
390 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100391 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000392 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100393 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000394 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
395 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000396 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100397 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100398 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000399 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100400 sPasswordAuthentication, sKbdInteractiveAuthentication,
401 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000402 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100403 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100404 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000405 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000406 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000407 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000408 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
409 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000410 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000411 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000412 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000413 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000414 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
415 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100416 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100417 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100418 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000419 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000420 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000421 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100422 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000423 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000424 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000425 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000426 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000427} ServerOpCodes;
428
Darren Tucker45150472006-07-12 22:34:17 +1000429#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
430#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
431#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
432
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000433/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100434static struct {
435 const char *name;
436 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000437 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100438} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100439 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000440#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000441 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000442#else
Darren Tucker45150472006-07-12 22:34:17 +1000443 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000444#endif
Darren Tucker45150472006-07-12 22:34:17 +1000445 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100446 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000447 { "port", sPort, SSHCFG_GLOBAL },
448 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
449 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000450 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "pidfile", sPidFile, SSHCFG_GLOBAL },
452 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
453 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
454 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100455 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000456 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
457 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
458 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100459 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
460 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000461 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000462 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000463 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
465 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000466 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000467 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000468#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100469 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000470 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
471 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100472#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000473 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000474#else
Darren Tucker45150472006-07-12 22:34:17 +1000475 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100476#endif
477#else
Darren Tucker1629c072007-02-19 22:25:37 +1100478 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000479 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
480 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
481 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000482#endif
Darren Tucker45150472006-07-12 22:34:17 +1000483 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
484 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000485#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100486 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000487 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000488 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000489#else
Darren Tucker1629c072007-02-19 22:25:37 +1100490 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000491 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000492 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000493#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100494 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
495 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100496 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000497 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
498 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
499 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
500 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
501 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
502 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
503 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
504 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000505 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
506 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
507 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000508 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
509 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100510 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
512 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
513 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000514 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000515 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
516 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
517 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000518 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000519 { "allowusers", sAllowUsers, SSHCFG_ALL },
520 { "denyusers", sDenyUsers, SSHCFG_ALL },
521 { "allowgroups", sAllowGroups, SSHCFG_ALL },
522 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000523 { "ciphers", sCiphers, SSHCFG_GLOBAL },
524 { "macs", sMacs, SSHCFG_GLOBAL },
525 { "protocol", sProtocol, SSHCFG_GLOBAL },
526 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
527 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
528 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000529 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000530 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100531 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000532 { "usedns", sUseDNS, SSHCFG_GLOBAL },
533 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
534 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
535 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
536 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000537 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000538 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000539 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000540 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000541 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100542 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000543 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000544 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000545 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000546 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100547 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100548 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100549 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
550 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000551 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000552 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100553 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100554 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
555 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000556 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
557 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000558 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100559 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000560 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
561 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
562 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000563 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000564 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000565};
566
Darren Tuckere7140f22008-06-10 23:01:51 +1000567static struct {
568 int val;
569 char *text;
570} tunmode_desc[] = {
571 { SSH_TUNMODE_NO, "no" },
572 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
573 { SSH_TUNMODE_ETHERNET, "ethernet" },
574 { SSH_TUNMODE_YES, "yes" },
575 { -1, NULL }
576};
577
Damien Miller5428f641999-11-25 11:54:57 +1100578/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000579 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100580 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581
Damien Miller4af51302000-04-16 11:18:38 +1000582static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100583parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000584 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000585{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000586 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000587
Damien Miller95def091999-11-25 00:26:21 +1100588 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000589 if (strcasecmp(cp, keywords[i].name) == 0) {
590 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100591 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000592 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000593
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000594 error("%s: line %d: Bad configuration option: %s",
595 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100596 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000597}
598
Darren Tucker88b6fb22010-01-13 22:44:29 +1100599char *
600derelativise_path(const char *path)
601{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000602 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100603
djm@openbsd.org161cf412014-12-22 07:55:51 +0000604 if (strcasecmp(path, "none") == 0)
605 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100606 expanded = tilde_expand_filename(path, getuid());
607 if (*expanded == '/')
608 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100609 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100610 fatal("%s: getcwd: %s", __func__, strerror(errno));
611 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000612 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100613 return ret;
614}
615
Ben Lindstrombba81212001-06-25 05:01:22 +0000616static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100617add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100618{
Damien Millereccb9de2005-06-17 12:59:34 +1000619 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100620
Ben Lindstrom19066a12001-04-12 23:39:26 +0000621 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000622 for (i = 0; i < options->num_ports; i++)
623 add_one_listen_addr(options, addr, options->ports[i]);
624 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000625 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000626}
627
Ben Lindstrombba81212001-06-25 05:01:22 +0000628static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100629add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000630{
631 struct addrinfo hints, *ai, *aitop;
632 char strport[NI_MAXSERV];
633 int gaierr;
634
635 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100636 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000637 hints.ai_socktype = SOCK_STREAM;
638 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100639 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000640 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
641 fatal("bad addr or host: %s (%s)",
642 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100643 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000644 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
645 ;
646 ai->ai_next = options->listen_addrs;
647 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100648}
649
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000650/*
651 * Queue a ListenAddress to be processed once we have all of the Ports
652 * and AddressFamily options.
653 */
654static void
655queue_listen_addr(ServerOptions *options, char *addr, int port)
656{
657 options->queued_listen_addrs = xreallocarray(
658 options->queued_listen_addrs, options->num_queued_listens + 1,
659 sizeof(addr));
660 options->queued_listen_ports = xreallocarray(
661 options->queued_listen_ports, options->num_queued_listens + 1,
662 sizeof(port));
663 options->queued_listen_addrs[options->num_queued_listens] =
664 xstrdup(addr);
665 options->queued_listen_ports[options->num_queued_listens] = port;
666 options->num_queued_listens++;
667}
668
669/*
670 * Process queued (text) ListenAddress entries.
671 */
672static void
673process_queued_listen_addrs(ServerOptions *options)
674{
675 u_int i;
676
677 if (options->num_ports == 0)
678 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
679 if (options->address_family == -1)
680 options->address_family = AF_UNSPEC;
681
682 for (i = 0; i < options->num_queued_listens; i++) {
683 add_listen_addr(options, options->queued_listen_addrs[i],
684 options->queued_listen_ports[i]);
685 free(options->queued_listen_addrs[i]);
686 options->queued_listen_addrs[i] = NULL;
687 }
688 free(options->queued_listen_addrs);
689 options->queued_listen_addrs = NULL;
690 free(options->queued_listen_ports);
691 options->queued_listen_ports = NULL;
692 options->num_queued_listens = 0;
693}
694
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695struct connection_info *
696get_connection_info(int populate, int use_dns)
697{
698 static struct connection_info ci;
699
700 if (!populate)
701 return &ci;
702 ci.host = get_canonical_hostname(use_dns);
703 ci.address = get_remote_ipaddr();
704 ci.laddress = get_local_ipaddr(packet_get_connection_in());
705 ci.lport = get_local_port();
706 return &ci;
707}
708
Darren Tucker45150472006-07-12 22:34:17 +1000709/*
710 * The strategy for the Match blocks is that the config file is parsed twice.
711 *
712 * The first time is at startup. activep is initialized to 1 and the
713 * directives in the global context are processed and acted on. Hitting a
714 * Match directive unsets activep and the directives inside the block are
715 * checked for syntax only.
716 *
717 * The second time is after a connection has been established but before
718 * authentication. activep is initialized to 2 and global config directives
719 * are ignored since they have already been processed. If the criteria in a
720 * Match block is met, activep is set and the subsequent directives
721 * processed and actioned until EOF or another Match block unsets it. Any
722 * options set are copied into the main server config.
723 *
724 * Potential additions/improvements:
725 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
726 *
727 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
728 * Match Address 192.168.0.*
729 * Tag trusted
730 * Match Group wheel
731 * Tag trusted
732 * Match Tag trusted
733 * AllowTcpForwarding yes
734 * GatewayPorts clientspecified
735 * [...]
736 *
737 * - Add a PermittedChannelRequests directive
738 * Match Group shell
739 * PermittedChannelRequests session,forwarded-tcpip
740 */
741
742static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000743match_cfg_line_group(const char *grps, int line, const char *user)
744{
745 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000746 struct passwd *pw;
747
Damien Miller565ca3f2006-08-19 00:23:15 +1000748 if (user == NULL)
749 goto out;
750
751 if ((pw = getpwnam(user)) == NULL) {
752 debug("Can't match group at line %d because user %.100s does "
753 "not exist", line, user);
754 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
755 debug("Can't Match group because user %.100s not in any group "
756 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000757 } else if (ga_match_pattern_list(grps) != 1) {
758 debug("user %.100s does not match group list %.100s at line %d",
759 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000760 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000761 debug("user %.100s matched group list %.100s at line %d", user,
762 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000763 result = 1;
764 }
765out:
766 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000767 return result;
768}
769
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000770/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000771 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100772 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000773 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000774 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000775static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000776match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000777{
Damien Millercf31f382013-10-24 21:02:56 +1100778 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000779 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000780
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000781 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000782 debug3("checking syntax for 'Match %s'", cp);
783 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000784 debug3("checking match for '%s' user %s host %s addr %s "
785 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
786 ci->host ? ci->host : "(null)",
787 ci->address ? ci->address : "(null)",
788 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000789
790 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100791 attributes++;
792 if (strcasecmp(attrib, "all") == 0) {
793 if (attributes != 1 ||
794 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
795 error("'all' cannot be combined with other "
796 "Match attributes");
797 return -1;
798 }
799 *condition = cp;
800 return 1;
801 }
Darren Tucker45150472006-07-12 22:34:17 +1000802 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
803 error("Missing Match criteria for %s", attrib);
804 return -1;
805 }
Darren Tucker45150472006-07-12 22:34:17 +1000806 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000807 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000808 result = 0;
809 continue;
810 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000811 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000812 result = 0;
813 else
814 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000815 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000816 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000817 if (ci == NULL || ci->user == NULL) {
818 result = 0;
819 continue;
820 }
821 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000822 case -1:
823 return -1;
824 case 0:
825 result = 0;
826 }
Darren Tucker45150472006-07-12 22:34:17 +1000827 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000828 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000829 result = 0;
830 continue;
831 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000832 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000833 result = 0;
834 else
835 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000836 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000837 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000838 if (ci == NULL || ci->address == NULL) {
839 result = 0;
840 continue;
841 }
842 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000843 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000844 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000845 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000846 break;
847 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000848 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000849 result = 0;
850 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000851 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000852 return -1;
853 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000854 } else if (strcasecmp(attrib, "localaddress") == 0){
855 if (ci == NULL || ci->laddress == NULL) {
856 result = 0;
857 continue;
858 }
859 switch (addr_match_list(ci->laddress, arg)) {
860 case 1:
861 debug("connection from %.100s matched "
862 "'LocalAddress %.100s' at line %d",
863 ci->laddress, arg, line);
864 break;
865 case 0:
866 case -1:
867 result = 0;
868 break;
869 case -2:
870 return -1;
871 }
872 } else if (strcasecmp(attrib, "localport") == 0) {
873 if ((port = a2port(arg)) == -1) {
874 error("Invalid LocalPort '%s' on Match line",
875 arg);
876 return -1;
877 }
878 if (ci == NULL || ci->lport == 0) {
879 result = 0;
880 continue;
881 }
882 /* TODO support port lists */
883 if (port == ci->lport)
884 debug("connection from %.100s matched "
885 "'LocalPort %d' at line %d",
886 ci->laddress, port, line);
887 else
888 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000889 } else {
890 error("Unsupported Match attribute %s", attrib);
891 return -1;
892 }
893 }
Damien Millercf31f382013-10-24 21:02:56 +1100894 if (attributes == 0) {
895 error("One or more attributes required for Match");
896 return -1;
897 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000898 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000899 debug3("match %sfound", result ? "" : "not ");
900 *condition = cp;
901 return result;
902}
903
Damien Millere2754432006-07-24 14:06:47 +1000904#define WHITESPACE " \t\r\n"
905
Damien Miller33322122011-06-20 14:43:11 +1000906/* Multistate option parsing */
907struct multistate {
908 char *key;
909 int value;
910};
911static const struct multistate multistate_addressfamily[] = {
912 { "inet", AF_INET },
913 { "inet6", AF_INET6 },
914 { "any", AF_UNSPEC },
915 { NULL, -1 }
916};
917static const struct multistate multistate_permitrootlogin[] = {
918 { "without-password", PERMIT_NO_PASSWD },
919 { "forced-commands-only", PERMIT_FORCED_ONLY },
920 { "yes", PERMIT_YES },
921 { "no", PERMIT_NO },
922 { NULL, -1 }
923};
924static const struct multistate multistate_compression[] = {
925 { "delayed", COMP_DELAYED },
926 { "yes", COMP_ZLIB },
927 { "no", COMP_NONE },
928 { NULL, -1 }
929};
930static const struct multistate multistate_gatewayports[] = {
931 { "clientspecified", 2 },
932 { "yes", 1 },
933 { "no", 0 },
934 { NULL, -1 }
935};
Damien Miller69ff1df2011-06-23 08:30:03 +1000936static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000937 { "yes", PRIVSEP_NOSANDBOX },
938 { "sandbox", PRIVSEP_ON },
939 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000940 { "no", PRIVSEP_OFF },
941 { NULL, -1 }
942};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100943static const struct multistate multistate_tcpfwd[] = {
944 { "yes", FORWARD_ALLOW },
945 { "all", FORWARD_ALLOW },
946 { "no", FORWARD_DENY },
947 { "remote", FORWARD_REMOTE },
948 { "local", FORWARD_LOCAL },
949 { NULL, -1 }
950};
Damien Miller33322122011-06-20 14:43:11 +1000951
Ben Lindstromade03f62001-12-06 18:22:17 +0000952int
953process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000954 const char *filename, int linenum, int *activep,
955 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000956{
Darren Tucker09c0f032013-05-16 20:48:57 +1000957 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000958 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100959 SyslogFacility *log_facility_ptr;
960 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000961 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000962 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000963 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000964 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000965 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000966
967 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100968 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100969 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000970 /* Ignore leading whitespace */
971 if (*arg == '\0')
972 arg = strdelim(&cp);
973 if (!arg || !*arg || *arg == '#')
974 return 0;
975 intptr = NULL;
976 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000977 opcode = parse_token(arg, filename, linenum, &flags);
978
979 if (activep == NULL) { /* We are processing a command line directive */
980 cmdline = 1;
981 activep = &cmdline;
982 }
983 if (*activep && opcode != sMatch)
984 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
985 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000986 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000987 fatal("%s line %d: Directive '%s' is not allowed "
988 "within a Match block", filename, linenum, arg);
989 } else { /* this is a directive we have already processed */
990 while (arg)
991 arg = strdelim(&cp);
992 return 0;
993 }
994 }
995
Ben Lindstromade03f62001-12-06 18:22:17 +0000996 switch (opcode) {
997 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000998 case sUsePAM:
999 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001000 goto parse_flag;
1001
1002 /* Standard Options */
1003 case sBadOption:
1004 return -1;
1005 case sPort:
1006 /* ignore ports from configfile if cmdline specifies ports */
1007 if (options->ports_from_cmdline)
1008 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001009 if (options->num_ports >= MAX_PORTS)
1010 fatal("%s line %d: too many ports.",
1011 filename, linenum);
1012 arg = strdelim(&cp);
1013 if (!arg || *arg == '\0')
1014 fatal("%s line %d: missing port number.",
1015 filename, linenum);
1016 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001017 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001018 fatal("%s line %d: Badly formatted port number.",
1019 filename, linenum);
1020 break;
1021
1022 case sServerKeyBits:
1023 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001024 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001025 arg = strdelim(&cp);
1026 if (!arg || *arg == '\0')
1027 fatal("%s line %d: missing integer value.",
1028 filename, linenum);
1029 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001030 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001031 *intptr = value;
1032 break;
1033
1034 case sLoginGraceTime:
1035 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001036 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001037 arg = strdelim(&cp);
1038 if (!arg || *arg == '\0')
1039 fatal("%s line %d: missing time value.",
1040 filename, linenum);
1041 if ((value = convtime(arg)) == -1)
1042 fatal("%s line %d: invalid time value.",
1043 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001044 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001045 *intptr = value;
1046 break;
1047
1048 case sKeyRegenerationTime:
1049 intptr = &options->key_regeneration_time;
1050 goto parse_time;
1051
1052 case sListenAddress:
1053 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001054 if (arg == NULL || *arg == '\0')
1055 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001056 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001057 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1058 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1059 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001060 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001061 break;
1062 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001063 p = hpdelim(&arg);
1064 if (p == NULL)
1065 fatal("%s line %d: bad address:port usage",
1066 filename, linenum);
1067 p = cleanhostname(p);
1068 if (arg == NULL)
1069 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001070 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001071 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001072
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001073 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001074
Ben Lindstromade03f62001-12-06 18:22:17 +00001075 break;
1076
Darren Tucker0f383232005-01-20 10:57:56 +11001077 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001078 intptr = &options->address_family;
1079 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001080 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001081 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001082 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001083 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001084 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001085 value = -1;
1086 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1087 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1088 value = multistate_ptr[i].value;
1089 break;
1090 }
1091 }
1092 if (value == -1)
1093 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001094 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001095 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001096 *intptr = value;
1097 break;
1098
Ben Lindstromade03f62001-12-06 18:22:17 +00001099 case sHostKeyFile:
1100 intptr = &options->num_host_key_files;
1101 if (*intptr >= MAX_HOSTKEYS)
1102 fatal("%s line %d: too many host keys specified (max %d).",
1103 filename, linenum, MAX_HOSTKEYS);
1104 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001105 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001106 arg = strdelim(&cp);
1107 if (!arg || *arg == '\0')
1108 fatal("%s line %d: missing file name.",
1109 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001110 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001111 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001112 /* increase optional counter */
1113 if (intptr != NULL)
1114 *intptr = *intptr + 1;
1115 }
1116 break;
1117
Damien Miller85b45e02013-07-20 13:21:52 +10001118 case sHostKeyAgent:
1119 charptr = &options->host_key_agent;
1120 arg = strdelim(&cp);
1121 if (!arg || *arg == '\0')
1122 fatal("%s line %d: missing socket name.",
1123 filename, linenum);
1124 if (*activep && *charptr == NULL)
1125 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1126 xstrdup(arg) : derelativise_path(arg);
1127 break;
1128
Damien Miller0a80ca12010-02-27 07:55:05 +11001129 case sHostCertificate:
1130 intptr = &options->num_host_cert_files;
1131 if (*intptr >= MAX_HOSTKEYS)
1132 fatal("%s line %d: too many host certificates "
1133 "specified (max %d).", filename, linenum,
1134 MAX_HOSTCERTS);
1135 charptr = &options->host_cert_files[*intptr];
1136 goto parse_filename;
1137 break;
1138
Ben Lindstromade03f62001-12-06 18:22:17 +00001139 case sPidFile:
1140 charptr = &options->pid_file;
1141 goto parse_filename;
1142
1143 case sPermitRootLogin:
1144 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001145 multistate_ptr = multistate_permitrootlogin;
1146 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001147
1148 case sIgnoreRhosts:
1149 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001150 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001151 arg = strdelim(&cp);
1152 if (!arg || *arg == '\0')
1153 fatal("%s line %d: missing yes/no argument.",
1154 filename, linenum);
1155 value = 0; /* silence compiler */
1156 if (strcmp(arg, "yes") == 0)
1157 value = 1;
1158 else if (strcmp(arg, "no") == 0)
1159 value = 0;
1160 else
1161 fatal("%s line %d: Bad yes/no argument: %s",
1162 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001163 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001164 *intptr = value;
1165 break;
1166
1167 case sIgnoreUserKnownHosts:
1168 intptr = &options->ignore_user_known_hosts;
1169 goto parse_flag;
1170
Ben Lindstromade03f62001-12-06 18:22:17 +00001171 case sRhostsRSAAuthentication:
1172 intptr = &options->rhosts_rsa_authentication;
1173 goto parse_flag;
1174
1175 case sHostbasedAuthentication:
1176 intptr = &options->hostbased_authentication;
1177 goto parse_flag;
1178
1179 case sHostbasedUsesNameFromPacketOnly:
1180 intptr = &options->hostbased_uses_name_from_packet_only;
1181 goto parse_flag;
1182
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001183 case sHostbasedAcceptedKeyTypes:
1184 charptr = &options->hostbased_key_types;
1185 parse_keytypes:
1186 arg = strdelim(&cp);
1187 if (!arg || *arg == '\0')
1188 fatal("%s line %d: Missing argument.",
1189 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001190 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001191 fatal("%s line %d: Bad key types '%s'.",
1192 filename, linenum, arg ? arg : "<NONE>");
1193 if (*activep && *charptr == NULL)
1194 *charptr = xstrdup(arg);
1195 break;
1196
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001197 case sHostKeyAlgorithms:
1198 charptr = &options->hostkeyalgorithms;
1199 goto parse_keytypes;
1200
Ben Lindstromade03f62001-12-06 18:22:17 +00001201 case sRSAAuthentication:
1202 intptr = &options->rsa_authentication;
1203 goto parse_flag;
1204
1205 case sPubkeyAuthentication:
1206 intptr = &options->pubkey_authentication;
1207 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001208
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001209 case sPubkeyAcceptedKeyTypes:
1210 charptr = &options->pubkey_key_types;
1211 goto parse_keytypes;
1212
Ben Lindstromade03f62001-12-06 18:22:17 +00001213 case sKerberosAuthentication:
1214 intptr = &options->kerberos_authentication;
1215 goto parse_flag;
1216
1217 case sKerberosOrLocalPasswd:
1218 intptr = &options->kerberos_or_local_passwd;
1219 goto parse_flag;
1220
1221 case sKerberosTicketCleanup:
1222 intptr = &options->kerberos_ticket_cleanup;
1223 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001224
Darren Tucker22ef5082003-12-31 11:37:34 +11001225 case sKerberosGetAFSToken:
1226 intptr = &options->kerberos_get_afs_token;
1227 goto parse_flag;
1228
Darren Tucker0efd1552003-08-26 11:49:55 +10001229 case sGssAuthentication:
1230 intptr = &options->gss_authentication;
1231 goto parse_flag;
1232
1233 case sGssCleanupCreds:
1234 intptr = &options->gss_cleanup_creds;
1235 goto parse_flag;
1236
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001237 case sGssStrictAcceptor:
1238 intptr = &options->gss_strict_acceptor;
1239 goto parse_flag;
1240
Ben Lindstromade03f62001-12-06 18:22:17 +00001241 case sPasswordAuthentication:
1242 intptr = &options->password_authentication;
1243 goto parse_flag;
1244
1245 case sKbdInteractiveAuthentication:
1246 intptr = &options->kbd_interactive_authentication;
1247 goto parse_flag;
1248
1249 case sChallengeResponseAuthentication:
1250 intptr = &options->challenge_response_authentication;
1251 goto parse_flag;
1252
1253 case sPrintMotd:
1254 intptr = &options->print_motd;
1255 goto parse_flag;
1256
1257 case sPrintLastLog:
1258 intptr = &options->print_lastlog;
1259 goto parse_flag;
1260
1261 case sX11Forwarding:
1262 intptr = &options->x11_forwarding;
1263 goto parse_flag;
1264
1265 case sX11DisplayOffset:
1266 intptr = &options->x11_display_offset;
1267 goto parse_int;
1268
Damien Miller95c249f2002-02-05 12:11:34 +11001269 case sX11UseLocalhost:
1270 intptr = &options->x11_use_localhost;
1271 goto parse_flag;
1272
Ben Lindstromade03f62001-12-06 18:22:17 +00001273 case sXAuthLocation:
1274 charptr = &options->xauth_location;
1275 goto parse_filename;
1276
Damien Miller5ff30c62013-10-30 22:21:50 +11001277 case sPermitTTY:
1278 intptr = &options->permit_tty;
1279 goto parse_flag;
1280
Damien Miller72e6b5c2014-07-04 09:00:04 +10001281 case sPermitUserRC:
1282 intptr = &options->permit_user_rc;
1283 goto parse_flag;
1284
Ben Lindstromade03f62001-12-06 18:22:17 +00001285 case sStrictModes:
1286 intptr = &options->strict_modes;
1287 goto parse_flag;
1288
Damien Miller12c150e2003-12-17 16:31:10 +11001289 case sTCPKeepAlive:
1290 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001291 goto parse_flag;
1292
1293 case sEmptyPasswd:
1294 intptr = &options->permit_empty_passwd;
1295 goto parse_flag;
1296
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001297 case sPermitUserEnvironment:
1298 intptr = &options->permit_user_env;
1299 goto parse_flag;
1300
Ben Lindstromade03f62001-12-06 18:22:17 +00001301 case sUseLogin:
1302 intptr = &options->use_login;
1303 goto parse_flag;
1304
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001305 case sCompression:
1306 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001307 multistate_ptr = multistate_compression;
1308 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001309
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001310 case sRekeyLimit:
1311 arg = strdelim(&cp);
1312 if (!arg || *arg == '\0')
1313 fatal("%.200s line %d: Missing argument.", filename,
1314 linenum);
1315 if (strcmp(arg, "default") == 0) {
1316 val64 = 0;
1317 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001318 if (scan_scaled(arg, &val64) == -1)
1319 fatal("%.200s line %d: Bad number '%s': %s",
1320 filename, linenum, arg, strerror(errno));
1321 /* check for too-large or too-small limits */
1322 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001323 fatal("%.200s line %d: RekeyLimit too large",
1324 filename, linenum);
1325 if (val64 != 0 && val64 < 16)
1326 fatal("%.200s line %d: RekeyLimit too small",
1327 filename, linenum);
1328 }
1329 if (*activep && options->rekey_limit == -1)
1330 options->rekey_limit = (u_int32_t)val64;
1331 if (cp != NULL) { /* optional rekey interval present */
1332 if (strcmp(cp, "none") == 0) {
1333 (void)strdelim(&cp); /* discard */
1334 break;
1335 }
1336 intptr = &options->rekey_interval;
1337 goto parse_time;
1338 }
1339 break;
1340
Ben Lindstromade03f62001-12-06 18:22:17 +00001341 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001342 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001343 multistate_ptr = multistate_gatewayports;
1344 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001345
Damien Miller3a961dc2003-06-03 10:25:48 +10001346 case sUseDNS:
1347 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001348 goto parse_flag;
1349
1350 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001351 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001352 arg = strdelim(&cp);
1353 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001354 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001355 fatal("%.200s line %d: unsupported log facility '%s'",
1356 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001357 if (*log_facility_ptr == -1)
1358 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001359 break;
1360
1361 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001362 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001363 arg = strdelim(&cp);
1364 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001365 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001366 fatal("%.200s line %d: unsupported log level '%s'",
1367 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001368 if (*log_level_ptr == -1)
1369 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001370 break;
1371
1372 case sAllowTcpForwarding:
1373 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001374 multistate_ptr = multistate_tcpfwd;
1375 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001376
Damien Miller7acefbb2014-07-18 14:11:24 +10001377 case sAllowStreamLocalForwarding:
1378 intptr = &options->allow_streamlocal_forwarding;
1379 multistate_ptr = multistate_tcpfwd;
1380 goto parse_multistate;
1381
Damien Miller4f755cd2008-05-19 14:57:41 +10001382 case sAllowAgentForwarding:
1383 intptr = &options->allow_agent_forwarding;
1384 goto parse_flag;
1385
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001386 case sUsePrivilegeSeparation:
1387 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001388 multistate_ptr = multistate_privsep;
1389 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001390
Ben Lindstromade03f62001-12-06 18:22:17 +00001391 case sAllowUsers:
1392 while ((arg = strdelim(&cp)) && *arg != '\0') {
1393 if (options->num_allow_users >= MAX_ALLOW_USERS)
1394 fatal("%s line %d: too many allow users.",
1395 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001396 if (!*activep)
1397 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001398 options->allow_users[options->num_allow_users++] =
1399 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001400 }
1401 break;
1402
1403 case sDenyUsers:
1404 while ((arg = strdelim(&cp)) && *arg != '\0') {
1405 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001406 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001407 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001408 if (!*activep)
1409 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001410 options->deny_users[options->num_deny_users++] =
1411 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001412 }
1413 break;
1414
1415 case sAllowGroups:
1416 while ((arg = strdelim(&cp)) && *arg != '\0') {
1417 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1418 fatal("%s line %d: too many allow groups.",
1419 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001420 if (!*activep)
1421 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001422 options->allow_groups[options->num_allow_groups++] =
1423 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001424 }
1425 break;
1426
1427 case sDenyGroups:
1428 while ((arg = strdelim(&cp)) && *arg != '\0') {
1429 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1430 fatal("%s line %d: too many deny groups.",
1431 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001432 if (!*activep)
1433 continue;
1434 options->deny_groups[options->num_deny_groups++] =
1435 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001436 }
1437 break;
1438
1439 case sCiphers:
1440 arg = strdelim(&cp);
1441 if (!arg || *arg == '\0')
1442 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001443 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001444 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1445 filename, linenum, arg ? arg : "<NONE>");
1446 if (options->ciphers == NULL)
1447 options->ciphers = xstrdup(arg);
1448 break;
1449
1450 case sMacs:
1451 arg = strdelim(&cp);
1452 if (!arg || *arg == '\0')
1453 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001454 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001455 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1456 filename, linenum, arg ? arg : "<NONE>");
1457 if (options->macs == NULL)
1458 options->macs = xstrdup(arg);
1459 break;
1460
Damien Millerd5f62bf2010-09-24 22:11:14 +10001461 case sKexAlgorithms:
1462 arg = strdelim(&cp);
1463 if (!arg || *arg == '\0')
1464 fatal("%s line %d: Missing argument.",
1465 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001466 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001467 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1468 filename, linenum, arg ? arg : "<NONE>");
1469 if (options->kex_algorithms == NULL)
1470 options->kex_algorithms = xstrdup(arg);
1471 break;
1472
Ben Lindstromade03f62001-12-06 18:22:17 +00001473 case sProtocol:
1474 intptr = &options->protocol;
1475 arg = strdelim(&cp);
1476 if (!arg || *arg == '\0')
1477 fatal("%s line %d: Missing argument.", filename, linenum);
1478 value = proto_spec(arg);
1479 if (value == SSH_PROTO_UNKNOWN)
1480 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001481 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001482 if (*intptr == SSH_PROTO_UNKNOWN)
1483 *intptr = value;
1484 break;
1485
1486 case sSubsystem:
1487 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1488 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001489 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001490 }
1491 arg = strdelim(&cp);
1492 if (!arg || *arg == '\0')
1493 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001494 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001495 if (!*activep) {
1496 arg = strdelim(&cp);
1497 break;
1498 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001499 for (i = 0; i < options->num_subsystems; i++)
1500 if (strcmp(arg, options->subsystem_name[i]) == 0)
1501 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001502 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001503 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1504 arg = strdelim(&cp);
1505 if (!arg || *arg == '\0')
1506 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001507 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001508 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001509
1510 /* Collect arguments (separate to executable) */
1511 p = xstrdup(arg);
1512 len = strlen(p) + 1;
1513 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1514 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001515 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001516 strlcat(p, " ", len);
1517 strlcat(p, arg, len);
1518 }
1519 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001520 options->num_subsystems++;
1521 break;
1522
1523 case sMaxStartups:
1524 arg = strdelim(&cp);
1525 if (!arg || *arg == '\0')
1526 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001527 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001528 if ((n = sscanf(arg, "%d:%d:%d",
1529 &options->max_startups_begin,
1530 &options->max_startups_rate,
1531 &options->max_startups)) == 3) {
1532 if (options->max_startups_begin >
1533 options->max_startups ||
1534 options->max_startups_rate > 100 ||
1535 options->max_startups_rate < 1)
1536 fatal("%s line %d: Illegal MaxStartups spec.",
1537 filename, linenum);
1538 } else if (n != 1)
1539 fatal("%s line %d: Illegal MaxStartups spec.",
1540 filename, linenum);
1541 else
1542 options->max_startups = options->max_startups_begin;
1543 break;
1544
Darren Tucker89413db2004-05-24 10:36:23 +10001545 case sMaxAuthTries:
1546 intptr = &options->max_authtries;
1547 goto parse_int;
1548
Damien Miller7207f642008-05-19 15:34:50 +10001549 case sMaxSessions:
1550 intptr = &options->max_sessions;
1551 goto parse_int;
1552
Ben Lindstromade03f62001-12-06 18:22:17 +00001553 case sBanner:
1554 charptr = &options->banner;
1555 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001556
Ben Lindstromade03f62001-12-06 18:22:17 +00001557 /*
1558 * These options can contain %X options expanded at
1559 * connect time, so that you can specify paths like:
1560 *
1561 * AuthorizedKeysFile /etc/ssh_keys/%u
1562 */
1563 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001564 if (*activep && options->num_authkeys_files == 0) {
1565 while ((arg = strdelim(&cp)) && *arg != '\0') {
1566 if (options->num_authkeys_files >=
1567 MAX_AUTHKEYS_FILES)
1568 fatal("%s line %d: "
1569 "too many authorized keys files.",
1570 filename, linenum);
1571 options->authorized_keys_files[
1572 options->num_authkeys_files++] =
1573 tilde_expand_filename(arg, getuid());
1574 }
1575 }
1576 return 0;
1577
Damien Miller30da3442010-05-10 11:58:03 +10001578 case sAuthorizedPrincipalsFile:
1579 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001580 arg = strdelim(&cp);
1581 if (!arg || *arg == '\0')
1582 fatal("%s line %d: missing file name.",
1583 filename, linenum);
1584 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001585 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001586 /* increase optional counter */
1587 if (intptr != NULL)
1588 *intptr = *intptr + 1;
1589 }
1590 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001591
1592 case sClientAliveInterval:
1593 intptr = &options->client_alive_interval;
1594 goto parse_time;
1595
1596 case sClientAliveCountMax:
1597 intptr = &options->client_alive_count_max;
1598 goto parse_int;
1599
Darren Tucker46bc0752004-05-02 22:11:30 +10001600 case sAcceptEnv:
1601 while ((arg = strdelim(&cp)) && *arg != '\0') {
1602 if (strchr(arg, '=') != NULL)
1603 fatal("%s line %d: Invalid environment name.",
1604 filename, linenum);
1605 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1606 fatal("%s line %d: too many allow env.",
1607 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001608 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001609 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001610 options->accept_env[options->num_accept_env++] =
1611 xstrdup(arg);
1612 }
1613 break;
1614
Damien Millerd27b9472005-12-13 19:29:02 +11001615 case sPermitTunnel:
1616 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001617 arg = strdelim(&cp);
1618 if (!arg || *arg == '\0')
1619 fatal("%s line %d: Missing yes/point-to-point/"
1620 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001621 value = -1;
1622 for (i = 0; tunmode_desc[i].val != -1; i++)
1623 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1624 value = tunmode_desc[i].val;
1625 break;
1626 }
1627 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001628 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1629 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001630 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001631 *intptr = value;
1632 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001633
Darren Tucker45150472006-07-12 22:34:17 +10001634 case sMatch:
1635 if (cmdline)
1636 fatal("Match directive not supported as a command-line "
1637 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001638 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001639 if (value < 0)
1640 fatal("%s line %d: Bad Match condition", filename,
1641 linenum);
1642 *activep = value;
1643 break;
1644
Damien Miller9b439df2006-07-24 14:04:00 +10001645 case sPermitOpen:
1646 arg = strdelim(&cp);
1647 if (!arg || *arg == '\0')
1648 fatal("%s line %d: missing PermitOpen specification",
1649 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001650 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001651 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001652 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001653 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001654 options->num_permitted_opens = 0;
1655 }
Damien Miller9b439df2006-07-24 14:04:00 +10001656 break;
1657 }
Damien Millerc6081482012-04-22 11:18:53 +10001658 if (strcmp(arg, "none") == 0) {
1659 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001660 options->num_permitted_opens = 1;
1661 channel_disable_adm_local_opens();
1662 }
1663 break;
1664 }
Damien Millera29b95e2007-01-05 16:28:36 +11001665 if (*activep && n == -1)
1666 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001667 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1668 p = hpdelim(&arg);
1669 if (p == NULL)
1670 fatal("%s line %d: missing host in PermitOpen",
1671 filename, linenum);
1672 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001673 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001674 fatal("%s line %d: bad port number in "
1675 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001676 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001677 options->num_permitted_opens =
1678 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001679 }
Damien Miller9b439df2006-07-24 14:04:00 +10001680 break;
1681
Damien Millere2754432006-07-24 14:06:47 +10001682 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001683 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001684 fatal("%.200s line %d: Missing argument.", filename,
1685 linenum);
1686 len = strspn(cp, WHITESPACE);
1687 if (*activep && options->adm_forced_command == NULL)
1688 options->adm_forced_command = xstrdup(cp + len);
1689 return 0;
1690
Damien Millerd8cb1f12008-02-10 22:40:12 +11001691 case sChrootDirectory:
1692 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001693
1694 arg = strdelim(&cp);
1695 if (!arg || *arg == '\0')
1696 fatal("%s line %d: missing file name.",
1697 filename, linenum);
1698 if (*activep && *charptr == NULL)
1699 *charptr = xstrdup(arg);
1700 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001701
Damien Miller1aed65e2010-03-04 21:53:35 +11001702 case sTrustedUserCAKeys:
1703 charptr = &options->trusted_user_ca_keys;
1704 goto parse_filename;
1705
1706 case sRevokedKeys:
1707 charptr = &options->revoked_keys_file;
1708 goto parse_filename;
1709
Damien Miller0dac6fb2010-11-20 15:19:38 +11001710 case sIPQoS:
1711 arg = strdelim(&cp);
1712 if ((value = parse_ipqos(arg)) == -1)
1713 fatal("%s line %d: Bad IPQoS value: %s",
1714 filename, linenum, arg);
1715 arg = strdelim(&cp);
1716 if (arg == NULL)
1717 value2 = value;
1718 else if ((value2 = parse_ipqos(arg)) == -1)
1719 fatal("%s line %d: Bad IPQoS value: %s",
1720 filename, linenum, arg);
1721 if (*activep) {
1722 options->ip_qos_interactive = value;
1723 options->ip_qos_bulk = value2;
1724 }
1725 break;
1726
Damien Miller23528812012-04-22 11:24:43 +10001727 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001728 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001729 fatal("%.200s line %d: Missing argument.", filename,
1730 linenum);
1731 len = strspn(cp, WHITESPACE);
1732 if (*activep && options->version_addendum == NULL) {
1733 if (strcasecmp(cp + len, "none") == 0)
1734 options->version_addendum = xstrdup("");
1735 else if (strchr(cp + len, '\r') != NULL)
1736 fatal("%.200s line %d: Invalid argument",
1737 filename, linenum);
1738 else
1739 options->version_addendum = xstrdup(cp + len);
1740 }
1741 return 0;
1742
Damien Miller09d3e122012-10-31 08:58:58 +11001743 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001744 if (cp == NULL)
1745 fatal("%.200s line %d: Missing argument.", filename,
1746 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001747 len = strspn(cp, WHITESPACE);
1748 if (*activep && options->authorized_keys_command == NULL) {
1749 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1750 fatal("%.200s line %d: AuthorizedKeysCommand "
1751 "must be an absolute path",
1752 filename, linenum);
1753 options->authorized_keys_command = xstrdup(cp + len);
1754 }
1755 return 0;
1756
1757 case sAuthorizedKeysCommandUser:
1758 charptr = &options->authorized_keys_command_user;
1759
1760 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001761 if (!arg || *arg == '\0')
1762 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1763 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001764 if (*activep && *charptr == NULL)
1765 *charptr = xstrdup(arg);
1766 break;
1767
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001768 case sAuthorizedPrincipalsCommand:
1769 if (cp == NULL)
1770 fatal("%.200s line %d: Missing argument.", filename,
1771 linenum);
1772 len = strspn(cp, WHITESPACE);
1773 if (*activep &&
1774 options->authorized_principals_command == NULL) {
1775 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1776 fatal("%.200s line %d: "
1777 "AuthorizedPrincipalsCommand must be "
1778 "an absolute path", filename, linenum);
1779 options->authorized_principals_command =
1780 xstrdup(cp + len);
1781 }
1782 return 0;
1783
1784 case sAuthorizedPrincipalsCommandUser:
1785 charptr = &options->authorized_principals_command_user;
1786
1787 arg = strdelim(&cp);
1788 if (!arg || *arg == '\0')
1789 fatal("%s line %d: missing "
1790 "AuthorizedPrincipalsCommandUser argument.",
1791 filename, linenum);
1792 if (*activep && *charptr == NULL)
1793 *charptr = xstrdup(arg);
1794 break;
1795
Damien Millera6e3f012012-11-04 23:21:40 +11001796 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001797 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001798 while ((arg = strdelim(&cp)) && *arg != '\0') {
1799 if (options->num_auth_methods >=
1800 MAX_AUTH_METHODS)
1801 fatal("%s line %d: "
1802 "too many authentication methods.",
1803 filename, linenum);
1804 if (auth2_methods_valid(arg, 0) != 0)
1805 fatal("%s line %d: invalid "
1806 "authentication method list.",
1807 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001808 if (!*activep)
1809 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001810 options->auth_methods[
1811 options->num_auth_methods++] = xstrdup(arg);
1812 }
1813 }
1814 return 0;
1815
Damien Miller7acefbb2014-07-18 14:11:24 +10001816 case sStreamLocalBindMask:
1817 arg = strdelim(&cp);
1818 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001819 fatal("%s line %d: missing StreamLocalBindMask "
1820 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001821 /* Parse mode in octal format */
1822 value = strtol(arg, &p, 8);
1823 if (arg == p || value < 0 || value > 0777)
1824 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001825 if (*activep)
1826 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001827 break;
1828
1829 case sStreamLocalBindUnlink:
1830 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1831 goto parse_flag;
1832
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001833 case sFingerprintHash:
1834 arg = strdelim(&cp);
1835 if (!arg || *arg == '\0')
1836 fatal("%.200s line %d: Missing argument.",
1837 filename, linenum);
1838 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1839 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1840 filename, linenum, arg);
1841 if (*activep)
1842 options->fingerprint_hash = value;
1843 break;
1844
Ben Lindstromade03f62001-12-06 18:22:17 +00001845 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001846 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001847 filename, linenum, arg);
1848 while (arg)
1849 arg = strdelim(&cp);
1850 break;
1851
Damien Millerf9b3feb2003-05-16 11:38:32 +10001852 case sUnsupported:
1853 logit("%s line %d: Unsupported option %s",
1854 filename, linenum, arg);
1855 while (arg)
1856 arg = strdelim(&cp);
1857 break;
1858
Ben Lindstromade03f62001-12-06 18:22:17 +00001859 default:
1860 fatal("%s line %d: Missing handler for opcode %s (%d)",
1861 filename, linenum, arg, opcode);
1862 }
1863 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1864 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1865 filename, linenum, arg);
1866 return 0;
1867}
1868
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001869/* Reads the server configuration file. */
1870
Damien Miller4af51302000-04-16 11:18:38 +10001871void
Darren Tucker645ab752004-06-25 13:33:20 +10001872load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001873{
Damien Miller46cb75a2012-07-31 12:22:37 +10001874 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001875 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001876 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001877
Darren Tucker645ab752004-06-25 13:33:20 +10001878 debug2("%s: filename %s", __func__, filename);
1879 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001880 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001881 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001882 }
Darren Tucker645ab752004-06-25 13:33:20 +10001883 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001884 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001885 lineno++;
1886 if (strlen(line) == sizeof(line) - 1)
1887 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001888 /*
1889 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001890 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001891 * line numbers later for error messages
1892 */
1893 if ((cp = strchr(line, '#')) != NULL)
1894 memcpy(cp, "\n", 2);
1895 cp = line + strspn(line, " \t\r");
1896
1897 buffer_append(conf, cp, strlen(cp));
1898 }
1899 buffer_append(conf, "\0", 1);
1900 fclose(f);
1901 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1902}
1903
1904void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001905parse_server_match_config(ServerOptions *options,
1906 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001907{
Darren Tucker45150472006-07-12 22:34:17 +10001908 ServerOptions mo;
1909
1910 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001911 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001912 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001913}
1914
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001915int parse_server_match_testspec(struct connection_info *ci, char *spec)
1916{
1917 char *p;
1918
1919 while ((p = strsep(&spec, ",")) && *p != '\0') {
1920 if (strncmp(p, "addr=", 5) == 0) {
1921 ci->address = xstrdup(p + 5);
1922 } else if (strncmp(p, "host=", 5) == 0) {
1923 ci->host = xstrdup(p + 5);
1924 } else if (strncmp(p, "user=", 5) == 0) {
1925 ci->user = xstrdup(p + 5);
1926 } else if (strncmp(p, "laddr=", 6) == 0) {
1927 ci->laddress = xstrdup(p + 6);
1928 } else if (strncmp(p, "lport=", 6) == 0) {
1929 ci->lport = a2port(p + 6);
1930 if (ci->lport == -1) {
1931 fprintf(stderr, "Invalid port '%s' in test mode"
1932 " specification %s\n", p+6, p);
1933 return -1;
1934 }
1935 } else {
1936 fprintf(stderr, "Invalid test mode specification %s\n",
1937 p);
1938 return -1;
1939 }
1940 }
1941 return 0;
1942}
1943
1944/*
1945 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1946 * empty spec.
1947 */
1948int server_match_spec_complete(struct connection_info *ci)
1949{
1950 if (ci->user && ci->host && ci->address)
1951 return 1; /* complete */
1952 if (!ci->user && !ci->host && !ci->address)
1953 return -1; /* empty */
1954 return 0; /* partial */
1955}
1956
Darren Tucker1629c072007-02-19 22:25:37 +11001957/*
1958 * Copy any supported values that are set.
1959 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001960 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001961 * array values that are not used pre-authentication, because any that we
1962 * do use must be explictly sent in mm_getpwnamallow().
1963 */
Darren Tucker45150472006-07-12 22:34:17 +10001964void
Darren Tucker1629c072007-02-19 22:25:37 +11001965copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001966{
Damien Miller534b2cc2013-12-05 14:07:27 +11001967#define M_CP_INTOPT(n) do {\
1968 if (src->n != -1) \
1969 dst->n = src->n; \
1970} while (0)
1971
Darren Tucker1629c072007-02-19 22:25:37 +11001972 M_CP_INTOPT(password_authentication);
1973 M_CP_INTOPT(gss_authentication);
1974 M_CP_INTOPT(rsa_authentication);
1975 M_CP_INTOPT(pubkey_authentication);
1976 M_CP_INTOPT(kerberos_authentication);
1977 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001978 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001979 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001980 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001981 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001982
1983 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001984 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001985 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001986 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001987 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001988 M_CP_INTOPT(x11_display_offset);
1989 M_CP_INTOPT(x11_forwarding);
1990 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001991 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001992 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001993 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001994 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001995 M_CP_INTOPT(ip_qos_interactive);
1996 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001997 M_CP_INTOPT(rekey_limit);
1998 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001999
Damien Miller534b2cc2013-12-05 14:07:27 +11002000 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2001#define M_CP_STROPT(n) do {\
2002 if (src->n != NULL && dst->n != src->n) { \
2003 free(dst->n); \
2004 dst->n = src->n; \
2005 } \
2006} while(0)
2007#define M_CP_STRARRAYOPT(n, num_n) do {\
2008 if (src->num_n != 0) { \
2009 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2010 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2011 } \
2012} while(0)
2013
Damien Millerf2e407e2011-05-20 19:04:14 +10002014 /* See comment in servconf.h */
2015 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002016
Damien Millerc2411902011-05-20 19:03:49 +10002017 /*
2018 * The only things that should be below this point are string options
2019 * which are only used after authentication.
2020 */
Damien Miller5d74e582011-05-20 19:03:31 +10002021 if (preauth)
2022 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002023
Damien Miller5d74e582011-05-20 19:03:31 +10002024 M_CP_STROPT(adm_forced_command);
2025 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10002026}
2027
Darren Tucker1629c072007-02-19 22:25:37 +11002028#undef M_CP_INTOPT
2029#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002030#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002031
Darren Tucker45150472006-07-12 22:34:17 +10002032void
2033parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002034 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002035{
2036 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002037 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002038
2039 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2040
Darren Tucker9fbac712004-08-12 22:41:44 +10002041 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002042 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002043 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002044 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002045 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002046 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002047 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002048 }
Darren Tuckera627d422013-06-02 07:31:17 +10002049 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002050 if (bad_options > 0)
2051 fatal("%s: terminating, %d bad configuration options",
2052 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002053 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002054}
Darren Tuckere7140f22008-06-10 23:01:51 +10002055
2056static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002057fmt_multistate_int(int val, const struct multistate *m)
2058{
2059 u_int i;
2060
2061 for (i = 0; m[i].key != NULL; i++) {
2062 if (m[i].value == val)
2063 return m[i].key;
2064 }
2065 return "UNKNOWN";
2066}
2067
2068static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002069fmt_intarg(ServerOpCodes code, int val)
2070{
Damien Miller82c55872011-06-23 08:20:30 +10002071 if (val == -1)
2072 return "unset";
2073 switch (code) {
2074 case sAddressFamily:
2075 return fmt_multistate_int(val, multistate_addressfamily);
2076 case sPermitRootLogin:
2077 return fmt_multistate_int(val, multistate_permitrootlogin);
2078 case sGatewayPorts:
2079 return fmt_multistate_int(val, multistate_gatewayports);
2080 case sCompression:
2081 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002082 case sUsePrivilegeSeparation:
2083 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002084 case sAllowTcpForwarding:
2085 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002086 case sAllowStreamLocalForwarding:
2087 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002088 case sFingerprintHash:
2089 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002090 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002091 switch (val) {
2092 case SSH_PROTO_1:
2093 return "1";
2094 case SSH_PROTO_2:
2095 return "2";
2096 case (SSH_PROTO_1|SSH_PROTO_2):
2097 return "2,1";
2098 default:
2099 return "UNKNOWN";
2100 }
Damien Miller82c55872011-06-23 08:20:30 +10002101 default:
2102 switch (val) {
2103 case 0:
2104 return "no";
2105 case 1:
2106 return "yes";
2107 default:
2108 return "UNKNOWN";
2109 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002110 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002111}
2112
2113static const char *
2114lookup_opcode_name(ServerOpCodes code)
2115{
2116 u_int i;
2117
2118 for (i = 0; keywords[i].name != NULL; i++)
2119 if (keywords[i].opcode == code)
2120 return(keywords[i].name);
2121 return "UNKNOWN";
2122}
2123
2124static void
2125dump_cfg_int(ServerOpCodes code, int val)
2126{
2127 printf("%s %d\n", lookup_opcode_name(code), val);
2128}
2129
2130static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002131dump_cfg_oct(ServerOpCodes code, int val)
2132{
2133 printf("%s 0%o\n", lookup_opcode_name(code), val);
2134}
2135
2136static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002137dump_cfg_fmtint(ServerOpCodes code, int val)
2138{
2139 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2140}
2141
2142static void
2143dump_cfg_string(ServerOpCodes code, const char *val)
2144{
2145 if (val == NULL)
2146 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002147 printf("%s %s\n", lookup_opcode_name(code),
2148 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002149}
2150
2151static void
2152dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2153{
2154 u_int i;
2155
2156 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002157 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2158}
2159
2160static void
2161dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2162{
2163 u_int i;
2164
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002165 if (count <= 0)
2166 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002167 printf("%s", lookup_opcode_name(code));
2168 for (i = 0; i < count; i++)
2169 printf(" %s", vals[i]);
2170 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002171}
2172
2173void
2174dump_config(ServerOptions *o)
2175{
2176 u_int i;
2177 int ret;
2178 struct addrinfo *ai;
2179 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002180 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002181
2182 /* these are usually at the top of the config */
2183 for (i = 0; i < o->num_ports; i++)
2184 printf("port %d\n", o->ports[i]);
2185 dump_cfg_fmtint(sProtocol, o->protocol);
2186 dump_cfg_fmtint(sAddressFamily, o->address_family);
2187
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002188 /*
2189 * ListenAddress must be after Port. add_one_listen_addr pushes
2190 * addresses onto a stack, so to maintain ordering we need to
2191 * print these in reverse order.
2192 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002193 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2194 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2195 sizeof(addr), port, sizeof(port),
2196 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2197 error("getnameinfo failed: %.100s",
2198 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2199 strerror(errno));
2200 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002201 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002202 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002203 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2204 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002205 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002206 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2207 addr, port, laddr2);
2208 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002209 }
2210 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002211 printf("%s", laddr1);
2212 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002213
2214 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002215#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002216 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002217#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002218 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2219 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2220 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2221 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2222 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002223 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002224 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2225 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002226 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002227
2228 /* formatted integer arguments */
2229 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2230 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2231 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2232 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2233 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2234 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2235 o->hostbased_uses_name_from_packet_only);
2236 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2237 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002238#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002239 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2240 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2241 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002242# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002243 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002244# endif
2245#endif
2246#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002247 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2248 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002249#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002250 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2251 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2252 o->kbd_interactive_authentication);
2253 dump_cfg_fmtint(sChallengeResponseAuthentication,
2254 o->challenge_response_authentication);
2255 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2256 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2257 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2258 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002259 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002260 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002261 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2262 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2263 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2264 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2265 dump_cfg_fmtint(sUseLogin, o->use_login);
2266 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002267 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002268 dump_cfg_fmtint(sUseDNS, o->use_dns);
2269 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002270 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002271 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002272 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002273 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002274
2275 /* string arguments */
2276 dump_cfg_string(sPidFile, o->pid_file);
2277 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002278 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2279 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002280 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002282 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002283 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2284 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002285 dump_cfg_string(sAuthorizedPrincipalsFile,
2286 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002287 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2288 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002289 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2290 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002291 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2292 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002293 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002294 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002295 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002296 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2297 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002298 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2299 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002300 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2301 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002302
2303 /* string arguments requiring a lookup */
2304 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2305 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2306
2307 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002308 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2309 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002310 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2311 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002312 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002313 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002314 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2315 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2316 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2317 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2318 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002319 dump_cfg_strarray_oneline(sAuthenticationMethods,
2320 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002321
2322 /* other arguments */
2323 for (i = 0; i < o->num_subsystems; i++)
2324 printf("subsystem %s %s\n", o->subsystem_name[i],
2325 o->subsystem_args[i]);
2326
2327 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2328 o->max_startups_rate, o->max_startups);
2329
2330 for (i = 0; tunmode_desc[i].val != -1; i++)
2331 if (tunmode_desc[i].val == o->permit_tun) {
2332 s = tunmode_desc[i].text;
2333 break;
2334 }
2335 dump_cfg_string(sPermitTunnel, s);
2336
Damien Miller91475862011-05-05 14:14:34 +10002337 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2338 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002339
Damien Millera6d6c1f2013-08-21 02:40:01 +10002340 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2341 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002342
Darren Tuckere7140f22008-06-10 23:01:51 +10002343 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002344}