blob: 1cb45f5360d522fecd4dd8f6ddf4716830f18f0b [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002/* $OpenBSD: servconf.c,v 1.290 2016/05/04 14:00:09 dtucker 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
djm@openbsd.orged085102015-10-29 08:05:01 +0000181static void
182assemble_algorithms(ServerOptions *o)
183{
184 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
185 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
186 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
187 kex_assemble_names(KEX_DEFAULT_PK_ALG,
188 &o->hostkeyalgorithms) != 0 ||
189 kex_assemble_names(KEX_DEFAULT_PK_ALG,
190 &o->hostbased_key_types) != 0 ||
191 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
192 fatal("kex_assemble_names failed");
193}
194
Damien Miller4af51302000-04-16 11:18:38 +1000195void
Damien Miller95def091999-11-25 00:26:21 +1100196fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000197{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000198 int i;
199
Damien Miller726273e2001-11-12 11:40:11 +1100200 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000201 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000202 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100203
204 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100205 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100206 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100207 if (options->num_host_key_files == 0) {
208 /* fill default hostkeys for protocols */
209 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100210 options->host_key_files[options->num_host_key_files++] =
211 _PATH_HOST_KEY_FILE;
212 if (options->protocol & SSH_PROTO_2) {
213 options->host_key_files[options->num_host_key_files++] =
214 _PATH_HOST_RSA_KEY_FILE;
215 options->host_key_files[options->num_host_key_files++] =
216 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100217#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000218 options->host_key_files[options->num_host_key_files++] =
219 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100220#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100221 options->host_key_files[options->num_host_key_files++] =
222 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100223 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100224 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100225 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100226 if (options->num_ports == 0)
227 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000228 if (options->address_family == -1)
229 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100230 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000231 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000232 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000233 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000235 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000237 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100238 if (options->key_regeneration_time == -1)
239 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000240 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000241 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100242 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100243 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100244 if (options->ignore_user_known_hosts == -1)
245 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->print_motd == -1)
247 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000248 if (options->print_lastlog == -1)
249 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100250 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100251 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100252 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100253 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100254 if (options->x11_use_localhost == -1)
255 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000256 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000257 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100258 if (options->permit_tty == -1)
259 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000260 if (options->permit_user_rc == -1)
261 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->strict_modes == -1)
263 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100264 if (options->tcp_keep_alive == -1)
265 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100266 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100267 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100268 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000269 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100270 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100271 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000272 if (options->hostbased_authentication == -1)
273 options->hostbased_authentication = 0;
274 if (options->hostbased_uses_name_from_packet_only == -1)
275 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100276 if (options->rsa_authentication == -1)
277 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100278 if (options->pubkey_authentication == -1)
279 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000281 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100282 if (options->kerberos_or_local_passwd == -1)
283 options->kerberos_or_local_passwd = 1;
284 if (options->kerberos_ticket_cleanup == -1)
285 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100286 if (options->kerberos_get_afs_token == -1)
287 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000288 if (options->gss_authentication == -1)
289 options->gss_authentication = 0;
290 if (options->gss_cleanup_creds == -1)
291 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000292 if (options->gss_strict_acceptor == -1)
293 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100294 if (options->password_authentication == -1)
295 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100296 if (options->kbd_interactive_authentication == -1)
297 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000298 if (options->challenge_response_authentication == -1)
299 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100300 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100301 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000302 if (options->permit_user_env == -1)
303 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100304 if (options->use_login == -1)
305 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000306 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000307 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000308 if (options->rekey_limit == -1)
309 options->rekey_limit = 0;
310 if (options->rekey_interval == -1)
311 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100312 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100313 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000314 if (options->allow_streamlocal_forwarding == -1)
315 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000316 if (options->allow_agent_forwarding == -1)
317 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000318 if (options->fwd_opts.gateway_ports == -1)
319 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000320 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100321 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000322 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100323 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000324 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100325 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000326 if (options->max_authtries == -1)
327 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000328 if (options->max_sessions == -1)
329 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000330 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000331 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000332 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100333 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000334 if (options->client_alive_count_max == -1)
335 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000336 if (options->num_authkeys_files == 0) {
337 options->authorized_keys_files[options->num_authkeys_files++] =
338 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
339 options->authorized_keys_files[options->num_authkeys_files++] =
340 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
341 }
Damien Millerd27b9472005-12-13 19:29:02 +1100342 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100343 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100344 if (options->ip_qos_interactive == -1)
345 options->ip_qos_interactive = IPTOS_LOWDELAY;
346 if (options->ip_qos_bulk == -1)
347 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000348 if (options->version_addendum == NULL)
349 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000350 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
351 options->fwd_opts.streamlocal_bind_mask = 0177;
352 if (options->fwd_opts.streamlocal_bind_unlink == -1)
353 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000354 if (options->fingerprint_hash == -1)
355 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000356
djm@openbsd.orged085102015-10-29 08:05:01 +0000357 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000358
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000359 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000360 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000361 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000362
djm@openbsd.org161cf412014-12-22 07:55:51 +0000363#define CLEAR_ON_NONE(v) \
364 do { \
365 if (option_clear_or_none(v)) { \
366 free(v); \
367 v = NULL; \
368 } \
369 } while(0)
370 CLEAR_ON_NONE(options->pid_file);
371 CLEAR_ON_NONE(options->xauth_location);
372 CLEAR_ON_NONE(options->banner);
373 CLEAR_ON_NONE(options->trusted_user_ca_keys);
374 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000375 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000376 CLEAR_ON_NONE(options->adm_forced_command);
377 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000378 for (i = 0; i < options->num_host_key_files; i++)
379 CLEAR_ON_NONE(options->host_key_files[i]);
380 for (i = 0; i < options->num_host_cert_files; i++)
381 CLEAR_ON_NONE(options->host_cert_files[i]);
382#undef CLEAR_ON_NONE
383
Tim Rice40017b02002-07-14 13:36:49 -0700384#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000385 if (use_privsep && options->compression == 1) {
386 error("This platform does not support both privilege "
387 "separation and compression");
388 error("Compression disabled");
389 options->compression = 0;
390 }
391#endif
392
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000393}
394
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000395/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100396typedef enum {
397 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100398 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000399 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100400 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000401 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
402 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000403 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100404 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100405 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000406 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100407 sPasswordAuthentication, sKbdInteractiveAuthentication,
408 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000409 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100410 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100411 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000412 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000413 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000414 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000415 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
416 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000417 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000418 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000419 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000420 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000421 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
422 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100423 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100424 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100425 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000426 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000427 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000428 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100429 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000430 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000431 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000432 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000433 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000434} ServerOpCodes;
435
Darren Tucker45150472006-07-12 22:34:17 +1000436#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
437#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
438#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
439
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000440/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100441static struct {
442 const char *name;
443 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000444 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100445} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100446 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000447#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000448 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000449#else
Darren Tucker45150472006-07-12 22:34:17 +1000450 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000451#endif
Darren Tucker45150472006-07-12 22:34:17 +1000452 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100453 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000454 { "port", sPort, SSHCFG_GLOBAL },
455 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
456 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000457 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000458 { "pidfile", sPidFile, SSHCFG_GLOBAL },
459 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
460 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
461 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100462 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000463 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
464 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
465 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100466 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
467 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000468 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000469 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000470 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100471 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
472 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000473 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000474 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000475#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100476 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000477 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
478 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100479#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000480 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000481#else
Darren Tucker45150472006-07-12 22:34:17 +1000482 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100483#endif
484#else
Darren Tucker1629c072007-02-19 22:25:37 +1100485 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
487 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
488 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000489#endif
Darren Tucker45150472006-07-12 22:34:17 +1000490 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
491 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000492#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100493 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000494 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000495 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000496#else
Darren Tucker1629c072007-02-19 22:25:37 +1100497 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000498 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000499 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000500#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100501 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
502 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100503 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000504 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
505 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
506 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
507 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
508 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100509#ifdef DISABLE_LASTLOG
510 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
511#else
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100513#endif
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
515 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000516 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
517 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
518 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000519 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
520 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100521 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
523 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
524 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000525 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000526 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
527 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
528 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000529 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000530 { "allowusers", sAllowUsers, SSHCFG_ALL },
531 { "denyusers", sDenyUsers, SSHCFG_ALL },
532 { "allowgroups", sAllowGroups, SSHCFG_ALL },
533 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000534 { "ciphers", sCiphers, SSHCFG_GLOBAL },
535 { "macs", sMacs, SSHCFG_GLOBAL },
536 { "protocol", sProtocol, SSHCFG_GLOBAL },
537 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
538 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
539 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000540 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000541 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100542 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000543 { "usedns", sUseDNS, SSHCFG_GLOBAL },
544 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
545 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
546 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
547 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000548 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000549 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000550 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000551 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000552 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100553 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000554 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000555 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000556 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000557 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100558 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100559 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100560 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
561 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000562 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000563 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100564 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100565 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
566 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000567 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
568 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000569 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100570 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000571 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
572 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
573 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000574 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000575 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000576};
577
Darren Tuckere7140f22008-06-10 23:01:51 +1000578static struct {
579 int val;
580 char *text;
581} tunmode_desc[] = {
582 { SSH_TUNMODE_NO, "no" },
583 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
584 { SSH_TUNMODE_ETHERNET, "ethernet" },
585 { SSH_TUNMODE_YES, "yes" },
586 { -1, NULL }
587};
588
Damien Miller5428f641999-11-25 11:54:57 +1100589/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000590 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100591 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000592
Damien Miller4af51302000-04-16 11:18:38 +1000593static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100594parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000595 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000596{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000597 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000598
Damien Miller95def091999-11-25 00:26:21 +1100599 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000600 if (strcasecmp(cp, keywords[i].name) == 0) {
601 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100602 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000603 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000604
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000605 error("%s: line %d: Bad configuration option: %s",
606 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100607 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000608}
609
Darren Tucker88b6fb22010-01-13 22:44:29 +1100610char *
611derelativise_path(const char *path)
612{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000613 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100614
djm@openbsd.org161cf412014-12-22 07:55:51 +0000615 if (strcasecmp(path, "none") == 0)
616 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100617 expanded = tilde_expand_filename(path, getuid());
618 if (*expanded == '/')
619 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100620 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100621 fatal("%s: getcwd: %s", __func__, strerror(errno));
622 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000623 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100624 return ret;
625}
626
Ben Lindstrombba81212001-06-25 05:01:22 +0000627static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100628add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100629{
Damien Millereccb9de2005-06-17 12:59:34 +1000630 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100631
Ben Lindstrom19066a12001-04-12 23:39:26 +0000632 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000633 for (i = 0; i < options->num_ports; i++)
634 add_one_listen_addr(options, addr, options->ports[i]);
635 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000636 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000637}
638
Ben Lindstrombba81212001-06-25 05:01:22 +0000639static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100640add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000641{
642 struct addrinfo hints, *ai, *aitop;
643 char strport[NI_MAXSERV];
644 int gaierr;
645
646 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100647 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000648 hints.ai_socktype = SOCK_STREAM;
649 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100650 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000651 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
652 fatal("bad addr or host: %s (%s)",
653 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100654 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000655 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
656 ;
657 ai->ai_next = options->listen_addrs;
658 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100659}
660
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000661/*
662 * Queue a ListenAddress to be processed once we have all of the Ports
663 * and AddressFamily options.
664 */
665static void
666queue_listen_addr(ServerOptions *options, char *addr, int port)
667{
668 options->queued_listen_addrs = xreallocarray(
669 options->queued_listen_addrs, options->num_queued_listens + 1,
670 sizeof(addr));
671 options->queued_listen_ports = xreallocarray(
672 options->queued_listen_ports, options->num_queued_listens + 1,
673 sizeof(port));
674 options->queued_listen_addrs[options->num_queued_listens] =
675 xstrdup(addr);
676 options->queued_listen_ports[options->num_queued_listens] = port;
677 options->num_queued_listens++;
678}
679
680/*
681 * Process queued (text) ListenAddress entries.
682 */
683static void
684process_queued_listen_addrs(ServerOptions *options)
685{
686 u_int i;
687
688 if (options->num_ports == 0)
689 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
690 if (options->address_family == -1)
691 options->address_family = AF_UNSPEC;
692
693 for (i = 0; i < options->num_queued_listens; i++) {
694 add_listen_addr(options, options->queued_listen_addrs[i],
695 options->queued_listen_ports[i]);
696 free(options->queued_listen_addrs[i]);
697 options->queued_listen_addrs[i] = NULL;
698 }
699 free(options->queued_listen_addrs);
700 options->queued_listen_addrs = NULL;
701 free(options->queued_listen_ports);
702 options->queued_listen_ports = NULL;
703 options->num_queued_listens = 0;
704}
705
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000706struct connection_info *
707get_connection_info(int populate, int use_dns)
708{
djm@openbsd.org95767262016-03-07 19:02:43 +0000709 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000710 static struct connection_info ci;
711
712 if (!populate)
713 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000714 ci.host = auth_get_canonical_hostname(ssh, use_dns);
715 ci.address = ssh_remote_ipaddr(ssh);
716 ci.laddress = ssh_local_ipaddr(ssh);
717 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000718 return &ci;
719}
720
Darren Tucker45150472006-07-12 22:34:17 +1000721/*
722 * The strategy for the Match blocks is that the config file is parsed twice.
723 *
724 * The first time is at startup. activep is initialized to 1 and the
725 * directives in the global context are processed and acted on. Hitting a
726 * Match directive unsets activep and the directives inside the block are
727 * checked for syntax only.
728 *
729 * The second time is after a connection has been established but before
730 * authentication. activep is initialized to 2 and global config directives
731 * are ignored since they have already been processed. If the criteria in a
732 * Match block is met, activep is set and the subsequent directives
733 * processed and actioned until EOF or another Match block unsets it. Any
734 * options set are copied into the main server config.
735 *
736 * Potential additions/improvements:
737 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
738 *
739 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
740 * Match Address 192.168.0.*
741 * Tag trusted
742 * Match Group wheel
743 * Tag trusted
744 * Match Tag trusted
745 * AllowTcpForwarding yes
746 * GatewayPorts clientspecified
747 * [...]
748 *
749 * - Add a PermittedChannelRequests directive
750 * Match Group shell
751 * PermittedChannelRequests session,forwarded-tcpip
752 */
753
754static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000755match_cfg_line_group(const char *grps, int line, const char *user)
756{
757 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000758 struct passwd *pw;
759
Damien Miller565ca3f2006-08-19 00:23:15 +1000760 if (user == NULL)
761 goto out;
762
763 if ((pw = getpwnam(user)) == NULL) {
764 debug("Can't match group at line %d because user %.100s does "
765 "not exist", line, user);
766 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
767 debug("Can't Match group because user %.100s not in any group "
768 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000769 } else if (ga_match_pattern_list(grps) != 1) {
770 debug("user %.100s does not match group list %.100s at line %d",
771 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000772 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000773 debug("user %.100s matched group list %.100s at line %d", user,
774 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000775 result = 1;
776 }
777out:
778 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000779 return result;
780}
781
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000782/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000783 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100784 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000785 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000786 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000787static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000788match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000789{
Damien Millercf31f382013-10-24 21:02:56 +1100790 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000791 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000792
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000793 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000794 debug3("checking syntax for 'Match %s'", cp);
795 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000796 debug3("checking match for '%s' user %s host %s addr %s "
797 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
798 ci->host ? ci->host : "(null)",
799 ci->address ? ci->address : "(null)",
800 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000801
802 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100803 attributes++;
804 if (strcasecmp(attrib, "all") == 0) {
805 if (attributes != 1 ||
806 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
807 error("'all' cannot be combined with other "
808 "Match attributes");
809 return -1;
810 }
811 *condition = cp;
812 return 1;
813 }
Darren Tucker45150472006-07-12 22:34:17 +1000814 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
815 error("Missing Match criteria for %s", attrib);
816 return -1;
817 }
Darren Tucker45150472006-07-12 22:34:17 +1000818 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000819 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000820 result = 0;
821 continue;
822 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000823 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000824 result = 0;
825 else
826 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000827 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000828 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000829 if (ci == NULL || ci->user == NULL) {
830 result = 0;
831 continue;
832 }
833 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000834 case -1:
835 return -1;
836 case 0:
837 result = 0;
838 }
Darren Tucker45150472006-07-12 22:34:17 +1000839 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000840 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000841 result = 0;
842 continue;
843 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000844 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000845 result = 0;
846 else
847 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000848 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000849 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000850 if (ci == NULL || ci->address == NULL) {
851 result = 0;
852 continue;
853 }
854 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000855 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000856 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000857 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000858 break;
859 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000860 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000861 result = 0;
862 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000863 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000864 return -1;
865 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000866 } else if (strcasecmp(attrib, "localaddress") == 0){
867 if (ci == NULL || ci->laddress == NULL) {
868 result = 0;
869 continue;
870 }
871 switch (addr_match_list(ci->laddress, arg)) {
872 case 1:
873 debug("connection from %.100s matched "
874 "'LocalAddress %.100s' at line %d",
875 ci->laddress, arg, line);
876 break;
877 case 0:
878 case -1:
879 result = 0;
880 break;
881 case -2:
882 return -1;
883 }
884 } else if (strcasecmp(attrib, "localport") == 0) {
885 if ((port = a2port(arg)) == -1) {
886 error("Invalid LocalPort '%s' on Match line",
887 arg);
888 return -1;
889 }
890 if (ci == NULL || ci->lport == 0) {
891 result = 0;
892 continue;
893 }
894 /* TODO support port lists */
895 if (port == ci->lport)
896 debug("connection from %.100s matched "
897 "'LocalPort %d' at line %d",
898 ci->laddress, port, line);
899 else
900 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000901 } else {
902 error("Unsupported Match attribute %s", attrib);
903 return -1;
904 }
905 }
Damien Millercf31f382013-10-24 21:02:56 +1100906 if (attributes == 0) {
907 error("One or more attributes required for Match");
908 return -1;
909 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000910 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000911 debug3("match %sfound", result ? "" : "not ");
912 *condition = cp;
913 return result;
914}
915
Damien Millere2754432006-07-24 14:06:47 +1000916#define WHITESPACE " \t\r\n"
917
Damien Miller33322122011-06-20 14:43:11 +1000918/* Multistate option parsing */
919struct multistate {
920 char *key;
921 int value;
922};
923static const struct multistate multistate_addressfamily[] = {
924 { "inet", AF_INET },
925 { "inet6", AF_INET6 },
926 { "any", AF_UNSPEC },
927 { NULL, -1 }
928};
929static const struct multistate multistate_permitrootlogin[] = {
930 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000931 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000932 { "forced-commands-only", PERMIT_FORCED_ONLY },
933 { "yes", PERMIT_YES },
934 { "no", PERMIT_NO },
935 { NULL, -1 }
936};
937static const struct multistate multistate_compression[] = {
938 { "delayed", COMP_DELAYED },
939 { "yes", COMP_ZLIB },
940 { "no", COMP_NONE },
941 { NULL, -1 }
942};
943static const struct multistate multistate_gatewayports[] = {
944 { "clientspecified", 2 },
945 { "yes", 1 },
946 { "no", 0 },
947 { NULL, -1 }
948};
Damien Miller69ff1df2011-06-23 08:30:03 +1000949static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000950 { "yes", PRIVSEP_NOSANDBOX },
951 { "sandbox", PRIVSEP_ON },
952 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000953 { "no", PRIVSEP_OFF },
954 { NULL, -1 }
955};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100956static const struct multistate multistate_tcpfwd[] = {
957 { "yes", FORWARD_ALLOW },
958 { "all", FORWARD_ALLOW },
959 { "no", FORWARD_DENY },
960 { "remote", FORWARD_REMOTE },
961 { "local", FORWARD_LOCAL },
962 { NULL, -1 }
963};
Damien Miller33322122011-06-20 14:43:11 +1000964
Ben Lindstromade03f62001-12-06 18:22:17 +0000965int
966process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000967 const char *filename, int linenum, int *activep,
968 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000969{
Darren Tucker09c0f032013-05-16 20:48:57 +1000970 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000971 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100972 SyslogFacility *log_facility_ptr;
973 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000974 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000975 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000976 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000977 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000978 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000979
980 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100981 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100982 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000983 /* Ignore leading whitespace */
984 if (*arg == '\0')
985 arg = strdelim(&cp);
986 if (!arg || !*arg || *arg == '#')
987 return 0;
988 intptr = NULL;
989 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000990 opcode = parse_token(arg, filename, linenum, &flags);
991
992 if (activep == NULL) { /* We are processing a command line directive */
993 cmdline = 1;
994 activep = &cmdline;
995 }
996 if (*activep && opcode != sMatch)
997 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
998 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000999 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001000 fatal("%s line %d: Directive '%s' is not allowed "
1001 "within a Match block", filename, linenum, arg);
1002 } else { /* this is a directive we have already processed */
1003 while (arg)
1004 arg = strdelim(&cp);
1005 return 0;
1006 }
1007 }
1008
Ben Lindstromade03f62001-12-06 18:22:17 +00001009 switch (opcode) {
1010 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001011 case sUsePAM:
1012 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001013 goto parse_flag;
1014
1015 /* Standard Options */
1016 case sBadOption:
1017 return -1;
1018 case sPort:
1019 /* ignore ports from configfile if cmdline specifies ports */
1020 if (options->ports_from_cmdline)
1021 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001022 if (options->num_ports >= MAX_PORTS)
1023 fatal("%s line %d: too many ports.",
1024 filename, linenum);
1025 arg = strdelim(&cp);
1026 if (!arg || *arg == '\0')
1027 fatal("%s line %d: missing port number.",
1028 filename, linenum);
1029 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001030 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001031 fatal("%s line %d: Badly formatted port number.",
1032 filename, linenum);
1033 break;
1034
1035 case sServerKeyBits:
1036 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001037 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 arg = strdelim(&cp);
1039 if (!arg || *arg == '\0')
1040 fatal("%s line %d: missing integer value.",
1041 filename, linenum);
1042 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001043 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 *intptr = value;
1045 break;
1046
1047 case sLoginGraceTime:
1048 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001049 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001050 arg = strdelim(&cp);
1051 if (!arg || *arg == '\0')
1052 fatal("%s line %d: missing time value.",
1053 filename, linenum);
1054 if ((value = convtime(arg)) == -1)
1055 fatal("%s line %d: invalid time value.",
1056 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001057 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001058 *intptr = value;
1059 break;
1060
1061 case sKeyRegenerationTime:
1062 intptr = &options->key_regeneration_time;
1063 goto parse_time;
1064
1065 case sListenAddress:
1066 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001067 if (arg == NULL || *arg == '\0')
1068 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001069 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001070 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1071 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1072 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001073 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001074 break;
1075 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001076 p = hpdelim(&arg);
1077 if (p == NULL)
1078 fatal("%s line %d: bad address:port usage",
1079 filename, linenum);
1080 p = cleanhostname(p);
1081 if (arg == NULL)
1082 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001083 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001084 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001085
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001086 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001087
Ben Lindstromade03f62001-12-06 18:22:17 +00001088 break;
1089
Darren Tucker0f383232005-01-20 10:57:56 +11001090 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001091 intptr = &options->address_family;
1092 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001093 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001094 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001095 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001096 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001097 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001098 value = -1;
1099 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1100 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1101 value = multistate_ptr[i].value;
1102 break;
1103 }
1104 }
1105 if (value == -1)
1106 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001107 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001108 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001109 *intptr = value;
1110 break;
1111
Ben Lindstromade03f62001-12-06 18:22:17 +00001112 case sHostKeyFile:
1113 intptr = &options->num_host_key_files;
1114 if (*intptr >= MAX_HOSTKEYS)
1115 fatal("%s line %d: too many host keys specified (max %d).",
1116 filename, linenum, MAX_HOSTKEYS);
1117 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001118 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001119 arg = strdelim(&cp);
1120 if (!arg || *arg == '\0')
1121 fatal("%s line %d: missing file name.",
1122 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001123 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001124 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001125 /* increase optional counter */
1126 if (intptr != NULL)
1127 *intptr = *intptr + 1;
1128 }
1129 break;
1130
Damien Miller85b45e02013-07-20 13:21:52 +10001131 case sHostKeyAgent:
1132 charptr = &options->host_key_agent;
1133 arg = strdelim(&cp);
1134 if (!arg || *arg == '\0')
1135 fatal("%s line %d: missing socket name.",
1136 filename, linenum);
1137 if (*activep && *charptr == NULL)
1138 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1139 xstrdup(arg) : derelativise_path(arg);
1140 break;
1141
Damien Miller0a80ca12010-02-27 07:55:05 +11001142 case sHostCertificate:
1143 intptr = &options->num_host_cert_files;
1144 if (*intptr >= MAX_HOSTKEYS)
1145 fatal("%s line %d: too many host certificates "
1146 "specified (max %d).", filename, linenum,
1147 MAX_HOSTCERTS);
1148 charptr = &options->host_cert_files[*intptr];
1149 goto parse_filename;
1150 break;
1151
Ben Lindstromade03f62001-12-06 18:22:17 +00001152 case sPidFile:
1153 charptr = &options->pid_file;
1154 goto parse_filename;
1155
1156 case sPermitRootLogin:
1157 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001158 multistate_ptr = multistate_permitrootlogin;
1159 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001160
1161 case sIgnoreRhosts:
1162 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001163 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001164 arg = strdelim(&cp);
1165 if (!arg || *arg == '\0')
1166 fatal("%s line %d: missing yes/no argument.",
1167 filename, linenum);
1168 value = 0; /* silence compiler */
1169 if (strcmp(arg, "yes") == 0)
1170 value = 1;
1171 else if (strcmp(arg, "no") == 0)
1172 value = 0;
1173 else
1174 fatal("%s line %d: Bad yes/no argument: %s",
1175 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001176 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001177 *intptr = value;
1178 break;
1179
1180 case sIgnoreUserKnownHosts:
1181 intptr = &options->ignore_user_known_hosts;
1182 goto parse_flag;
1183
Ben Lindstromade03f62001-12-06 18:22:17 +00001184 case sRhostsRSAAuthentication:
1185 intptr = &options->rhosts_rsa_authentication;
1186 goto parse_flag;
1187
1188 case sHostbasedAuthentication:
1189 intptr = &options->hostbased_authentication;
1190 goto parse_flag;
1191
1192 case sHostbasedUsesNameFromPacketOnly:
1193 intptr = &options->hostbased_uses_name_from_packet_only;
1194 goto parse_flag;
1195
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001196 case sHostbasedAcceptedKeyTypes:
1197 charptr = &options->hostbased_key_types;
1198 parse_keytypes:
1199 arg = strdelim(&cp);
1200 if (!arg || *arg == '\0')
1201 fatal("%s line %d: Missing argument.",
1202 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001203 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001204 fatal("%s line %d: Bad key types '%s'.",
1205 filename, linenum, arg ? arg : "<NONE>");
1206 if (*activep && *charptr == NULL)
1207 *charptr = xstrdup(arg);
1208 break;
1209
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001210 case sHostKeyAlgorithms:
1211 charptr = &options->hostkeyalgorithms;
1212 goto parse_keytypes;
1213
Ben Lindstromade03f62001-12-06 18:22:17 +00001214 case sRSAAuthentication:
1215 intptr = &options->rsa_authentication;
1216 goto parse_flag;
1217
1218 case sPubkeyAuthentication:
1219 intptr = &options->pubkey_authentication;
1220 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001221
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001222 case sPubkeyAcceptedKeyTypes:
1223 charptr = &options->pubkey_key_types;
1224 goto parse_keytypes;
1225
Ben Lindstromade03f62001-12-06 18:22:17 +00001226 case sKerberosAuthentication:
1227 intptr = &options->kerberos_authentication;
1228 goto parse_flag;
1229
1230 case sKerberosOrLocalPasswd:
1231 intptr = &options->kerberos_or_local_passwd;
1232 goto parse_flag;
1233
1234 case sKerberosTicketCleanup:
1235 intptr = &options->kerberos_ticket_cleanup;
1236 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001237
Darren Tucker22ef5082003-12-31 11:37:34 +11001238 case sKerberosGetAFSToken:
1239 intptr = &options->kerberos_get_afs_token;
1240 goto parse_flag;
1241
Darren Tucker0efd1552003-08-26 11:49:55 +10001242 case sGssAuthentication:
1243 intptr = &options->gss_authentication;
1244 goto parse_flag;
1245
1246 case sGssCleanupCreds:
1247 intptr = &options->gss_cleanup_creds;
1248 goto parse_flag;
1249
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001250 case sGssStrictAcceptor:
1251 intptr = &options->gss_strict_acceptor;
1252 goto parse_flag;
1253
Ben Lindstromade03f62001-12-06 18:22:17 +00001254 case sPasswordAuthentication:
1255 intptr = &options->password_authentication;
1256 goto parse_flag;
1257
1258 case sKbdInteractiveAuthentication:
1259 intptr = &options->kbd_interactive_authentication;
1260 goto parse_flag;
1261
1262 case sChallengeResponseAuthentication:
1263 intptr = &options->challenge_response_authentication;
1264 goto parse_flag;
1265
1266 case sPrintMotd:
1267 intptr = &options->print_motd;
1268 goto parse_flag;
1269
1270 case sPrintLastLog:
1271 intptr = &options->print_lastlog;
1272 goto parse_flag;
1273
1274 case sX11Forwarding:
1275 intptr = &options->x11_forwarding;
1276 goto parse_flag;
1277
1278 case sX11DisplayOffset:
1279 intptr = &options->x11_display_offset;
1280 goto parse_int;
1281
Damien Miller95c249f2002-02-05 12:11:34 +11001282 case sX11UseLocalhost:
1283 intptr = &options->x11_use_localhost;
1284 goto parse_flag;
1285
Ben Lindstromade03f62001-12-06 18:22:17 +00001286 case sXAuthLocation:
1287 charptr = &options->xauth_location;
1288 goto parse_filename;
1289
Damien Miller5ff30c62013-10-30 22:21:50 +11001290 case sPermitTTY:
1291 intptr = &options->permit_tty;
1292 goto parse_flag;
1293
Damien Miller72e6b5c2014-07-04 09:00:04 +10001294 case sPermitUserRC:
1295 intptr = &options->permit_user_rc;
1296 goto parse_flag;
1297
Ben Lindstromade03f62001-12-06 18:22:17 +00001298 case sStrictModes:
1299 intptr = &options->strict_modes;
1300 goto parse_flag;
1301
Damien Miller12c150e2003-12-17 16:31:10 +11001302 case sTCPKeepAlive:
1303 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001304 goto parse_flag;
1305
1306 case sEmptyPasswd:
1307 intptr = &options->permit_empty_passwd;
1308 goto parse_flag;
1309
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001310 case sPermitUserEnvironment:
1311 intptr = &options->permit_user_env;
1312 goto parse_flag;
1313
Ben Lindstromade03f62001-12-06 18:22:17 +00001314 case sUseLogin:
1315 intptr = &options->use_login;
1316 goto parse_flag;
1317
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001318 case sCompression:
1319 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001320 multistate_ptr = multistate_compression;
1321 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001322
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001323 case sRekeyLimit:
1324 arg = strdelim(&cp);
1325 if (!arg || *arg == '\0')
1326 fatal("%.200s line %d: Missing argument.", filename,
1327 linenum);
1328 if (strcmp(arg, "default") == 0) {
1329 val64 = 0;
1330 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001331 if (scan_scaled(arg, &val64) == -1)
1332 fatal("%.200s line %d: Bad number '%s': %s",
1333 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001334 if (val64 != 0 && val64 < 16)
1335 fatal("%.200s line %d: RekeyLimit too small",
1336 filename, linenum);
1337 }
1338 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001339 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001340 if (cp != NULL) { /* optional rekey interval present */
1341 if (strcmp(cp, "none") == 0) {
1342 (void)strdelim(&cp); /* discard */
1343 break;
1344 }
1345 intptr = &options->rekey_interval;
1346 goto parse_time;
1347 }
1348 break;
1349
Ben Lindstromade03f62001-12-06 18:22:17 +00001350 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001351 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001352 multistate_ptr = multistate_gatewayports;
1353 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001354
Damien Miller3a961dc2003-06-03 10:25:48 +10001355 case sUseDNS:
1356 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001357 goto parse_flag;
1358
1359 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001360 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001361 arg = strdelim(&cp);
1362 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001363 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 fatal("%.200s line %d: unsupported log facility '%s'",
1365 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001366 if (*log_facility_ptr == -1)
1367 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001368 break;
1369
1370 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001371 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001372 arg = strdelim(&cp);
1373 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001374 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001375 fatal("%.200s line %d: unsupported log level '%s'",
1376 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001377 if (*log_level_ptr == -1)
1378 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001379 break;
1380
1381 case sAllowTcpForwarding:
1382 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001383 multistate_ptr = multistate_tcpfwd;
1384 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001385
Damien Miller7acefbb2014-07-18 14:11:24 +10001386 case sAllowStreamLocalForwarding:
1387 intptr = &options->allow_streamlocal_forwarding;
1388 multistate_ptr = multistate_tcpfwd;
1389 goto parse_multistate;
1390
Damien Miller4f755cd2008-05-19 14:57:41 +10001391 case sAllowAgentForwarding:
1392 intptr = &options->allow_agent_forwarding;
1393 goto parse_flag;
1394
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001395 case sUsePrivilegeSeparation:
1396 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001397 multistate_ptr = multistate_privsep;
1398 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001399
Ben Lindstromade03f62001-12-06 18:22:17 +00001400 case sAllowUsers:
1401 while ((arg = strdelim(&cp)) && *arg != '\0') {
1402 if (options->num_allow_users >= MAX_ALLOW_USERS)
1403 fatal("%s line %d: too many allow users.",
1404 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001405 if (!*activep)
1406 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001407 options->allow_users[options->num_allow_users++] =
1408 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001409 }
1410 break;
1411
1412 case sDenyUsers:
1413 while ((arg = strdelim(&cp)) && *arg != '\0') {
1414 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001415 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001416 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001417 if (!*activep)
1418 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001419 options->deny_users[options->num_deny_users++] =
1420 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001421 }
1422 break;
1423
1424 case sAllowGroups:
1425 while ((arg = strdelim(&cp)) && *arg != '\0') {
1426 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1427 fatal("%s line %d: too many allow groups.",
1428 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001429 if (!*activep)
1430 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001431 options->allow_groups[options->num_allow_groups++] =
1432 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001433 }
1434 break;
1435
1436 case sDenyGroups:
1437 while ((arg = strdelim(&cp)) && *arg != '\0') {
1438 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1439 fatal("%s line %d: too many deny groups.",
1440 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001441 if (!*activep)
1442 continue;
1443 options->deny_groups[options->num_deny_groups++] =
1444 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001445 }
1446 break;
1447
1448 case sCiphers:
1449 arg = strdelim(&cp);
1450 if (!arg || *arg == '\0')
1451 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001452 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001453 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1454 filename, linenum, arg ? arg : "<NONE>");
1455 if (options->ciphers == NULL)
1456 options->ciphers = xstrdup(arg);
1457 break;
1458
1459 case sMacs:
1460 arg = strdelim(&cp);
1461 if (!arg || *arg == '\0')
1462 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001463 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001464 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1465 filename, linenum, arg ? arg : "<NONE>");
1466 if (options->macs == NULL)
1467 options->macs = xstrdup(arg);
1468 break;
1469
Damien Millerd5f62bf2010-09-24 22:11:14 +10001470 case sKexAlgorithms:
1471 arg = strdelim(&cp);
1472 if (!arg || *arg == '\0')
1473 fatal("%s line %d: Missing argument.",
1474 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001475 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001476 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1477 filename, linenum, arg ? arg : "<NONE>");
1478 if (options->kex_algorithms == NULL)
1479 options->kex_algorithms = xstrdup(arg);
1480 break;
1481
Ben Lindstromade03f62001-12-06 18:22:17 +00001482 case sProtocol:
1483 intptr = &options->protocol;
1484 arg = strdelim(&cp);
1485 if (!arg || *arg == '\0')
1486 fatal("%s line %d: Missing argument.", filename, linenum);
1487 value = proto_spec(arg);
1488 if (value == SSH_PROTO_UNKNOWN)
1489 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001490 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001491 if (*intptr == SSH_PROTO_UNKNOWN)
1492 *intptr = value;
1493 break;
1494
1495 case sSubsystem:
1496 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1497 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001498 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001499 }
1500 arg = strdelim(&cp);
1501 if (!arg || *arg == '\0')
1502 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001503 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001504 if (!*activep) {
1505 arg = strdelim(&cp);
1506 break;
1507 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001508 for (i = 0; i < options->num_subsystems; i++)
1509 if (strcmp(arg, options->subsystem_name[i]) == 0)
1510 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001511 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001512 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1513 arg = strdelim(&cp);
1514 if (!arg || *arg == '\0')
1515 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001516 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001517 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001518
1519 /* Collect arguments (separate to executable) */
1520 p = xstrdup(arg);
1521 len = strlen(p) + 1;
1522 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1523 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001524 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001525 strlcat(p, " ", len);
1526 strlcat(p, arg, len);
1527 }
1528 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001529 options->num_subsystems++;
1530 break;
1531
1532 case sMaxStartups:
1533 arg = strdelim(&cp);
1534 if (!arg || *arg == '\0')
1535 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001536 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001537 if ((n = sscanf(arg, "%d:%d:%d",
1538 &options->max_startups_begin,
1539 &options->max_startups_rate,
1540 &options->max_startups)) == 3) {
1541 if (options->max_startups_begin >
1542 options->max_startups ||
1543 options->max_startups_rate > 100 ||
1544 options->max_startups_rate < 1)
1545 fatal("%s line %d: Illegal MaxStartups spec.",
1546 filename, linenum);
1547 } else if (n != 1)
1548 fatal("%s line %d: Illegal MaxStartups spec.",
1549 filename, linenum);
1550 else
1551 options->max_startups = options->max_startups_begin;
1552 break;
1553
Darren Tucker89413db2004-05-24 10:36:23 +10001554 case sMaxAuthTries:
1555 intptr = &options->max_authtries;
1556 goto parse_int;
1557
Damien Miller7207f642008-05-19 15:34:50 +10001558 case sMaxSessions:
1559 intptr = &options->max_sessions;
1560 goto parse_int;
1561
Ben Lindstromade03f62001-12-06 18:22:17 +00001562 case sBanner:
1563 charptr = &options->banner;
1564 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001565
Ben Lindstromade03f62001-12-06 18:22:17 +00001566 /*
1567 * These options can contain %X options expanded at
1568 * connect time, so that you can specify paths like:
1569 *
1570 * AuthorizedKeysFile /etc/ssh_keys/%u
1571 */
1572 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001573 if (*activep && options->num_authkeys_files == 0) {
1574 while ((arg = strdelim(&cp)) && *arg != '\0') {
1575 if (options->num_authkeys_files >=
1576 MAX_AUTHKEYS_FILES)
1577 fatal("%s line %d: "
1578 "too many authorized keys files.",
1579 filename, linenum);
1580 options->authorized_keys_files[
1581 options->num_authkeys_files++] =
1582 tilde_expand_filename(arg, getuid());
1583 }
1584 }
1585 return 0;
1586
Damien Miller30da3442010-05-10 11:58:03 +10001587 case sAuthorizedPrincipalsFile:
1588 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001589 arg = strdelim(&cp);
1590 if (!arg || *arg == '\0')
1591 fatal("%s line %d: missing file name.",
1592 filename, linenum);
1593 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001594 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001595 /* increase optional counter */
1596 if (intptr != NULL)
1597 *intptr = *intptr + 1;
1598 }
1599 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001600
1601 case sClientAliveInterval:
1602 intptr = &options->client_alive_interval;
1603 goto parse_time;
1604
1605 case sClientAliveCountMax:
1606 intptr = &options->client_alive_count_max;
1607 goto parse_int;
1608
Darren Tucker46bc0752004-05-02 22:11:30 +10001609 case sAcceptEnv:
1610 while ((arg = strdelim(&cp)) && *arg != '\0') {
1611 if (strchr(arg, '=') != NULL)
1612 fatal("%s line %d: Invalid environment name.",
1613 filename, linenum);
1614 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1615 fatal("%s line %d: too many allow env.",
1616 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001617 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001618 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001619 options->accept_env[options->num_accept_env++] =
1620 xstrdup(arg);
1621 }
1622 break;
1623
Damien Millerd27b9472005-12-13 19:29:02 +11001624 case sPermitTunnel:
1625 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001626 arg = strdelim(&cp);
1627 if (!arg || *arg == '\0')
1628 fatal("%s line %d: Missing yes/point-to-point/"
1629 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001630 value = -1;
1631 for (i = 0; tunmode_desc[i].val != -1; i++)
1632 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1633 value = tunmode_desc[i].val;
1634 break;
1635 }
1636 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001637 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1638 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001639 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001640 *intptr = value;
1641 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001642
Darren Tucker45150472006-07-12 22:34:17 +10001643 case sMatch:
1644 if (cmdline)
1645 fatal("Match directive not supported as a command-line "
1646 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001647 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001648 if (value < 0)
1649 fatal("%s line %d: Bad Match condition", filename,
1650 linenum);
1651 *activep = value;
1652 break;
1653
Damien Miller9b439df2006-07-24 14:04:00 +10001654 case sPermitOpen:
1655 arg = strdelim(&cp);
1656 if (!arg || *arg == '\0')
1657 fatal("%s line %d: missing PermitOpen specification",
1658 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001659 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001660 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001661 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001662 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001663 options->num_permitted_opens = 0;
1664 }
Damien Miller9b439df2006-07-24 14:04:00 +10001665 break;
1666 }
Damien Millerc6081482012-04-22 11:18:53 +10001667 if (strcmp(arg, "none") == 0) {
1668 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001669 options->num_permitted_opens = 1;
1670 channel_disable_adm_local_opens();
1671 }
1672 break;
1673 }
Damien Millera29b95e2007-01-05 16:28:36 +11001674 if (*activep && n == -1)
1675 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001676 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1677 p = hpdelim(&arg);
1678 if (p == NULL)
1679 fatal("%s line %d: missing host in PermitOpen",
1680 filename, linenum);
1681 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001682 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001683 fatal("%s line %d: bad port number in "
1684 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001685 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001686 options->num_permitted_opens =
1687 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001688 }
Damien Miller9b439df2006-07-24 14:04:00 +10001689 break;
1690
Damien Millere2754432006-07-24 14:06:47 +10001691 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001692 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001693 fatal("%.200s line %d: Missing argument.", filename,
1694 linenum);
1695 len = strspn(cp, WHITESPACE);
1696 if (*activep && options->adm_forced_command == NULL)
1697 options->adm_forced_command = xstrdup(cp + len);
1698 return 0;
1699
Damien Millerd8cb1f12008-02-10 22:40:12 +11001700 case sChrootDirectory:
1701 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001702
1703 arg = strdelim(&cp);
1704 if (!arg || *arg == '\0')
1705 fatal("%s line %d: missing file name.",
1706 filename, linenum);
1707 if (*activep && *charptr == NULL)
1708 *charptr = xstrdup(arg);
1709 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001710
Damien Miller1aed65e2010-03-04 21:53:35 +11001711 case sTrustedUserCAKeys:
1712 charptr = &options->trusted_user_ca_keys;
1713 goto parse_filename;
1714
1715 case sRevokedKeys:
1716 charptr = &options->revoked_keys_file;
1717 goto parse_filename;
1718
Damien Miller0dac6fb2010-11-20 15:19:38 +11001719 case sIPQoS:
1720 arg = strdelim(&cp);
1721 if ((value = parse_ipqos(arg)) == -1)
1722 fatal("%s line %d: Bad IPQoS value: %s",
1723 filename, linenum, arg);
1724 arg = strdelim(&cp);
1725 if (arg == NULL)
1726 value2 = value;
1727 else if ((value2 = parse_ipqos(arg)) == -1)
1728 fatal("%s line %d: Bad IPQoS value: %s",
1729 filename, linenum, arg);
1730 if (*activep) {
1731 options->ip_qos_interactive = value;
1732 options->ip_qos_bulk = value2;
1733 }
1734 break;
1735
Damien Miller23528812012-04-22 11:24:43 +10001736 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001737 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001738 fatal("%.200s line %d: Missing argument.", filename,
1739 linenum);
1740 len = strspn(cp, WHITESPACE);
1741 if (*activep && options->version_addendum == NULL) {
1742 if (strcasecmp(cp + len, "none") == 0)
1743 options->version_addendum = xstrdup("");
1744 else if (strchr(cp + len, '\r') != NULL)
1745 fatal("%.200s line %d: Invalid argument",
1746 filename, linenum);
1747 else
1748 options->version_addendum = xstrdup(cp + len);
1749 }
1750 return 0;
1751
Damien Miller09d3e122012-10-31 08:58:58 +11001752 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001753 if (cp == NULL)
1754 fatal("%.200s line %d: Missing argument.", filename,
1755 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001756 len = strspn(cp, WHITESPACE);
1757 if (*activep && options->authorized_keys_command == NULL) {
1758 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1759 fatal("%.200s line %d: AuthorizedKeysCommand "
1760 "must be an absolute path",
1761 filename, linenum);
1762 options->authorized_keys_command = xstrdup(cp + len);
1763 }
1764 return 0;
1765
1766 case sAuthorizedKeysCommandUser:
1767 charptr = &options->authorized_keys_command_user;
1768
1769 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001770 if (!arg || *arg == '\0')
1771 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1772 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001773 if (*activep && *charptr == NULL)
1774 *charptr = xstrdup(arg);
1775 break;
1776
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001777 case sAuthorizedPrincipalsCommand:
1778 if (cp == NULL)
1779 fatal("%.200s line %d: Missing argument.", filename,
1780 linenum);
1781 len = strspn(cp, WHITESPACE);
1782 if (*activep &&
1783 options->authorized_principals_command == NULL) {
1784 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1785 fatal("%.200s line %d: "
1786 "AuthorizedPrincipalsCommand must be "
1787 "an absolute path", filename, linenum);
1788 options->authorized_principals_command =
1789 xstrdup(cp + len);
1790 }
1791 return 0;
1792
1793 case sAuthorizedPrincipalsCommandUser:
1794 charptr = &options->authorized_principals_command_user;
1795
1796 arg = strdelim(&cp);
1797 if (!arg || *arg == '\0')
1798 fatal("%s line %d: missing "
1799 "AuthorizedPrincipalsCommandUser argument.",
1800 filename, linenum);
1801 if (*activep && *charptr == NULL)
1802 *charptr = xstrdup(arg);
1803 break;
1804
Damien Millera6e3f012012-11-04 23:21:40 +11001805 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001806 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001807 while ((arg = strdelim(&cp)) && *arg != '\0') {
1808 if (options->num_auth_methods >=
1809 MAX_AUTH_METHODS)
1810 fatal("%s line %d: "
1811 "too many authentication methods.",
1812 filename, linenum);
1813 if (auth2_methods_valid(arg, 0) != 0)
1814 fatal("%s line %d: invalid "
1815 "authentication method list.",
1816 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001817 if (!*activep)
1818 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001819 options->auth_methods[
1820 options->num_auth_methods++] = xstrdup(arg);
1821 }
1822 }
1823 return 0;
1824
Damien Miller7acefbb2014-07-18 14:11:24 +10001825 case sStreamLocalBindMask:
1826 arg = strdelim(&cp);
1827 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001828 fatal("%s line %d: missing StreamLocalBindMask "
1829 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001830 /* Parse mode in octal format */
1831 value = strtol(arg, &p, 8);
1832 if (arg == p || value < 0 || value > 0777)
1833 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001834 if (*activep)
1835 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001836 break;
1837
1838 case sStreamLocalBindUnlink:
1839 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1840 goto parse_flag;
1841
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001842 case sFingerprintHash:
1843 arg = strdelim(&cp);
1844 if (!arg || *arg == '\0')
1845 fatal("%.200s line %d: Missing argument.",
1846 filename, linenum);
1847 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1848 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1849 filename, linenum, arg);
1850 if (*activep)
1851 options->fingerprint_hash = value;
1852 break;
1853
Ben Lindstromade03f62001-12-06 18:22:17 +00001854 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001855 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001856 filename, linenum, arg);
1857 while (arg)
1858 arg = strdelim(&cp);
1859 break;
1860
Damien Millerf9b3feb2003-05-16 11:38:32 +10001861 case sUnsupported:
1862 logit("%s line %d: Unsupported option %s",
1863 filename, linenum, arg);
1864 while (arg)
1865 arg = strdelim(&cp);
1866 break;
1867
Ben Lindstromade03f62001-12-06 18:22:17 +00001868 default:
1869 fatal("%s line %d: Missing handler for opcode %s (%d)",
1870 filename, linenum, arg, opcode);
1871 }
1872 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1873 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1874 filename, linenum, arg);
1875 return 0;
1876}
1877
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001878/* Reads the server configuration file. */
1879
Damien Miller4af51302000-04-16 11:18:38 +10001880void
Darren Tucker645ab752004-06-25 13:33:20 +10001881load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001882{
Damien Miller46cb75a2012-07-31 12:22:37 +10001883 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001884 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001885 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001886
Darren Tucker645ab752004-06-25 13:33:20 +10001887 debug2("%s: filename %s", __func__, filename);
1888 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001889 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001890 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001891 }
Darren Tucker645ab752004-06-25 13:33:20 +10001892 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001893 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001894 lineno++;
1895 if (strlen(line) == sizeof(line) - 1)
1896 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001897 /*
1898 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001899 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001900 * line numbers later for error messages
1901 */
1902 if ((cp = strchr(line, '#')) != NULL)
1903 memcpy(cp, "\n", 2);
1904 cp = line + strspn(line, " \t\r");
1905
1906 buffer_append(conf, cp, strlen(cp));
1907 }
1908 buffer_append(conf, "\0", 1);
1909 fclose(f);
1910 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1911}
1912
1913void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001914parse_server_match_config(ServerOptions *options,
1915 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001916{
Darren Tucker45150472006-07-12 22:34:17 +10001917 ServerOptions mo;
1918
1919 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001920 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001921 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001922}
1923
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001924int parse_server_match_testspec(struct connection_info *ci, char *spec)
1925{
1926 char *p;
1927
1928 while ((p = strsep(&spec, ",")) && *p != '\0') {
1929 if (strncmp(p, "addr=", 5) == 0) {
1930 ci->address = xstrdup(p + 5);
1931 } else if (strncmp(p, "host=", 5) == 0) {
1932 ci->host = xstrdup(p + 5);
1933 } else if (strncmp(p, "user=", 5) == 0) {
1934 ci->user = xstrdup(p + 5);
1935 } else if (strncmp(p, "laddr=", 6) == 0) {
1936 ci->laddress = xstrdup(p + 6);
1937 } else if (strncmp(p, "lport=", 6) == 0) {
1938 ci->lport = a2port(p + 6);
1939 if (ci->lport == -1) {
1940 fprintf(stderr, "Invalid port '%s' in test mode"
1941 " specification %s\n", p+6, p);
1942 return -1;
1943 }
1944 } else {
1945 fprintf(stderr, "Invalid test mode specification %s\n",
1946 p);
1947 return -1;
1948 }
1949 }
1950 return 0;
1951}
1952
1953/*
1954 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1955 * empty spec.
1956 */
1957int server_match_spec_complete(struct connection_info *ci)
1958{
1959 if (ci->user && ci->host && ci->address)
1960 return 1; /* complete */
1961 if (!ci->user && !ci->host && !ci->address)
1962 return -1; /* empty */
1963 return 0; /* partial */
1964}
1965
Darren Tucker1629c072007-02-19 22:25:37 +11001966/*
1967 * Copy any supported values that are set.
1968 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001969 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001970 * array values that are not used pre-authentication, because any that we
1971 * do use must be explictly sent in mm_getpwnamallow().
1972 */
Darren Tucker45150472006-07-12 22:34:17 +10001973void
Darren Tucker1629c072007-02-19 22:25:37 +11001974copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001975{
Damien Miller534b2cc2013-12-05 14:07:27 +11001976#define M_CP_INTOPT(n) do {\
1977 if (src->n != -1) \
1978 dst->n = src->n; \
1979} while (0)
1980
Darren Tucker1629c072007-02-19 22:25:37 +11001981 M_CP_INTOPT(password_authentication);
1982 M_CP_INTOPT(gss_authentication);
1983 M_CP_INTOPT(rsa_authentication);
1984 M_CP_INTOPT(pubkey_authentication);
1985 M_CP_INTOPT(kerberos_authentication);
1986 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001987 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001988 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001989 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001990 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001991
1992 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001993 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001994 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001995 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001996 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001997 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11001998 M_CP_INTOPT(x11_display_offset);
1999 M_CP_INTOPT(x11_forwarding);
2000 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002001 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002002 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002003 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002004 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002005 M_CP_INTOPT(ip_qos_interactive);
2006 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002007 M_CP_INTOPT(rekey_limit);
2008 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002009
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002010 /*
2011 * The bind_mask is a mode_t that may be unsigned, so we can't use
2012 * M_CP_INTOPT - it does a signed comparison that causes compiler
2013 * warnings.
2014 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002015 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002016 dst->fwd_opts.streamlocal_bind_mask =
2017 src->fwd_opts.streamlocal_bind_mask;
2018 }
2019
Damien Miller534b2cc2013-12-05 14:07:27 +11002020 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2021#define M_CP_STROPT(n) do {\
2022 if (src->n != NULL && dst->n != src->n) { \
2023 free(dst->n); \
2024 dst->n = src->n; \
2025 } \
2026} while(0)
2027#define M_CP_STRARRAYOPT(n, num_n) do {\
2028 if (src->num_n != 0) { \
2029 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2030 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2031 } \
2032} while(0)
2033
Damien Millerf2e407e2011-05-20 19:04:14 +10002034 /* See comment in servconf.h */
2035 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002036
djm@openbsd.orged085102015-10-29 08:05:01 +00002037 /* Arguments that accept '+...' need to be expanded */
2038 assemble_algorithms(dst);
2039
Damien Millerc2411902011-05-20 19:03:49 +10002040 /*
2041 * The only things that should be below this point are string options
2042 * which are only used after authentication.
2043 */
Damien Miller5d74e582011-05-20 19:03:31 +10002044 if (preauth)
2045 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002046
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002047 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002048 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002049 if (option_clear_or_none(dst->adm_forced_command)) {
2050 free(dst->adm_forced_command);
2051 dst->adm_forced_command = NULL;
2052 }
Damien Miller5d74e582011-05-20 19:03:31 +10002053 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002054 if (option_clear_or_none(dst->chroot_directory)) {
2055 free(dst->chroot_directory);
2056 dst->chroot_directory = NULL;
2057 }
Darren Tucker45150472006-07-12 22:34:17 +10002058}
2059
Darren Tucker1629c072007-02-19 22:25:37 +11002060#undef M_CP_INTOPT
2061#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002062#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002063
Darren Tucker45150472006-07-12 22:34:17 +10002064void
2065parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002066 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002067{
2068 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002069 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002070
2071 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2072
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002073 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2074 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002075 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002076 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002077 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002078 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002079 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002080 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002081 }
Darren Tuckera627d422013-06-02 07:31:17 +10002082 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002083 if (bad_options > 0)
2084 fatal("%s: terminating, %d bad configuration options",
2085 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002086 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002087}
Darren Tuckere7140f22008-06-10 23:01:51 +10002088
2089static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002090fmt_multistate_int(int val, const struct multistate *m)
2091{
2092 u_int i;
2093
2094 for (i = 0; m[i].key != NULL; i++) {
2095 if (m[i].value == val)
2096 return m[i].key;
2097 }
2098 return "UNKNOWN";
2099}
2100
2101static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002102fmt_intarg(ServerOpCodes code, int val)
2103{
Damien Miller82c55872011-06-23 08:20:30 +10002104 if (val == -1)
2105 return "unset";
2106 switch (code) {
2107 case sAddressFamily:
2108 return fmt_multistate_int(val, multistate_addressfamily);
2109 case sPermitRootLogin:
2110 return fmt_multistate_int(val, multistate_permitrootlogin);
2111 case sGatewayPorts:
2112 return fmt_multistate_int(val, multistate_gatewayports);
2113 case sCompression:
2114 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002115 case sUsePrivilegeSeparation:
2116 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002117 case sAllowTcpForwarding:
2118 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002119 case sAllowStreamLocalForwarding:
2120 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002121 case sFingerprintHash:
2122 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002123 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002124 switch (val) {
2125 case SSH_PROTO_1:
2126 return "1";
2127 case SSH_PROTO_2:
2128 return "2";
2129 case (SSH_PROTO_1|SSH_PROTO_2):
2130 return "2,1";
2131 default:
2132 return "UNKNOWN";
2133 }
Damien Miller82c55872011-06-23 08:20:30 +10002134 default:
2135 switch (val) {
2136 case 0:
2137 return "no";
2138 case 1:
2139 return "yes";
2140 default:
2141 return "UNKNOWN";
2142 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002143 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002144}
2145
2146static const char *
2147lookup_opcode_name(ServerOpCodes code)
2148{
2149 u_int i;
2150
2151 for (i = 0; keywords[i].name != NULL; i++)
2152 if (keywords[i].opcode == code)
2153 return(keywords[i].name);
2154 return "UNKNOWN";
2155}
2156
2157static void
2158dump_cfg_int(ServerOpCodes code, int val)
2159{
2160 printf("%s %d\n", lookup_opcode_name(code), val);
2161}
2162
2163static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002164dump_cfg_oct(ServerOpCodes code, int val)
2165{
2166 printf("%s 0%o\n", lookup_opcode_name(code), val);
2167}
2168
2169static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002170dump_cfg_fmtint(ServerOpCodes code, int val)
2171{
2172 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2173}
2174
2175static void
2176dump_cfg_string(ServerOpCodes code, const char *val)
2177{
2178 if (val == NULL)
2179 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002180 printf("%s %s\n", lookup_opcode_name(code),
2181 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002182}
2183
2184static void
2185dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2186{
2187 u_int i;
2188
2189 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002190 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2191}
2192
2193static void
2194dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2195{
2196 u_int i;
2197
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002198 if (count <= 0)
2199 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002200 printf("%s", lookup_opcode_name(code));
2201 for (i = 0; i < count; i++)
2202 printf(" %s", vals[i]);
2203 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002204}
2205
2206void
2207dump_config(ServerOptions *o)
2208{
2209 u_int i;
2210 int ret;
2211 struct addrinfo *ai;
2212 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002213 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002214
2215 /* these are usually at the top of the config */
2216 for (i = 0; i < o->num_ports; i++)
2217 printf("port %d\n", o->ports[i]);
2218 dump_cfg_fmtint(sProtocol, o->protocol);
2219 dump_cfg_fmtint(sAddressFamily, o->address_family);
2220
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002221 /*
2222 * ListenAddress must be after Port. add_one_listen_addr pushes
2223 * addresses onto a stack, so to maintain ordering we need to
2224 * print these in reverse order.
2225 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002226 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2227 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2228 sizeof(addr), port, sizeof(port),
2229 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2230 error("getnameinfo failed: %.100s",
2231 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2232 strerror(errno));
2233 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002234 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002235 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002236 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2237 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002238 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002239 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2240 addr, port, laddr2);
2241 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002242 }
2243 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002244 printf("%s", laddr1);
2245 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002246
2247 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002248#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002249 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002250#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002251 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2252 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2253 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2254 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2255 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002256 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002257 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2258 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002259 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002260
2261 /* formatted integer arguments */
2262 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2263 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2264 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2265 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2266 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2267 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2268 o->hostbased_uses_name_from_packet_only);
2269 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2270 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002271#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002272 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2273 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2274 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002275# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002276 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002277# endif
2278#endif
2279#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002280 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2281 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002282#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002283 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2284 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2285 o->kbd_interactive_authentication);
2286 dump_cfg_fmtint(sChallengeResponseAuthentication,
2287 o->challenge_response_authentication);
2288 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002289#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002290 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002291#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002292 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2293 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002294 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002295 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002296 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2297 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2298 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2299 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2300 dump_cfg_fmtint(sUseLogin, o->use_login);
2301 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002302 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002303 dump_cfg_fmtint(sUseDNS, o->use_dns);
2304 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002305 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002306 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002307 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
Darren Tuckere7140f22008-06-10 23:01:51 +10002308 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002309 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002310
2311 /* string arguments */
2312 dump_cfg_string(sPidFile, o->pid_file);
2313 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002314 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2315 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002316 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002317 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002318 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002319 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2320 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002321 dump_cfg_string(sAuthorizedPrincipalsFile,
2322 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002323 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2324 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002325 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2326 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002327 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2328 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002329 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002330 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002331 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002332 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2333 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002334 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2335 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002336 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2337 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002338
2339 /* string arguments requiring a lookup */
2340 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2341 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2342
2343 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002344 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2345 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002346 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2347 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002348 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002349 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002350 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2351 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2352 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2353 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2354 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002355 dump_cfg_strarray_oneline(sAuthenticationMethods,
2356 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002357
2358 /* other arguments */
2359 for (i = 0; i < o->num_subsystems; i++)
2360 printf("subsystem %s %s\n", o->subsystem_name[i],
2361 o->subsystem_args[i]);
2362
2363 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2364 o->max_startups_rate, o->max_startups);
2365
2366 for (i = 0; tunmode_desc[i].val != -1; i++)
2367 if (tunmode_desc[i].val == o->permit_tun) {
2368 s = tunmode_desc[i].text;
2369 break;
2370 }
2371 dump_cfg_string(sPermitTunnel, s);
2372
Damien Miller91475862011-05-05 14:14:34 +10002373 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2374 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002375
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002376 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002377 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002378
Darren Tuckere7140f22008-06-10 23:01:51 +10002379 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002380}