blob: 17cb094c7db077b542007c8870a70da01117ea43 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.orged085102015-10-29 08:05:01 +00002/* $OpenBSD: servconf.c,v 1.282 2015/10/29 08:05:01 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100032#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100033#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100034#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100035#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100036#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100037
Damien Millerb84886b2008-05-19 15:05:07 +100038#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100042#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100043#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100045#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000049#include "kex.h"
50#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100051#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100052#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100053#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100054#include "canohost.h"
55#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110056#include "hostfile.h"
57#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000058#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000059#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000060
Damien Miller3dc71ad2009-01-28 16:31:22 +110061static void add_listen_addr(ServerOptions *, char *, int);
62static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110063
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000064/* Use of privilege separation or not */
65extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100066extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068/* Initializes the server options to their default values. */
69
Damien Miller4af51302000-04-16 11:18:38 +100070void
Damien Miller95def091999-11-25 00:26:21 +110071initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072{
Damien Miller95def091999-11-25 00:26:21 +110073 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100076 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110077
78 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110079 options->num_ports = 0;
80 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000081 options->queued_listen_addrs = NULL;
82 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110083 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110084 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110085 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110086 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100087 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100088 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110089 options->server_key_bits = -1;
90 options->login_grace_time = -1;
91 options->key_regeneration_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +000092 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110093 options->ignore_rhosts = -1;
94 options->ignore_user_known_hosts = -1;
95 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000096 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110097 options->x11_forwarding = -1;
98 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110099 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100100 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000101 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000102 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100104 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100105 options->log_facility = SYSLOG_FACILITY_NOT_SET;
106 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000108 options->hostbased_authentication = -1;
109 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000110 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000111 options->hostkeyalgorithms = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100113 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000114 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100115 options->kerberos_authentication = -1;
116 options->kerberos_or_local_passwd = -1;
117 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100118 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000119 options->gss_authentication=-1;
120 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000121 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100122 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100123 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000124 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100125 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000126 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100127 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000128 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000129 options->rekey_limit = -1;
130 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100131 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000132 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000133 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100134 options->num_allow_users = 0;
135 options->num_deny_users = 0;
136 options->num_allow_groups = 0;
137 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000138 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000139 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000140 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000141 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller7acefbb2014-07-18 14:11:24 +1000142 options->fwd_opts.gateway_ports = -1;
143 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
144 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000145 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000146 options->max_startups_begin = -1;
147 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000148 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000149 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000150 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000151 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000152 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000153 options->client_alive_interval = -1;
154 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000155 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000156 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100157 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000158 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000159 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100160 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100161 options->authorized_keys_command = NULL;
162 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100163 options->revoked_keys_file = NULL;
164 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000165 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000166 options->authorized_principals_command = NULL;
167 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100168 options->ip_qos_interactive = -1;
169 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000170 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000171 options->fingerprint_hash = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000172}
173
djm@openbsd.org161cf412014-12-22 07:55:51 +0000174/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
175static int
176option_clear_or_none(const char *o)
177{
178 return o == NULL || strcasecmp(o, "none") == 0;
179}
180
djm@openbsd.orged085102015-10-29 08:05:01 +0000181static void
182assemble_algorithms(ServerOptions *o)
183{
184 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
185 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
186 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
187 kex_assemble_names(KEX_DEFAULT_PK_ALG,
188 &o->hostkeyalgorithms) != 0 ||
189 kex_assemble_names(KEX_DEFAULT_PK_ALG,
190 &o->hostbased_key_types) != 0 ||
191 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
192 fatal("kex_assemble_names failed");
193}
194
Damien Miller4af51302000-04-16 11:18:38 +1000195void
Damien Miller95def091999-11-25 00:26:21 +1100196fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000197{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000198 int i;
199
Damien Miller726273e2001-11-12 11:40:11 +1100200 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000201 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000202 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100203
204 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100205 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100206 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100207 if (options->num_host_key_files == 0) {
208 /* fill default hostkeys for protocols */
209 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100210 options->host_key_files[options->num_host_key_files++] =
211 _PATH_HOST_KEY_FILE;
212 if (options->protocol & SSH_PROTO_2) {
213 options->host_key_files[options->num_host_key_files++] =
214 _PATH_HOST_RSA_KEY_FILE;
215 options->host_key_files[options->num_host_key_files++] =
216 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100217#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000218 options->host_key_files[options->num_host_key_files++] =
219 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100220#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100221 options->host_key_files[options->num_host_key_files++] =
222 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100223 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100224 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100225 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100226 if (options->num_ports == 0)
227 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000228 if (options->address_family == -1)
229 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100230 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000231 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000232 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000233 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000235 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000237 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100238 if (options->key_regeneration_time == -1)
239 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000240 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000241 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100242 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100243 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100244 if (options->ignore_user_known_hosts == -1)
245 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->print_motd == -1)
247 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000248 if (options->print_lastlog == -1)
249 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100250 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100251 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100252 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100253 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100254 if (options->x11_use_localhost == -1)
255 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000256 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000257 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100258 if (options->permit_tty == -1)
259 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000260 if (options->permit_user_rc == -1)
261 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->strict_modes == -1)
263 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100264 if (options->tcp_keep_alive == -1)
265 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100266 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100267 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100268 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000269 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100270 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100271 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000272 if (options->hostbased_authentication == -1)
273 options->hostbased_authentication = 0;
274 if (options->hostbased_uses_name_from_packet_only == -1)
275 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100276 if (options->rsa_authentication == -1)
277 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100278 if (options->pubkey_authentication == -1)
279 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000281 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100282 if (options->kerberos_or_local_passwd == -1)
283 options->kerberos_or_local_passwd = 1;
284 if (options->kerberos_ticket_cleanup == -1)
285 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100286 if (options->kerberos_get_afs_token == -1)
287 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000288 if (options->gss_authentication == -1)
289 options->gss_authentication = 0;
290 if (options->gss_cleanup_creds == -1)
291 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000292 if (options->gss_strict_acceptor == -1)
293 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100294 if (options->password_authentication == -1)
295 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100296 if (options->kbd_interactive_authentication == -1)
297 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000298 if (options->challenge_response_authentication == -1)
299 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100300 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100301 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000302 if (options->permit_user_env == -1)
303 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100304 if (options->use_login == -1)
305 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000306 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000307 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000308 if (options->rekey_limit == -1)
309 options->rekey_limit = 0;
310 if (options->rekey_interval == -1)
311 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100312 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100313 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000314 if (options->allow_streamlocal_forwarding == -1)
315 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000316 if (options->allow_agent_forwarding == -1)
317 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000318 if (options->fwd_opts.gateway_ports == -1)
319 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000320 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100321 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000322 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100323 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000324 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100325 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000326 if (options->max_authtries == -1)
327 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000328 if (options->max_sessions == -1)
329 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000330 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000331 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000332 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100333 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000334 if (options->client_alive_count_max == -1)
335 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000336 if (options->num_authkeys_files == 0) {
337 options->authorized_keys_files[options->num_authkeys_files++] =
338 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
339 options->authorized_keys_files[options->num_authkeys_files++] =
340 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
341 }
Damien Millerd27b9472005-12-13 19:29:02 +1100342 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100343 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100344 if (options->ip_qos_interactive == -1)
345 options->ip_qos_interactive = IPTOS_LOWDELAY;
346 if (options->ip_qos_bulk == -1)
347 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000348 if (options->version_addendum == NULL)
349 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000350 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
351 options->fwd_opts.streamlocal_bind_mask = 0177;
352 if (options->fwd_opts.streamlocal_bind_unlink == -1)
353 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000354 if (options->fingerprint_hash == -1)
355 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000356
djm@openbsd.orged085102015-10-29 08:05:01 +0000357 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000358
Ben Lindstromfb62a692002-06-06 19:47:11 +0000359 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000360 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000361 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000362
djm@openbsd.org161cf412014-12-22 07:55:51 +0000363#define CLEAR_ON_NONE(v) \
364 do { \
365 if (option_clear_or_none(v)) { \
366 free(v); \
367 v = NULL; \
368 } \
369 } while(0)
370 CLEAR_ON_NONE(options->pid_file);
371 CLEAR_ON_NONE(options->xauth_location);
372 CLEAR_ON_NONE(options->banner);
373 CLEAR_ON_NONE(options->trusted_user_ca_keys);
374 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000375 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000376 for (i = 0; i < options->num_host_key_files; i++)
377 CLEAR_ON_NONE(options->host_key_files[i]);
378 for (i = 0; i < options->num_host_cert_files; i++)
379 CLEAR_ON_NONE(options->host_cert_files[i]);
380#undef CLEAR_ON_NONE
381
Tim Rice40017b02002-07-14 13:36:49 -0700382#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000383 if (use_privsep && options->compression == 1) {
384 error("This platform does not support both privilege "
385 "separation and compression");
386 error("Compression disabled");
387 options->compression = 0;
388 }
389#endif
390
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000391}
392
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000393/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100394typedef enum {
395 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100396 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000397 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100398 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000399 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
400 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000401 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100402 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100403 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000404 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100405 sPasswordAuthentication, sKbdInteractiveAuthentication,
406 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000407 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100408 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100409 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000410 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000411 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000412 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000413 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
414 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000415 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000416 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000417 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000418 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000419 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
420 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100421 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100422 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100423 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000424 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000425 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000426 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100427 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000428 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000429 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000430 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000431 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000432} ServerOpCodes;
433
Darren Tucker45150472006-07-12 22:34:17 +1000434#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
435#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
436#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
437
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000438/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100439static struct {
440 const char *name;
441 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000442 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100443} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100444 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000445#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000447#else
Darren Tucker45150472006-07-12 22:34:17 +1000448 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000449#endif
Darren Tucker45150472006-07-12 22:34:17 +1000450 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100451 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000452 { "port", sPort, SSHCFG_GLOBAL },
453 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
454 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000455 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000456 { "pidfile", sPidFile, SSHCFG_GLOBAL },
457 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
458 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
459 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100460 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000461 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
462 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
463 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
465 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000466 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000467 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000468 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100469 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
470 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000471 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000472 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000473#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100474 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000475 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
476 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100477#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000478 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000479#else
Darren Tucker45150472006-07-12 22:34:17 +1000480 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100481#endif
482#else
Darren Tucker1629c072007-02-19 22:25:37 +1100483 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000484 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
485 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
486 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000487#endif
Darren Tucker45150472006-07-12 22:34:17 +1000488 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
489 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000490#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100491 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000492 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000493 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000494#else
Darren Tucker1629c072007-02-19 22:25:37 +1100495 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000496 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000497 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000498#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100499 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
500 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100501 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
503 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
504 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
505 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
506 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100507#ifdef DISABLE_LASTLOG
508 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
509#else
Darren Tucker45150472006-07-12 22:34:17 +1000510 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100511#endif
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
513 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000514 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
515 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
516 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000517 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
518 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100519 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000520 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
521 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
522 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000523 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000524 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
525 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
526 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000527 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000528 { "allowusers", sAllowUsers, SSHCFG_ALL },
529 { "denyusers", sDenyUsers, SSHCFG_ALL },
530 { "allowgroups", sAllowGroups, SSHCFG_ALL },
531 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000532 { "ciphers", sCiphers, SSHCFG_GLOBAL },
533 { "macs", sMacs, SSHCFG_GLOBAL },
534 { "protocol", sProtocol, SSHCFG_GLOBAL },
535 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
536 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
537 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000538 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000539 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100540 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000541 { "usedns", sUseDNS, SSHCFG_GLOBAL },
542 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
543 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
544 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
545 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000546 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000547 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000548 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000549 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000550 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100551 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000552 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000553 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000554 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000555 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100556 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100557 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100558 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
559 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000560 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000561 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100562 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100563 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
564 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000565 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
566 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000567 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100568 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000569 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
570 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
571 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000572 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000573 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000574};
575
Darren Tuckere7140f22008-06-10 23:01:51 +1000576static struct {
577 int val;
578 char *text;
579} tunmode_desc[] = {
580 { SSH_TUNMODE_NO, "no" },
581 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
582 { SSH_TUNMODE_ETHERNET, "ethernet" },
583 { SSH_TUNMODE_YES, "yes" },
584 { -1, NULL }
585};
586
Damien Miller5428f641999-11-25 11:54:57 +1100587/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000588 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100589 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000590
Damien Miller4af51302000-04-16 11:18:38 +1000591static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100592parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000593 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000594{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000595 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000596
Damien Miller95def091999-11-25 00:26:21 +1100597 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000598 if (strcasecmp(cp, keywords[i].name) == 0) {
599 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100600 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000601 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000602
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000603 error("%s: line %d: Bad configuration option: %s",
604 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100605 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000606}
607
Darren Tucker88b6fb22010-01-13 22:44:29 +1100608char *
609derelativise_path(const char *path)
610{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000611 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100612
djm@openbsd.org161cf412014-12-22 07:55:51 +0000613 if (strcasecmp(path, "none") == 0)
614 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100615 expanded = tilde_expand_filename(path, getuid());
616 if (*expanded == '/')
617 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100618 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100619 fatal("%s: getcwd: %s", __func__, strerror(errno));
620 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000621 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100622 return ret;
623}
624
Ben Lindstrombba81212001-06-25 05:01:22 +0000625static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100626add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100627{
Damien Millereccb9de2005-06-17 12:59:34 +1000628 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100629
Ben Lindstrom19066a12001-04-12 23:39:26 +0000630 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000631 for (i = 0; i < options->num_ports; i++)
632 add_one_listen_addr(options, addr, options->ports[i]);
633 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000634 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000635}
636
Ben Lindstrombba81212001-06-25 05:01:22 +0000637static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100638add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000639{
640 struct addrinfo hints, *ai, *aitop;
641 char strport[NI_MAXSERV];
642 int gaierr;
643
644 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100645 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000646 hints.ai_socktype = SOCK_STREAM;
647 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100648 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000649 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
650 fatal("bad addr or host: %s (%s)",
651 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100652 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000653 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
654 ;
655 ai->ai_next = options->listen_addrs;
656 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100657}
658
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000659/*
660 * Queue a ListenAddress to be processed once we have all of the Ports
661 * and AddressFamily options.
662 */
663static void
664queue_listen_addr(ServerOptions *options, char *addr, int port)
665{
666 options->queued_listen_addrs = xreallocarray(
667 options->queued_listen_addrs, options->num_queued_listens + 1,
668 sizeof(addr));
669 options->queued_listen_ports = xreallocarray(
670 options->queued_listen_ports, options->num_queued_listens + 1,
671 sizeof(port));
672 options->queued_listen_addrs[options->num_queued_listens] =
673 xstrdup(addr);
674 options->queued_listen_ports[options->num_queued_listens] = port;
675 options->num_queued_listens++;
676}
677
678/*
679 * Process queued (text) ListenAddress entries.
680 */
681static void
682process_queued_listen_addrs(ServerOptions *options)
683{
684 u_int i;
685
686 if (options->num_ports == 0)
687 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
688 if (options->address_family == -1)
689 options->address_family = AF_UNSPEC;
690
691 for (i = 0; i < options->num_queued_listens; i++) {
692 add_listen_addr(options, options->queued_listen_addrs[i],
693 options->queued_listen_ports[i]);
694 free(options->queued_listen_addrs[i]);
695 options->queued_listen_addrs[i] = NULL;
696 }
697 free(options->queued_listen_addrs);
698 options->queued_listen_addrs = NULL;
699 free(options->queued_listen_ports);
700 options->queued_listen_ports = NULL;
701 options->num_queued_listens = 0;
702}
703
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000704struct connection_info *
705get_connection_info(int populate, int use_dns)
706{
707 static struct connection_info ci;
708
709 if (!populate)
710 return &ci;
711 ci.host = get_canonical_hostname(use_dns);
712 ci.address = get_remote_ipaddr();
713 ci.laddress = get_local_ipaddr(packet_get_connection_in());
714 ci.lport = get_local_port();
715 return &ci;
716}
717
Darren Tucker45150472006-07-12 22:34:17 +1000718/*
719 * The strategy for the Match blocks is that the config file is parsed twice.
720 *
721 * The first time is at startup. activep is initialized to 1 and the
722 * directives in the global context are processed and acted on. Hitting a
723 * Match directive unsets activep and the directives inside the block are
724 * checked for syntax only.
725 *
726 * The second time is after a connection has been established but before
727 * authentication. activep is initialized to 2 and global config directives
728 * are ignored since they have already been processed. If the criteria in a
729 * Match block is met, activep is set and the subsequent directives
730 * processed and actioned until EOF or another Match block unsets it. Any
731 * options set are copied into the main server config.
732 *
733 * Potential additions/improvements:
734 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
735 *
736 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
737 * Match Address 192.168.0.*
738 * Tag trusted
739 * Match Group wheel
740 * Tag trusted
741 * Match Tag trusted
742 * AllowTcpForwarding yes
743 * GatewayPorts clientspecified
744 * [...]
745 *
746 * - Add a PermittedChannelRequests directive
747 * Match Group shell
748 * PermittedChannelRequests session,forwarded-tcpip
749 */
750
751static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000752match_cfg_line_group(const char *grps, int line, const char *user)
753{
754 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000755 struct passwd *pw;
756
Damien Miller565ca3f2006-08-19 00:23:15 +1000757 if (user == NULL)
758 goto out;
759
760 if ((pw = getpwnam(user)) == NULL) {
761 debug("Can't match group at line %d because user %.100s does "
762 "not exist", line, user);
763 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
764 debug("Can't Match group because user %.100s not in any group "
765 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000766 } else if (ga_match_pattern_list(grps) != 1) {
767 debug("user %.100s does not match group list %.100s at line %d",
768 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000769 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000770 debug("user %.100s matched group list %.100s at line %d", user,
771 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000772 result = 1;
773 }
774out:
775 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000776 return result;
777}
778
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000779/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000780 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100781 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000782 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000783 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000784static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000785match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000786{
Damien Millercf31f382013-10-24 21:02:56 +1100787 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000788 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000789
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000790 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000791 debug3("checking syntax for 'Match %s'", cp);
792 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000793 debug3("checking match for '%s' user %s host %s addr %s "
794 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
795 ci->host ? ci->host : "(null)",
796 ci->address ? ci->address : "(null)",
797 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000798
799 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100800 attributes++;
801 if (strcasecmp(attrib, "all") == 0) {
802 if (attributes != 1 ||
803 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
804 error("'all' cannot be combined with other "
805 "Match attributes");
806 return -1;
807 }
808 *condition = cp;
809 return 1;
810 }
Darren Tucker45150472006-07-12 22:34:17 +1000811 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
812 error("Missing Match criteria for %s", attrib);
813 return -1;
814 }
Darren Tucker45150472006-07-12 22:34:17 +1000815 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000816 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000817 result = 0;
818 continue;
819 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000820 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000821 result = 0;
822 else
823 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000824 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000825 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000826 if (ci == NULL || ci->user == NULL) {
827 result = 0;
828 continue;
829 }
830 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000831 case -1:
832 return -1;
833 case 0:
834 result = 0;
835 }
Darren Tucker45150472006-07-12 22:34:17 +1000836 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000837 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000838 result = 0;
839 continue;
840 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000841 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000842 result = 0;
843 else
844 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000845 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000846 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000847 if (ci == NULL || ci->address == NULL) {
848 result = 0;
849 continue;
850 }
851 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000852 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000853 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000854 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000855 break;
856 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000857 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000858 result = 0;
859 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000860 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000861 return -1;
862 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000863 } else if (strcasecmp(attrib, "localaddress") == 0){
864 if (ci == NULL || ci->laddress == NULL) {
865 result = 0;
866 continue;
867 }
868 switch (addr_match_list(ci->laddress, arg)) {
869 case 1:
870 debug("connection from %.100s matched "
871 "'LocalAddress %.100s' at line %d",
872 ci->laddress, arg, line);
873 break;
874 case 0:
875 case -1:
876 result = 0;
877 break;
878 case -2:
879 return -1;
880 }
881 } else if (strcasecmp(attrib, "localport") == 0) {
882 if ((port = a2port(arg)) == -1) {
883 error("Invalid LocalPort '%s' on Match line",
884 arg);
885 return -1;
886 }
887 if (ci == NULL || ci->lport == 0) {
888 result = 0;
889 continue;
890 }
891 /* TODO support port lists */
892 if (port == ci->lport)
893 debug("connection from %.100s matched "
894 "'LocalPort %d' at line %d",
895 ci->laddress, port, line);
896 else
897 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000898 } else {
899 error("Unsupported Match attribute %s", attrib);
900 return -1;
901 }
902 }
Damien Millercf31f382013-10-24 21:02:56 +1100903 if (attributes == 0) {
904 error("One or more attributes required for Match");
905 return -1;
906 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000907 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000908 debug3("match %sfound", result ? "" : "not ");
909 *condition = cp;
910 return result;
911}
912
Damien Millere2754432006-07-24 14:06:47 +1000913#define WHITESPACE " \t\r\n"
914
Damien Miller33322122011-06-20 14:43:11 +1000915/* Multistate option parsing */
916struct multistate {
917 char *key;
918 int value;
919};
920static const struct multistate multistate_addressfamily[] = {
921 { "inet", AF_INET },
922 { "inet6", AF_INET6 },
923 { "any", AF_UNSPEC },
924 { NULL, -1 }
925};
926static const struct multistate multistate_permitrootlogin[] = {
927 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000928 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000929 { "forced-commands-only", PERMIT_FORCED_ONLY },
930 { "yes", PERMIT_YES },
931 { "no", PERMIT_NO },
932 { NULL, -1 }
933};
934static const struct multistate multistate_compression[] = {
935 { "delayed", COMP_DELAYED },
936 { "yes", COMP_ZLIB },
937 { "no", COMP_NONE },
938 { NULL, -1 }
939};
940static const struct multistate multistate_gatewayports[] = {
941 { "clientspecified", 2 },
942 { "yes", 1 },
943 { "no", 0 },
944 { NULL, -1 }
945};
Damien Miller69ff1df2011-06-23 08:30:03 +1000946static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000947 { "yes", PRIVSEP_NOSANDBOX },
948 { "sandbox", PRIVSEP_ON },
949 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000950 { "no", PRIVSEP_OFF },
951 { NULL, -1 }
952};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100953static const struct multistate multistate_tcpfwd[] = {
954 { "yes", FORWARD_ALLOW },
955 { "all", FORWARD_ALLOW },
956 { "no", FORWARD_DENY },
957 { "remote", FORWARD_REMOTE },
958 { "local", FORWARD_LOCAL },
959 { NULL, -1 }
960};
Damien Miller33322122011-06-20 14:43:11 +1000961
Ben Lindstromade03f62001-12-06 18:22:17 +0000962int
963process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000964 const char *filename, int linenum, int *activep,
965 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000966{
Darren Tucker09c0f032013-05-16 20:48:57 +1000967 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000968 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100969 SyslogFacility *log_facility_ptr;
970 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000971 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000972 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000973 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000974 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000975 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000976
977 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100978 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100979 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000980 /* Ignore leading whitespace */
981 if (*arg == '\0')
982 arg = strdelim(&cp);
983 if (!arg || !*arg || *arg == '#')
984 return 0;
985 intptr = NULL;
986 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000987 opcode = parse_token(arg, filename, linenum, &flags);
988
989 if (activep == NULL) { /* We are processing a command line directive */
990 cmdline = 1;
991 activep = &cmdline;
992 }
993 if (*activep && opcode != sMatch)
994 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
995 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000996 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000997 fatal("%s line %d: Directive '%s' is not allowed "
998 "within a Match block", filename, linenum, arg);
999 } else { /* this is a directive we have already processed */
1000 while (arg)
1001 arg = strdelim(&cp);
1002 return 0;
1003 }
1004 }
1005
Ben Lindstromade03f62001-12-06 18:22:17 +00001006 switch (opcode) {
1007 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001008 case sUsePAM:
1009 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001010 goto parse_flag;
1011
1012 /* Standard Options */
1013 case sBadOption:
1014 return -1;
1015 case sPort:
1016 /* ignore ports from configfile if cmdline specifies ports */
1017 if (options->ports_from_cmdline)
1018 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001019 if (options->num_ports >= MAX_PORTS)
1020 fatal("%s line %d: too many ports.",
1021 filename, linenum);
1022 arg = strdelim(&cp);
1023 if (!arg || *arg == '\0')
1024 fatal("%s line %d: missing port number.",
1025 filename, linenum);
1026 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001027 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001028 fatal("%s line %d: Badly formatted port number.",
1029 filename, linenum);
1030 break;
1031
1032 case sServerKeyBits:
1033 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001034 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001035 arg = strdelim(&cp);
1036 if (!arg || *arg == '\0')
1037 fatal("%s line %d: missing integer value.",
1038 filename, linenum);
1039 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001040 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001041 *intptr = value;
1042 break;
1043
1044 case sLoginGraceTime:
1045 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001046 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001047 arg = strdelim(&cp);
1048 if (!arg || *arg == '\0')
1049 fatal("%s line %d: missing time value.",
1050 filename, linenum);
1051 if ((value = convtime(arg)) == -1)
1052 fatal("%s line %d: invalid time value.",
1053 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001054 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001055 *intptr = value;
1056 break;
1057
1058 case sKeyRegenerationTime:
1059 intptr = &options->key_regeneration_time;
1060 goto parse_time;
1061
1062 case sListenAddress:
1063 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001064 if (arg == NULL || *arg == '\0')
1065 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001066 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001067 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1068 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1069 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001070 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001071 break;
1072 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001073 p = hpdelim(&arg);
1074 if (p == NULL)
1075 fatal("%s line %d: bad address:port usage",
1076 filename, linenum);
1077 p = cleanhostname(p);
1078 if (arg == NULL)
1079 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001080 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001081 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001082
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001083 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001084
Ben Lindstromade03f62001-12-06 18:22:17 +00001085 break;
1086
Darren Tucker0f383232005-01-20 10:57:56 +11001087 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001088 intptr = &options->address_family;
1089 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001090 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001091 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001092 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001093 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001094 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001095 value = -1;
1096 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1097 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1098 value = multistate_ptr[i].value;
1099 break;
1100 }
1101 }
1102 if (value == -1)
1103 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001104 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001105 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001106 *intptr = value;
1107 break;
1108
Ben Lindstromade03f62001-12-06 18:22:17 +00001109 case sHostKeyFile:
1110 intptr = &options->num_host_key_files;
1111 if (*intptr >= MAX_HOSTKEYS)
1112 fatal("%s line %d: too many host keys specified (max %d).",
1113 filename, linenum, MAX_HOSTKEYS);
1114 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001115 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001116 arg = strdelim(&cp);
1117 if (!arg || *arg == '\0')
1118 fatal("%s line %d: missing file name.",
1119 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001120 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001121 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001122 /* increase optional counter */
1123 if (intptr != NULL)
1124 *intptr = *intptr + 1;
1125 }
1126 break;
1127
Damien Miller85b45e02013-07-20 13:21:52 +10001128 case sHostKeyAgent:
1129 charptr = &options->host_key_agent;
1130 arg = strdelim(&cp);
1131 if (!arg || *arg == '\0')
1132 fatal("%s line %d: missing socket name.",
1133 filename, linenum);
1134 if (*activep && *charptr == NULL)
1135 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1136 xstrdup(arg) : derelativise_path(arg);
1137 break;
1138
Damien Miller0a80ca12010-02-27 07:55:05 +11001139 case sHostCertificate:
1140 intptr = &options->num_host_cert_files;
1141 if (*intptr >= MAX_HOSTKEYS)
1142 fatal("%s line %d: too many host certificates "
1143 "specified (max %d).", filename, linenum,
1144 MAX_HOSTCERTS);
1145 charptr = &options->host_cert_files[*intptr];
1146 goto parse_filename;
1147 break;
1148
Ben Lindstromade03f62001-12-06 18:22:17 +00001149 case sPidFile:
1150 charptr = &options->pid_file;
1151 goto parse_filename;
1152
1153 case sPermitRootLogin:
1154 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001155 multistate_ptr = multistate_permitrootlogin;
1156 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001157
1158 case sIgnoreRhosts:
1159 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001160 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001161 arg = strdelim(&cp);
1162 if (!arg || *arg == '\0')
1163 fatal("%s line %d: missing yes/no argument.",
1164 filename, linenum);
1165 value = 0; /* silence compiler */
1166 if (strcmp(arg, "yes") == 0)
1167 value = 1;
1168 else if (strcmp(arg, "no") == 0)
1169 value = 0;
1170 else
1171 fatal("%s line %d: Bad yes/no argument: %s",
1172 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001173 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001174 *intptr = value;
1175 break;
1176
1177 case sIgnoreUserKnownHosts:
1178 intptr = &options->ignore_user_known_hosts;
1179 goto parse_flag;
1180
Ben Lindstromade03f62001-12-06 18:22:17 +00001181 case sRhostsRSAAuthentication:
1182 intptr = &options->rhosts_rsa_authentication;
1183 goto parse_flag;
1184
1185 case sHostbasedAuthentication:
1186 intptr = &options->hostbased_authentication;
1187 goto parse_flag;
1188
1189 case sHostbasedUsesNameFromPacketOnly:
1190 intptr = &options->hostbased_uses_name_from_packet_only;
1191 goto parse_flag;
1192
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001193 case sHostbasedAcceptedKeyTypes:
1194 charptr = &options->hostbased_key_types;
1195 parse_keytypes:
1196 arg = strdelim(&cp);
1197 if (!arg || *arg == '\0')
1198 fatal("%s line %d: Missing argument.",
1199 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001200 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001201 fatal("%s line %d: Bad key types '%s'.",
1202 filename, linenum, arg ? arg : "<NONE>");
1203 if (*activep && *charptr == NULL)
1204 *charptr = xstrdup(arg);
1205 break;
1206
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001207 case sHostKeyAlgorithms:
1208 charptr = &options->hostkeyalgorithms;
1209 goto parse_keytypes;
1210
Ben Lindstromade03f62001-12-06 18:22:17 +00001211 case sRSAAuthentication:
1212 intptr = &options->rsa_authentication;
1213 goto parse_flag;
1214
1215 case sPubkeyAuthentication:
1216 intptr = &options->pubkey_authentication;
1217 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001218
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001219 case sPubkeyAcceptedKeyTypes:
1220 charptr = &options->pubkey_key_types;
1221 goto parse_keytypes;
1222
Ben Lindstromade03f62001-12-06 18:22:17 +00001223 case sKerberosAuthentication:
1224 intptr = &options->kerberos_authentication;
1225 goto parse_flag;
1226
1227 case sKerberosOrLocalPasswd:
1228 intptr = &options->kerberos_or_local_passwd;
1229 goto parse_flag;
1230
1231 case sKerberosTicketCleanup:
1232 intptr = &options->kerberos_ticket_cleanup;
1233 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001234
Darren Tucker22ef5082003-12-31 11:37:34 +11001235 case sKerberosGetAFSToken:
1236 intptr = &options->kerberos_get_afs_token;
1237 goto parse_flag;
1238
Darren Tucker0efd1552003-08-26 11:49:55 +10001239 case sGssAuthentication:
1240 intptr = &options->gss_authentication;
1241 goto parse_flag;
1242
1243 case sGssCleanupCreds:
1244 intptr = &options->gss_cleanup_creds;
1245 goto parse_flag;
1246
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001247 case sGssStrictAcceptor:
1248 intptr = &options->gss_strict_acceptor;
1249 goto parse_flag;
1250
Ben Lindstromade03f62001-12-06 18:22:17 +00001251 case sPasswordAuthentication:
1252 intptr = &options->password_authentication;
1253 goto parse_flag;
1254
1255 case sKbdInteractiveAuthentication:
1256 intptr = &options->kbd_interactive_authentication;
1257 goto parse_flag;
1258
1259 case sChallengeResponseAuthentication:
1260 intptr = &options->challenge_response_authentication;
1261 goto parse_flag;
1262
1263 case sPrintMotd:
1264 intptr = &options->print_motd;
1265 goto parse_flag;
1266
1267 case sPrintLastLog:
1268 intptr = &options->print_lastlog;
1269 goto parse_flag;
1270
1271 case sX11Forwarding:
1272 intptr = &options->x11_forwarding;
1273 goto parse_flag;
1274
1275 case sX11DisplayOffset:
1276 intptr = &options->x11_display_offset;
1277 goto parse_int;
1278
Damien Miller95c249f2002-02-05 12:11:34 +11001279 case sX11UseLocalhost:
1280 intptr = &options->x11_use_localhost;
1281 goto parse_flag;
1282
Ben Lindstromade03f62001-12-06 18:22:17 +00001283 case sXAuthLocation:
1284 charptr = &options->xauth_location;
1285 goto parse_filename;
1286
Damien Miller5ff30c62013-10-30 22:21:50 +11001287 case sPermitTTY:
1288 intptr = &options->permit_tty;
1289 goto parse_flag;
1290
Damien Miller72e6b5c2014-07-04 09:00:04 +10001291 case sPermitUserRC:
1292 intptr = &options->permit_user_rc;
1293 goto parse_flag;
1294
Ben Lindstromade03f62001-12-06 18:22:17 +00001295 case sStrictModes:
1296 intptr = &options->strict_modes;
1297 goto parse_flag;
1298
Damien Miller12c150e2003-12-17 16:31:10 +11001299 case sTCPKeepAlive:
1300 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001301 goto parse_flag;
1302
1303 case sEmptyPasswd:
1304 intptr = &options->permit_empty_passwd;
1305 goto parse_flag;
1306
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001307 case sPermitUserEnvironment:
1308 intptr = &options->permit_user_env;
1309 goto parse_flag;
1310
Ben Lindstromade03f62001-12-06 18:22:17 +00001311 case sUseLogin:
1312 intptr = &options->use_login;
1313 goto parse_flag;
1314
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001315 case sCompression:
1316 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001317 multistate_ptr = multistate_compression;
1318 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001319
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001320 case sRekeyLimit:
1321 arg = strdelim(&cp);
1322 if (!arg || *arg == '\0')
1323 fatal("%.200s line %d: Missing argument.", filename,
1324 linenum);
1325 if (strcmp(arg, "default") == 0) {
1326 val64 = 0;
1327 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001328 if (scan_scaled(arg, &val64) == -1)
1329 fatal("%.200s line %d: Bad number '%s': %s",
1330 filename, linenum, arg, strerror(errno));
1331 /* check for too-large or too-small limits */
1332 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001333 fatal("%.200s line %d: RekeyLimit too large",
1334 filename, linenum);
1335 if (val64 != 0 && val64 < 16)
1336 fatal("%.200s line %d: RekeyLimit too small",
1337 filename, linenum);
1338 }
1339 if (*activep && options->rekey_limit == -1)
1340 options->rekey_limit = (u_int32_t)val64;
1341 if (cp != NULL) { /* optional rekey interval present */
1342 if (strcmp(cp, "none") == 0) {
1343 (void)strdelim(&cp); /* discard */
1344 break;
1345 }
1346 intptr = &options->rekey_interval;
1347 goto parse_time;
1348 }
1349 break;
1350
Ben Lindstromade03f62001-12-06 18:22:17 +00001351 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001352 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001353 multistate_ptr = multistate_gatewayports;
1354 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001355
Damien Miller3a961dc2003-06-03 10:25:48 +10001356 case sUseDNS:
1357 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001358 goto parse_flag;
1359
1360 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001361 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001362 arg = strdelim(&cp);
1363 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001364 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001365 fatal("%.200s line %d: unsupported log facility '%s'",
1366 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001367 if (*log_facility_ptr == -1)
1368 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001369 break;
1370
1371 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001372 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001373 arg = strdelim(&cp);
1374 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001375 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001376 fatal("%.200s line %d: unsupported log level '%s'",
1377 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001378 if (*log_level_ptr == -1)
1379 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001380 break;
1381
1382 case sAllowTcpForwarding:
1383 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001384 multistate_ptr = multistate_tcpfwd;
1385 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001386
Damien Miller7acefbb2014-07-18 14:11:24 +10001387 case sAllowStreamLocalForwarding:
1388 intptr = &options->allow_streamlocal_forwarding;
1389 multistate_ptr = multistate_tcpfwd;
1390 goto parse_multistate;
1391
Damien Miller4f755cd2008-05-19 14:57:41 +10001392 case sAllowAgentForwarding:
1393 intptr = &options->allow_agent_forwarding;
1394 goto parse_flag;
1395
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001396 case sUsePrivilegeSeparation:
1397 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001398 multistate_ptr = multistate_privsep;
1399 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001400
Ben Lindstromade03f62001-12-06 18:22:17 +00001401 case sAllowUsers:
1402 while ((arg = strdelim(&cp)) && *arg != '\0') {
1403 if (options->num_allow_users >= MAX_ALLOW_USERS)
1404 fatal("%s line %d: too many allow users.",
1405 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001406 if (!*activep)
1407 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001408 options->allow_users[options->num_allow_users++] =
1409 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001410 }
1411 break;
1412
1413 case sDenyUsers:
1414 while ((arg = strdelim(&cp)) && *arg != '\0') {
1415 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001416 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001417 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001418 if (!*activep)
1419 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001420 options->deny_users[options->num_deny_users++] =
1421 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001422 }
1423 break;
1424
1425 case sAllowGroups:
1426 while ((arg = strdelim(&cp)) && *arg != '\0') {
1427 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1428 fatal("%s line %d: too many allow groups.",
1429 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001430 if (!*activep)
1431 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001432 options->allow_groups[options->num_allow_groups++] =
1433 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001434 }
1435 break;
1436
1437 case sDenyGroups:
1438 while ((arg = strdelim(&cp)) && *arg != '\0') {
1439 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1440 fatal("%s line %d: too many deny groups.",
1441 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001442 if (!*activep)
1443 continue;
1444 options->deny_groups[options->num_deny_groups++] =
1445 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001446 }
1447 break;
1448
1449 case sCiphers:
1450 arg = strdelim(&cp);
1451 if (!arg || *arg == '\0')
1452 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001453 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001454 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1455 filename, linenum, arg ? arg : "<NONE>");
1456 if (options->ciphers == NULL)
1457 options->ciphers = xstrdup(arg);
1458 break;
1459
1460 case sMacs:
1461 arg = strdelim(&cp);
1462 if (!arg || *arg == '\0')
1463 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001464 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001465 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1466 filename, linenum, arg ? arg : "<NONE>");
1467 if (options->macs == NULL)
1468 options->macs = xstrdup(arg);
1469 break;
1470
Damien Millerd5f62bf2010-09-24 22:11:14 +10001471 case sKexAlgorithms:
1472 arg = strdelim(&cp);
1473 if (!arg || *arg == '\0')
1474 fatal("%s line %d: Missing argument.",
1475 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001476 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001477 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1478 filename, linenum, arg ? arg : "<NONE>");
1479 if (options->kex_algorithms == NULL)
1480 options->kex_algorithms = xstrdup(arg);
1481 break;
1482
Ben Lindstromade03f62001-12-06 18:22:17 +00001483 case sProtocol:
1484 intptr = &options->protocol;
1485 arg = strdelim(&cp);
1486 if (!arg || *arg == '\0')
1487 fatal("%s line %d: Missing argument.", filename, linenum);
1488 value = proto_spec(arg);
1489 if (value == SSH_PROTO_UNKNOWN)
1490 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001491 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001492 if (*intptr == SSH_PROTO_UNKNOWN)
1493 *intptr = value;
1494 break;
1495
1496 case sSubsystem:
1497 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1498 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001499 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001500 }
1501 arg = strdelim(&cp);
1502 if (!arg || *arg == '\0')
1503 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001504 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001505 if (!*activep) {
1506 arg = strdelim(&cp);
1507 break;
1508 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001509 for (i = 0; i < options->num_subsystems; i++)
1510 if (strcmp(arg, options->subsystem_name[i]) == 0)
1511 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001512 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001513 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1514 arg = strdelim(&cp);
1515 if (!arg || *arg == '\0')
1516 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001517 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001518 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001519
1520 /* Collect arguments (separate to executable) */
1521 p = xstrdup(arg);
1522 len = strlen(p) + 1;
1523 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1524 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001525 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001526 strlcat(p, " ", len);
1527 strlcat(p, arg, len);
1528 }
1529 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001530 options->num_subsystems++;
1531 break;
1532
1533 case sMaxStartups:
1534 arg = strdelim(&cp);
1535 if (!arg || *arg == '\0')
1536 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001537 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001538 if ((n = sscanf(arg, "%d:%d:%d",
1539 &options->max_startups_begin,
1540 &options->max_startups_rate,
1541 &options->max_startups)) == 3) {
1542 if (options->max_startups_begin >
1543 options->max_startups ||
1544 options->max_startups_rate > 100 ||
1545 options->max_startups_rate < 1)
1546 fatal("%s line %d: Illegal MaxStartups spec.",
1547 filename, linenum);
1548 } else if (n != 1)
1549 fatal("%s line %d: Illegal MaxStartups spec.",
1550 filename, linenum);
1551 else
1552 options->max_startups = options->max_startups_begin;
1553 break;
1554
Darren Tucker89413db2004-05-24 10:36:23 +10001555 case sMaxAuthTries:
1556 intptr = &options->max_authtries;
1557 goto parse_int;
1558
Damien Miller7207f642008-05-19 15:34:50 +10001559 case sMaxSessions:
1560 intptr = &options->max_sessions;
1561 goto parse_int;
1562
Ben Lindstromade03f62001-12-06 18:22:17 +00001563 case sBanner:
1564 charptr = &options->banner;
1565 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001566
Ben Lindstromade03f62001-12-06 18:22:17 +00001567 /*
1568 * These options can contain %X options expanded at
1569 * connect time, so that you can specify paths like:
1570 *
1571 * AuthorizedKeysFile /etc/ssh_keys/%u
1572 */
1573 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001574 if (*activep && options->num_authkeys_files == 0) {
1575 while ((arg = strdelim(&cp)) && *arg != '\0') {
1576 if (options->num_authkeys_files >=
1577 MAX_AUTHKEYS_FILES)
1578 fatal("%s line %d: "
1579 "too many authorized keys files.",
1580 filename, linenum);
1581 options->authorized_keys_files[
1582 options->num_authkeys_files++] =
1583 tilde_expand_filename(arg, getuid());
1584 }
1585 }
1586 return 0;
1587
Damien Miller30da3442010-05-10 11:58:03 +10001588 case sAuthorizedPrincipalsFile:
1589 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001590 arg = strdelim(&cp);
1591 if (!arg || *arg == '\0')
1592 fatal("%s line %d: missing file name.",
1593 filename, linenum);
1594 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001595 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001596 /* increase optional counter */
1597 if (intptr != NULL)
1598 *intptr = *intptr + 1;
1599 }
1600 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001601
1602 case sClientAliveInterval:
1603 intptr = &options->client_alive_interval;
1604 goto parse_time;
1605
1606 case sClientAliveCountMax:
1607 intptr = &options->client_alive_count_max;
1608 goto parse_int;
1609
Darren Tucker46bc0752004-05-02 22:11:30 +10001610 case sAcceptEnv:
1611 while ((arg = strdelim(&cp)) && *arg != '\0') {
1612 if (strchr(arg, '=') != NULL)
1613 fatal("%s line %d: Invalid environment name.",
1614 filename, linenum);
1615 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1616 fatal("%s line %d: too many allow env.",
1617 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001618 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001619 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001620 options->accept_env[options->num_accept_env++] =
1621 xstrdup(arg);
1622 }
1623 break;
1624
Damien Millerd27b9472005-12-13 19:29:02 +11001625 case sPermitTunnel:
1626 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001627 arg = strdelim(&cp);
1628 if (!arg || *arg == '\0')
1629 fatal("%s line %d: Missing yes/point-to-point/"
1630 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001631 value = -1;
1632 for (i = 0; tunmode_desc[i].val != -1; i++)
1633 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1634 value = tunmode_desc[i].val;
1635 break;
1636 }
1637 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001638 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1639 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001640 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001641 *intptr = value;
1642 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001643
Darren Tucker45150472006-07-12 22:34:17 +10001644 case sMatch:
1645 if (cmdline)
1646 fatal("Match directive not supported as a command-line "
1647 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001648 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001649 if (value < 0)
1650 fatal("%s line %d: Bad Match condition", filename,
1651 linenum);
1652 *activep = value;
1653 break;
1654
Damien Miller9b439df2006-07-24 14:04:00 +10001655 case sPermitOpen:
1656 arg = strdelim(&cp);
1657 if (!arg || *arg == '\0')
1658 fatal("%s line %d: missing PermitOpen specification",
1659 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001660 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001661 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001662 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001663 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001664 options->num_permitted_opens = 0;
1665 }
Damien Miller9b439df2006-07-24 14:04:00 +10001666 break;
1667 }
Damien Millerc6081482012-04-22 11:18:53 +10001668 if (strcmp(arg, "none") == 0) {
1669 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001670 options->num_permitted_opens = 1;
1671 channel_disable_adm_local_opens();
1672 }
1673 break;
1674 }
Damien Millera29b95e2007-01-05 16:28:36 +11001675 if (*activep && n == -1)
1676 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001677 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1678 p = hpdelim(&arg);
1679 if (p == NULL)
1680 fatal("%s line %d: missing host in PermitOpen",
1681 filename, linenum);
1682 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001683 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001684 fatal("%s line %d: bad port number in "
1685 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001686 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001687 options->num_permitted_opens =
1688 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001689 }
Damien Miller9b439df2006-07-24 14:04:00 +10001690 break;
1691
Damien Millere2754432006-07-24 14:06:47 +10001692 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001693 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001694 fatal("%.200s line %d: Missing argument.", filename,
1695 linenum);
1696 len = strspn(cp, WHITESPACE);
1697 if (*activep && options->adm_forced_command == NULL)
1698 options->adm_forced_command = xstrdup(cp + len);
1699 return 0;
1700
Damien Millerd8cb1f12008-02-10 22:40:12 +11001701 case sChrootDirectory:
1702 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001703
1704 arg = strdelim(&cp);
1705 if (!arg || *arg == '\0')
1706 fatal("%s line %d: missing file name.",
1707 filename, linenum);
1708 if (*activep && *charptr == NULL)
1709 *charptr = xstrdup(arg);
1710 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001711
Damien Miller1aed65e2010-03-04 21:53:35 +11001712 case sTrustedUserCAKeys:
1713 charptr = &options->trusted_user_ca_keys;
1714 goto parse_filename;
1715
1716 case sRevokedKeys:
1717 charptr = &options->revoked_keys_file;
1718 goto parse_filename;
1719
Damien Miller0dac6fb2010-11-20 15:19:38 +11001720 case sIPQoS:
1721 arg = strdelim(&cp);
1722 if ((value = parse_ipqos(arg)) == -1)
1723 fatal("%s line %d: Bad IPQoS value: %s",
1724 filename, linenum, arg);
1725 arg = strdelim(&cp);
1726 if (arg == NULL)
1727 value2 = value;
1728 else if ((value2 = parse_ipqos(arg)) == -1)
1729 fatal("%s line %d: Bad IPQoS value: %s",
1730 filename, linenum, arg);
1731 if (*activep) {
1732 options->ip_qos_interactive = value;
1733 options->ip_qos_bulk = value2;
1734 }
1735 break;
1736
Damien Miller23528812012-04-22 11:24:43 +10001737 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001738 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001739 fatal("%.200s line %d: Missing argument.", filename,
1740 linenum);
1741 len = strspn(cp, WHITESPACE);
1742 if (*activep && options->version_addendum == NULL) {
1743 if (strcasecmp(cp + len, "none") == 0)
1744 options->version_addendum = xstrdup("");
1745 else if (strchr(cp + len, '\r') != NULL)
1746 fatal("%.200s line %d: Invalid argument",
1747 filename, linenum);
1748 else
1749 options->version_addendum = xstrdup(cp + len);
1750 }
1751 return 0;
1752
Damien Miller09d3e122012-10-31 08:58:58 +11001753 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001754 if (cp == NULL)
1755 fatal("%.200s line %d: Missing argument.", filename,
1756 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001757 len = strspn(cp, WHITESPACE);
1758 if (*activep && options->authorized_keys_command == NULL) {
1759 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1760 fatal("%.200s line %d: AuthorizedKeysCommand "
1761 "must be an absolute path",
1762 filename, linenum);
1763 options->authorized_keys_command = xstrdup(cp + len);
1764 }
1765 return 0;
1766
1767 case sAuthorizedKeysCommandUser:
1768 charptr = &options->authorized_keys_command_user;
1769
1770 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001771 if (!arg || *arg == '\0')
1772 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1773 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001774 if (*activep && *charptr == NULL)
1775 *charptr = xstrdup(arg);
1776 break;
1777
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001778 case sAuthorizedPrincipalsCommand:
1779 if (cp == NULL)
1780 fatal("%.200s line %d: Missing argument.", filename,
1781 linenum);
1782 len = strspn(cp, WHITESPACE);
1783 if (*activep &&
1784 options->authorized_principals_command == NULL) {
1785 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1786 fatal("%.200s line %d: "
1787 "AuthorizedPrincipalsCommand must be "
1788 "an absolute path", filename, linenum);
1789 options->authorized_principals_command =
1790 xstrdup(cp + len);
1791 }
1792 return 0;
1793
1794 case sAuthorizedPrincipalsCommandUser:
1795 charptr = &options->authorized_principals_command_user;
1796
1797 arg = strdelim(&cp);
1798 if (!arg || *arg == '\0')
1799 fatal("%s line %d: missing "
1800 "AuthorizedPrincipalsCommandUser argument.",
1801 filename, linenum);
1802 if (*activep && *charptr == NULL)
1803 *charptr = xstrdup(arg);
1804 break;
1805
Damien Millera6e3f012012-11-04 23:21:40 +11001806 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001807 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001808 while ((arg = strdelim(&cp)) && *arg != '\0') {
1809 if (options->num_auth_methods >=
1810 MAX_AUTH_METHODS)
1811 fatal("%s line %d: "
1812 "too many authentication methods.",
1813 filename, linenum);
1814 if (auth2_methods_valid(arg, 0) != 0)
1815 fatal("%s line %d: invalid "
1816 "authentication method list.",
1817 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001818 if (!*activep)
1819 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001820 options->auth_methods[
1821 options->num_auth_methods++] = xstrdup(arg);
1822 }
1823 }
1824 return 0;
1825
Damien Miller7acefbb2014-07-18 14:11:24 +10001826 case sStreamLocalBindMask:
1827 arg = strdelim(&cp);
1828 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001829 fatal("%s line %d: missing StreamLocalBindMask "
1830 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001831 /* Parse mode in octal format */
1832 value = strtol(arg, &p, 8);
1833 if (arg == p || value < 0 || value > 0777)
1834 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001835 if (*activep)
1836 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001837 break;
1838
1839 case sStreamLocalBindUnlink:
1840 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1841 goto parse_flag;
1842
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001843 case sFingerprintHash:
1844 arg = strdelim(&cp);
1845 if (!arg || *arg == '\0')
1846 fatal("%.200s line %d: Missing argument.",
1847 filename, linenum);
1848 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1849 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1850 filename, linenum, arg);
1851 if (*activep)
1852 options->fingerprint_hash = value;
1853 break;
1854
Ben Lindstromade03f62001-12-06 18:22:17 +00001855 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001856 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001857 filename, linenum, arg);
1858 while (arg)
1859 arg = strdelim(&cp);
1860 break;
1861
Damien Millerf9b3feb2003-05-16 11:38:32 +10001862 case sUnsupported:
1863 logit("%s line %d: Unsupported option %s",
1864 filename, linenum, arg);
1865 while (arg)
1866 arg = strdelim(&cp);
1867 break;
1868
Ben Lindstromade03f62001-12-06 18:22:17 +00001869 default:
1870 fatal("%s line %d: Missing handler for opcode %s (%d)",
1871 filename, linenum, arg, opcode);
1872 }
1873 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1874 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1875 filename, linenum, arg);
1876 return 0;
1877}
1878
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001879/* Reads the server configuration file. */
1880
Damien Miller4af51302000-04-16 11:18:38 +10001881void
Darren Tucker645ab752004-06-25 13:33:20 +10001882load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001883{
Damien Miller46cb75a2012-07-31 12:22:37 +10001884 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001885 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001886 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001887
Darren Tucker645ab752004-06-25 13:33:20 +10001888 debug2("%s: filename %s", __func__, filename);
1889 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001890 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001891 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001892 }
Darren Tucker645ab752004-06-25 13:33:20 +10001893 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001894 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001895 lineno++;
1896 if (strlen(line) == sizeof(line) - 1)
1897 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001898 /*
1899 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001900 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001901 * line numbers later for error messages
1902 */
1903 if ((cp = strchr(line, '#')) != NULL)
1904 memcpy(cp, "\n", 2);
1905 cp = line + strspn(line, " \t\r");
1906
1907 buffer_append(conf, cp, strlen(cp));
1908 }
1909 buffer_append(conf, "\0", 1);
1910 fclose(f);
1911 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1912}
1913
1914void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001915parse_server_match_config(ServerOptions *options,
1916 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001917{
Darren Tucker45150472006-07-12 22:34:17 +10001918 ServerOptions mo;
1919
1920 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001921 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001922 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001923}
1924
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001925int parse_server_match_testspec(struct connection_info *ci, char *spec)
1926{
1927 char *p;
1928
1929 while ((p = strsep(&spec, ",")) && *p != '\0') {
1930 if (strncmp(p, "addr=", 5) == 0) {
1931 ci->address = xstrdup(p + 5);
1932 } else if (strncmp(p, "host=", 5) == 0) {
1933 ci->host = xstrdup(p + 5);
1934 } else if (strncmp(p, "user=", 5) == 0) {
1935 ci->user = xstrdup(p + 5);
1936 } else if (strncmp(p, "laddr=", 6) == 0) {
1937 ci->laddress = xstrdup(p + 6);
1938 } else if (strncmp(p, "lport=", 6) == 0) {
1939 ci->lport = a2port(p + 6);
1940 if (ci->lport == -1) {
1941 fprintf(stderr, "Invalid port '%s' in test mode"
1942 " specification %s\n", p+6, p);
1943 return -1;
1944 }
1945 } else {
1946 fprintf(stderr, "Invalid test mode specification %s\n",
1947 p);
1948 return -1;
1949 }
1950 }
1951 return 0;
1952}
1953
1954/*
1955 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1956 * empty spec.
1957 */
1958int server_match_spec_complete(struct connection_info *ci)
1959{
1960 if (ci->user && ci->host && ci->address)
1961 return 1; /* complete */
1962 if (!ci->user && !ci->host && !ci->address)
1963 return -1; /* empty */
1964 return 0; /* partial */
1965}
1966
Darren Tucker1629c072007-02-19 22:25:37 +11001967/*
1968 * Copy any supported values that are set.
1969 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001970 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001971 * array values that are not used pre-authentication, because any that we
1972 * do use must be explictly sent in mm_getpwnamallow().
1973 */
Darren Tucker45150472006-07-12 22:34:17 +10001974void
Darren Tucker1629c072007-02-19 22:25:37 +11001975copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001976{
Damien Miller534b2cc2013-12-05 14:07:27 +11001977#define M_CP_INTOPT(n) do {\
1978 if (src->n != -1) \
1979 dst->n = src->n; \
1980} while (0)
1981
Darren Tucker1629c072007-02-19 22:25:37 +11001982 M_CP_INTOPT(password_authentication);
1983 M_CP_INTOPT(gss_authentication);
1984 M_CP_INTOPT(rsa_authentication);
1985 M_CP_INTOPT(pubkey_authentication);
1986 M_CP_INTOPT(kerberos_authentication);
1987 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001988 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001989 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001990 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001991 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001992
1993 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001994 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001995 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001996 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001997 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001998 M_CP_INTOPT(x11_display_offset);
1999 M_CP_INTOPT(x11_forwarding);
2000 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002001 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002002 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10002003 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10002004 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002005 M_CP_INTOPT(ip_qos_interactive);
2006 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002007 M_CP_INTOPT(rekey_limit);
2008 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002009
Damien Miller534b2cc2013-12-05 14:07:27 +11002010 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2011#define M_CP_STROPT(n) do {\
2012 if (src->n != NULL && dst->n != src->n) { \
2013 free(dst->n); \
2014 dst->n = src->n; \
2015 } \
2016} while(0)
2017#define M_CP_STRARRAYOPT(n, num_n) do {\
2018 if (src->num_n != 0) { \
2019 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2020 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2021 } \
2022} while(0)
2023
Damien Millerf2e407e2011-05-20 19:04:14 +10002024 /* See comment in servconf.h */
2025 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002026
djm@openbsd.orged085102015-10-29 08:05:01 +00002027 /* Arguments that accept '+...' need to be expanded */
2028 assemble_algorithms(dst);
2029
Damien Millerc2411902011-05-20 19:03:49 +10002030 /*
2031 * The only things that should be below this point are string options
2032 * which are only used after authentication.
2033 */
Damien Miller5d74e582011-05-20 19:03:31 +10002034 if (preauth)
2035 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002036
Damien Miller5d74e582011-05-20 19:03:31 +10002037 M_CP_STROPT(adm_forced_command);
2038 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10002039}
2040
Darren Tucker1629c072007-02-19 22:25:37 +11002041#undef M_CP_INTOPT
2042#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002043#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002044
Darren Tucker45150472006-07-12 22:34:17 +10002045void
2046parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002047 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002048{
2049 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002050 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002051
2052 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2053
Darren Tucker9fbac712004-08-12 22:41:44 +10002054 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002055 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002056 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002057 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002058 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002059 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002060 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002061 }
Darren Tuckera627d422013-06-02 07:31:17 +10002062 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002063 if (bad_options > 0)
2064 fatal("%s: terminating, %d bad configuration options",
2065 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002066 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002067}
Darren Tuckere7140f22008-06-10 23:01:51 +10002068
2069static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002070fmt_multistate_int(int val, const struct multistate *m)
2071{
2072 u_int i;
2073
2074 for (i = 0; m[i].key != NULL; i++) {
2075 if (m[i].value == val)
2076 return m[i].key;
2077 }
2078 return "UNKNOWN";
2079}
2080
2081static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002082fmt_intarg(ServerOpCodes code, int val)
2083{
Damien Miller82c55872011-06-23 08:20:30 +10002084 if (val == -1)
2085 return "unset";
2086 switch (code) {
2087 case sAddressFamily:
2088 return fmt_multistate_int(val, multistate_addressfamily);
2089 case sPermitRootLogin:
2090 return fmt_multistate_int(val, multistate_permitrootlogin);
2091 case sGatewayPorts:
2092 return fmt_multistate_int(val, multistate_gatewayports);
2093 case sCompression:
2094 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002095 case sUsePrivilegeSeparation:
2096 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002097 case sAllowTcpForwarding:
2098 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002099 case sAllowStreamLocalForwarding:
2100 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002101 case sFingerprintHash:
2102 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002103 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002104 switch (val) {
2105 case SSH_PROTO_1:
2106 return "1";
2107 case SSH_PROTO_2:
2108 return "2";
2109 case (SSH_PROTO_1|SSH_PROTO_2):
2110 return "2,1";
2111 default:
2112 return "UNKNOWN";
2113 }
Damien Miller82c55872011-06-23 08:20:30 +10002114 default:
2115 switch (val) {
2116 case 0:
2117 return "no";
2118 case 1:
2119 return "yes";
2120 default:
2121 return "UNKNOWN";
2122 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002123 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002124}
2125
2126static const char *
2127lookup_opcode_name(ServerOpCodes code)
2128{
2129 u_int i;
2130
2131 for (i = 0; keywords[i].name != NULL; i++)
2132 if (keywords[i].opcode == code)
2133 return(keywords[i].name);
2134 return "UNKNOWN";
2135}
2136
2137static void
2138dump_cfg_int(ServerOpCodes code, int val)
2139{
2140 printf("%s %d\n", lookup_opcode_name(code), val);
2141}
2142
2143static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002144dump_cfg_oct(ServerOpCodes code, int val)
2145{
2146 printf("%s 0%o\n", lookup_opcode_name(code), val);
2147}
2148
2149static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002150dump_cfg_fmtint(ServerOpCodes code, int val)
2151{
2152 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2153}
2154
2155static void
2156dump_cfg_string(ServerOpCodes code, const char *val)
2157{
2158 if (val == NULL)
2159 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002160 printf("%s %s\n", lookup_opcode_name(code),
2161 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002162}
2163
2164static void
2165dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2166{
2167 u_int i;
2168
2169 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002170 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2171}
2172
2173static void
2174dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2175{
2176 u_int i;
2177
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002178 if (count <= 0)
2179 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002180 printf("%s", lookup_opcode_name(code));
2181 for (i = 0; i < count; i++)
2182 printf(" %s", vals[i]);
2183 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002184}
2185
2186void
2187dump_config(ServerOptions *o)
2188{
2189 u_int i;
2190 int ret;
2191 struct addrinfo *ai;
2192 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002193 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002194
2195 /* these are usually at the top of the config */
2196 for (i = 0; i < o->num_ports; i++)
2197 printf("port %d\n", o->ports[i]);
2198 dump_cfg_fmtint(sProtocol, o->protocol);
2199 dump_cfg_fmtint(sAddressFamily, o->address_family);
2200
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002201 /*
2202 * ListenAddress must be after Port. add_one_listen_addr pushes
2203 * addresses onto a stack, so to maintain ordering we need to
2204 * print these in reverse order.
2205 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002206 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2207 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2208 sizeof(addr), port, sizeof(port),
2209 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2210 error("getnameinfo failed: %.100s",
2211 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2212 strerror(errno));
2213 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002214 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002215 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002216 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2217 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002218 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002219 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2220 addr, port, laddr2);
2221 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002222 }
2223 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002224 printf("%s", laddr1);
2225 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002226
2227 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002228#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002229 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002230#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002231 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2232 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2233 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2234 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2235 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002236 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002237 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2238 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002239 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002240
2241 /* formatted integer arguments */
2242 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2243 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2244 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2245 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2246 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2247 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2248 o->hostbased_uses_name_from_packet_only);
2249 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2250 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002251#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002252 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2253 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2254 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002255# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002256 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002257# endif
2258#endif
2259#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002260 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2261 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002262#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002263 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2264 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2265 o->kbd_interactive_authentication);
2266 dump_cfg_fmtint(sChallengeResponseAuthentication,
2267 o->challenge_response_authentication);
2268 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2269 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2270 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2271 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002272 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002273 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002274 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2275 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2276 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2277 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2278 dump_cfg_fmtint(sUseLogin, o->use_login);
2279 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002280 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_fmtint(sUseDNS, o->use_dns);
2282 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002283 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002284 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002285 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002286 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002287
2288 /* string arguments */
2289 dump_cfg_string(sPidFile, o->pid_file);
2290 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002291 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2292 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002293 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002294 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002295 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002296 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2297 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002298 dump_cfg_string(sAuthorizedPrincipalsFile,
2299 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002300 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2301 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002302 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2303 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002304 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2305 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002306 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002307 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002308 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002309 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2310 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002311 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2312 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002313 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2314 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002315
2316 /* string arguments requiring a lookup */
2317 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2318 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2319
2320 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002321 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2322 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002323 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2324 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002325 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002326 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002327 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2328 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2329 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2330 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2331 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002332 dump_cfg_strarray_oneline(sAuthenticationMethods,
2333 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002334
2335 /* other arguments */
2336 for (i = 0; i < o->num_subsystems; i++)
2337 printf("subsystem %s %s\n", o->subsystem_name[i],
2338 o->subsystem_args[i]);
2339
2340 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2341 o->max_startups_rate, o->max_startups);
2342
2343 for (i = 0; tunmode_desc[i].val != -1; i++)
2344 if (tunmode_desc[i].val == o->permit_tun) {
2345 s = tunmode_desc[i].text;
2346 break;
2347 }
2348 dump_cfg_string(sPermitTunnel, s);
2349
Damien Miller91475862011-05-05 14:14:34 +10002350 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2351 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002352
Damien Millera6d6c1f2013-08-21 02:40:01 +10002353 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2354 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002355
Darren Tuckere7140f22008-06-10 23:01:51 +10002356 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002357}