blob: 19c68e2d7c0e5d7adb88de727a689a6c58bb70bf [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002/* $OpenBSD: servconf.c,v 1.283 2015/11/13 04:38:06 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100032#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100033#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100034#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100035#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100036#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100037
Damien Millerb84886b2008-05-19 15:05:07 +100038#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100042#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100043#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100045#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000049#include "kex.h"
50#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100051#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100052#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100053#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100054#include "canohost.h"
55#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110056#include "hostfile.h"
57#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000058#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000059#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000060
Damien Miller3dc71ad2009-01-28 16:31:22 +110061static void add_listen_addr(ServerOptions *, char *, int);
62static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110063
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000064/* Use of privilege separation or not */
65extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100066extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068/* Initializes the server options to their default values. */
69
Damien Miller4af51302000-04-16 11:18:38 +100070void
Damien Miller95def091999-11-25 00:26:21 +110071initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072{
Damien Miller95def091999-11-25 00:26:21 +110073 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100076 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110077
78 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110079 options->num_ports = 0;
80 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000081 options->queued_listen_addrs = NULL;
82 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110083 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110084 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110085 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110086 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100087 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100088 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110089 options->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
Ben Lindstromfb62a692002-06-06 19:47:11 +0000359 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000360 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000361 use_privsep = PRIVSEP_NOSANDBOX;
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{
709 static struct connection_info ci;
710
711 if (!populate)
712 return &ci;
713 ci.host = get_canonical_hostname(use_dns);
714 ci.address = get_remote_ipaddr();
715 ci.laddress = get_local_ipaddr(packet_get_connection_in());
716 ci.lport = get_local_port();
717 return &ci;
718}
719
Darren Tucker45150472006-07-12 22:34:17 +1000720/*
721 * The strategy for the Match blocks is that the config file is parsed twice.
722 *
723 * The first time is at startup. activep is initialized to 1 and the
724 * directives in the global context are processed and acted on. Hitting a
725 * Match directive unsets activep and the directives inside the block are
726 * checked for syntax only.
727 *
728 * The second time is after a connection has been established but before
729 * authentication. activep is initialized to 2 and global config directives
730 * are ignored since they have already been processed. If the criteria in a
731 * Match block is met, activep is set and the subsequent directives
732 * processed and actioned until EOF or another Match block unsets it. Any
733 * options set are copied into the main server config.
734 *
735 * Potential additions/improvements:
736 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
737 *
738 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
739 * Match Address 192.168.0.*
740 * Tag trusted
741 * Match Group wheel
742 * Tag trusted
743 * Match Tag trusted
744 * AllowTcpForwarding yes
745 * GatewayPorts clientspecified
746 * [...]
747 *
748 * - Add a PermittedChannelRequests directive
749 * Match Group shell
750 * PermittedChannelRequests session,forwarded-tcpip
751 */
752
753static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000754match_cfg_line_group(const char *grps, int line, const char *user)
755{
756 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000757 struct passwd *pw;
758
Damien Miller565ca3f2006-08-19 00:23:15 +1000759 if (user == NULL)
760 goto out;
761
762 if ((pw = getpwnam(user)) == NULL) {
763 debug("Can't match group at line %d because user %.100s does "
764 "not exist", line, user);
765 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
766 debug("Can't Match group because user %.100s not in any group "
767 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000768 } else if (ga_match_pattern_list(grps) != 1) {
769 debug("user %.100s does not match group list %.100s at line %d",
770 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000771 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000772 debug("user %.100s matched group list %.100s at line %d", user,
773 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000774 result = 1;
775 }
776out:
777 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000778 return result;
779}
780
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000781/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000782 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100783 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000784 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000785 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000786static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000787match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000788{
Damien Millercf31f382013-10-24 21:02:56 +1100789 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000790 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000791
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000792 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000793 debug3("checking syntax for 'Match %s'", cp);
794 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000795 debug3("checking match for '%s' user %s host %s addr %s "
796 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
797 ci->host ? ci->host : "(null)",
798 ci->address ? ci->address : "(null)",
799 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000800
801 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100802 attributes++;
803 if (strcasecmp(attrib, "all") == 0) {
804 if (attributes != 1 ||
805 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
806 error("'all' cannot be combined with other "
807 "Match attributes");
808 return -1;
809 }
810 *condition = cp;
811 return 1;
812 }
Darren Tucker45150472006-07-12 22:34:17 +1000813 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
814 error("Missing Match criteria for %s", attrib);
815 return -1;
816 }
Darren Tucker45150472006-07-12 22:34:17 +1000817 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000818 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000819 result = 0;
820 continue;
821 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000822 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000823 result = 0;
824 else
825 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000826 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000827 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000828 if (ci == NULL || ci->user == NULL) {
829 result = 0;
830 continue;
831 }
832 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000833 case -1:
834 return -1;
835 case 0:
836 result = 0;
837 }
Darren Tucker45150472006-07-12 22:34:17 +1000838 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000839 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000840 result = 0;
841 continue;
842 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000843 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000844 result = 0;
845 else
846 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000847 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000848 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000849 if (ci == NULL || ci->address == NULL) {
850 result = 0;
851 continue;
852 }
853 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000854 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000855 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000856 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000857 break;
858 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000859 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000860 result = 0;
861 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000862 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000863 return -1;
864 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000865 } else if (strcasecmp(attrib, "localaddress") == 0){
866 if (ci == NULL || ci->laddress == NULL) {
867 result = 0;
868 continue;
869 }
870 switch (addr_match_list(ci->laddress, arg)) {
871 case 1:
872 debug("connection from %.100s matched "
873 "'LocalAddress %.100s' at line %d",
874 ci->laddress, arg, line);
875 break;
876 case 0:
877 case -1:
878 result = 0;
879 break;
880 case -2:
881 return -1;
882 }
883 } else if (strcasecmp(attrib, "localport") == 0) {
884 if ((port = a2port(arg)) == -1) {
885 error("Invalid LocalPort '%s' on Match line",
886 arg);
887 return -1;
888 }
889 if (ci == NULL || ci->lport == 0) {
890 result = 0;
891 continue;
892 }
893 /* TODO support port lists */
894 if (port == ci->lport)
895 debug("connection from %.100s matched "
896 "'LocalPort %d' at line %d",
897 ci->laddress, port, line);
898 else
899 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000900 } else {
901 error("Unsupported Match attribute %s", attrib);
902 return -1;
903 }
904 }
Damien Millercf31f382013-10-24 21:02:56 +1100905 if (attributes == 0) {
906 error("One or more attributes required for Match");
907 return -1;
908 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000909 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000910 debug3("match %sfound", result ? "" : "not ");
911 *condition = cp;
912 return result;
913}
914
Damien Millere2754432006-07-24 14:06:47 +1000915#define WHITESPACE " \t\r\n"
916
Damien Miller33322122011-06-20 14:43:11 +1000917/* Multistate option parsing */
918struct multistate {
919 char *key;
920 int value;
921};
922static const struct multistate multistate_addressfamily[] = {
923 { "inet", AF_INET },
924 { "inet6", AF_INET6 },
925 { "any", AF_UNSPEC },
926 { NULL, -1 }
927};
928static const struct multistate multistate_permitrootlogin[] = {
929 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000930 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000931 { "forced-commands-only", PERMIT_FORCED_ONLY },
932 { "yes", PERMIT_YES },
933 { "no", PERMIT_NO },
934 { NULL, -1 }
935};
936static const struct multistate multistate_compression[] = {
937 { "delayed", COMP_DELAYED },
938 { "yes", COMP_ZLIB },
939 { "no", COMP_NONE },
940 { NULL, -1 }
941};
942static const struct multistate multistate_gatewayports[] = {
943 { "clientspecified", 2 },
944 { "yes", 1 },
945 { "no", 0 },
946 { NULL, -1 }
947};
Damien Miller69ff1df2011-06-23 08:30:03 +1000948static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000949 { "yes", PRIVSEP_NOSANDBOX },
950 { "sandbox", PRIVSEP_ON },
951 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000952 { "no", PRIVSEP_OFF },
953 { NULL, -1 }
954};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100955static const struct multistate multistate_tcpfwd[] = {
956 { "yes", FORWARD_ALLOW },
957 { "all", FORWARD_ALLOW },
958 { "no", FORWARD_DENY },
959 { "remote", FORWARD_REMOTE },
960 { "local", FORWARD_LOCAL },
961 { NULL, -1 }
962};
Damien Miller33322122011-06-20 14:43:11 +1000963
Ben Lindstromade03f62001-12-06 18:22:17 +0000964int
965process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000966 const char *filename, int linenum, int *activep,
967 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000968{
Darren Tucker09c0f032013-05-16 20:48:57 +1000969 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000970 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100971 SyslogFacility *log_facility_ptr;
972 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000973 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000974 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000975 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000976 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000977 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000978
979 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100980 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100981 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000982 /* Ignore leading whitespace */
983 if (*arg == '\0')
984 arg = strdelim(&cp);
985 if (!arg || !*arg || *arg == '#')
986 return 0;
987 intptr = NULL;
988 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000989 opcode = parse_token(arg, filename, linenum, &flags);
990
991 if (activep == NULL) { /* We are processing a command line directive */
992 cmdline = 1;
993 activep = &cmdline;
994 }
995 if (*activep && opcode != sMatch)
996 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
997 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000998 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000999 fatal("%s line %d: Directive '%s' is not allowed "
1000 "within a Match block", filename, linenum, arg);
1001 } else { /* this is a directive we have already processed */
1002 while (arg)
1003 arg = strdelim(&cp);
1004 return 0;
1005 }
1006 }
1007
Ben Lindstromade03f62001-12-06 18:22:17 +00001008 switch (opcode) {
1009 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001010 case sUsePAM:
1011 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001012 goto parse_flag;
1013
1014 /* Standard Options */
1015 case sBadOption:
1016 return -1;
1017 case sPort:
1018 /* ignore ports from configfile if cmdline specifies ports */
1019 if (options->ports_from_cmdline)
1020 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001021 if (options->num_ports >= MAX_PORTS)
1022 fatal("%s line %d: too many ports.",
1023 filename, linenum);
1024 arg = strdelim(&cp);
1025 if (!arg || *arg == '\0')
1026 fatal("%s line %d: missing port number.",
1027 filename, linenum);
1028 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001029 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001030 fatal("%s line %d: Badly formatted port number.",
1031 filename, linenum);
1032 break;
1033
1034 case sServerKeyBits:
1035 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001036 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001037 arg = strdelim(&cp);
1038 if (!arg || *arg == '\0')
1039 fatal("%s line %d: missing integer value.",
1040 filename, linenum);
1041 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001042 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001043 *intptr = value;
1044 break;
1045
1046 case sLoginGraceTime:
1047 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001048 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001049 arg = strdelim(&cp);
1050 if (!arg || *arg == '\0')
1051 fatal("%s line %d: missing time value.",
1052 filename, linenum);
1053 if ((value = convtime(arg)) == -1)
1054 fatal("%s line %d: invalid time value.",
1055 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001056 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001057 *intptr = value;
1058 break;
1059
1060 case sKeyRegenerationTime:
1061 intptr = &options->key_regeneration_time;
1062 goto parse_time;
1063
1064 case sListenAddress:
1065 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001066 if (arg == NULL || *arg == '\0')
1067 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001068 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001069 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1070 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1071 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001072 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001073 break;
1074 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001075 p = hpdelim(&arg);
1076 if (p == NULL)
1077 fatal("%s line %d: bad address:port usage",
1078 filename, linenum);
1079 p = cleanhostname(p);
1080 if (arg == NULL)
1081 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001082 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001083 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001084
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001085 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001086
Ben Lindstromade03f62001-12-06 18:22:17 +00001087 break;
1088
Darren Tucker0f383232005-01-20 10:57:56 +11001089 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001090 intptr = &options->address_family;
1091 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001092 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001093 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001094 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001095 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001096 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001097 value = -1;
1098 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1099 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1100 value = multistate_ptr[i].value;
1101 break;
1102 }
1103 }
1104 if (value == -1)
1105 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001106 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001107 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001108 *intptr = value;
1109 break;
1110
Ben Lindstromade03f62001-12-06 18:22:17 +00001111 case sHostKeyFile:
1112 intptr = &options->num_host_key_files;
1113 if (*intptr >= MAX_HOSTKEYS)
1114 fatal("%s line %d: too many host keys specified (max %d).",
1115 filename, linenum, MAX_HOSTKEYS);
1116 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001117 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001118 arg = strdelim(&cp);
1119 if (!arg || *arg == '\0')
1120 fatal("%s line %d: missing file name.",
1121 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001122 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001123 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001124 /* increase optional counter */
1125 if (intptr != NULL)
1126 *intptr = *intptr + 1;
1127 }
1128 break;
1129
Damien Miller85b45e02013-07-20 13:21:52 +10001130 case sHostKeyAgent:
1131 charptr = &options->host_key_agent;
1132 arg = strdelim(&cp);
1133 if (!arg || *arg == '\0')
1134 fatal("%s line %d: missing socket name.",
1135 filename, linenum);
1136 if (*activep && *charptr == NULL)
1137 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1138 xstrdup(arg) : derelativise_path(arg);
1139 break;
1140
Damien Miller0a80ca12010-02-27 07:55:05 +11001141 case sHostCertificate:
1142 intptr = &options->num_host_cert_files;
1143 if (*intptr >= MAX_HOSTKEYS)
1144 fatal("%s line %d: too many host certificates "
1145 "specified (max %d).", filename, linenum,
1146 MAX_HOSTCERTS);
1147 charptr = &options->host_cert_files[*intptr];
1148 goto parse_filename;
1149 break;
1150
Ben Lindstromade03f62001-12-06 18:22:17 +00001151 case sPidFile:
1152 charptr = &options->pid_file;
1153 goto parse_filename;
1154
1155 case sPermitRootLogin:
1156 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001157 multistate_ptr = multistate_permitrootlogin;
1158 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001159
1160 case sIgnoreRhosts:
1161 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001162 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001163 arg = strdelim(&cp);
1164 if (!arg || *arg == '\0')
1165 fatal("%s line %d: missing yes/no argument.",
1166 filename, linenum);
1167 value = 0; /* silence compiler */
1168 if (strcmp(arg, "yes") == 0)
1169 value = 1;
1170 else if (strcmp(arg, "no") == 0)
1171 value = 0;
1172 else
1173 fatal("%s line %d: Bad yes/no argument: %s",
1174 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001175 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001176 *intptr = value;
1177 break;
1178
1179 case sIgnoreUserKnownHosts:
1180 intptr = &options->ignore_user_known_hosts;
1181 goto parse_flag;
1182
Ben Lindstromade03f62001-12-06 18:22:17 +00001183 case sRhostsRSAAuthentication:
1184 intptr = &options->rhosts_rsa_authentication;
1185 goto parse_flag;
1186
1187 case sHostbasedAuthentication:
1188 intptr = &options->hostbased_authentication;
1189 goto parse_flag;
1190
1191 case sHostbasedUsesNameFromPacketOnly:
1192 intptr = &options->hostbased_uses_name_from_packet_only;
1193 goto parse_flag;
1194
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001195 case sHostbasedAcceptedKeyTypes:
1196 charptr = &options->hostbased_key_types;
1197 parse_keytypes:
1198 arg = strdelim(&cp);
1199 if (!arg || *arg == '\0')
1200 fatal("%s line %d: Missing argument.",
1201 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001202 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001203 fatal("%s line %d: Bad key types '%s'.",
1204 filename, linenum, arg ? arg : "<NONE>");
1205 if (*activep && *charptr == NULL)
1206 *charptr = xstrdup(arg);
1207 break;
1208
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001209 case sHostKeyAlgorithms:
1210 charptr = &options->hostkeyalgorithms;
1211 goto parse_keytypes;
1212
Ben Lindstromade03f62001-12-06 18:22:17 +00001213 case sRSAAuthentication:
1214 intptr = &options->rsa_authentication;
1215 goto parse_flag;
1216
1217 case sPubkeyAuthentication:
1218 intptr = &options->pubkey_authentication;
1219 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001220
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001221 case sPubkeyAcceptedKeyTypes:
1222 charptr = &options->pubkey_key_types;
1223 goto parse_keytypes;
1224
Ben Lindstromade03f62001-12-06 18:22:17 +00001225 case sKerberosAuthentication:
1226 intptr = &options->kerberos_authentication;
1227 goto parse_flag;
1228
1229 case sKerberosOrLocalPasswd:
1230 intptr = &options->kerberos_or_local_passwd;
1231 goto parse_flag;
1232
1233 case sKerberosTicketCleanup:
1234 intptr = &options->kerberos_ticket_cleanup;
1235 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001236
Darren Tucker22ef5082003-12-31 11:37:34 +11001237 case sKerberosGetAFSToken:
1238 intptr = &options->kerberos_get_afs_token;
1239 goto parse_flag;
1240
Darren Tucker0efd1552003-08-26 11:49:55 +10001241 case sGssAuthentication:
1242 intptr = &options->gss_authentication;
1243 goto parse_flag;
1244
1245 case sGssCleanupCreds:
1246 intptr = &options->gss_cleanup_creds;
1247 goto parse_flag;
1248
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001249 case sGssStrictAcceptor:
1250 intptr = &options->gss_strict_acceptor;
1251 goto parse_flag;
1252
Ben Lindstromade03f62001-12-06 18:22:17 +00001253 case sPasswordAuthentication:
1254 intptr = &options->password_authentication;
1255 goto parse_flag;
1256
1257 case sKbdInteractiveAuthentication:
1258 intptr = &options->kbd_interactive_authentication;
1259 goto parse_flag;
1260
1261 case sChallengeResponseAuthentication:
1262 intptr = &options->challenge_response_authentication;
1263 goto parse_flag;
1264
1265 case sPrintMotd:
1266 intptr = &options->print_motd;
1267 goto parse_flag;
1268
1269 case sPrintLastLog:
1270 intptr = &options->print_lastlog;
1271 goto parse_flag;
1272
1273 case sX11Forwarding:
1274 intptr = &options->x11_forwarding;
1275 goto parse_flag;
1276
1277 case sX11DisplayOffset:
1278 intptr = &options->x11_display_offset;
1279 goto parse_int;
1280
Damien Miller95c249f2002-02-05 12:11:34 +11001281 case sX11UseLocalhost:
1282 intptr = &options->x11_use_localhost;
1283 goto parse_flag;
1284
Ben Lindstromade03f62001-12-06 18:22:17 +00001285 case sXAuthLocation:
1286 charptr = &options->xauth_location;
1287 goto parse_filename;
1288
Damien Miller5ff30c62013-10-30 22:21:50 +11001289 case sPermitTTY:
1290 intptr = &options->permit_tty;
1291 goto parse_flag;
1292
Damien Miller72e6b5c2014-07-04 09:00:04 +10001293 case sPermitUserRC:
1294 intptr = &options->permit_user_rc;
1295 goto parse_flag;
1296
Ben Lindstromade03f62001-12-06 18:22:17 +00001297 case sStrictModes:
1298 intptr = &options->strict_modes;
1299 goto parse_flag;
1300
Damien Miller12c150e2003-12-17 16:31:10 +11001301 case sTCPKeepAlive:
1302 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001303 goto parse_flag;
1304
1305 case sEmptyPasswd:
1306 intptr = &options->permit_empty_passwd;
1307 goto parse_flag;
1308
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001309 case sPermitUserEnvironment:
1310 intptr = &options->permit_user_env;
1311 goto parse_flag;
1312
Ben Lindstromade03f62001-12-06 18:22:17 +00001313 case sUseLogin:
1314 intptr = &options->use_login;
1315 goto parse_flag;
1316
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001317 case sCompression:
1318 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001319 multistate_ptr = multistate_compression;
1320 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001321
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001322 case sRekeyLimit:
1323 arg = strdelim(&cp);
1324 if (!arg || *arg == '\0')
1325 fatal("%.200s line %d: Missing argument.", filename,
1326 linenum);
1327 if (strcmp(arg, "default") == 0) {
1328 val64 = 0;
1329 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001330 if (scan_scaled(arg, &val64) == -1)
1331 fatal("%.200s line %d: Bad number '%s': %s",
1332 filename, linenum, arg, strerror(errno));
1333 /* check for too-large or too-small limits */
1334 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001335 fatal("%.200s line %d: RekeyLimit too large",
1336 filename, linenum);
1337 if (val64 != 0 && val64 < 16)
1338 fatal("%.200s line %d: RekeyLimit too small",
1339 filename, linenum);
1340 }
1341 if (*activep && options->rekey_limit == -1)
1342 options->rekey_limit = (u_int32_t)val64;
1343 if (cp != NULL) { /* optional rekey interval present */
1344 if (strcmp(cp, "none") == 0) {
1345 (void)strdelim(&cp); /* discard */
1346 break;
1347 }
1348 intptr = &options->rekey_interval;
1349 goto parse_time;
1350 }
1351 break;
1352
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001354 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001355 multistate_ptr = multistate_gatewayports;
1356 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001357
Damien Miller3a961dc2003-06-03 10:25:48 +10001358 case sUseDNS:
1359 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001360 goto parse_flag;
1361
1362 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001363 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 arg = strdelim(&cp);
1365 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001366 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001367 fatal("%.200s line %d: unsupported log facility '%s'",
1368 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001369 if (*log_facility_ptr == -1)
1370 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 break;
1372
1373 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001374 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001375 arg = strdelim(&cp);
1376 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001377 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001378 fatal("%.200s line %d: unsupported log level '%s'",
1379 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001380 if (*log_level_ptr == -1)
1381 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001382 break;
1383
1384 case sAllowTcpForwarding:
1385 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001386 multistate_ptr = multistate_tcpfwd;
1387 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001388
Damien Miller7acefbb2014-07-18 14:11:24 +10001389 case sAllowStreamLocalForwarding:
1390 intptr = &options->allow_streamlocal_forwarding;
1391 multistate_ptr = multistate_tcpfwd;
1392 goto parse_multistate;
1393
Damien Miller4f755cd2008-05-19 14:57:41 +10001394 case sAllowAgentForwarding:
1395 intptr = &options->allow_agent_forwarding;
1396 goto parse_flag;
1397
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001398 case sUsePrivilegeSeparation:
1399 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001400 multistate_ptr = multistate_privsep;
1401 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001402
Ben Lindstromade03f62001-12-06 18:22:17 +00001403 case sAllowUsers:
1404 while ((arg = strdelim(&cp)) && *arg != '\0') {
1405 if (options->num_allow_users >= MAX_ALLOW_USERS)
1406 fatal("%s line %d: too many allow users.",
1407 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001408 if (!*activep)
1409 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001410 options->allow_users[options->num_allow_users++] =
1411 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001412 }
1413 break;
1414
1415 case sDenyUsers:
1416 while ((arg = strdelim(&cp)) && *arg != '\0') {
1417 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001418 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001419 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001420 if (!*activep)
1421 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001422 options->deny_users[options->num_deny_users++] =
1423 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001424 }
1425 break;
1426
1427 case sAllowGroups:
1428 while ((arg = strdelim(&cp)) && *arg != '\0') {
1429 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1430 fatal("%s line %d: too many allow groups.",
1431 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001432 if (!*activep)
1433 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001434 options->allow_groups[options->num_allow_groups++] =
1435 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001436 }
1437 break;
1438
1439 case sDenyGroups:
1440 while ((arg = strdelim(&cp)) && *arg != '\0') {
1441 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1442 fatal("%s line %d: too many deny groups.",
1443 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001444 if (!*activep)
1445 continue;
1446 options->deny_groups[options->num_deny_groups++] =
1447 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001448 }
1449 break;
1450
1451 case sCiphers:
1452 arg = strdelim(&cp);
1453 if (!arg || *arg == '\0')
1454 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001455 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001456 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1457 filename, linenum, arg ? arg : "<NONE>");
1458 if (options->ciphers == NULL)
1459 options->ciphers = xstrdup(arg);
1460 break;
1461
1462 case sMacs:
1463 arg = strdelim(&cp);
1464 if (!arg || *arg == '\0')
1465 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001466 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001467 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1468 filename, linenum, arg ? arg : "<NONE>");
1469 if (options->macs == NULL)
1470 options->macs = xstrdup(arg);
1471 break;
1472
Damien Millerd5f62bf2010-09-24 22:11:14 +10001473 case sKexAlgorithms:
1474 arg = strdelim(&cp);
1475 if (!arg || *arg == '\0')
1476 fatal("%s line %d: Missing argument.",
1477 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001478 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001479 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1480 filename, linenum, arg ? arg : "<NONE>");
1481 if (options->kex_algorithms == NULL)
1482 options->kex_algorithms = xstrdup(arg);
1483 break;
1484
Ben Lindstromade03f62001-12-06 18:22:17 +00001485 case sProtocol:
1486 intptr = &options->protocol;
1487 arg = strdelim(&cp);
1488 if (!arg || *arg == '\0')
1489 fatal("%s line %d: Missing argument.", filename, linenum);
1490 value = proto_spec(arg);
1491 if (value == SSH_PROTO_UNKNOWN)
1492 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001493 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001494 if (*intptr == SSH_PROTO_UNKNOWN)
1495 *intptr = value;
1496 break;
1497
1498 case sSubsystem:
1499 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1500 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001501 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001502 }
1503 arg = strdelim(&cp);
1504 if (!arg || *arg == '\0')
1505 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001506 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001507 if (!*activep) {
1508 arg = strdelim(&cp);
1509 break;
1510 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001511 for (i = 0; i < options->num_subsystems; i++)
1512 if (strcmp(arg, options->subsystem_name[i]) == 0)
1513 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001514 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001515 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1516 arg = strdelim(&cp);
1517 if (!arg || *arg == '\0')
1518 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001519 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001520 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001521
1522 /* Collect arguments (separate to executable) */
1523 p = xstrdup(arg);
1524 len = strlen(p) + 1;
1525 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1526 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001527 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001528 strlcat(p, " ", len);
1529 strlcat(p, arg, len);
1530 }
1531 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001532 options->num_subsystems++;
1533 break;
1534
1535 case sMaxStartups:
1536 arg = strdelim(&cp);
1537 if (!arg || *arg == '\0')
1538 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001539 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001540 if ((n = sscanf(arg, "%d:%d:%d",
1541 &options->max_startups_begin,
1542 &options->max_startups_rate,
1543 &options->max_startups)) == 3) {
1544 if (options->max_startups_begin >
1545 options->max_startups ||
1546 options->max_startups_rate > 100 ||
1547 options->max_startups_rate < 1)
1548 fatal("%s line %d: Illegal MaxStartups spec.",
1549 filename, linenum);
1550 } else if (n != 1)
1551 fatal("%s line %d: Illegal MaxStartups spec.",
1552 filename, linenum);
1553 else
1554 options->max_startups = options->max_startups_begin;
1555 break;
1556
Darren Tucker89413db2004-05-24 10:36:23 +10001557 case sMaxAuthTries:
1558 intptr = &options->max_authtries;
1559 goto parse_int;
1560
Damien Miller7207f642008-05-19 15:34:50 +10001561 case sMaxSessions:
1562 intptr = &options->max_sessions;
1563 goto parse_int;
1564
Ben Lindstromade03f62001-12-06 18:22:17 +00001565 case sBanner:
1566 charptr = &options->banner;
1567 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001568
Ben Lindstromade03f62001-12-06 18:22:17 +00001569 /*
1570 * These options can contain %X options expanded at
1571 * connect time, so that you can specify paths like:
1572 *
1573 * AuthorizedKeysFile /etc/ssh_keys/%u
1574 */
1575 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001576 if (*activep && options->num_authkeys_files == 0) {
1577 while ((arg = strdelim(&cp)) && *arg != '\0') {
1578 if (options->num_authkeys_files >=
1579 MAX_AUTHKEYS_FILES)
1580 fatal("%s line %d: "
1581 "too many authorized keys files.",
1582 filename, linenum);
1583 options->authorized_keys_files[
1584 options->num_authkeys_files++] =
1585 tilde_expand_filename(arg, getuid());
1586 }
1587 }
1588 return 0;
1589
Damien Miller30da3442010-05-10 11:58:03 +10001590 case sAuthorizedPrincipalsFile:
1591 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001592 arg = strdelim(&cp);
1593 if (!arg || *arg == '\0')
1594 fatal("%s line %d: missing file name.",
1595 filename, linenum);
1596 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001597 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001598 /* increase optional counter */
1599 if (intptr != NULL)
1600 *intptr = *intptr + 1;
1601 }
1602 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001603
1604 case sClientAliveInterval:
1605 intptr = &options->client_alive_interval;
1606 goto parse_time;
1607
1608 case sClientAliveCountMax:
1609 intptr = &options->client_alive_count_max;
1610 goto parse_int;
1611
Darren Tucker46bc0752004-05-02 22:11:30 +10001612 case sAcceptEnv:
1613 while ((arg = strdelim(&cp)) && *arg != '\0') {
1614 if (strchr(arg, '=') != NULL)
1615 fatal("%s line %d: Invalid environment name.",
1616 filename, linenum);
1617 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1618 fatal("%s line %d: too many allow env.",
1619 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001620 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001621 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001622 options->accept_env[options->num_accept_env++] =
1623 xstrdup(arg);
1624 }
1625 break;
1626
Damien Millerd27b9472005-12-13 19:29:02 +11001627 case sPermitTunnel:
1628 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001629 arg = strdelim(&cp);
1630 if (!arg || *arg == '\0')
1631 fatal("%s line %d: Missing yes/point-to-point/"
1632 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001633 value = -1;
1634 for (i = 0; tunmode_desc[i].val != -1; i++)
1635 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1636 value = tunmode_desc[i].val;
1637 break;
1638 }
1639 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001640 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1641 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001642 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001643 *intptr = value;
1644 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001645
Darren Tucker45150472006-07-12 22:34:17 +10001646 case sMatch:
1647 if (cmdline)
1648 fatal("Match directive not supported as a command-line "
1649 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001650 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001651 if (value < 0)
1652 fatal("%s line %d: Bad Match condition", filename,
1653 linenum);
1654 *activep = value;
1655 break;
1656
Damien Miller9b439df2006-07-24 14:04:00 +10001657 case sPermitOpen:
1658 arg = strdelim(&cp);
1659 if (!arg || *arg == '\0')
1660 fatal("%s line %d: missing PermitOpen specification",
1661 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001662 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001663 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001664 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001665 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001666 options->num_permitted_opens = 0;
1667 }
Damien Miller9b439df2006-07-24 14:04:00 +10001668 break;
1669 }
Damien Millerc6081482012-04-22 11:18:53 +10001670 if (strcmp(arg, "none") == 0) {
1671 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001672 options->num_permitted_opens = 1;
1673 channel_disable_adm_local_opens();
1674 }
1675 break;
1676 }
Damien Millera29b95e2007-01-05 16:28:36 +11001677 if (*activep && n == -1)
1678 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001679 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1680 p = hpdelim(&arg);
1681 if (p == NULL)
1682 fatal("%s line %d: missing host in PermitOpen",
1683 filename, linenum);
1684 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001685 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001686 fatal("%s line %d: bad port number in "
1687 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001688 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001689 options->num_permitted_opens =
1690 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001691 }
Damien Miller9b439df2006-07-24 14:04:00 +10001692 break;
1693
Damien Millere2754432006-07-24 14:06:47 +10001694 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001695 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001696 fatal("%.200s line %d: Missing argument.", filename,
1697 linenum);
1698 len = strspn(cp, WHITESPACE);
1699 if (*activep && options->adm_forced_command == NULL)
1700 options->adm_forced_command = xstrdup(cp + len);
1701 return 0;
1702
Damien Millerd8cb1f12008-02-10 22:40:12 +11001703 case sChrootDirectory:
1704 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001705
1706 arg = strdelim(&cp);
1707 if (!arg || *arg == '\0')
1708 fatal("%s line %d: missing file name.",
1709 filename, linenum);
1710 if (*activep && *charptr == NULL)
1711 *charptr = xstrdup(arg);
1712 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001713
Damien Miller1aed65e2010-03-04 21:53:35 +11001714 case sTrustedUserCAKeys:
1715 charptr = &options->trusted_user_ca_keys;
1716 goto parse_filename;
1717
1718 case sRevokedKeys:
1719 charptr = &options->revoked_keys_file;
1720 goto parse_filename;
1721
Damien Miller0dac6fb2010-11-20 15:19:38 +11001722 case sIPQoS:
1723 arg = strdelim(&cp);
1724 if ((value = parse_ipqos(arg)) == -1)
1725 fatal("%s line %d: Bad IPQoS value: %s",
1726 filename, linenum, arg);
1727 arg = strdelim(&cp);
1728 if (arg == NULL)
1729 value2 = value;
1730 else if ((value2 = parse_ipqos(arg)) == -1)
1731 fatal("%s line %d: Bad IPQoS value: %s",
1732 filename, linenum, arg);
1733 if (*activep) {
1734 options->ip_qos_interactive = value;
1735 options->ip_qos_bulk = value2;
1736 }
1737 break;
1738
Damien Miller23528812012-04-22 11:24:43 +10001739 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001740 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001741 fatal("%.200s line %d: Missing argument.", filename,
1742 linenum);
1743 len = strspn(cp, WHITESPACE);
1744 if (*activep && options->version_addendum == NULL) {
1745 if (strcasecmp(cp + len, "none") == 0)
1746 options->version_addendum = xstrdup("");
1747 else if (strchr(cp + len, '\r') != NULL)
1748 fatal("%.200s line %d: Invalid argument",
1749 filename, linenum);
1750 else
1751 options->version_addendum = xstrdup(cp + len);
1752 }
1753 return 0;
1754
Damien Miller09d3e122012-10-31 08:58:58 +11001755 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001756 if (cp == NULL)
1757 fatal("%.200s line %d: Missing argument.", filename,
1758 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001759 len = strspn(cp, WHITESPACE);
1760 if (*activep && options->authorized_keys_command == NULL) {
1761 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1762 fatal("%.200s line %d: AuthorizedKeysCommand "
1763 "must be an absolute path",
1764 filename, linenum);
1765 options->authorized_keys_command = xstrdup(cp + len);
1766 }
1767 return 0;
1768
1769 case sAuthorizedKeysCommandUser:
1770 charptr = &options->authorized_keys_command_user;
1771
1772 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001773 if (!arg || *arg == '\0')
1774 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1775 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001776 if (*activep && *charptr == NULL)
1777 *charptr = xstrdup(arg);
1778 break;
1779
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001780 case sAuthorizedPrincipalsCommand:
1781 if (cp == NULL)
1782 fatal("%.200s line %d: Missing argument.", filename,
1783 linenum);
1784 len = strspn(cp, WHITESPACE);
1785 if (*activep &&
1786 options->authorized_principals_command == NULL) {
1787 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1788 fatal("%.200s line %d: "
1789 "AuthorizedPrincipalsCommand must be "
1790 "an absolute path", filename, linenum);
1791 options->authorized_principals_command =
1792 xstrdup(cp + len);
1793 }
1794 return 0;
1795
1796 case sAuthorizedPrincipalsCommandUser:
1797 charptr = &options->authorized_principals_command_user;
1798
1799 arg = strdelim(&cp);
1800 if (!arg || *arg == '\0')
1801 fatal("%s line %d: missing "
1802 "AuthorizedPrincipalsCommandUser argument.",
1803 filename, linenum);
1804 if (*activep && *charptr == NULL)
1805 *charptr = xstrdup(arg);
1806 break;
1807
Damien Millera6e3f012012-11-04 23:21:40 +11001808 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001809 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001810 while ((arg = strdelim(&cp)) && *arg != '\0') {
1811 if (options->num_auth_methods >=
1812 MAX_AUTH_METHODS)
1813 fatal("%s line %d: "
1814 "too many authentication methods.",
1815 filename, linenum);
1816 if (auth2_methods_valid(arg, 0) != 0)
1817 fatal("%s line %d: invalid "
1818 "authentication method list.",
1819 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001820 if (!*activep)
1821 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001822 options->auth_methods[
1823 options->num_auth_methods++] = xstrdup(arg);
1824 }
1825 }
1826 return 0;
1827
Damien Miller7acefbb2014-07-18 14:11:24 +10001828 case sStreamLocalBindMask:
1829 arg = strdelim(&cp);
1830 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001831 fatal("%s line %d: missing StreamLocalBindMask "
1832 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001833 /* Parse mode in octal format */
1834 value = strtol(arg, &p, 8);
1835 if (arg == p || value < 0 || value > 0777)
1836 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001837 if (*activep)
1838 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001839 break;
1840
1841 case sStreamLocalBindUnlink:
1842 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1843 goto parse_flag;
1844
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001845 case sFingerprintHash:
1846 arg = strdelim(&cp);
1847 if (!arg || *arg == '\0')
1848 fatal("%.200s line %d: Missing argument.",
1849 filename, linenum);
1850 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1851 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1852 filename, linenum, arg);
1853 if (*activep)
1854 options->fingerprint_hash = value;
1855 break;
1856
Ben Lindstromade03f62001-12-06 18:22:17 +00001857 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001858 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001859 filename, linenum, arg);
1860 while (arg)
1861 arg = strdelim(&cp);
1862 break;
1863
Damien Millerf9b3feb2003-05-16 11:38:32 +10001864 case sUnsupported:
1865 logit("%s line %d: Unsupported option %s",
1866 filename, linenum, arg);
1867 while (arg)
1868 arg = strdelim(&cp);
1869 break;
1870
Ben Lindstromade03f62001-12-06 18:22:17 +00001871 default:
1872 fatal("%s line %d: Missing handler for opcode %s (%d)",
1873 filename, linenum, arg, opcode);
1874 }
1875 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1876 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1877 filename, linenum, arg);
1878 return 0;
1879}
1880
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001881/* Reads the server configuration file. */
1882
Damien Miller4af51302000-04-16 11:18:38 +10001883void
Darren Tucker645ab752004-06-25 13:33:20 +10001884load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001885{
Damien Miller46cb75a2012-07-31 12:22:37 +10001886 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001887 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001888 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001889
Darren Tucker645ab752004-06-25 13:33:20 +10001890 debug2("%s: filename %s", __func__, filename);
1891 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001892 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001893 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001894 }
Darren Tucker645ab752004-06-25 13:33:20 +10001895 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001896 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001897 lineno++;
1898 if (strlen(line) == sizeof(line) - 1)
1899 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001900 /*
1901 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001902 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001903 * line numbers later for error messages
1904 */
1905 if ((cp = strchr(line, '#')) != NULL)
1906 memcpy(cp, "\n", 2);
1907 cp = line + strspn(line, " \t\r");
1908
1909 buffer_append(conf, cp, strlen(cp));
1910 }
1911 buffer_append(conf, "\0", 1);
1912 fclose(f);
1913 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1914}
1915
1916void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001917parse_server_match_config(ServerOptions *options,
1918 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001919{
Darren Tucker45150472006-07-12 22:34:17 +10001920 ServerOptions mo;
1921
1922 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001923 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001924 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001925}
1926
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001927int parse_server_match_testspec(struct connection_info *ci, char *spec)
1928{
1929 char *p;
1930
1931 while ((p = strsep(&spec, ",")) && *p != '\0') {
1932 if (strncmp(p, "addr=", 5) == 0) {
1933 ci->address = xstrdup(p + 5);
1934 } else if (strncmp(p, "host=", 5) == 0) {
1935 ci->host = xstrdup(p + 5);
1936 } else if (strncmp(p, "user=", 5) == 0) {
1937 ci->user = xstrdup(p + 5);
1938 } else if (strncmp(p, "laddr=", 6) == 0) {
1939 ci->laddress = xstrdup(p + 6);
1940 } else if (strncmp(p, "lport=", 6) == 0) {
1941 ci->lport = a2port(p + 6);
1942 if (ci->lport == -1) {
1943 fprintf(stderr, "Invalid port '%s' in test mode"
1944 " specification %s\n", p+6, p);
1945 return -1;
1946 }
1947 } else {
1948 fprintf(stderr, "Invalid test mode specification %s\n",
1949 p);
1950 return -1;
1951 }
1952 }
1953 return 0;
1954}
1955
1956/*
1957 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1958 * empty spec.
1959 */
1960int server_match_spec_complete(struct connection_info *ci)
1961{
1962 if (ci->user && ci->host && ci->address)
1963 return 1; /* complete */
1964 if (!ci->user && !ci->host && !ci->address)
1965 return -1; /* empty */
1966 return 0; /* partial */
1967}
1968
Darren Tucker1629c072007-02-19 22:25:37 +11001969/*
1970 * Copy any supported values that are set.
1971 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001972 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001973 * array values that are not used pre-authentication, because any that we
1974 * do use must be explictly sent in mm_getpwnamallow().
1975 */
Darren Tucker45150472006-07-12 22:34:17 +10001976void
Darren Tucker1629c072007-02-19 22:25:37 +11001977copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001978{
Damien Miller534b2cc2013-12-05 14:07:27 +11001979#define M_CP_INTOPT(n) do {\
1980 if (src->n != -1) \
1981 dst->n = src->n; \
1982} while (0)
1983
Darren Tucker1629c072007-02-19 22:25:37 +11001984 M_CP_INTOPT(password_authentication);
1985 M_CP_INTOPT(gss_authentication);
1986 M_CP_INTOPT(rsa_authentication);
1987 M_CP_INTOPT(pubkey_authentication);
1988 M_CP_INTOPT(kerberos_authentication);
1989 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001990 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001991 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001992 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001993 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001994
1995 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001996 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001997 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001998 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001999 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11002000 M_CP_INTOPT(x11_display_offset);
2001 M_CP_INTOPT(x11_forwarding);
2002 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002003 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002004 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002005 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002006 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002007 M_CP_INTOPT(ip_qos_interactive);
2008 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002009 M_CP_INTOPT(rekey_limit);
2010 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002011
Damien Miller534b2cc2013-12-05 14:07:27 +11002012 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2013#define M_CP_STROPT(n) do {\
2014 if (src->n != NULL && dst->n != src->n) { \
2015 free(dst->n); \
2016 dst->n = src->n; \
2017 } \
2018} while(0)
2019#define M_CP_STRARRAYOPT(n, num_n) do {\
2020 if (src->num_n != 0) { \
2021 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2022 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2023 } \
2024} while(0)
2025
Damien Millerf2e407e2011-05-20 19:04:14 +10002026 /* See comment in servconf.h */
2027 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002028
djm@openbsd.orged085102015-10-29 08:05:01 +00002029 /* Arguments that accept '+...' need to be expanded */
2030 assemble_algorithms(dst);
2031
Damien Millerc2411902011-05-20 19:03:49 +10002032 /*
2033 * The only things that should be below this point are string options
2034 * which are only used after authentication.
2035 */
Damien Miller5d74e582011-05-20 19:03:31 +10002036 if (preauth)
2037 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002038
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002039 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002040 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002041 if (option_clear_or_none(dst->adm_forced_command)) {
2042 free(dst->adm_forced_command);
2043 dst->adm_forced_command = NULL;
2044 }
Damien Miller5d74e582011-05-20 19:03:31 +10002045 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002046 if (option_clear_or_none(dst->chroot_directory)) {
2047 free(dst->chroot_directory);
2048 dst->chroot_directory = NULL;
2049 }
Darren Tucker45150472006-07-12 22:34:17 +10002050}
2051
Darren Tucker1629c072007-02-19 22:25:37 +11002052#undef M_CP_INTOPT
2053#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002054#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002055
Darren Tucker45150472006-07-12 22:34:17 +10002056void
2057parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002058 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002059{
2060 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002061 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002062
2063 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2064
Darren Tucker9fbac712004-08-12 22:41:44 +10002065 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002066 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002067 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002068 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002069 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002070 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002071 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002072 }
Darren Tuckera627d422013-06-02 07:31:17 +10002073 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002074 if (bad_options > 0)
2075 fatal("%s: terminating, %d bad configuration options",
2076 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002077 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002078}
Darren Tuckere7140f22008-06-10 23:01:51 +10002079
2080static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002081fmt_multistate_int(int val, const struct multistate *m)
2082{
2083 u_int i;
2084
2085 for (i = 0; m[i].key != NULL; i++) {
2086 if (m[i].value == val)
2087 return m[i].key;
2088 }
2089 return "UNKNOWN";
2090}
2091
2092static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002093fmt_intarg(ServerOpCodes code, int val)
2094{
Damien Miller82c55872011-06-23 08:20:30 +10002095 if (val == -1)
2096 return "unset";
2097 switch (code) {
2098 case sAddressFamily:
2099 return fmt_multistate_int(val, multistate_addressfamily);
2100 case sPermitRootLogin:
2101 return fmt_multistate_int(val, multistate_permitrootlogin);
2102 case sGatewayPorts:
2103 return fmt_multistate_int(val, multistate_gatewayports);
2104 case sCompression:
2105 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002106 case sUsePrivilegeSeparation:
2107 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002108 case sAllowTcpForwarding:
2109 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002110 case sAllowStreamLocalForwarding:
2111 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002112 case sFingerprintHash:
2113 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002114 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002115 switch (val) {
2116 case SSH_PROTO_1:
2117 return "1";
2118 case SSH_PROTO_2:
2119 return "2";
2120 case (SSH_PROTO_1|SSH_PROTO_2):
2121 return "2,1";
2122 default:
2123 return "UNKNOWN";
2124 }
Damien Miller82c55872011-06-23 08:20:30 +10002125 default:
2126 switch (val) {
2127 case 0:
2128 return "no";
2129 case 1:
2130 return "yes";
2131 default:
2132 return "UNKNOWN";
2133 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002134 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002135}
2136
2137static const char *
2138lookup_opcode_name(ServerOpCodes code)
2139{
2140 u_int i;
2141
2142 for (i = 0; keywords[i].name != NULL; i++)
2143 if (keywords[i].opcode == code)
2144 return(keywords[i].name);
2145 return "UNKNOWN";
2146}
2147
2148static void
2149dump_cfg_int(ServerOpCodes code, int val)
2150{
2151 printf("%s %d\n", lookup_opcode_name(code), val);
2152}
2153
2154static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002155dump_cfg_oct(ServerOpCodes code, int val)
2156{
2157 printf("%s 0%o\n", lookup_opcode_name(code), val);
2158}
2159
2160static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002161dump_cfg_fmtint(ServerOpCodes code, int val)
2162{
2163 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2164}
2165
2166static void
2167dump_cfg_string(ServerOpCodes code, const char *val)
2168{
2169 if (val == NULL)
2170 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002171 printf("%s %s\n", lookup_opcode_name(code),
2172 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002173}
2174
2175static void
2176dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2177{
2178 u_int i;
2179
2180 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002181 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2182}
2183
2184static void
2185dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2186{
2187 u_int i;
2188
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002189 if (count <= 0)
2190 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002191 printf("%s", lookup_opcode_name(code));
2192 for (i = 0; i < count; i++)
2193 printf(" %s", vals[i]);
2194 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002195}
2196
2197void
2198dump_config(ServerOptions *o)
2199{
2200 u_int i;
2201 int ret;
2202 struct addrinfo *ai;
2203 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002204 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002205
2206 /* these are usually at the top of the config */
2207 for (i = 0; i < o->num_ports; i++)
2208 printf("port %d\n", o->ports[i]);
2209 dump_cfg_fmtint(sProtocol, o->protocol);
2210 dump_cfg_fmtint(sAddressFamily, o->address_family);
2211
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002212 /*
2213 * ListenAddress must be after Port. add_one_listen_addr pushes
2214 * addresses onto a stack, so to maintain ordering we need to
2215 * print these in reverse order.
2216 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002217 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2218 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2219 sizeof(addr), port, sizeof(port),
2220 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2221 error("getnameinfo failed: %.100s",
2222 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2223 strerror(errno));
2224 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002225 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002226 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002227 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2228 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002229 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002230 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2231 addr, port, laddr2);
2232 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002233 }
2234 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002235 printf("%s", laddr1);
2236 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002237
2238 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002239#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002240 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002241#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002242 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2243 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2244 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2245 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2246 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002247 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002248 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2249 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002250 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002251
2252 /* formatted integer arguments */
2253 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2254 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2255 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2256 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2257 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2258 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2259 o->hostbased_uses_name_from_packet_only);
2260 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2261 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002262#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002263 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2264 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2265 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002266# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002267 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002268# endif
2269#endif
2270#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002271 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2272 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002273#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002274 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2275 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2276 o->kbd_interactive_authentication);
2277 dump_cfg_fmtint(sChallengeResponseAuthentication,
2278 o->challenge_response_authentication);
2279 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2280 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2281 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2282 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002283 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002284 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002285 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2286 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2287 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2288 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2289 dump_cfg_fmtint(sUseLogin, o->use_login);
2290 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002291 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002292 dump_cfg_fmtint(sUseDNS, o->use_dns);
2293 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002294 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002295 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002296 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002297 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002298
2299 /* string arguments */
2300 dump_cfg_string(sPidFile, o->pid_file);
2301 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002302 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2303 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002304 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002305 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002306 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002307 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2308 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002309 dump_cfg_string(sAuthorizedPrincipalsFile,
2310 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002311 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2312 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002313 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2314 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002315 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2316 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002317 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002318 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002319 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002320 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2321 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002322 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2323 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002324 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2325 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002326
2327 /* string arguments requiring a lookup */
2328 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2329 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2330
2331 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002332 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2333 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002334 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2335 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002336 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002337 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002338 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2339 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2340 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2341 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2342 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002343 dump_cfg_strarray_oneline(sAuthenticationMethods,
2344 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002345
2346 /* other arguments */
2347 for (i = 0; i < o->num_subsystems; i++)
2348 printf("subsystem %s %s\n", o->subsystem_name[i],
2349 o->subsystem_args[i]);
2350
2351 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2352 o->max_startups_rate, o->max_startups);
2353
2354 for (i = 0; tunmode_desc[i].val != -1; i++)
2355 if (tunmode_desc[i].val == o->permit_tun) {
2356 s = tunmode_desc[i].text;
2357 break;
2358 }
2359 dump_cfg_string(sPermitTunnel, s);
2360
Damien Miller91475862011-05-05 14:14:34 +10002361 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2362 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002363
Damien Millera6d6c1f2013-08-21 02:40:01 +10002364 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2365 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002366
Darren Tuckere7140f22008-06-10 23:01:51 +10002367 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002368}