blob: 6c7a91e6b22fe15e5b379e91264e3f04c4124f57 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +00002/* $OpenBSD: servconf.c,v 1.280 2015/08/06 14:53:21 deraadt 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 },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000919 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000920 { "forced-commands-only", PERMIT_FORCED_ONLY },
921 { "yes", PERMIT_YES },
922 { "no", PERMIT_NO },
923 { NULL, -1 }
924};
925static const struct multistate multistate_compression[] = {
926 { "delayed", COMP_DELAYED },
927 { "yes", COMP_ZLIB },
928 { "no", COMP_NONE },
929 { NULL, -1 }
930};
931static const struct multistate multistate_gatewayports[] = {
932 { "clientspecified", 2 },
933 { "yes", 1 },
934 { "no", 0 },
935 { NULL, -1 }
936};
Damien Miller69ff1df2011-06-23 08:30:03 +1000937static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000938 { "yes", PRIVSEP_NOSANDBOX },
939 { "sandbox", PRIVSEP_ON },
940 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000941 { "no", PRIVSEP_OFF },
942 { NULL, -1 }
943};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100944static const struct multistate multistate_tcpfwd[] = {
945 { "yes", FORWARD_ALLOW },
946 { "all", FORWARD_ALLOW },
947 { "no", FORWARD_DENY },
948 { "remote", FORWARD_REMOTE },
949 { "local", FORWARD_LOCAL },
950 { NULL, -1 }
951};
Damien Miller33322122011-06-20 14:43:11 +1000952
Ben Lindstromade03f62001-12-06 18:22:17 +0000953int
954process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000955 const char *filename, int linenum, int *activep,
956 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000957{
Darren Tucker09c0f032013-05-16 20:48:57 +1000958 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000959 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100960 SyslogFacility *log_facility_ptr;
961 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000962 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000963 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000964 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000965 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000966 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000967
968 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100969 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100970 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000971 /* Ignore leading whitespace */
972 if (*arg == '\0')
973 arg = strdelim(&cp);
974 if (!arg || !*arg || *arg == '#')
975 return 0;
976 intptr = NULL;
977 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000978 opcode = parse_token(arg, filename, linenum, &flags);
979
980 if (activep == NULL) { /* We are processing a command line directive */
981 cmdline = 1;
982 activep = &cmdline;
983 }
984 if (*activep && opcode != sMatch)
985 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
986 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000987 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000988 fatal("%s line %d: Directive '%s' is not allowed "
989 "within a Match block", filename, linenum, arg);
990 } else { /* this is a directive we have already processed */
991 while (arg)
992 arg = strdelim(&cp);
993 return 0;
994 }
995 }
996
Ben Lindstromade03f62001-12-06 18:22:17 +0000997 switch (opcode) {
998 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000999 case sUsePAM:
1000 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001001 goto parse_flag;
1002
1003 /* Standard Options */
1004 case sBadOption:
1005 return -1;
1006 case sPort:
1007 /* ignore ports from configfile if cmdline specifies ports */
1008 if (options->ports_from_cmdline)
1009 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001010 if (options->num_ports >= MAX_PORTS)
1011 fatal("%s line %d: too many ports.",
1012 filename, linenum);
1013 arg = strdelim(&cp);
1014 if (!arg || *arg == '\0')
1015 fatal("%s line %d: missing port number.",
1016 filename, linenum);
1017 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001018 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001019 fatal("%s line %d: Badly formatted port number.",
1020 filename, linenum);
1021 break;
1022
1023 case sServerKeyBits:
1024 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001025 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001026 arg = strdelim(&cp);
1027 if (!arg || *arg == '\0')
1028 fatal("%s line %d: missing integer value.",
1029 filename, linenum);
1030 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001031 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001032 *intptr = value;
1033 break;
1034
1035 case sLoginGraceTime:
1036 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001037 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 arg = strdelim(&cp);
1039 if (!arg || *arg == '\0')
1040 fatal("%s line %d: missing time value.",
1041 filename, linenum);
1042 if ((value = convtime(arg)) == -1)
1043 fatal("%s line %d: invalid time value.",
1044 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001045 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001046 *intptr = value;
1047 break;
1048
1049 case sKeyRegenerationTime:
1050 intptr = &options->key_regeneration_time;
1051 goto parse_time;
1052
1053 case sListenAddress:
1054 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001055 if (arg == NULL || *arg == '\0')
1056 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001057 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001058 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1059 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1060 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001061 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001062 break;
1063 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001064 p = hpdelim(&arg);
1065 if (p == NULL)
1066 fatal("%s line %d: bad address:port usage",
1067 filename, linenum);
1068 p = cleanhostname(p);
1069 if (arg == NULL)
1070 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001071 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001072 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001073
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001074 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001075
Ben Lindstromade03f62001-12-06 18:22:17 +00001076 break;
1077
Darren Tucker0f383232005-01-20 10:57:56 +11001078 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001079 intptr = &options->address_family;
1080 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001081 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001082 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001083 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001084 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001085 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001086 value = -1;
1087 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1088 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1089 value = multistate_ptr[i].value;
1090 break;
1091 }
1092 }
1093 if (value == -1)
1094 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001095 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001096 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001097 *intptr = value;
1098 break;
1099
Ben Lindstromade03f62001-12-06 18:22:17 +00001100 case sHostKeyFile:
1101 intptr = &options->num_host_key_files;
1102 if (*intptr >= MAX_HOSTKEYS)
1103 fatal("%s line %d: too many host keys specified (max %d).",
1104 filename, linenum, MAX_HOSTKEYS);
1105 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001106 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001107 arg = strdelim(&cp);
1108 if (!arg || *arg == '\0')
1109 fatal("%s line %d: missing file name.",
1110 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001111 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001112 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001113 /* increase optional counter */
1114 if (intptr != NULL)
1115 *intptr = *intptr + 1;
1116 }
1117 break;
1118
Damien Miller85b45e02013-07-20 13:21:52 +10001119 case sHostKeyAgent:
1120 charptr = &options->host_key_agent;
1121 arg = strdelim(&cp);
1122 if (!arg || *arg == '\0')
1123 fatal("%s line %d: missing socket name.",
1124 filename, linenum);
1125 if (*activep && *charptr == NULL)
1126 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1127 xstrdup(arg) : derelativise_path(arg);
1128 break;
1129
Damien Miller0a80ca12010-02-27 07:55:05 +11001130 case sHostCertificate:
1131 intptr = &options->num_host_cert_files;
1132 if (*intptr >= MAX_HOSTKEYS)
1133 fatal("%s line %d: too many host certificates "
1134 "specified (max %d).", filename, linenum,
1135 MAX_HOSTCERTS);
1136 charptr = &options->host_cert_files[*intptr];
1137 goto parse_filename;
1138 break;
1139
Ben Lindstromade03f62001-12-06 18:22:17 +00001140 case sPidFile:
1141 charptr = &options->pid_file;
1142 goto parse_filename;
1143
1144 case sPermitRootLogin:
1145 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001146 multistate_ptr = multistate_permitrootlogin;
1147 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001148
1149 case sIgnoreRhosts:
1150 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001151 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001152 arg = strdelim(&cp);
1153 if (!arg || *arg == '\0')
1154 fatal("%s line %d: missing yes/no argument.",
1155 filename, linenum);
1156 value = 0; /* silence compiler */
1157 if (strcmp(arg, "yes") == 0)
1158 value = 1;
1159 else if (strcmp(arg, "no") == 0)
1160 value = 0;
1161 else
1162 fatal("%s line %d: Bad yes/no argument: %s",
1163 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001164 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001165 *intptr = value;
1166 break;
1167
1168 case sIgnoreUserKnownHosts:
1169 intptr = &options->ignore_user_known_hosts;
1170 goto parse_flag;
1171
Ben Lindstromade03f62001-12-06 18:22:17 +00001172 case sRhostsRSAAuthentication:
1173 intptr = &options->rhosts_rsa_authentication;
1174 goto parse_flag;
1175
1176 case sHostbasedAuthentication:
1177 intptr = &options->hostbased_authentication;
1178 goto parse_flag;
1179
1180 case sHostbasedUsesNameFromPacketOnly:
1181 intptr = &options->hostbased_uses_name_from_packet_only;
1182 goto parse_flag;
1183
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001184 case sHostbasedAcceptedKeyTypes:
1185 charptr = &options->hostbased_key_types;
1186 parse_keytypes:
1187 arg = strdelim(&cp);
1188 if (!arg || *arg == '\0')
1189 fatal("%s line %d: Missing argument.",
1190 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001191 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001192 fatal("%s line %d: Bad key types '%s'.",
1193 filename, linenum, arg ? arg : "<NONE>");
1194 if (*activep && *charptr == NULL)
1195 *charptr = xstrdup(arg);
1196 break;
1197
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001198 case sHostKeyAlgorithms:
1199 charptr = &options->hostkeyalgorithms;
1200 goto parse_keytypes;
1201
Ben Lindstromade03f62001-12-06 18:22:17 +00001202 case sRSAAuthentication:
1203 intptr = &options->rsa_authentication;
1204 goto parse_flag;
1205
1206 case sPubkeyAuthentication:
1207 intptr = &options->pubkey_authentication;
1208 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001209
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001210 case sPubkeyAcceptedKeyTypes:
1211 charptr = &options->pubkey_key_types;
1212 goto parse_keytypes;
1213
Ben Lindstromade03f62001-12-06 18:22:17 +00001214 case sKerberosAuthentication:
1215 intptr = &options->kerberos_authentication;
1216 goto parse_flag;
1217
1218 case sKerberosOrLocalPasswd:
1219 intptr = &options->kerberos_or_local_passwd;
1220 goto parse_flag;
1221
1222 case sKerberosTicketCleanup:
1223 intptr = &options->kerberos_ticket_cleanup;
1224 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001225
Darren Tucker22ef5082003-12-31 11:37:34 +11001226 case sKerberosGetAFSToken:
1227 intptr = &options->kerberos_get_afs_token;
1228 goto parse_flag;
1229
Darren Tucker0efd1552003-08-26 11:49:55 +10001230 case sGssAuthentication:
1231 intptr = &options->gss_authentication;
1232 goto parse_flag;
1233
1234 case sGssCleanupCreds:
1235 intptr = &options->gss_cleanup_creds;
1236 goto parse_flag;
1237
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001238 case sGssStrictAcceptor:
1239 intptr = &options->gss_strict_acceptor;
1240 goto parse_flag;
1241
Ben Lindstromade03f62001-12-06 18:22:17 +00001242 case sPasswordAuthentication:
1243 intptr = &options->password_authentication;
1244 goto parse_flag;
1245
1246 case sKbdInteractiveAuthentication:
1247 intptr = &options->kbd_interactive_authentication;
1248 goto parse_flag;
1249
1250 case sChallengeResponseAuthentication:
1251 intptr = &options->challenge_response_authentication;
1252 goto parse_flag;
1253
1254 case sPrintMotd:
1255 intptr = &options->print_motd;
1256 goto parse_flag;
1257
1258 case sPrintLastLog:
1259 intptr = &options->print_lastlog;
1260 goto parse_flag;
1261
1262 case sX11Forwarding:
1263 intptr = &options->x11_forwarding;
1264 goto parse_flag;
1265
1266 case sX11DisplayOffset:
1267 intptr = &options->x11_display_offset;
1268 goto parse_int;
1269
Damien Miller95c249f2002-02-05 12:11:34 +11001270 case sX11UseLocalhost:
1271 intptr = &options->x11_use_localhost;
1272 goto parse_flag;
1273
Ben Lindstromade03f62001-12-06 18:22:17 +00001274 case sXAuthLocation:
1275 charptr = &options->xauth_location;
1276 goto parse_filename;
1277
Damien Miller5ff30c62013-10-30 22:21:50 +11001278 case sPermitTTY:
1279 intptr = &options->permit_tty;
1280 goto parse_flag;
1281
Damien Miller72e6b5c2014-07-04 09:00:04 +10001282 case sPermitUserRC:
1283 intptr = &options->permit_user_rc;
1284 goto parse_flag;
1285
Ben Lindstromade03f62001-12-06 18:22:17 +00001286 case sStrictModes:
1287 intptr = &options->strict_modes;
1288 goto parse_flag;
1289
Damien Miller12c150e2003-12-17 16:31:10 +11001290 case sTCPKeepAlive:
1291 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001292 goto parse_flag;
1293
1294 case sEmptyPasswd:
1295 intptr = &options->permit_empty_passwd;
1296 goto parse_flag;
1297
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001298 case sPermitUserEnvironment:
1299 intptr = &options->permit_user_env;
1300 goto parse_flag;
1301
Ben Lindstromade03f62001-12-06 18:22:17 +00001302 case sUseLogin:
1303 intptr = &options->use_login;
1304 goto parse_flag;
1305
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001306 case sCompression:
1307 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001308 multistate_ptr = multistate_compression;
1309 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001310
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001311 case sRekeyLimit:
1312 arg = strdelim(&cp);
1313 if (!arg || *arg == '\0')
1314 fatal("%.200s line %d: Missing argument.", filename,
1315 linenum);
1316 if (strcmp(arg, "default") == 0) {
1317 val64 = 0;
1318 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001319 if (scan_scaled(arg, &val64) == -1)
1320 fatal("%.200s line %d: Bad number '%s': %s",
1321 filename, linenum, arg, strerror(errno));
1322 /* check for too-large or too-small limits */
1323 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001324 fatal("%.200s line %d: RekeyLimit too large",
1325 filename, linenum);
1326 if (val64 != 0 && val64 < 16)
1327 fatal("%.200s line %d: RekeyLimit too small",
1328 filename, linenum);
1329 }
1330 if (*activep && options->rekey_limit == -1)
1331 options->rekey_limit = (u_int32_t)val64;
1332 if (cp != NULL) { /* optional rekey interval present */
1333 if (strcmp(cp, "none") == 0) {
1334 (void)strdelim(&cp); /* discard */
1335 break;
1336 }
1337 intptr = &options->rekey_interval;
1338 goto parse_time;
1339 }
1340 break;
1341
Ben Lindstromade03f62001-12-06 18:22:17 +00001342 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001343 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001344 multistate_ptr = multistate_gatewayports;
1345 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001346
Damien Miller3a961dc2003-06-03 10:25:48 +10001347 case sUseDNS:
1348 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001349 goto parse_flag;
1350
1351 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001352 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 arg = strdelim(&cp);
1354 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001355 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001356 fatal("%.200s line %d: unsupported log facility '%s'",
1357 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001358 if (*log_facility_ptr == -1)
1359 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001360 break;
1361
1362 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001363 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 arg = strdelim(&cp);
1365 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001366 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001367 fatal("%.200s line %d: unsupported log level '%s'",
1368 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001369 if (*log_level_ptr == -1)
1370 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 break;
1372
1373 case sAllowTcpForwarding:
1374 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001375 multistate_ptr = multistate_tcpfwd;
1376 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001377
Damien Miller7acefbb2014-07-18 14:11:24 +10001378 case sAllowStreamLocalForwarding:
1379 intptr = &options->allow_streamlocal_forwarding;
1380 multistate_ptr = multistate_tcpfwd;
1381 goto parse_multistate;
1382
Damien Miller4f755cd2008-05-19 14:57:41 +10001383 case sAllowAgentForwarding:
1384 intptr = &options->allow_agent_forwarding;
1385 goto parse_flag;
1386
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001387 case sUsePrivilegeSeparation:
1388 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001389 multistate_ptr = multistate_privsep;
1390 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001391
Ben Lindstromade03f62001-12-06 18:22:17 +00001392 case sAllowUsers:
1393 while ((arg = strdelim(&cp)) && *arg != '\0') {
1394 if (options->num_allow_users >= MAX_ALLOW_USERS)
1395 fatal("%s line %d: too many allow users.",
1396 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001397 if (!*activep)
1398 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001399 options->allow_users[options->num_allow_users++] =
1400 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001401 }
1402 break;
1403
1404 case sDenyUsers:
1405 while ((arg = strdelim(&cp)) && *arg != '\0') {
1406 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001407 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001408 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001409 if (!*activep)
1410 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001411 options->deny_users[options->num_deny_users++] =
1412 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001413 }
1414 break;
1415
1416 case sAllowGroups:
1417 while ((arg = strdelim(&cp)) && *arg != '\0') {
1418 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1419 fatal("%s line %d: too many allow groups.",
1420 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001421 if (!*activep)
1422 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001423 options->allow_groups[options->num_allow_groups++] =
1424 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001425 }
1426 break;
1427
1428 case sDenyGroups:
1429 while ((arg = strdelim(&cp)) && *arg != '\0') {
1430 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1431 fatal("%s line %d: too many deny groups.",
1432 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001433 if (!*activep)
1434 continue;
1435 options->deny_groups[options->num_deny_groups++] =
1436 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001437 }
1438 break;
1439
1440 case sCiphers:
1441 arg = strdelim(&cp);
1442 if (!arg || *arg == '\0')
1443 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001444 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001445 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1446 filename, linenum, arg ? arg : "<NONE>");
1447 if (options->ciphers == NULL)
1448 options->ciphers = xstrdup(arg);
1449 break;
1450
1451 case sMacs:
1452 arg = strdelim(&cp);
1453 if (!arg || *arg == '\0')
1454 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001455 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001456 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1457 filename, linenum, arg ? arg : "<NONE>");
1458 if (options->macs == NULL)
1459 options->macs = xstrdup(arg);
1460 break;
1461
Damien Millerd5f62bf2010-09-24 22:11:14 +10001462 case sKexAlgorithms:
1463 arg = strdelim(&cp);
1464 if (!arg || *arg == '\0')
1465 fatal("%s line %d: Missing argument.",
1466 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001467 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001468 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1469 filename, linenum, arg ? arg : "<NONE>");
1470 if (options->kex_algorithms == NULL)
1471 options->kex_algorithms = xstrdup(arg);
1472 break;
1473
Ben Lindstromade03f62001-12-06 18:22:17 +00001474 case sProtocol:
1475 intptr = &options->protocol;
1476 arg = strdelim(&cp);
1477 if (!arg || *arg == '\0')
1478 fatal("%s line %d: Missing argument.", filename, linenum);
1479 value = proto_spec(arg);
1480 if (value == SSH_PROTO_UNKNOWN)
1481 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001482 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001483 if (*intptr == SSH_PROTO_UNKNOWN)
1484 *intptr = value;
1485 break;
1486
1487 case sSubsystem:
1488 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1489 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001490 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001491 }
1492 arg = strdelim(&cp);
1493 if (!arg || *arg == '\0')
1494 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001495 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001496 if (!*activep) {
1497 arg = strdelim(&cp);
1498 break;
1499 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001500 for (i = 0; i < options->num_subsystems; i++)
1501 if (strcmp(arg, options->subsystem_name[i]) == 0)
1502 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001503 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001504 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1505 arg = strdelim(&cp);
1506 if (!arg || *arg == '\0')
1507 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001508 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001509 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001510
1511 /* Collect arguments (separate to executable) */
1512 p = xstrdup(arg);
1513 len = strlen(p) + 1;
1514 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1515 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001516 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001517 strlcat(p, " ", len);
1518 strlcat(p, arg, len);
1519 }
1520 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001521 options->num_subsystems++;
1522 break;
1523
1524 case sMaxStartups:
1525 arg = strdelim(&cp);
1526 if (!arg || *arg == '\0')
1527 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001528 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001529 if ((n = sscanf(arg, "%d:%d:%d",
1530 &options->max_startups_begin,
1531 &options->max_startups_rate,
1532 &options->max_startups)) == 3) {
1533 if (options->max_startups_begin >
1534 options->max_startups ||
1535 options->max_startups_rate > 100 ||
1536 options->max_startups_rate < 1)
1537 fatal("%s line %d: Illegal MaxStartups spec.",
1538 filename, linenum);
1539 } else if (n != 1)
1540 fatal("%s line %d: Illegal MaxStartups spec.",
1541 filename, linenum);
1542 else
1543 options->max_startups = options->max_startups_begin;
1544 break;
1545
Darren Tucker89413db2004-05-24 10:36:23 +10001546 case sMaxAuthTries:
1547 intptr = &options->max_authtries;
1548 goto parse_int;
1549
Damien Miller7207f642008-05-19 15:34:50 +10001550 case sMaxSessions:
1551 intptr = &options->max_sessions;
1552 goto parse_int;
1553
Ben Lindstromade03f62001-12-06 18:22:17 +00001554 case sBanner:
1555 charptr = &options->banner;
1556 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001557
Ben Lindstromade03f62001-12-06 18:22:17 +00001558 /*
1559 * These options can contain %X options expanded at
1560 * connect time, so that you can specify paths like:
1561 *
1562 * AuthorizedKeysFile /etc/ssh_keys/%u
1563 */
1564 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001565 if (*activep && options->num_authkeys_files == 0) {
1566 while ((arg = strdelim(&cp)) && *arg != '\0') {
1567 if (options->num_authkeys_files >=
1568 MAX_AUTHKEYS_FILES)
1569 fatal("%s line %d: "
1570 "too many authorized keys files.",
1571 filename, linenum);
1572 options->authorized_keys_files[
1573 options->num_authkeys_files++] =
1574 tilde_expand_filename(arg, getuid());
1575 }
1576 }
1577 return 0;
1578
Damien Miller30da3442010-05-10 11:58:03 +10001579 case sAuthorizedPrincipalsFile:
1580 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001581 arg = strdelim(&cp);
1582 if (!arg || *arg == '\0')
1583 fatal("%s line %d: missing file name.",
1584 filename, linenum);
1585 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001586 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001587 /* increase optional counter */
1588 if (intptr != NULL)
1589 *intptr = *intptr + 1;
1590 }
1591 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001592
1593 case sClientAliveInterval:
1594 intptr = &options->client_alive_interval;
1595 goto parse_time;
1596
1597 case sClientAliveCountMax:
1598 intptr = &options->client_alive_count_max;
1599 goto parse_int;
1600
Darren Tucker46bc0752004-05-02 22:11:30 +10001601 case sAcceptEnv:
1602 while ((arg = strdelim(&cp)) && *arg != '\0') {
1603 if (strchr(arg, '=') != NULL)
1604 fatal("%s line %d: Invalid environment name.",
1605 filename, linenum);
1606 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1607 fatal("%s line %d: too many allow env.",
1608 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001609 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001610 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001611 options->accept_env[options->num_accept_env++] =
1612 xstrdup(arg);
1613 }
1614 break;
1615
Damien Millerd27b9472005-12-13 19:29:02 +11001616 case sPermitTunnel:
1617 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001618 arg = strdelim(&cp);
1619 if (!arg || *arg == '\0')
1620 fatal("%s line %d: Missing yes/point-to-point/"
1621 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001622 value = -1;
1623 for (i = 0; tunmode_desc[i].val != -1; i++)
1624 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1625 value = tunmode_desc[i].val;
1626 break;
1627 }
1628 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001629 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1630 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001631 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001632 *intptr = value;
1633 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001634
Darren Tucker45150472006-07-12 22:34:17 +10001635 case sMatch:
1636 if (cmdline)
1637 fatal("Match directive not supported as a command-line "
1638 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001639 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001640 if (value < 0)
1641 fatal("%s line %d: Bad Match condition", filename,
1642 linenum);
1643 *activep = value;
1644 break;
1645
Damien Miller9b439df2006-07-24 14:04:00 +10001646 case sPermitOpen:
1647 arg = strdelim(&cp);
1648 if (!arg || *arg == '\0')
1649 fatal("%s line %d: missing PermitOpen specification",
1650 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001651 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001652 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001653 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001654 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001655 options->num_permitted_opens = 0;
1656 }
Damien Miller9b439df2006-07-24 14:04:00 +10001657 break;
1658 }
Damien Millerc6081482012-04-22 11:18:53 +10001659 if (strcmp(arg, "none") == 0) {
1660 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001661 options->num_permitted_opens = 1;
1662 channel_disable_adm_local_opens();
1663 }
1664 break;
1665 }
Damien Millera29b95e2007-01-05 16:28:36 +11001666 if (*activep && n == -1)
1667 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001668 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1669 p = hpdelim(&arg);
1670 if (p == NULL)
1671 fatal("%s line %d: missing host in PermitOpen",
1672 filename, linenum);
1673 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001674 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001675 fatal("%s line %d: bad port number in "
1676 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001677 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001678 options->num_permitted_opens =
1679 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001680 }
Damien Miller9b439df2006-07-24 14:04:00 +10001681 break;
1682
Damien Millere2754432006-07-24 14:06:47 +10001683 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001684 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001685 fatal("%.200s line %d: Missing argument.", filename,
1686 linenum);
1687 len = strspn(cp, WHITESPACE);
1688 if (*activep && options->adm_forced_command == NULL)
1689 options->adm_forced_command = xstrdup(cp + len);
1690 return 0;
1691
Damien Millerd8cb1f12008-02-10 22:40:12 +11001692 case sChrootDirectory:
1693 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001694
1695 arg = strdelim(&cp);
1696 if (!arg || *arg == '\0')
1697 fatal("%s line %d: missing file name.",
1698 filename, linenum);
1699 if (*activep && *charptr == NULL)
1700 *charptr = xstrdup(arg);
1701 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001702
Damien Miller1aed65e2010-03-04 21:53:35 +11001703 case sTrustedUserCAKeys:
1704 charptr = &options->trusted_user_ca_keys;
1705 goto parse_filename;
1706
1707 case sRevokedKeys:
1708 charptr = &options->revoked_keys_file;
1709 goto parse_filename;
1710
Damien Miller0dac6fb2010-11-20 15:19:38 +11001711 case sIPQoS:
1712 arg = strdelim(&cp);
1713 if ((value = parse_ipqos(arg)) == -1)
1714 fatal("%s line %d: Bad IPQoS value: %s",
1715 filename, linenum, arg);
1716 arg = strdelim(&cp);
1717 if (arg == NULL)
1718 value2 = value;
1719 else if ((value2 = parse_ipqos(arg)) == -1)
1720 fatal("%s line %d: Bad IPQoS value: %s",
1721 filename, linenum, arg);
1722 if (*activep) {
1723 options->ip_qos_interactive = value;
1724 options->ip_qos_bulk = value2;
1725 }
1726 break;
1727
Damien Miller23528812012-04-22 11:24:43 +10001728 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001729 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001730 fatal("%.200s line %d: Missing argument.", filename,
1731 linenum);
1732 len = strspn(cp, WHITESPACE);
1733 if (*activep && options->version_addendum == NULL) {
1734 if (strcasecmp(cp + len, "none") == 0)
1735 options->version_addendum = xstrdup("");
1736 else if (strchr(cp + len, '\r') != NULL)
1737 fatal("%.200s line %d: Invalid argument",
1738 filename, linenum);
1739 else
1740 options->version_addendum = xstrdup(cp + len);
1741 }
1742 return 0;
1743
Damien Miller09d3e122012-10-31 08:58:58 +11001744 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001745 if (cp == NULL)
1746 fatal("%.200s line %d: Missing argument.", filename,
1747 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001748 len = strspn(cp, WHITESPACE);
1749 if (*activep && options->authorized_keys_command == NULL) {
1750 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1751 fatal("%.200s line %d: AuthorizedKeysCommand "
1752 "must be an absolute path",
1753 filename, linenum);
1754 options->authorized_keys_command = xstrdup(cp + len);
1755 }
1756 return 0;
1757
1758 case sAuthorizedKeysCommandUser:
1759 charptr = &options->authorized_keys_command_user;
1760
1761 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001762 if (!arg || *arg == '\0')
1763 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1764 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001765 if (*activep && *charptr == NULL)
1766 *charptr = xstrdup(arg);
1767 break;
1768
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001769 case sAuthorizedPrincipalsCommand:
1770 if (cp == NULL)
1771 fatal("%.200s line %d: Missing argument.", filename,
1772 linenum);
1773 len = strspn(cp, WHITESPACE);
1774 if (*activep &&
1775 options->authorized_principals_command == NULL) {
1776 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1777 fatal("%.200s line %d: "
1778 "AuthorizedPrincipalsCommand must be "
1779 "an absolute path", filename, linenum);
1780 options->authorized_principals_command =
1781 xstrdup(cp + len);
1782 }
1783 return 0;
1784
1785 case sAuthorizedPrincipalsCommandUser:
1786 charptr = &options->authorized_principals_command_user;
1787
1788 arg = strdelim(&cp);
1789 if (!arg || *arg == '\0')
1790 fatal("%s line %d: missing "
1791 "AuthorizedPrincipalsCommandUser argument.",
1792 filename, linenum);
1793 if (*activep && *charptr == NULL)
1794 *charptr = xstrdup(arg);
1795 break;
1796
Damien Millera6e3f012012-11-04 23:21:40 +11001797 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001798 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001799 while ((arg = strdelim(&cp)) && *arg != '\0') {
1800 if (options->num_auth_methods >=
1801 MAX_AUTH_METHODS)
1802 fatal("%s line %d: "
1803 "too many authentication methods.",
1804 filename, linenum);
1805 if (auth2_methods_valid(arg, 0) != 0)
1806 fatal("%s line %d: invalid "
1807 "authentication method list.",
1808 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001809 if (!*activep)
1810 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001811 options->auth_methods[
1812 options->num_auth_methods++] = xstrdup(arg);
1813 }
1814 }
1815 return 0;
1816
Damien Miller7acefbb2014-07-18 14:11:24 +10001817 case sStreamLocalBindMask:
1818 arg = strdelim(&cp);
1819 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001820 fatal("%s line %d: missing StreamLocalBindMask "
1821 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001822 /* Parse mode in octal format */
1823 value = strtol(arg, &p, 8);
1824 if (arg == p || value < 0 || value > 0777)
1825 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001826 if (*activep)
1827 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001828 break;
1829
1830 case sStreamLocalBindUnlink:
1831 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1832 goto parse_flag;
1833
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001834 case sFingerprintHash:
1835 arg = strdelim(&cp);
1836 if (!arg || *arg == '\0')
1837 fatal("%.200s line %d: Missing argument.",
1838 filename, linenum);
1839 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1840 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1841 filename, linenum, arg);
1842 if (*activep)
1843 options->fingerprint_hash = value;
1844 break;
1845
Ben Lindstromade03f62001-12-06 18:22:17 +00001846 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001847 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001848 filename, linenum, arg);
1849 while (arg)
1850 arg = strdelim(&cp);
1851 break;
1852
Damien Millerf9b3feb2003-05-16 11:38:32 +10001853 case sUnsupported:
1854 logit("%s line %d: Unsupported option %s",
1855 filename, linenum, arg);
1856 while (arg)
1857 arg = strdelim(&cp);
1858 break;
1859
Ben Lindstromade03f62001-12-06 18:22:17 +00001860 default:
1861 fatal("%s line %d: Missing handler for opcode %s (%d)",
1862 filename, linenum, arg, opcode);
1863 }
1864 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1865 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1866 filename, linenum, arg);
1867 return 0;
1868}
1869
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001870/* Reads the server configuration file. */
1871
Damien Miller4af51302000-04-16 11:18:38 +10001872void
Darren Tucker645ab752004-06-25 13:33:20 +10001873load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001874{
Damien Miller46cb75a2012-07-31 12:22:37 +10001875 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001876 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001877 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001878
Darren Tucker645ab752004-06-25 13:33:20 +10001879 debug2("%s: filename %s", __func__, filename);
1880 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001881 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001882 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001883 }
Darren Tucker645ab752004-06-25 13:33:20 +10001884 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001885 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001886 lineno++;
1887 if (strlen(line) == sizeof(line) - 1)
1888 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001889 /*
1890 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001891 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001892 * line numbers later for error messages
1893 */
1894 if ((cp = strchr(line, '#')) != NULL)
1895 memcpy(cp, "\n", 2);
1896 cp = line + strspn(line, " \t\r");
1897
1898 buffer_append(conf, cp, strlen(cp));
1899 }
1900 buffer_append(conf, "\0", 1);
1901 fclose(f);
1902 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1903}
1904
1905void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001906parse_server_match_config(ServerOptions *options,
1907 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001908{
Darren Tucker45150472006-07-12 22:34:17 +10001909 ServerOptions mo;
1910
1911 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001912 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001913 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001914}
1915
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001916int parse_server_match_testspec(struct connection_info *ci, char *spec)
1917{
1918 char *p;
1919
1920 while ((p = strsep(&spec, ",")) && *p != '\0') {
1921 if (strncmp(p, "addr=", 5) == 0) {
1922 ci->address = xstrdup(p + 5);
1923 } else if (strncmp(p, "host=", 5) == 0) {
1924 ci->host = xstrdup(p + 5);
1925 } else if (strncmp(p, "user=", 5) == 0) {
1926 ci->user = xstrdup(p + 5);
1927 } else if (strncmp(p, "laddr=", 6) == 0) {
1928 ci->laddress = xstrdup(p + 6);
1929 } else if (strncmp(p, "lport=", 6) == 0) {
1930 ci->lport = a2port(p + 6);
1931 if (ci->lport == -1) {
1932 fprintf(stderr, "Invalid port '%s' in test mode"
1933 " specification %s\n", p+6, p);
1934 return -1;
1935 }
1936 } else {
1937 fprintf(stderr, "Invalid test mode specification %s\n",
1938 p);
1939 return -1;
1940 }
1941 }
1942 return 0;
1943}
1944
1945/*
1946 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1947 * empty spec.
1948 */
1949int server_match_spec_complete(struct connection_info *ci)
1950{
1951 if (ci->user && ci->host && ci->address)
1952 return 1; /* complete */
1953 if (!ci->user && !ci->host && !ci->address)
1954 return -1; /* empty */
1955 return 0; /* partial */
1956}
1957
Darren Tucker1629c072007-02-19 22:25:37 +11001958/*
1959 * Copy any supported values that are set.
1960 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001961 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001962 * array values that are not used pre-authentication, because any that we
1963 * do use must be explictly sent in mm_getpwnamallow().
1964 */
Darren Tucker45150472006-07-12 22:34:17 +10001965void
Darren Tucker1629c072007-02-19 22:25:37 +11001966copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001967{
Damien Miller534b2cc2013-12-05 14:07:27 +11001968#define M_CP_INTOPT(n) do {\
1969 if (src->n != -1) \
1970 dst->n = src->n; \
1971} while (0)
1972
Darren Tucker1629c072007-02-19 22:25:37 +11001973 M_CP_INTOPT(password_authentication);
1974 M_CP_INTOPT(gss_authentication);
1975 M_CP_INTOPT(rsa_authentication);
1976 M_CP_INTOPT(pubkey_authentication);
1977 M_CP_INTOPT(kerberos_authentication);
1978 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001979 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001980 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001981 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001982 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001983
1984 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001985 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001986 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001987 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001988 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001989 M_CP_INTOPT(x11_display_offset);
1990 M_CP_INTOPT(x11_forwarding);
1991 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001992 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001993 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001994 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001995 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001996 M_CP_INTOPT(ip_qos_interactive);
1997 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001998 M_CP_INTOPT(rekey_limit);
1999 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002000
Damien Miller534b2cc2013-12-05 14:07:27 +11002001 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2002#define M_CP_STROPT(n) do {\
2003 if (src->n != NULL && dst->n != src->n) { \
2004 free(dst->n); \
2005 dst->n = src->n; \
2006 } \
2007} while(0)
2008#define M_CP_STRARRAYOPT(n, num_n) do {\
2009 if (src->num_n != 0) { \
2010 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2011 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2012 } \
2013} while(0)
2014
Damien Millerf2e407e2011-05-20 19:04:14 +10002015 /* See comment in servconf.h */
2016 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002017
Damien Millerc2411902011-05-20 19:03:49 +10002018 /*
2019 * The only things that should be below this point are string options
2020 * which are only used after authentication.
2021 */
Damien Miller5d74e582011-05-20 19:03:31 +10002022 if (preauth)
2023 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002024
Damien Miller5d74e582011-05-20 19:03:31 +10002025 M_CP_STROPT(adm_forced_command);
2026 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10002027}
2028
Darren Tucker1629c072007-02-19 22:25:37 +11002029#undef M_CP_INTOPT
2030#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002031#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002032
Darren Tucker45150472006-07-12 22:34:17 +10002033void
2034parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002035 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002036{
2037 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002038 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002039
2040 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2041
Darren Tucker9fbac712004-08-12 22:41:44 +10002042 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002043 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002044 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002045 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002046 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002047 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002048 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002049 }
Darren Tuckera627d422013-06-02 07:31:17 +10002050 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002051 if (bad_options > 0)
2052 fatal("%s: terminating, %d bad configuration options",
2053 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002054 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002055}
Darren Tuckere7140f22008-06-10 23:01:51 +10002056
2057static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002058fmt_multistate_int(int val, const struct multistate *m)
2059{
2060 u_int i;
2061
2062 for (i = 0; m[i].key != NULL; i++) {
2063 if (m[i].value == val)
2064 return m[i].key;
2065 }
2066 return "UNKNOWN";
2067}
2068
2069static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002070fmt_intarg(ServerOpCodes code, int val)
2071{
Damien Miller82c55872011-06-23 08:20:30 +10002072 if (val == -1)
2073 return "unset";
2074 switch (code) {
2075 case sAddressFamily:
2076 return fmt_multistate_int(val, multistate_addressfamily);
2077 case sPermitRootLogin:
2078 return fmt_multistate_int(val, multistate_permitrootlogin);
2079 case sGatewayPorts:
2080 return fmt_multistate_int(val, multistate_gatewayports);
2081 case sCompression:
2082 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002083 case sUsePrivilegeSeparation:
2084 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002085 case sAllowTcpForwarding:
2086 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002087 case sAllowStreamLocalForwarding:
2088 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002089 case sFingerprintHash:
2090 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002091 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002092 switch (val) {
2093 case SSH_PROTO_1:
2094 return "1";
2095 case SSH_PROTO_2:
2096 return "2";
2097 case (SSH_PROTO_1|SSH_PROTO_2):
2098 return "2,1";
2099 default:
2100 return "UNKNOWN";
2101 }
Damien Miller82c55872011-06-23 08:20:30 +10002102 default:
2103 switch (val) {
2104 case 0:
2105 return "no";
2106 case 1:
2107 return "yes";
2108 default:
2109 return "UNKNOWN";
2110 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002111 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002112}
2113
2114static const char *
2115lookup_opcode_name(ServerOpCodes code)
2116{
2117 u_int i;
2118
2119 for (i = 0; keywords[i].name != NULL; i++)
2120 if (keywords[i].opcode == code)
2121 return(keywords[i].name);
2122 return "UNKNOWN";
2123}
2124
2125static void
2126dump_cfg_int(ServerOpCodes code, int val)
2127{
2128 printf("%s %d\n", lookup_opcode_name(code), val);
2129}
2130
2131static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002132dump_cfg_oct(ServerOpCodes code, int val)
2133{
2134 printf("%s 0%o\n", lookup_opcode_name(code), val);
2135}
2136
2137static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002138dump_cfg_fmtint(ServerOpCodes code, int val)
2139{
2140 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2141}
2142
2143static void
2144dump_cfg_string(ServerOpCodes code, const char *val)
2145{
2146 if (val == NULL)
2147 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002148 printf("%s %s\n", lookup_opcode_name(code),
2149 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002150}
2151
2152static void
2153dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2154{
2155 u_int i;
2156
2157 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002158 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2159}
2160
2161static void
2162dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2163{
2164 u_int i;
2165
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002166 if (count <= 0)
2167 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002168 printf("%s", lookup_opcode_name(code));
2169 for (i = 0; i < count; i++)
2170 printf(" %s", vals[i]);
2171 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002172}
2173
2174void
2175dump_config(ServerOptions *o)
2176{
2177 u_int i;
2178 int ret;
2179 struct addrinfo *ai;
2180 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002181 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002182
2183 /* these are usually at the top of the config */
2184 for (i = 0; i < o->num_ports; i++)
2185 printf("port %d\n", o->ports[i]);
2186 dump_cfg_fmtint(sProtocol, o->protocol);
2187 dump_cfg_fmtint(sAddressFamily, o->address_family);
2188
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002189 /*
2190 * ListenAddress must be after Port. add_one_listen_addr pushes
2191 * addresses onto a stack, so to maintain ordering we need to
2192 * print these in reverse order.
2193 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002194 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2195 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2196 sizeof(addr), port, sizeof(port),
2197 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2198 error("getnameinfo failed: %.100s",
2199 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2200 strerror(errno));
2201 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002202 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002203 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002204 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2205 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002206 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002207 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2208 addr, port, laddr2);
2209 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002210 }
2211 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002212 printf("%s", laddr1);
2213 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002214
2215 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002216#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002217 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002218#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002219 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2220 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2221 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2222 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2223 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002224 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002225 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2226 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002227 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002228
2229 /* formatted integer arguments */
2230 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2231 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2232 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2233 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2234 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2235 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2236 o->hostbased_uses_name_from_packet_only);
2237 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2238 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002239#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002240 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2241 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2242 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002243# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002244 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002245# endif
2246#endif
2247#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002248 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2249 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002250#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002251 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2252 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2253 o->kbd_interactive_authentication);
2254 dump_cfg_fmtint(sChallengeResponseAuthentication,
2255 o->challenge_response_authentication);
2256 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2257 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2258 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2259 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002260 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002261 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002262 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2263 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2264 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2265 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2266 dump_cfg_fmtint(sUseLogin, o->use_login);
2267 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002268 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002269 dump_cfg_fmtint(sUseDNS, o->use_dns);
2270 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002271 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002272 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002273 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002274 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002275
2276 /* string arguments */
2277 dump_cfg_string(sPidFile, o->pid_file);
2278 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002279 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2280 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002282 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002283 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002284 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2285 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002286 dump_cfg_string(sAuthorizedPrincipalsFile,
2287 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002288 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2289 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002290 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2291 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002292 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2293 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002294 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002295 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002296 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002297 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2298 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002299 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2300 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002301 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2302 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002303
2304 /* string arguments requiring a lookup */
2305 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2306 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2307
2308 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002309 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2310 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002311 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2312 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002313 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002314 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002315 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2316 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2317 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2318 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2319 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002320 dump_cfg_strarray_oneline(sAuthenticationMethods,
2321 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002322
2323 /* other arguments */
2324 for (i = 0; i < o->num_subsystems; i++)
2325 printf("subsystem %s %s\n", o->subsystem_name[i],
2326 o->subsystem_args[i]);
2327
2328 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2329 o->max_startups_rate, o->max_startups);
2330
2331 for (i = 0; tunmode_desc[i].val != -1; i++)
2332 if (tunmode_desc[i].val == o->permit_tun) {
2333 s = tunmode_desc[i].text;
2334 break;
2335 }
2336 dump_cfg_string(sPermitTunnel, s);
2337
Damien Miller91475862011-05-05 14:14:34 +10002338 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2339 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002340
Damien Millera6d6c1f2013-08-21 02:40:01 +10002341 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2342 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002343
Darren Tuckere7140f22008-06-10 23:01:51 +10002344 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002345}