blob: 873b0d02a08ca08fddba2caad39dff1f9297a119 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org46ecd192016-06-23 05:17:51 +00002/* $OpenBSD: servconf.c,v 1.292 2016/06/23 05:17:51 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
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000359 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000360 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000361 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000362
djm@openbsd.org161cf412014-12-22 07:55:51 +0000363#define CLEAR_ON_NONE(v) \
364 do { \
365 if (option_clear_or_none(v)) { \
366 free(v); \
367 v = NULL; \
368 } \
369 } while(0)
370 CLEAR_ON_NONE(options->pid_file);
371 CLEAR_ON_NONE(options->xauth_location);
372 CLEAR_ON_NONE(options->banner);
373 CLEAR_ON_NONE(options->trusted_user_ca_keys);
374 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000375 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000376 CLEAR_ON_NONE(options->adm_forced_command);
377 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000378 for (i = 0; i < options->num_host_key_files; i++)
379 CLEAR_ON_NONE(options->host_key_files[i]);
380 for (i = 0; i < options->num_host_cert_files; i++)
381 CLEAR_ON_NONE(options->host_cert_files[i]);
382#undef CLEAR_ON_NONE
383
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000384 /* Similar handling for AuthenticationMethods=any */
385 if (options->num_auth_methods == 1 &&
386 strcmp(options->auth_methods[0], "any") == 0) {
387 free(options->auth_methods[0]);
388 options->auth_methods[0] = NULL;
389 options->num_auth_methods = 0;
390 }
391
Tim Rice40017b02002-07-14 13:36:49 -0700392#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000393 if (use_privsep && options->compression == 1) {
394 error("This platform does not support both privilege "
395 "separation and compression");
396 error("Compression disabled");
397 options->compression = 0;
398 }
399#endif
400
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401}
402
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000403/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100404typedef enum {
405 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100406 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000407 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100408 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000409 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
410 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000411 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100412 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100413 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000414 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100415 sPasswordAuthentication, sKbdInteractiveAuthentication,
416 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000417 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100418 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100419 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000420 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000421 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000422 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000423 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
424 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000425 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000426 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000427 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000428 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000429 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
430 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100431 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100432 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100433 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000434 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000435 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000436 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100437 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000438 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000439 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000440 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000441 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000442} ServerOpCodes;
443
Darren Tucker45150472006-07-12 22:34:17 +1000444#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
445#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
446#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
447
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000448/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100449static struct {
450 const char *name;
451 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000452 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100453} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100454 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000455#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000456 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000457#else
Darren Tucker45150472006-07-12 22:34:17 +1000458 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000459#endif
Darren Tucker45150472006-07-12 22:34:17 +1000460 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100461 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000462 { "port", sPort, SSHCFG_GLOBAL },
463 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
464 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000465 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000466 { "pidfile", sPidFile, SSHCFG_GLOBAL },
467 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
468 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
469 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100470 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000471 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
472 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
473 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100474 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
475 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000476 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000477 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000478 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100479 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
480 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000481 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000482 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000483#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100484 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000485 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
486 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100487#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000488 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000489#else
Darren Tucker45150472006-07-12 22:34:17 +1000490 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100491#endif
492#else
Darren Tucker1629c072007-02-19 22:25:37 +1100493 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000494 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
495 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
496 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000497#endif
Darren Tucker45150472006-07-12 22:34:17 +1000498 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
499 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000500#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100501 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000503 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000504#else
Darren Tucker1629c072007-02-19 22:25:37 +1100505 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000506 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000507 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000508#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100509 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
510 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100511 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
513 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
514 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
515 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
516 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100517#ifdef DISABLE_LASTLOG
518 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
519#else
Darren Tucker45150472006-07-12 22:34:17 +1000520 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100521#endif
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
523 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000524 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
525 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
526 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000527 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
528 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100529 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000530 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
531 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
532 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000533 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000534 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
535 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
536 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000537 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000538 { "allowusers", sAllowUsers, SSHCFG_ALL },
539 { "denyusers", sDenyUsers, SSHCFG_ALL },
540 { "allowgroups", sAllowGroups, SSHCFG_ALL },
541 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000542 { "ciphers", sCiphers, SSHCFG_GLOBAL },
543 { "macs", sMacs, SSHCFG_GLOBAL },
544 { "protocol", sProtocol, SSHCFG_GLOBAL },
545 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
546 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
547 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000548 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000549 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100550 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000551 { "usedns", sUseDNS, SSHCFG_GLOBAL },
552 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
553 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
554 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
555 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000556 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000557 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000558 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000559 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000560 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100561 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000562 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000563 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000564 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000565 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100566 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100567 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100568 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
569 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000570 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000571 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100572 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100573 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
574 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000575 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
576 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000577 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100578 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000579 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
580 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
581 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000582 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000583 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000584};
585
Darren Tuckere7140f22008-06-10 23:01:51 +1000586static struct {
587 int val;
588 char *text;
589} tunmode_desc[] = {
590 { SSH_TUNMODE_NO, "no" },
591 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
592 { SSH_TUNMODE_ETHERNET, "ethernet" },
593 { SSH_TUNMODE_YES, "yes" },
594 { -1, NULL }
595};
596
Damien Miller5428f641999-11-25 11:54:57 +1100597/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000598 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100599 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000600
Damien Miller4af51302000-04-16 11:18:38 +1000601static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100602parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000603 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000604{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000605 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000606
Damien Miller95def091999-11-25 00:26:21 +1100607 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000608 if (strcasecmp(cp, keywords[i].name) == 0) {
609 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100610 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000611 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000612
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000613 error("%s: line %d: Bad configuration option: %s",
614 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100615 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000616}
617
Darren Tucker88b6fb22010-01-13 22:44:29 +1100618char *
619derelativise_path(const char *path)
620{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000621 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100622
djm@openbsd.org161cf412014-12-22 07:55:51 +0000623 if (strcasecmp(path, "none") == 0)
624 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100625 expanded = tilde_expand_filename(path, getuid());
626 if (*expanded == '/')
627 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100628 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100629 fatal("%s: getcwd: %s", __func__, strerror(errno));
630 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000631 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100632 return ret;
633}
634
Ben Lindstrombba81212001-06-25 05:01:22 +0000635static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100636add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100637{
Damien Millereccb9de2005-06-17 12:59:34 +1000638 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100639
Ben Lindstrom19066a12001-04-12 23:39:26 +0000640 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000641 for (i = 0; i < options->num_ports; i++)
642 add_one_listen_addr(options, addr, options->ports[i]);
643 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000644 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000645}
646
Ben Lindstrombba81212001-06-25 05:01:22 +0000647static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100648add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000649{
650 struct addrinfo hints, *ai, *aitop;
651 char strport[NI_MAXSERV];
652 int gaierr;
653
654 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100655 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000656 hints.ai_socktype = SOCK_STREAM;
657 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100658 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000659 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
660 fatal("bad addr or host: %s (%s)",
661 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100662 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000663 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
664 ;
665 ai->ai_next = options->listen_addrs;
666 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100667}
668
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000669/*
670 * Queue a ListenAddress to be processed once we have all of the Ports
671 * and AddressFamily options.
672 */
673static void
674queue_listen_addr(ServerOptions *options, char *addr, int port)
675{
676 options->queued_listen_addrs = xreallocarray(
677 options->queued_listen_addrs, options->num_queued_listens + 1,
678 sizeof(addr));
679 options->queued_listen_ports = xreallocarray(
680 options->queued_listen_ports, options->num_queued_listens + 1,
681 sizeof(port));
682 options->queued_listen_addrs[options->num_queued_listens] =
683 xstrdup(addr);
684 options->queued_listen_ports[options->num_queued_listens] = port;
685 options->num_queued_listens++;
686}
687
688/*
689 * Process queued (text) ListenAddress entries.
690 */
691static void
692process_queued_listen_addrs(ServerOptions *options)
693{
694 u_int i;
695
696 if (options->num_ports == 0)
697 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
698 if (options->address_family == -1)
699 options->address_family = AF_UNSPEC;
700
701 for (i = 0; i < options->num_queued_listens; i++) {
702 add_listen_addr(options, options->queued_listen_addrs[i],
703 options->queued_listen_ports[i]);
704 free(options->queued_listen_addrs[i]);
705 options->queued_listen_addrs[i] = NULL;
706 }
707 free(options->queued_listen_addrs);
708 options->queued_listen_addrs = NULL;
709 free(options->queued_listen_ports);
710 options->queued_listen_ports = NULL;
711 options->num_queued_listens = 0;
712}
713
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000714struct connection_info *
715get_connection_info(int populate, int use_dns)
716{
djm@openbsd.org95767262016-03-07 19:02:43 +0000717 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000718 static struct connection_info ci;
719
720 if (!populate)
721 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000722 ci.host = auth_get_canonical_hostname(ssh, use_dns);
723 ci.address = ssh_remote_ipaddr(ssh);
724 ci.laddress = ssh_local_ipaddr(ssh);
725 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000726 return &ci;
727}
728
Darren Tucker45150472006-07-12 22:34:17 +1000729/*
730 * The strategy for the Match blocks is that the config file is parsed twice.
731 *
732 * The first time is at startup. activep is initialized to 1 and the
733 * directives in the global context are processed and acted on. Hitting a
734 * Match directive unsets activep and the directives inside the block are
735 * checked for syntax only.
736 *
737 * The second time is after a connection has been established but before
738 * authentication. activep is initialized to 2 and global config directives
739 * are ignored since they have already been processed. If the criteria in a
740 * Match block is met, activep is set and the subsequent directives
741 * processed and actioned until EOF or another Match block unsets it. Any
742 * options set are copied into the main server config.
743 *
744 * Potential additions/improvements:
745 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
746 *
747 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
748 * Match Address 192.168.0.*
749 * Tag trusted
750 * Match Group wheel
751 * Tag trusted
752 * Match Tag trusted
753 * AllowTcpForwarding yes
754 * GatewayPorts clientspecified
755 * [...]
756 *
757 * - Add a PermittedChannelRequests directive
758 * Match Group shell
759 * PermittedChannelRequests session,forwarded-tcpip
760 */
761
762static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000763match_cfg_line_group(const char *grps, int line, const char *user)
764{
765 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000766 struct passwd *pw;
767
Damien Miller565ca3f2006-08-19 00:23:15 +1000768 if (user == NULL)
769 goto out;
770
771 if ((pw = getpwnam(user)) == NULL) {
772 debug("Can't match group at line %d because user %.100s does "
773 "not exist", line, user);
774 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
775 debug("Can't Match group because user %.100s not in any group "
776 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000777 } else if (ga_match_pattern_list(grps) != 1) {
778 debug("user %.100s does not match group list %.100s at line %d",
779 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000780 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000781 debug("user %.100s matched group list %.100s at line %d", user,
782 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000783 result = 1;
784 }
785out:
786 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000787 return result;
788}
789
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000790/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000791 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100792 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000793 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000794 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000795static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000796match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000797{
Damien Millercf31f382013-10-24 21:02:56 +1100798 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000799 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000800
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000801 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000802 debug3("checking syntax for 'Match %s'", cp);
803 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000804 debug3("checking match for '%s' user %s host %s addr %s "
805 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
806 ci->host ? ci->host : "(null)",
807 ci->address ? ci->address : "(null)",
808 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000809
810 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100811 attributes++;
812 if (strcasecmp(attrib, "all") == 0) {
813 if (attributes != 1 ||
814 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
815 error("'all' cannot be combined with other "
816 "Match attributes");
817 return -1;
818 }
819 *condition = cp;
820 return 1;
821 }
Darren Tucker45150472006-07-12 22:34:17 +1000822 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
823 error("Missing Match criteria for %s", attrib);
824 return -1;
825 }
Darren Tucker45150472006-07-12 22:34:17 +1000826 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000827 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000828 result = 0;
829 continue;
830 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000831 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000832 result = 0;
833 else
834 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000835 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000836 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000837 if (ci == NULL || ci->user == NULL) {
838 result = 0;
839 continue;
840 }
841 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000842 case -1:
843 return -1;
844 case 0:
845 result = 0;
846 }
Darren Tucker45150472006-07-12 22:34:17 +1000847 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000848 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000849 result = 0;
850 continue;
851 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000852 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000853 result = 0;
854 else
855 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000856 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000857 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000858 if (ci == NULL || ci->address == NULL) {
859 result = 0;
860 continue;
861 }
862 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000863 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000864 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000865 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000866 break;
867 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000868 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000869 result = 0;
870 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000871 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000872 return -1;
873 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000874 } else if (strcasecmp(attrib, "localaddress") == 0){
875 if (ci == NULL || ci->laddress == NULL) {
876 result = 0;
877 continue;
878 }
879 switch (addr_match_list(ci->laddress, arg)) {
880 case 1:
881 debug("connection from %.100s matched "
882 "'LocalAddress %.100s' at line %d",
883 ci->laddress, arg, line);
884 break;
885 case 0:
886 case -1:
887 result = 0;
888 break;
889 case -2:
890 return -1;
891 }
892 } else if (strcasecmp(attrib, "localport") == 0) {
893 if ((port = a2port(arg)) == -1) {
894 error("Invalid LocalPort '%s' on Match line",
895 arg);
896 return -1;
897 }
898 if (ci == NULL || ci->lport == 0) {
899 result = 0;
900 continue;
901 }
902 /* TODO support port lists */
903 if (port == ci->lport)
904 debug("connection from %.100s matched "
905 "'LocalPort %d' at line %d",
906 ci->laddress, port, line);
907 else
908 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000909 } else {
910 error("Unsupported Match attribute %s", attrib);
911 return -1;
912 }
913 }
Damien Millercf31f382013-10-24 21:02:56 +1100914 if (attributes == 0) {
915 error("One or more attributes required for Match");
916 return -1;
917 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000918 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000919 debug3("match %sfound", result ? "" : "not ");
920 *condition = cp;
921 return result;
922}
923
Damien Millere2754432006-07-24 14:06:47 +1000924#define WHITESPACE " \t\r\n"
925
Damien Miller33322122011-06-20 14:43:11 +1000926/* Multistate option parsing */
927struct multistate {
928 char *key;
929 int value;
930};
931static const struct multistate multistate_addressfamily[] = {
932 { "inet", AF_INET },
933 { "inet6", AF_INET6 },
934 { "any", AF_UNSPEC },
935 { NULL, -1 }
936};
937static const struct multistate multistate_permitrootlogin[] = {
938 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000939 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000940 { "forced-commands-only", PERMIT_FORCED_ONLY },
941 { "yes", PERMIT_YES },
942 { "no", PERMIT_NO },
943 { NULL, -1 }
944};
945static const struct multistate multistate_compression[] = {
946 { "delayed", COMP_DELAYED },
947 { "yes", COMP_ZLIB },
948 { "no", COMP_NONE },
949 { NULL, -1 }
950};
951static const struct multistate multistate_gatewayports[] = {
952 { "clientspecified", 2 },
953 { "yes", 1 },
954 { "no", 0 },
955 { NULL, -1 }
956};
Damien Miller69ff1df2011-06-23 08:30:03 +1000957static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000958 { "yes", PRIVSEP_NOSANDBOX },
959 { "sandbox", PRIVSEP_ON },
960 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000961 { "no", PRIVSEP_OFF },
962 { NULL, -1 }
963};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100964static const struct multistate multistate_tcpfwd[] = {
965 { "yes", FORWARD_ALLOW },
966 { "all", FORWARD_ALLOW },
967 { "no", FORWARD_DENY },
968 { "remote", FORWARD_REMOTE },
969 { "local", FORWARD_LOCAL },
970 { NULL, -1 }
971};
Damien Miller33322122011-06-20 14:43:11 +1000972
Ben Lindstromade03f62001-12-06 18:22:17 +0000973int
974process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000975 const char *filename, int linenum, int *activep,
976 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000977{
Darren Tucker09c0f032013-05-16 20:48:57 +1000978 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000979 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100980 SyslogFacility *log_facility_ptr;
981 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000982 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000983 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000984 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000985 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000986 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000987
988 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100989 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100990 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000991 /* Ignore leading whitespace */
992 if (*arg == '\0')
993 arg = strdelim(&cp);
994 if (!arg || !*arg || *arg == '#')
995 return 0;
996 intptr = NULL;
997 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000998 opcode = parse_token(arg, filename, linenum, &flags);
999
1000 if (activep == NULL) { /* We are processing a command line directive */
1001 cmdline = 1;
1002 activep = &cmdline;
1003 }
1004 if (*activep && opcode != sMatch)
1005 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1006 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001007 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +10001008 fatal("%s line %d: Directive '%s' is not allowed "
1009 "within a Match block", filename, linenum, arg);
1010 } else { /* this is a directive we have already processed */
1011 while (arg)
1012 arg = strdelim(&cp);
1013 return 0;
1014 }
1015 }
1016
Ben Lindstromade03f62001-12-06 18:22:17 +00001017 switch (opcode) {
1018 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001019 case sUsePAM:
1020 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001021 goto parse_flag;
1022
1023 /* Standard Options */
1024 case sBadOption:
1025 return -1;
1026 case sPort:
1027 /* ignore ports from configfile if cmdline specifies ports */
1028 if (options->ports_from_cmdline)
1029 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001030 if (options->num_ports >= MAX_PORTS)
1031 fatal("%s line %d: too many ports.",
1032 filename, linenum);
1033 arg = strdelim(&cp);
1034 if (!arg || *arg == '\0')
1035 fatal("%s line %d: missing port number.",
1036 filename, linenum);
1037 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001038 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001039 fatal("%s line %d: Badly formatted port number.",
1040 filename, linenum);
1041 break;
1042
1043 case sServerKeyBits:
1044 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001045 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001046 arg = strdelim(&cp);
1047 if (!arg || *arg == '\0')
1048 fatal("%s line %d: missing integer value.",
1049 filename, linenum);
1050 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001051 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001052 *intptr = value;
1053 break;
1054
1055 case sLoginGraceTime:
1056 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001057 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001058 arg = strdelim(&cp);
1059 if (!arg || *arg == '\0')
1060 fatal("%s line %d: missing time value.",
1061 filename, linenum);
1062 if ((value = convtime(arg)) == -1)
1063 fatal("%s line %d: invalid time value.",
1064 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001065 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001066 *intptr = value;
1067 break;
1068
1069 case sKeyRegenerationTime:
1070 intptr = &options->key_regeneration_time;
1071 goto parse_time;
1072
1073 case sListenAddress:
1074 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001075 if (arg == NULL || *arg == '\0')
1076 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001077 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001078 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1079 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1080 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001081 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001082 break;
1083 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001084 p = hpdelim(&arg);
1085 if (p == NULL)
1086 fatal("%s line %d: bad address:port usage",
1087 filename, linenum);
1088 p = cleanhostname(p);
1089 if (arg == NULL)
1090 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001091 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001092 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001093
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001094 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001095
Ben Lindstromade03f62001-12-06 18:22:17 +00001096 break;
1097
Darren Tucker0f383232005-01-20 10:57:56 +11001098 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001099 intptr = &options->address_family;
1100 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001101 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001102 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001103 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001104 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001105 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001106 value = -1;
1107 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1108 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1109 value = multistate_ptr[i].value;
1110 break;
1111 }
1112 }
1113 if (value == -1)
1114 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001115 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001116 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001117 *intptr = value;
1118 break;
1119
Ben Lindstromade03f62001-12-06 18:22:17 +00001120 case sHostKeyFile:
1121 intptr = &options->num_host_key_files;
1122 if (*intptr >= MAX_HOSTKEYS)
1123 fatal("%s line %d: too many host keys specified (max %d).",
1124 filename, linenum, MAX_HOSTKEYS);
1125 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001126 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001127 arg = strdelim(&cp);
1128 if (!arg || *arg == '\0')
1129 fatal("%s line %d: missing file name.",
1130 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001131 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001132 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001133 /* increase optional counter */
1134 if (intptr != NULL)
1135 *intptr = *intptr + 1;
1136 }
1137 break;
1138
Damien Miller85b45e02013-07-20 13:21:52 +10001139 case sHostKeyAgent:
1140 charptr = &options->host_key_agent;
1141 arg = strdelim(&cp);
1142 if (!arg || *arg == '\0')
1143 fatal("%s line %d: missing socket name.",
1144 filename, linenum);
1145 if (*activep && *charptr == NULL)
1146 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1147 xstrdup(arg) : derelativise_path(arg);
1148 break;
1149
Damien Miller0a80ca12010-02-27 07:55:05 +11001150 case sHostCertificate:
1151 intptr = &options->num_host_cert_files;
1152 if (*intptr >= MAX_HOSTKEYS)
1153 fatal("%s line %d: too many host certificates "
1154 "specified (max %d).", filename, linenum,
1155 MAX_HOSTCERTS);
1156 charptr = &options->host_cert_files[*intptr];
1157 goto parse_filename;
1158 break;
1159
Ben Lindstromade03f62001-12-06 18:22:17 +00001160 case sPidFile:
1161 charptr = &options->pid_file;
1162 goto parse_filename;
1163
1164 case sPermitRootLogin:
1165 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001166 multistate_ptr = multistate_permitrootlogin;
1167 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001168
1169 case sIgnoreRhosts:
1170 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001171 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001172 arg = strdelim(&cp);
1173 if (!arg || *arg == '\0')
1174 fatal("%s line %d: missing yes/no argument.",
1175 filename, linenum);
1176 value = 0; /* silence compiler */
1177 if (strcmp(arg, "yes") == 0)
1178 value = 1;
1179 else if (strcmp(arg, "no") == 0)
1180 value = 0;
1181 else
1182 fatal("%s line %d: Bad yes/no argument: %s",
1183 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001184 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001185 *intptr = value;
1186 break;
1187
1188 case sIgnoreUserKnownHosts:
1189 intptr = &options->ignore_user_known_hosts;
1190 goto parse_flag;
1191
Ben Lindstromade03f62001-12-06 18:22:17 +00001192 case sRhostsRSAAuthentication:
1193 intptr = &options->rhosts_rsa_authentication;
1194 goto parse_flag;
1195
1196 case sHostbasedAuthentication:
1197 intptr = &options->hostbased_authentication;
1198 goto parse_flag;
1199
1200 case sHostbasedUsesNameFromPacketOnly:
1201 intptr = &options->hostbased_uses_name_from_packet_only;
1202 goto parse_flag;
1203
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001204 case sHostbasedAcceptedKeyTypes:
1205 charptr = &options->hostbased_key_types;
1206 parse_keytypes:
1207 arg = strdelim(&cp);
1208 if (!arg || *arg == '\0')
1209 fatal("%s line %d: Missing argument.",
1210 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001211 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001212 fatal("%s line %d: Bad key types '%s'.",
1213 filename, linenum, arg ? arg : "<NONE>");
1214 if (*activep && *charptr == NULL)
1215 *charptr = xstrdup(arg);
1216 break;
1217
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001218 case sHostKeyAlgorithms:
1219 charptr = &options->hostkeyalgorithms;
1220 goto parse_keytypes;
1221
Ben Lindstromade03f62001-12-06 18:22:17 +00001222 case sRSAAuthentication:
1223 intptr = &options->rsa_authentication;
1224 goto parse_flag;
1225
1226 case sPubkeyAuthentication:
1227 intptr = &options->pubkey_authentication;
1228 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001229
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001230 case sPubkeyAcceptedKeyTypes:
1231 charptr = &options->pubkey_key_types;
1232 goto parse_keytypes;
1233
Ben Lindstromade03f62001-12-06 18:22:17 +00001234 case sKerberosAuthentication:
1235 intptr = &options->kerberos_authentication;
1236 goto parse_flag;
1237
1238 case sKerberosOrLocalPasswd:
1239 intptr = &options->kerberos_or_local_passwd;
1240 goto parse_flag;
1241
1242 case sKerberosTicketCleanup:
1243 intptr = &options->kerberos_ticket_cleanup;
1244 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001245
Darren Tucker22ef5082003-12-31 11:37:34 +11001246 case sKerberosGetAFSToken:
1247 intptr = &options->kerberos_get_afs_token;
1248 goto parse_flag;
1249
Darren Tucker0efd1552003-08-26 11:49:55 +10001250 case sGssAuthentication:
1251 intptr = &options->gss_authentication;
1252 goto parse_flag;
1253
1254 case sGssCleanupCreds:
1255 intptr = &options->gss_cleanup_creds;
1256 goto parse_flag;
1257
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001258 case sGssStrictAcceptor:
1259 intptr = &options->gss_strict_acceptor;
1260 goto parse_flag;
1261
Ben Lindstromade03f62001-12-06 18:22:17 +00001262 case sPasswordAuthentication:
1263 intptr = &options->password_authentication;
1264 goto parse_flag;
1265
1266 case sKbdInteractiveAuthentication:
1267 intptr = &options->kbd_interactive_authentication;
1268 goto parse_flag;
1269
1270 case sChallengeResponseAuthentication:
1271 intptr = &options->challenge_response_authentication;
1272 goto parse_flag;
1273
1274 case sPrintMotd:
1275 intptr = &options->print_motd;
1276 goto parse_flag;
1277
1278 case sPrintLastLog:
1279 intptr = &options->print_lastlog;
1280 goto parse_flag;
1281
1282 case sX11Forwarding:
1283 intptr = &options->x11_forwarding;
1284 goto parse_flag;
1285
1286 case sX11DisplayOffset:
1287 intptr = &options->x11_display_offset;
1288 goto parse_int;
1289
Damien Miller95c249f2002-02-05 12:11:34 +11001290 case sX11UseLocalhost:
1291 intptr = &options->x11_use_localhost;
1292 goto parse_flag;
1293
Ben Lindstromade03f62001-12-06 18:22:17 +00001294 case sXAuthLocation:
1295 charptr = &options->xauth_location;
1296 goto parse_filename;
1297
Damien Miller5ff30c62013-10-30 22:21:50 +11001298 case sPermitTTY:
1299 intptr = &options->permit_tty;
1300 goto parse_flag;
1301
Damien Miller72e6b5c2014-07-04 09:00:04 +10001302 case sPermitUserRC:
1303 intptr = &options->permit_user_rc;
1304 goto parse_flag;
1305
Ben Lindstromade03f62001-12-06 18:22:17 +00001306 case sStrictModes:
1307 intptr = &options->strict_modes;
1308 goto parse_flag;
1309
Damien Miller12c150e2003-12-17 16:31:10 +11001310 case sTCPKeepAlive:
1311 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001312 goto parse_flag;
1313
1314 case sEmptyPasswd:
1315 intptr = &options->permit_empty_passwd;
1316 goto parse_flag;
1317
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001318 case sPermitUserEnvironment:
1319 intptr = &options->permit_user_env;
1320 goto parse_flag;
1321
Ben Lindstromade03f62001-12-06 18:22:17 +00001322 case sUseLogin:
1323 intptr = &options->use_login;
1324 goto parse_flag;
1325
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001326 case sCompression:
1327 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001328 multistate_ptr = multistate_compression;
1329 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001330
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001331 case sRekeyLimit:
1332 arg = strdelim(&cp);
1333 if (!arg || *arg == '\0')
1334 fatal("%.200s line %d: Missing argument.", filename,
1335 linenum);
1336 if (strcmp(arg, "default") == 0) {
1337 val64 = 0;
1338 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001339 if (scan_scaled(arg, &val64) == -1)
1340 fatal("%.200s line %d: Bad number '%s': %s",
1341 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001342 if (val64 != 0 && val64 < 16)
1343 fatal("%.200s line %d: RekeyLimit too small",
1344 filename, linenum);
1345 }
1346 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001347 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001348 if (cp != NULL) { /* optional rekey interval present */
1349 if (strcmp(cp, "none") == 0) {
1350 (void)strdelim(&cp); /* discard */
1351 break;
1352 }
1353 intptr = &options->rekey_interval;
1354 goto parse_time;
1355 }
1356 break;
1357
Ben Lindstromade03f62001-12-06 18:22:17 +00001358 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001359 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001360 multistate_ptr = multistate_gatewayports;
1361 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001362
Damien Miller3a961dc2003-06-03 10:25:48 +10001363 case sUseDNS:
1364 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001365 goto parse_flag;
1366
1367 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001368 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001369 arg = strdelim(&cp);
1370 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001371 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001372 fatal("%.200s line %d: unsupported log facility '%s'",
1373 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001374 if (*log_facility_ptr == -1)
1375 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001376 break;
1377
1378 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001379 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001380 arg = strdelim(&cp);
1381 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001382 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001383 fatal("%.200s line %d: unsupported log level '%s'",
1384 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001385 if (*log_level_ptr == -1)
1386 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001387 break;
1388
1389 case sAllowTcpForwarding:
1390 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001391 multistate_ptr = multistate_tcpfwd;
1392 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001393
Damien Miller7acefbb2014-07-18 14:11:24 +10001394 case sAllowStreamLocalForwarding:
1395 intptr = &options->allow_streamlocal_forwarding;
1396 multistate_ptr = multistate_tcpfwd;
1397 goto parse_multistate;
1398
Damien Miller4f755cd2008-05-19 14:57:41 +10001399 case sAllowAgentForwarding:
1400 intptr = &options->allow_agent_forwarding;
1401 goto parse_flag;
1402
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001403 case sUsePrivilegeSeparation:
1404 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001405 multistate_ptr = multistate_privsep;
1406 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001407
Ben Lindstromade03f62001-12-06 18:22:17 +00001408 case sAllowUsers:
1409 while ((arg = strdelim(&cp)) && *arg != '\0') {
1410 if (options->num_allow_users >= MAX_ALLOW_USERS)
1411 fatal("%s line %d: too many allow users.",
1412 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001413 if (!*activep)
1414 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001415 options->allow_users[options->num_allow_users++] =
1416 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001417 }
1418 break;
1419
1420 case sDenyUsers:
1421 while ((arg = strdelim(&cp)) && *arg != '\0') {
1422 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001423 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001424 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001425 if (!*activep)
1426 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001427 options->deny_users[options->num_deny_users++] =
1428 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001429 }
1430 break;
1431
1432 case sAllowGroups:
1433 while ((arg = strdelim(&cp)) && *arg != '\0') {
1434 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1435 fatal("%s line %d: too many allow groups.",
1436 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001437 if (!*activep)
1438 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001439 options->allow_groups[options->num_allow_groups++] =
1440 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001441 }
1442 break;
1443
1444 case sDenyGroups:
1445 while ((arg = strdelim(&cp)) && *arg != '\0') {
1446 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1447 fatal("%s line %d: too many deny groups.",
1448 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001449 if (!*activep)
1450 continue;
1451 options->deny_groups[options->num_deny_groups++] =
1452 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001453 }
1454 break;
1455
1456 case sCiphers:
1457 arg = strdelim(&cp);
1458 if (!arg || *arg == '\0')
1459 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001460 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001461 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1462 filename, linenum, arg ? arg : "<NONE>");
1463 if (options->ciphers == NULL)
1464 options->ciphers = xstrdup(arg);
1465 break;
1466
1467 case sMacs:
1468 arg = strdelim(&cp);
1469 if (!arg || *arg == '\0')
1470 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001471 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001472 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1473 filename, linenum, arg ? arg : "<NONE>");
1474 if (options->macs == NULL)
1475 options->macs = xstrdup(arg);
1476 break;
1477
Damien Millerd5f62bf2010-09-24 22:11:14 +10001478 case sKexAlgorithms:
1479 arg = strdelim(&cp);
1480 if (!arg || *arg == '\0')
1481 fatal("%s line %d: Missing argument.",
1482 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001483 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001484 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1485 filename, linenum, arg ? arg : "<NONE>");
1486 if (options->kex_algorithms == NULL)
1487 options->kex_algorithms = xstrdup(arg);
1488 break;
1489
Ben Lindstromade03f62001-12-06 18:22:17 +00001490 case sProtocol:
1491 intptr = &options->protocol;
1492 arg = strdelim(&cp);
1493 if (!arg || *arg == '\0')
1494 fatal("%s line %d: Missing argument.", filename, linenum);
1495 value = proto_spec(arg);
1496 if (value == SSH_PROTO_UNKNOWN)
1497 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001498 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001499 if (*intptr == SSH_PROTO_UNKNOWN)
1500 *intptr = value;
1501 break;
1502
1503 case sSubsystem:
1504 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1505 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001506 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001507 }
1508 arg = strdelim(&cp);
1509 if (!arg || *arg == '\0')
1510 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001511 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001512 if (!*activep) {
1513 arg = strdelim(&cp);
1514 break;
1515 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001516 for (i = 0; i < options->num_subsystems; i++)
1517 if (strcmp(arg, options->subsystem_name[i]) == 0)
1518 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001519 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001520 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1521 arg = strdelim(&cp);
1522 if (!arg || *arg == '\0')
1523 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001524 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001525 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001526
1527 /* Collect arguments (separate to executable) */
1528 p = xstrdup(arg);
1529 len = strlen(p) + 1;
1530 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1531 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001532 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001533 strlcat(p, " ", len);
1534 strlcat(p, arg, len);
1535 }
1536 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001537 options->num_subsystems++;
1538 break;
1539
1540 case sMaxStartups:
1541 arg = strdelim(&cp);
1542 if (!arg || *arg == '\0')
1543 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001544 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001545 if ((n = sscanf(arg, "%d:%d:%d",
1546 &options->max_startups_begin,
1547 &options->max_startups_rate,
1548 &options->max_startups)) == 3) {
1549 if (options->max_startups_begin >
1550 options->max_startups ||
1551 options->max_startups_rate > 100 ||
1552 options->max_startups_rate < 1)
1553 fatal("%s line %d: Illegal MaxStartups spec.",
1554 filename, linenum);
1555 } else if (n != 1)
1556 fatal("%s line %d: Illegal MaxStartups spec.",
1557 filename, linenum);
1558 else
1559 options->max_startups = options->max_startups_begin;
1560 break;
1561
Darren Tucker89413db2004-05-24 10:36:23 +10001562 case sMaxAuthTries:
1563 intptr = &options->max_authtries;
1564 goto parse_int;
1565
Damien Miller7207f642008-05-19 15:34:50 +10001566 case sMaxSessions:
1567 intptr = &options->max_sessions;
1568 goto parse_int;
1569
Ben Lindstromade03f62001-12-06 18:22:17 +00001570 case sBanner:
1571 charptr = &options->banner;
1572 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001573
Ben Lindstromade03f62001-12-06 18:22:17 +00001574 /*
1575 * These options can contain %X options expanded at
1576 * connect time, so that you can specify paths like:
1577 *
1578 * AuthorizedKeysFile /etc/ssh_keys/%u
1579 */
1580 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001581 if (*activep && options->num_authkeys_files == 0) {
1582 while ((arg = strdelim(&cp)) && *arg != '\0') {
1583 if (options->num_authkeys_files >=
1584 MAX_AUTHKEYS_FILES)
1585 fatal("%s line %d: "
1586 "too many authorized keys files.",
1587 filename, linenum);
1588 options->authorized_keys_files[
1589 options->num_authkeys_files++] =
1590 tilde_expand_filename(arg, getuid());
1591 }
1592 }
1593 return 0;
1594
Damien Miller30da3442010-05-10 11:58:03 +10001595 case sAuthorizedPrincipalsFile:
1596 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001597 arg = strdelim(&cp);
1598 if (!arg || *arg == '\0')
1599 fatal("%s line %d: missing file name.",
1600 filename, linenum);
1601 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001602 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001603 /* increase optional counter */
1604 if (intptr != NULL)
1605 *intptr = *intptr + 1;
1606 }
1607 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001608
1609 case sClientAliveInterval:
1610 intptr = &options->client_alive_interval;
1611 goto parse_time;
1612
1613 case sClientAliveCountMax:
1614 intptr = &options->client_alive_count_max;
1615 goto parse_int;
1616
Darren Tucker46bc0752004-05-02 22:11:30 +10001617 case sAcceptEnv:
1618 while ((arg = strdelim(&cp)) && *arg != '\0') {
1619 if (strchr(arg, '=') != NULL)
1620 fatal("%s line %d: Invalid environment name.",
1621 filename, linenum);
1622 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1623 fatal("%s line %d: too many allow env.",
1624 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001625 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001626 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001627 options->accept_env[options->num_accept_env++] =
1628 xstrdup(arg);
1629 }
1630 break;
1631
Damien Millerd27b9472005-12-13 19:29:02 +11001632 case sPermitTunnel:
1633 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001634 arg = strdelim(&cp);
1635 if (!arg || *arg == '\0')
1636 fatal("%s line %d: Missing yes/point-to-point/"
1637 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001638 value = -1;
1639 for (i = 0; tunmode_desc[i].val != -1; i++)
1640 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1641 value = tunmode_desc[i].val;
1642 break;
1643 }
1644 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001645 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1646 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001647 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001648 *intptr = value;
1649 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001650
Darren Tucker45150472006-07-12 22:34:17 +10001651 case sMatch:
1652 if (cmdline)
1653 fatal("Match directive not supported as a command-line "
1654 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001655 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001656 if (value < 0)
1657 fatal("%s line %d: Bad Match condition", filename,
1658 linenum);
1659 *activep = value;
1660 break;
1661
Damien Miller9b439df2006-07-24 14:04:00 +10001662 case sPermitOpen:
1663 arg = strdelim(&cp);
1664 if (!arg || *arg == '\0')
1665 fatal("%s line %d: missing PermitOpen specification",
1666 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001667 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001668 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001669 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001670 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001671 options->num_permitted_opens = 0;
1672 }
Damien Miller9b439df2006-07-24 14:04:00 +10001673 break;
1674 }
Damien Millerc6081482012-04-22 11:18:53 +10001675 if (strcmp(arg, "none") == 0) {
1676 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001677 options->num_permitted_opens = 1;
1678 channel_disable_adm_local_opens();
1679 }
1680 break;
1681 }
Damien Millera29b95e2007-01-05 16:28:36 +11001682 if (*activep && n == -1)
1683 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001684 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1685 p = hpdelim(&arg);
1686 if (p == NULL)
1687 fatal("%s line %d: missing host in PermitOpen",
1688 filename, linenum);
1689 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001690 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001691 fatal("%s line %d: bad port number in "
1692 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001693 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001694 options->num_permitted_opens =
1695 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001696 }
Damien Miller9b439df2006-07-24 14:04:00 +10001697 break;
1698
Damien Millere2754432006-07-24 14:06:47 +10001699 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001700 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001701 fatal("%.200s line %d: Missing argument.", filename,
1702 linenum);
1703 len = strspn(cp, WHITESPACE);
1704 if (*activep && options->adm_forced_command == NULL)
1705 options->adm_forced_command = xstrdup(cp + len);
1706 return 0;
1707
Damien Millerd8cb1f12008-02-10 22:40:12 +11001708 case sChrootDirectory:
1709 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001710
1711 arg = strdelim(&cp);
1712 if (!arg || *arg == '\0')
1713 fatal("%s line %d: missing file name.",
1714 filename, linenum);
1715 if (*activep && *charptr == NULL)
1716 *charptr = xstrdup(arg);
1717 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001718
Damien Miller1aed65e2010-03-04 21:53:35 +11001719 case sTrustedUserCAKeys:
1720 charptr = &options->trusted_user_ca_keys;
1721 goto parse_filename;
1722
1723 case sRevokedKeys:
1724 charptr = &options->revoked_keys_file;
1725 goto parse_filename;
1726
Damien Miller0dac6fb2010-11-20 15:19:38 +11001727 case sIPQoS:
1728 arg = strdelim(&cp);
1729 if ((value = parse_ipqos(arg)) == -1)
1730 fatal("%s line %d: Bad IPQoS value: %s",
1731 filename, linenum, arg);
1732 arg = strdelim(&cp);
1733 if (arg == NULL)
1734 value2 = value;
1735 else if ((value2 = parse_ipqos(arg)) == -1)
1736 fatal("%s line %d: Bad IPQoS value: %s",
1737 filename, linenum, arg);
1738 if (*activep) {
1739 options->ip_qos_interactive = value;
1740 options->ip_qos_bulk = value2;
1741 }
1742 break;
1743
Damien Miller23528812012-04-22 11:24:43 +10001744 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001745 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001746 fatal("%.200s line %d: Missing argument.", filename,
1747 linenum);
1748 len = strspn(cp, WHITESPACE);
1749 if (*activep && options->version_addendum == NULL) {
1750 if (strcasecmp(cp + len, "none") == 0)
1751 options->version_addendum = xstrdup("");
1752 else if (strchr(cp + len, '\r') != NULL)
1753 fatal("%.200s line %d: Invalid argument",
1754 filename, linenum);
1755 else
1756 options->version_addendum = xstrdup(cp + len);
1757 }
1758 return 0;
1759
Damien Miller09d3e122012-10-31 08:58:58 +11001760 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001761 if (cp == NULL)
1762 fatal("%.200s line %d: Missing argument.", filename,
1763 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001764 len = strspn(cp, WHITESPACE);
1765 if (*activep && options->authorized_keys_command == NULL) {
1766 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1767 fatal("%.200s line %d: AuthorizedKeysCommand "
1768 "must be an absolute path",
1769 filename, linenum);
1770 options->authorized_keys_command = xstrdup(cp + len);
1771 }
1772 return 0;
1773
1774 case sAuthorizedKeysCommandUser:
1775 charptr = &options->authorized_keys_command_user;
1776
1777 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001778 if (!arg || *arg == '\0')
1779 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1780 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001781 if (*activep && *charptr == NULL)
1782 *charptr = xstrdup(arg);
1783 break;
1784
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001785 case sAuthorizedPrincipalsCommand:
1786 if (cp == NULL)
1787 fatal("%.200s line %d: Missing argument.", filename,
1788 linenum);
1789 len = strspn(cp, WHITESPACE);
1790 if (*activep &&
1791 options->authorized_principals_command == NULL) {
1792 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1793 fatal("%.200s line %d: "
1794 "AuthorizedPrincipalsCommand must be "
1795 "an absolute path", filename, linenum);
1796 options->authorized_principals_command =
1797 xstrdup(cp + len);
1798 }
1799 return 0;
1800
1801 case sAuthorizedPrincipalsCommandUser:
1802 charptr = &options->authorized_principals_command_user;
1803
1804 arg = strdelim(&cp);
1805 if (!arg || *arg == '\0')
1806 fatal("%s line %d: missing "
1807 "AuthorizedPrincipalsCommandUser argument.",
1808 filename, linenum);
1809 if (*activep && *charptr == NULL)
1810 *charptr = xstrdup(arg);
1811 break;
1812
Damien Millera6e3f012012-11-04 23:21:40 +11001813 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001814 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001815 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001816 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001817 while ((arg = strdelim(&cp)) && *arg != '\0') {
1818 if (options->num_auth_methods >=
1819 MAX_AUTH_METHODS)
1820 fatal("%s line %d: "
1821 "too many authentication methods.",
1822 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001823 if (strcmp(arg, "any") == 0) {
1824 if (options->num_auth_methods > 0) {
1825 fatal("%s line %d: \"any\" "
1826 "must appear alone in "
1827 "AuthenticationMethods",
1828 filename, linenum);
1829 }
1830 value = 1;
1831 } else if (value) {
1832 fatal("%s line %d: \"any\" must appear "
1833 "alone in AuthenticationMethods",
1834 filename, linenum);
1835 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001836 fatal("%s line %d: invalid "
1837 "authentication method list.",
1838 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001839 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001840 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001841 if (!*activep)
1842 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001843 options->auth_methods[
1844 options->num_auth_methods++] = xstrdup(arg);
1845 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001846 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001847 fatal("%s line %d: no AuthenticationMethods "
1848 "specified", filename, linenum);
1849 }
Damien Millera6e3f012012-11-04 23:21:40 +11001850 }
1851 return 0;
1852
Damien Miller7acefbb2014-07-18 14:11:24 +10001853 case sStreamLocalBindMask:
1854 arg = strdelim(&cp);
1855 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001856 fatal("%s line %d: missing StreamLocalBindMask "
1857 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001858 /* Parse mode in octal format */
1859 value = strtol(arg, &p, 8);
1860 if (arg == p || value < 0 || value > 0777)
1861 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001862 if (*activep)
1863 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001864 break;
1865
1866 case sStreamLocalBindUnlink:
1867 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1868 goto parse_flag;
1869
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001870 case sFingerprintHash:
1871 arg = strdelim(&cp);
1872 if (!arg || *arg == '\0')
1873 fatal("%.200s line %d: Missing argument.",
1874 filename, linenum);
1875 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1876 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1877 filename, linenum, arg);
1878 if (*activep)
1879 options->fingerprint_hash = value;
1880 break;
1881
Ben Lindstromade03f62001-12-06 18:22:17 +00001882 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001883 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001884 filename, linenum, arg);
1885 while (arg)
1886 arg = strdelim(&cp);
1887 break;
1888
Damien Millerf9b3feb2003-05-16 11:38:32 +10001889 case sUnsupported:
1890 logit("%s line %d: Unsupported option %s",
1891 filename, linenum, arg);
1892 while (arg)
1893 arg = strdelim(&cp);
1894 break;
1895
Ben Lindstromade03f62001-12-06 18:22:17 +00001896 default:
1897 fatal("%s line %d: Missing handler for opcode %s (%d)",
1898 filename, linenum, arg, opcode);
1899 }
1900 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1901 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1902 filename, linenum, arg);
1903 return 0;
1904}
1905
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001906/* Reads the server configuration file. */
1907
Damien Miller4af51302000-04-16 11:18:38 +10001908void
Darren Tucker645ab752004-06-25 13:33:20 +10001909load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001910{
Damien Miller46cb75a2012-07-31 12:22:37 +10001911 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001912 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001913 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001914
Darren Tucker645ab752004-06-25 13:33:20 +10001915 debug2("%s: filename %s", __func__, filename);
1916 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001917 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001918 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001919 }
Darren Tucker645ab752004-06-25 13:33:20 +10001920 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001921 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001922 lineno++;
1923 if (strlen(line) == sizeof(line) - 1)
1924 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001925 /*
1926 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001927 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001928 * line numbers later for error messages
1929 */
1930 if ((cp = strchr(line, '#')) != NULL)
1931 memcpy(cp, "\n", 2);
1932 cp = line + strspn(line, " \t\r");
1933
1934 buffer_append(conf, cp, strlen(cp));
1935 }
1936 buffer_append(conf, "\0", 1);
1937 fclose(f);
1938 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1939}
1940
1941void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001942parse_server_match_config(ServerOptions *options,
1943 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001944{
Darren Tucker45150472006-07-12 22:34:17 +10001945 ServerOptions mo;
1946
1947 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001948 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001949 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001950}
1951
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001952int parse_server_match_testspec(struct connection_info *ci, char *spec)
1953{
1954 char *p;
1955
1956 while ((p = strsep(&spec, ",")) && *p != '\0') {
1957 if (strncmp(p, "addr=", 5) == 0) {
1958 ci->address = xstrdup(p + 5);
1959 } else if (strncmp(p, "host=", 5) == 0) {
1960 ci->host = xstrdup(p + 5);
1961 } else if (strncmp(p, "user=", 5) == 0) {
1962 ci->user = xstrdup(p + 5);
1963 } else if (strncmp(p, "laddr=", 6) == 0) {
1964 ci->laddress = xstrdup(p + 6);
1965 } else if (strncmp(p, "lport=", 6) == 0) {
1966 ci->lport = a2port(p + 6);
1967 if (ci->lport == -1) {
1968 fprintf(stderr, "Invalid port '%s' in test mode"
1969 " specification %s\n", p+6, p);
1970 return -1;
1971 }
1972 } else {
1973 fprintf(stderr, "Invalid test mode specification %s\n",
1974 p);
1975 return -1;
1976 }
1977 }
1978 return 0;
1979}
1980
1981/*
1982 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1983 * empty spec.
1984 */
1985int server_match_spec_complete(struct connection_info *ci)
1986{
1987 if (ci->user && ci->host && ci->address)
1988 return 1; /* complete */
1989 if (!ci->user && !ci->host && !ci->address)
1990 return -1; /* empty */
1991 return 0; /* partial */
1992}
1993
Darren Tucker1629c072007-02-19 22:25:37 +11001994/*
1995 * Copy any supported values that are set.
1996 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001997 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001998 * array values that are not used pre-authentication, because any that we
1999 * do use must be explictly sent in mm_getpwnamallow().
2000 */
Darren Tucker45150472006-07-12 22:34:17 +10002001void
Darren Tucker1629c072007-02-19 22:25:37 +11002002copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10002003{
Damien Miller534b2cc2013-12-05 14:07:27 +11002004#define M_CP_INTOPT(n) do {\
2005 if (src->n != -1) \
2006 dst->n = src->n; \
2007} while (0)
2008
Darren Tucker1629c072007-02-19 22:25:37 +11002009 M_CP_INTOPT(password_authentication);
2010 M_CP_INTOPT(gss_authentication);
2011 M_CP_INTOPT(rsa_authentication);
2012 M_CP_INTOPT(pubkey_authentication);
2013 M_CP_INTOPT(kerberos_authentication);
2014 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10002015 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11002016 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11002017 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11002018 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11002019
2020 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002021 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10002022 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10002023 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10002024 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002025 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11002026 M_CP_INTOPT(x11_display_offset);
2027 M_CP_INTOPT(x11_forwarding);
2028 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002029 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002030 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002031 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002032 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002033 M_CP_INTOPT(ip_qos_interactive);
2034 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002035 M_CP_INTOPT(rekey_limit);
2036 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002037
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002038 /*
2039 * The bind_mask is a mode_t that may be unsigned, so we can't use
2040 * M_CP_INTOPT - it does a signed comparison that causes compiler
2041 * warnings.
2042 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002043 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002044 dst->fwd_opts.streamlocal_bind_mask =
2045 src->fwd_opts.streamlocal_bind_mask;
2046 }
2047
Damien Miller534b2cc2013-12-05 14:07:27 +11002048 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2049#define M_CP_STROPT(n) do {\
2050 if (src->n != NULL && dst->n != src->n) { \
2051 free(dst->n); \
2052 dst->n = src->n; \
2053 } \
2054} while(0)
2055#define M_CP_STRARRAYOPT(n, num_n) do {\
2056 if (src->num_n != 0) { \
2057 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2058 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2059 } \
2060} while(0)
2061
Damien Millerf2e407e2011-05-20 19:04:14 +10002062 /* See comment in servconf.h */
2063 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002064
djm@openbsd.orged085102015-10-29 08:05:01 +00002065 /* Arguments that accept '+...' need to be expanded */
2066 assemble_algorithms(dst);
2067
Damien Millerc2411902011-05-20 19:03:49 +10002068 /*
2069 * The only things that should be below this point are string options
2070 * which are only used after authentication.
2071 */
Damien Miller5d74e582011-05-20 19:03:31 +10002072 if (preauth)
2073 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002074
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002075 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002076 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002077 if (option_clear_or_none(dst->adm_forced_command)) {
2078 free(dst->adm_forced_command);
2079 dst->adm_forced_command = NULL;
2080 }
Damien Miller5d74e582011-05-20 19:03:31 +10002081 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002082 if (option_clear_or_none(dst->chroot_directory)) {
2083 free(dst->chroot_directory);
2084 dst->chroot_directory = NULL;
2085 }
Darren Tucker45150472006-07-12 22:34:17 +10002086}
2087
Darren Tucker1629c072007-02-19 22:25:37 +11002088#undef M_CP_INTOPT
2089#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002090#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002091
Darren Tucker45150472006-07-12 22:34:17 +10002092void
2093parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002094 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002095{
2096 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002097 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002098
2099 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2100
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002101 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2102 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002103 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002104 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002105 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002106 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002107 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002108 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002109 }
Darren Tuckera627d422013-06-02 07:31:17 +10002110 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002111 if (bad_options > 0)
2112 fatal("%s: terminating, %d bad configuration options",
2113 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002114 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002115}
Darren Tuckere7140f22008-06-10 23:01:51 +10002116
2117static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002118fmt_multistate_int(int val, const struct multistate *m)
2119{
2120 u_int i;
2121
2122 for (i = 0; m[i].key != NULL; i++) {
2123 if (m[i].value == val)
2124 return m[i].key;
2125 }
2126 return "UNKNOWN";
2127}
2128
2129static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002130fmt_intarg(ServerOpCodes code, int val)
2131{
Damien Miller82c55872011-06-23 08:20:30 +10002132 if (val == -1)
2133 return "unset";
2134 switch (code) {
2135 case sAddressFamily:
2136 return fmt_multistate_int(val, multistate_addressfamily);
2137 case sPermitRootLogin:
2138 return fmt_multistate_int(val, multistate_permitrootlogin);
2139 case sGatewayPorts:
2140 return fmt_multistate_int(val, multistate_gatewayports);
2141 case sCompression:
2142 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002143 case sUsePrivilegeSeparation:
2144 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002145 case sAllowTcpForwarding:
2146 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002147 case sAllowStreamLocalForwarding:
2148 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002149 case sFingerprintHash:
2150 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002151 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002152 switch (val) {
2153 case SSH_PROTO_1:
2154 return "1";
2155 case SSH_PROTO_2:
2156 return "2";
2157 case (SSH_PROTO_1|SSH_PROTO_2):
2158 return "2,1";
2159 default:
2160 return "UNKNOWN";
2161 }
Damien Miller82c55872011-06-23 08:20:30 +10002162 default:
2163 switch (val) {
2164 case 0:
2165 return "no";
2166 case 1:
2167 return "yes";
2168 default:
2169 return "UNKNOWN";
2170 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002171 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002172}
2173
2174static const char *
2175lookup_opcode_name(ServerOpCodes code)
2176{
2177 u_int i;
2178
2179 for (i = 0; keywords[i].name != NULL; i++)
2180 if (keywords[i].opcode == code)
2181 return(keywords[i].name);
2182 return "UNKNOWN";
2183}
2184
2185static void
2186dump_cfg_int(ServerOpCodes code, int val)
2187{
2188 printf("%s %d\n", lookup_opcode_name(code), val);
2189}
2190
2191static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002192dump_cfg_oct(ServerOpCodes code, int val)
2193{
2194 printf("%s 0%o\n", lookup_opcode_name(code), val);
2195}
2196
2197static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002198dump_cfg_fmtint(ServerOpCodes code, int val)
2199{
2200 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2201}
2202
2203static void
2204dump_cfg_string(ServerOpCodes code, const char *val)
2205{
2206 if (val == NULL)
2207 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002208 printf("%s %s\n", lookup_opcode_name(code),
2209 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002210}
2211
2212static void
2213dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2214{
2215 u_int i;
2216
2217 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002218 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2219}
2220
2221static void
2222dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2223{
2224 u_int i;
2225
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002226 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002227 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002228 printf("%s", lookup_opcode_name(code));
2229 for (i = 0; i < count; i++)
2230 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002231 if (code == sAuthenticationMethods && count == 0)
2232 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002233 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002234}
2235
2236void
2237dump_config(ServerOptions *o)
2238{
2239 u_int i;
2240 int ret;
2241 struct addrinfo *ai;
2242 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002243 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002244
2245 /* these are usually at the top of the config */
2246 for (i = 0; i < o->num_ports; i++)
2247 printf("port %d\n", o->ports[i]);
2248 dump_cfg_fmtint(sProtocol, o->protocol);
2249 dump_cfg_fmtint(sAddressFamily, o->address_family);
2250
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002251 /*
2252 * ListenAddress must be after Port. add_one_listen_addr pushes
2253 * addresses onto a stack, so to maintain ordering we need to
2254 * print these in reverse order.
2255 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002256 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2257 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2258 sizeof(addr), port, sizeof(port),
2259 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2260 error("getnameinfo failed: %.100s",
2261 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2262 strerror(errno));
2263 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002264 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002265 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002266 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2267 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002268 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002269 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2270 addr, port, laddr2);
2271 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002272 }
2273 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002274 printf("%s", laddr1);
2275 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002276
2277 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002278#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002279 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002280#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2282 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2283 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2284 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2285 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002286 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002287 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2288 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002289 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002290
2291 /* formatted integer arguments */
2292 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2293 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2294 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2295 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2296 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2297 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2298 o->hostbased_uses_name_from_packet_only);
2299 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2300 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002301#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002302 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2303 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2304 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002305# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002306 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002307# endif
2308#endif
2309#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002310 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2311 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002312#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002313 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2314 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2315 o->kbd_interactive_authentication);
2316 dump_cfg_fmtint(sChallengeResponseAuthentication,
2317 o->challenge_response_authentication);
2318 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002319#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002320 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002321#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002322 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2323 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002324 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002325 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002326 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2327 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2328 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2329 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2330 dump_cfg_fmtint(sUseLogin, o->use_login);
2331 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002332 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002333 dump_cfg_fmtint(sUseDNS, o->use_dns);
2334 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002335 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002336 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002337 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
Darren Tuckere7140f22008-06-10 23:01:51 +10002338 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002339 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002340
2341 /* string arguments */
2342 dump_cfg_string(sPidFile, o->pid_file);
2343 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002344 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2345 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002346 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002347 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002348 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002349 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2350 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002351 dump_cfg_string(sAuthorizedPrincipalsFile,
2352 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002353 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2354 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002355 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2356 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002357 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2358 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002359 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002360 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002361 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002362 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2363 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002364 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2365 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002366 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2367 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002368
2369 /* string arguments requiring a lookup */
2370 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2371 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2372
2373 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002374 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2375 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002376 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2377 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002378 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002379 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002380 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2381 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2382 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2383 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2384 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002385 dump_cfg_strarray_oneline(sAuthenticationMethods,
2386 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002387
2388 /* other arguments */
2389 for (i = 0; i < o->num_subsystems; i++)
2390 printf("subsystem %s %s\n", o->subsystem_name[i],
2391 o->subsystem_args[i]);
2392
2393 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2394 o->max_startups_rate, o->max_startups);
2395
2396 for (i = 0; tunmode_desc[i].val != -1; i++)
2397 if (tunmode_desc[i].val == o->permit_tun) {
2398 s = tunmode_desc[i].text;
2399 break;
2400 }
2401 dump_cfg_string(sPermitTunnel, s);
2402
Damien Miller91475862011-05-05 14:14:34 +10002403 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2404 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002405
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002406 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002407 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002408
Darren Tuckere7140f22008-06-10 23:01:51 +10002409 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002410}