blob: 9bd659c41f12ec400e26c813d178c38aef67ce5a [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00002/* $OpenBSD: servconf.c,v 1.293 2016/08/15 12:27:56 naddy 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->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +000090 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110091 options->ignore_rhosts = -1;
92 options->ignore_user_known_hosts = -1;
93 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000094 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110095 options->x11_forwarding = -1;
96 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110097 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110098 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +100099 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000100 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100102 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100103 options->log_facility = SYSLOG_FACILITY_NOT_SET;
104 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000105 options->hostbased_authentication = -1;
106 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000107 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000108 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100109 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000110 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->kerberos_authentication = -1;
112 options->kerberos_or_local_passwd = -1;
113 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100114 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000115 options->gss_authentication=-1;
116 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000117 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100118 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100119 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000120 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000122 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100123 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000124 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000125 options->rekey_limit = -1;
126 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100127 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000128 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000129 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100130 options->num_allow_users = 0;
131 options->num_deny_users = 0;
132 options->num_allow_groups = 0;
133 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000134 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000135 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000136 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000137 options->fwd_opts.gateway_ports = -1;
138 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
139 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000140 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000141 options->max_startups_begin = -1;
142 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000143 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000144 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000145 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000146 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000147 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000148 options->client_alive_interval = -1;
149 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000150 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000151 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100152 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000153 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000154 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100155 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100156 options->authorized_keys_command = NULL;
157 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100158 options->revoked_keys_file = NULL;
159 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000160 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000161 options->authorized_principals_command = NULL;
162 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100163 options->ip_qos_interactive = -1;
164 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000165 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000166 options->fingerprint_hash = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000167}
168
djm@openbsd.org161cf412014-12-22 07:55:51 +0000169/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
170static int
171option_clear_or_none(const char *o)
172{
173 return o == NULL || strcasecmp(o, "none") == 0;
174}
175
djm@openbsd.orged085102015-10-29 08:05:01 +0000176static void
177assemble_algorithms(ServerOptions *o)
178{
179 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
180 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
181 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
182 kex_assemble_names(KEX_DEFAULT_PK_ALG,
183 &o->hostkeyalgorithms) != 0 ||
184 kex_assemble_names(KEX_DEFAULT_PK_ALG,
185 &o->hostbased_key_types) != 0 ||
186 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
187 fatal("kex_assemble_names failed");
188}
189
Damien Miller4af51302000-04-16 11:18:38 +1000190void
Damien Miller95def091999-11-25 00:26:21 +1100191fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000192{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000193 int i;
194
Damien Miller726273e2001-11-12 11:40:11 +1100195 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000196 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000197 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100198
199 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100200 if (options->num_host_key_files == 0) {
201 /* fill default hostkeys for protocols */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000202 options->host_key_files[options->num_host_key_files++] =
203 _PATH_HOST_RSA_KEY_FILE;
204 options->host_key_files[options->num_host_key_files++] =
205 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100206#ifdef OPENSSL_HAS_ECC
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000207 options->host_key_files[options->num_host_key_files++] =
208 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100209#endif
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000210 options->host_key_files[options->num_host_key_files++] =
211 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100212 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100213 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100214 if (options->num_ports == 0)
215 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000216 if (options->address_family == -1)
217 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100218 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000219 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000220 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000221 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000223 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000224 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000225 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100227 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->ignore_user_known_hosts == -1)
229 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->print_motd == -1)
231 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000232 if (options->print_lastlog == -1)
233 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100235 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100237 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100238 if (options->x11_use_localhost == -1)
239 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000240 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000241 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100242 if (options->permit_tty == -1)
243 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000244 if (options->permit_user_rc == -1)
245 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->strict_modes == -1)
247 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100248 if (options->tcp_keep_alive == -1)
249 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100250 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100251 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100252 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000253 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000254 if (options->hostbased_authentication == -1)
255 options->hostbased_authentication = 0;
256 if (options->hostbased_uses_name_from_packet_only == -1)
257 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100258 if (options->pubkey_authentication == -1)
259 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100260 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000261 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->kerberos_or_local_passwd == -1)
263 options->kerberos_or_local_passwd = 1;
264 if (options->kerberos_ticket_cleanup == -1)
265 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100266 if (options->kerberos_get_afs_token == -1)
267 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000268 if (options->gss_authentication == -1)
269 options->gss_authentication = 0;
270 if (options->gss_cleanup_creds == -1)
271 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000272 if (options->gss_strict_acceptor == -1)
273 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100274 if (options->password_authentication == -1)
275 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100276 if (options->kbd_interactive_authentication == -1)
277 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000278 if (options->challenge_response_authentication == -1)
279 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100281 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000282 if (options->permit_user_env == -1)
283 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100284 if (options->use_login == -1)
285 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000286 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000287 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000288 if (options->rekey_limit == -1)
289 options->rekey_limit = 0;
290 if (options->rekey_interval == -1)
291 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100292 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100293 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000294 if (options->allow_streamlocal_forwarding == -1)
295 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000296 if (options->allow_agent_forwarding == -1)
297 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000298 if (options->fwd_opts.gateway_ports == -1)
299 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000300 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100301 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000302 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100303 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000304 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100305 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000306 if (options->max_authtries == -1)
307 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000308 if (options->max_sessions == -1)
309 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000310 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000311 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000312 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100313 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000314 if (options->client_alive_count_max == -1)
315 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000316 if (options->num_authkeys_files == 0) {
317 options->authorized_keys_files[options->num_authkeys_files++] =
318 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
319 options->authorized_keys_files[options->num_authkeys_files++] =
320 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
321 }
Damien Millerd27b9472005-12-13 19:29:02 +1100322 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100323 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100324 if (options->ip_qos_interactive == -1)
325 options->ip_qos_interactive = IPTOS_LOWDELAY;
326 if (options->ip_qos_bulk == -1)
327 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000328 if (options->version_addendum == NULL)
329 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000330 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
331 options->fwd_opts.streamlocal_bind_mask = 0177;
332 if (options->fwd_opts.streamlocal_bind_unlink == -1)
333 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000334 if (options->fingerprint_hash == -1)
335 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000336
djm@openbsd.orged085102015-10-29 08:05:01 +0000337 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000338
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000339 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000340 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000341 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000342
djm@openbsd.org161cf412014-12-22 07:55:51 +0000343#define CLEAR_ON_NONE(v) \
344 do { \
345 if (option_clear_or_none(v)) { \
346 free(v); \
347 v = NULL; \
348 } \
349 } while(0)
350 CLEAR_ON_NONE(options->pid_file);
351 CLEAR_ON_NONE(options->xauth_location);
352 CLEAR_ON_NONE(options->banner);
353 CLEAR_ON_NONE(options->trusted_user_ca_keys);
354 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000355 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000356 CLEAR_ON_NONE(options->adm_forced_command);
357 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000358 for (i = 0; i < options->num_host_key_files; i++)
359 CLEAR_ON_NONE(options->host_key_files[i]);
360 for (i = 0; i < options->num_host_cert_files; i++)
361 CLEAR_ON_NONE(options->host_cert_files[i]);
362#undef CLEAR_ON_NONE
363
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000364 /* Similar handling for AuthenticationMethods=any */
365 if (options->num_auth_methods == 1 &&
366 strcmp(options->auth_methods[0], "any") == 0) {
367 free(options->auth_methods[0]);
368 options->auth_methods[0] = NULL;
369 options->num_auth_methods = 0;
370 }
371
Tim Rice40017b02002-07-14 13:36:49 -0700372#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000373 if (use_privsep && options->compression == 1) {
374 error("This platform does not support both privilege "
375 "separation and compression");
376 error("Compression disabled");
377 options->compression = 0;
378 }
379#endif
380
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381}
382
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100384typedef enum {
385 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100386 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000387 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100388 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000389 sPort, sHostKeyFile, sLoginGraceTime,
390 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000391 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100392 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100393 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000394 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100395 sPasswordAuthentication, sKbdInteractiveAuthentication,
396 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000397 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100398 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100399 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000400 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000401 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000402 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000403 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
404 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000405 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000406 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000407 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000408 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000409 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
410 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100411 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100412 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100413 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000414 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000415 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000416 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100417 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000418 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000419 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000420 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000421 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422} ServerOpCodes;
423
Darren Tucker45150472006-07-12 22:34:17 +1000424#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
425#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
426#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
427
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000428/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100429static struct {
430 const char *name;
431 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000432 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100433} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100434 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000435#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000436 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000437#else
Darren Tucker45150472006-07-12 22:34:17 +1000438 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000439#endif
Darren Tucker45150472006-07-12 22:34:17 +1000440 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100441 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "port", sPort, SSHCFG_GLOBAL },
443 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
444 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000445 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000447 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000448 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000449 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100450 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
452 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
453 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000454 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100455 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000456 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000457 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000458 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000459 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100460 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000461 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000462 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000463#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000465 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
466 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100467#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000468 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000469#else
Darren Tucker45150472006-07-12 22:34:17 +1000470 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100471#endif
472#else
Darren Tucker1629c072007-02-19 22:25:37 +1100473 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000474 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
475 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
476 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000477#endif
Darren Tucker45150472006-07-12 22:34:17 +1000478 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
479 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000480#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100481 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000482 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000483 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000484#else
Darren Tucker1629c072007-02-19 22:25:37 +1100485 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000487 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000488#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100489 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
490 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100491 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000492 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
493 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
494 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
495 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
496 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100497#ifdef DISABLE_LASTLOG
498 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
499#else
Darren Tucker45150472006-07-12 22:34:17 +1000500 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100501#endif
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
503 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000504 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
505 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
506 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000507 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
508 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100509 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000510 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
511 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
512 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000513 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
515 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
516 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000517 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000518 { "allowusers", sAllowUsers, SSHCFG_ALL },
519 { "denyusers", sDenyUsers, SSHCFG_ALL },
520 { "allowgroups", sAllowGroups, SSHCFG_ALL },
521 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "ciphers", sCiphers, SSHCFG_GLOBAL },
523 { "macs", sMacs, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000524 { "protocol", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
526 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
527 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000528 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000529 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100530 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000531 { "usedns", sUseDNS, SSHCFG_GLOBAL },
532 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
533 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
534 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
535 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000536 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000537 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000538 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000539 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000540 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100541 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000542 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000543 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000544 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000545 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100546 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100547 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100548 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
549 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000550 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000551 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100552 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100553 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
554 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000555 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
556 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000557 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100558 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000559 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
560 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
561 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000562 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000563 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000564};
565
Darren Tuckere7140f22008-06-10 23:01:51 +1000566static struct {
567 int val;
568 char *text;
569} tunmode_desc[] = {
570 { SSH_TUNMODE_NO, "no" },
571 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
572 { SSH_TUNMODE_ETHERNET, "ethernet" },
573 { SSH_TUNMODE_YES, "yes" },
574 { -1, NULL }
575};
576
Damien Miller5428f641999-11-25 11:54:57 +1100577/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000578 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100579 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000580
Damien Miller4af51302000-04-16 11:18:38 +1000581static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100582parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000583 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000584{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000585 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000586
Damien Miller95def091999-11-25 00:26:21 +1100587 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000588 if (strcasecmp(cp, keywords[i].name) == 0) {
589 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100590 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000591 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000592
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000593 error("%s: line %d: Bad configuration option: %s",
594 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100595 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000596}
597
Darren Tucker88b6fb22010-01-13 22:44:29 +1100598char *
599derelativise_path(const char *path)
600{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000601 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100602
djm@openbsd.org161cf412014-12-22 07:55:51 +0000603 if (strcasecmp(path, "none") == 0)
604 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100605 expanded = tilde_expand_filename(path, getuid());
606 if (*expanded == '/')
607 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100608 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100609 fatal("%s: getcwd: %s", __func__, strerror(errno));
610 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000611 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100612 return ret;
613}
614
Ben Lindstrombba81212001-06-25 05:01:22 +0000615static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100616add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100617{
Damien Millereccb9de2005-06-17 12:59:34 +1000618 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100619
Ben Lindstrom19066a12001-04-12 23:39:26 +0000620 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000621 for (i = 0; i < options->num_ports; i++)
622 add_one_listen_addr(options, addr, options->ports[i]);
623 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000624 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000625}
626
Ben Lindstrombba81212001-06-25 05:01:22 +0000627static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100628add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000629{
630 struct addrinfo hints, *ai, *aitop;
631 char strport[NI_MAXSERV];
632 int gaierr;
633
634 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100635 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000636 hints.ai_socktype = SOCK_STREAM;
637 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100638 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000639 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
640 fatal("bad addr or host: %s (%s)",
641 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100642 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000643 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
644 ;
645 ai->ai_next = options->listen_addrs;
646 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100647}
648
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000649/*
650 * Queue a ListenAddress to be processed once we have all of the Ports
651 * and AddressFamily options.
652 */
653static void
654queue_listen_addr(ServerOptions *options, char *addr, int port)
655{
656 options->queued_listen_addrs = xreallocarray(
657 options->queued_listen_addrs, options->num_queued_listens + 1,
658 sizeof(addr));
659 options->queued_listen_ports = xreallocarray(
660 options->queued_listen_ports, options->num_queued_listens + 1,
661 sizeof(port));
662 options->queued_listen_addrs[options->num_queued_listens] =
663 xstrdup(addr);
664 options->queued_listen_ports[options->num_queued_listens] = port;
665 options->num_queued_listens++;
666}
667
668/*
669 * Process queued (text) ListenAddress entries.
670 */
671static void
672process_queued_listen_addrs(ServerOptions *options)
673{
674 u_int i;
675
676 if (options->num_ports == 0)
677 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
678 if (options->address_family == -1)
679 options->address_family = AF_UNSPEC;
680
681 for (i = 0; i < options->num_queued_listens; i++) {
682 add_listen_addr(options, options->queued_listen_addrs[i],
683 options->queued_listen_ports[i]);
684 free(options->queued_listen_addrs[i]);
685 options->queued_listen_addrs[i] = NULL;
686 }
687 free(options->queued_listen_addrs);
688 options->queued_listen_addrs = NULL;
689 free(options->queued_listen_ports);
690 options->queued_listen_ports = NULL;
691 options->num_queued_listens = 0;
692}
693
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000694struct connection_info *
695get_connection_info(int populate, int use_dns)
696{
djm@openbsd.org95767262016-03-07 19:02:43 +0000697 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000698 static struct connection_info ci;
699
700 if (!populate)
701 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000702 ci.host = auth_get_canonical_hostname(ssh, use_dns);
703 ci.address = ssh_remote_ipaddr(ssh);
704 ci.laddress = ssh_local_ipaddr(ssh);
705 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000706 return &ci;
707}
708
Darren Tucker45150472006-07-12 22:34:17 +1000709/*
710 * The strategy for the Match blocks is that the config file is parsed twice.
711 *
712 * The first time is at startup. activep is initialized to 1 and the
713 * directives in the global context are processed and acted on. Hitting a
714 * Match directive unsets activep and the directives inside the block are
715 * checked for syntax only.
716 *
717 * The second time is after a connection has been established but before
718 * authentication. activep is initialized to 2 and global config directives
719 * are ignored since they have already been processed. If the criteria in a
720 * Match block is met, activep is set and the subsequent directives
721 * processed and actioned until EOF or another Match block unsets it. Any
722 * options set are copied into the main server config.
723 *
724 * Potential additions/improvements:
725 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
726 *
727 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
728 * Match Address 192.168.0.*
729 * Tag trusted
730 * Match Group wheel
731 * Tag trusted
732 * Match Tag trusted
733 * AllowTcpForwarding yes
734 * GatewayPorts clientspecified
735 * [...]
736 *
737 * - Add a PermittedChannelRequests directive
738 * Match Group shell
739 * PermittedChannelRequests session,forwarded-tcpip
740 */
741
742static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000743match_cfg_line_group(const char *grps, int line, const char *user)
744{
745 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000746 struct passwd *pw;
747
Damien Miller565ca3f2006-08-19 00:23:15 +1000748 if (user == NULL)
749 goto out;
750
751 if ((pw = getpwnam(user)) == NULL) {
752 debug("Can't match group at line %d because user %.100s does "
753 "not exist", line, user);
754 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
755 debug("Can't Match group because user %.100s not in any group "
756 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000757 } else if (ga_match_pattern_list(grps) != 1) {
758 debug("user %.100s does not match group list %.100s at line %d",
759 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000760 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000761 debug("user %.100s matched group list %.100s at line %d", user,
762 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000763 result = 1;
764 }
765out:
766 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000767 return result;
768}
769
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000770/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000771 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100772 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000773 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000774 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000775static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000776match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000777{
Damien Millercf31f382013-10-24 21:02:56 +1100778 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000779 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000780
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000781 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000782 debug3("checking syntax for 'Match %s'", cp);
783 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000784 debug3("checking match for '%s' user %s host %s addr %s "
785 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
786 ci->host ? ci->host : "(null)",
787 ci->address ? ci->address : "(null)",
788 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000789
790 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100791 attributes++;
792 if (strcasecmp(attrib, "all") == 0) {
793 if (attributes != 1 ||
794 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
795 error("'all' cannot be combined with other "
796 "Match attributes");
797 return -1;
798 }
799 *condition = cp;
800 return 1;
801 }
Darren Tucker45150472006-07-12 22:34:17 +1000802 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
803 error("Missing Match criteria for %s", attrib);
804 return -1;
805 }
Darren Tucker45150472006-07-12 22:34:17 +1000806 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000807 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000808 result = 0;
809 continue;
810 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000811 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000812 result = 0;
813 else
814 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000815 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000816 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000817 if (ci == NULL || ci->user == NULL) {
818 result = 0;
819 continue;
820 }
821 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000822 case -1:
823 return -1;
824 case 0:
825 result = 0;
826 }
Darren Tucker45150472006-07-12 22:34:17 +1000827 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000828 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000829 result = 0;
830 continue;
831 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000832 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000833 result = 0;
834 else
835 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000836 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000837 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000838 if (ci == NULL || ci->address == NULL) {
839 result = 0;
840 continue;
841 }
842 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000843 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000844 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000845 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000846 break;
847 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000848 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000849 result = 0;
850 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000851 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000852 return -1;
853 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000854 } else if (strcasecmp(attrib, "localaddress") == 0){
855 if (ci == NULL || ci->laddress == NULL) {
856 result = 0;
857 continue;
858 }
859 switch (addr_match_list(ci->laddress, arg)) {
860 case 1:
861 debug("connection from %.100s matched "
862 "'LocalAddress %.100s' at line %d",
863 ci->laddress, arg, line);
864 break;
865 case 0:
866 case -1:
867 result = 0;
868 break;
869 case -2:
870 return -1;
871 }
872 } else if (strcasecmp(attrib, "localport") == 0) {
873 if ((port = a2port(arg)) == -1) {
874 error("Invalid LocalPort '%s' on Match line",
875 arg);
876 return -1;
877 }
878 if (ci == NULL || ci->lport == 0) {
879 result = 0;
880 continue;
881 }
882 /* TODO support port lists */
883 if (port == ci->lport)
884 debug("connection from %.100s matched "
885 "'LocalPort %d' at line %d",
886 ci->laddress, port, line);
887 else
888 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000889 } else {
890 error("Unsupported Match attribute %s", attrib);
891 return -1;
892 }
893 }
Damien Millercf31f382013-10-24 21:02:56 +1100894 if (attributes == 0) {
895 error("One or more attributes required for Match");
896 return -1;
897 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000898 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000899 debug3("match %sfound", result ? "" : "not ");
900 *condition = cp;
901 return result;
902}
903
Damien Millere2754432006-07-24 14:06:47 +1000904#define WHITESPACE " \t\r\n"
905
Damien Miller33322122011-06-20 14:43:11 +1000906/* Multistate option parsing */
907struct multistate {
908 char *key;
909 int value;
910};
911static const struct multistate multistate_addressfamily[] = {
912 { "inet", AF_INET },
913 { "inet6", AF_INET6 },
914 { "any", AF_UNSPEC },
915 { NULL, -1 }
916};
917static const struct multistate multistate_permitrootlogin[] = {
918 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000919 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000920 { "forced-commands-only", PERMIT_FORCED_ONLY },
921 { "yes", PERMIT_YES },
922 { "no", PERMIT_NO },
923 { NULL, -1 }
924};
925static const struct multistate multistate_compression[] = {
926 { "delayed", COMP_DELAYED },
927 { "yes", COMP_ZLIB },
928 { "no", COMP_NONE },
929 { NULL, -1 }
930};
931static const struct multistate multistate_gatewayports[] = {
932 { "clientspecified", 2 },
933 { "yes", 1 },
934 { "no", 0 },
935 { NULL, -1 }
936};
Damien Miller69ff1df2011-06-23 08:30:03 +1000937static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000938 { "yes", PRIVSEP_NOSANDBOX },
939 { "sandbox", PRIVSEP_ON },
940 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000941 { "no", PRIVSEP_OFF },
942 { NULL, -1 }
943};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100944static const struct multistate multistate_tcpfwd[] = {
945 { "yes", FORWARD_ALLOW },
946 { "all", FORWARD_ALLOW },
947 { "no", FORWARD_DENY },
948 { "remote", FORWARD_REMOTE },
949 { "local", FORWARD_LOCAL },
950 { NULL, -1 }
951};
Damien Miller33322122011-06-20 14:43:11 +1000952
Ben Lindstromade03f62001-12-06 18:22:17 +0000953int
954process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000955 const char *filename, int linenum, int *activep,
956 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000957{
Darren Tucker09c0f032013-05-16 20:48:57 +1000958 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000959 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100960 SyslogFacility *log_facility_ptr;
961 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000962 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000963 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000964 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000965 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000966 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000967
968 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100969 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100970 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000971 /* Ignore leading whitespace */
972 if (*arg == '\0')
973 arg = strdelim(&cp);
974 if (!arg || !*arg || *arg == '#')
975 return 0;
976 intptr = NULL;
977 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000978 opcode = parse_token(arg, filename, linenum, &flags);
979
980 if (activep == NULL) { /* We are processing a command line directive */
981 cmdline = 1;
982 activep = &cmdline;
983 }
984 if (*activep && opcode != sMatch)
985 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
986 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000987 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000988 fatal("%s line %d: Directive '%s' is not allowed "
989 "within a Match block", filename, linenum, arg);
990 } else { /* this is a directive we have already processed */
991 while (arg)
992 arg = strdelim(&cp);
993 return 0;
994 }
995 }
996
Ben Lindstromade03f62001-12-06 18:22:17 +0000997 switch (opcode) {
998 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000999 case sUsePAM:
1000 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001001 goto parse_flag;
1002
1003 /* Standard Options */
1004 case sBadOption:
1005 return -1;
1006 case sPort:
1007 /* ignore ports from configfile if cmdline specifies ports */
1008 if (options->ports_from_cmdline)
1009 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001010 if (options->num_ports >= MAX_PORTS)
1011 fatal("%s line %d: too many ports.",
1012 filename, linenum);
1013 arg = strdelim(&cp);
1014 if (!arg || *arg == '\0')
1015 fatal("%s line %d: missing port number.",
1016 filename, linenum);
1017 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001018 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001019 fatal("%s line %d: Badly formatted port number.",
1020 filename, linenum);
1021 break;
1022
Ben Lindstromade03f62001-12-06 18:22:17 +00001023 case sLoginGraceTime:
1024 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001025 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001026 arg = strdelim(&cp);
1027 if (!arg || *arg == '\0')
1028 fatal("%s line %d: missing time value.",
1029 filename, linenum);
1030 if ((value = convtime(arg)) == -1)
1031 fatal("%s line %d: invalid time value.",
1032 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001033 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001034 *intptr = value;
1035 break;
1036
Ben Lindstromade03f62001-12-06 18:22:17 +00001037 case sListenAddress:
1038 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001039 if (arg == NULL || *arg == '\0')
1040 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001041 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001042 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1043 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1044 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001045 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001046 break;
1047 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001048 p = hpdelim(&arg);
1049 if (p == NULL)
1050 fatal("%s line %d: bad address:port usage",
1051 filename, linenum);
1052 p = cleanhostname(p);
1053 if (arg == NULL)
1054 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001055 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001056 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001057
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001058 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001059
Ben Lindstromade03f62001-12-06 18:22:17 +00001060 break;
1061
Darren Tucker0f383232005-01-20 10:57:56 +11001062 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001063 intptr = &options->address_family;
1064 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001065 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001066 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001067 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001068 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001069 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001070 value = -1;
1071 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1072 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1073 value = multistate_ptr[i].value;
1074 break;
1075 }
1076 }
1077 if (value == -1)
1078 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001079 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001080 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001081 *intptr = value;
1082 break;
1083
Ben Lindstromade03f62001-12-06 18:22:17 +00001084 case sHostKeyFile:
1085 intptr = &options->num_host_key_files;
1086 if (*intptr >= MAX_HOSTKEYS)
1087 fatal("%s line %d: too many host keys specified (max %d).",
1088 filename, linenum, MAX_HOSTKEYS);
1089 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001090 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001091 arg = strdelim(&cp);
1092 if (!arg || *arg == '\0')
1093 fatal("%s line %d: missing file name.",
1094 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001095 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001096 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001097 /* increase optional counter */
1098 if (intptr != NULL)
1099 *intptr = *intptr + 1;
1100 }
1101 break;
1102
Damien Miller85b45e02013-07-20 13:21:52 +10001103 case sHostKeyAgent:
1104 charptr = &options->host_key_agent;
1105 arg = strdelim(&cp);
1106 if (!arg || *arg == '\0')
1107 fatal("%s line %d: missing socket name.",
1108 filename, linenum);
1109 if (*activep && *charptr == NULL)
1110 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1111 xstrdup(arg) : derelativise_path(arg);
1112 break;
1113
Damien Miller0a80ca12010-02-27 07:55:05 +11001114 case sHostCertificate:
1115 intptr = &options->num_host_cert_files;
1116 if (*intptr >= MAX_HOSTKEYS)
1117 fatal("%s line %d: too many host certificates "
1118 "specified (max %d).", filename, linenum,
1119 MAX_HOSTCERTS);
1120 charptr = &options->host_cert_files[*intptr];
1121 goto parse_filename;
1122 break;
1123
Ben Lindstromade03f62001-12-06 18:22:17 +00001124 case sPidFile:
1125 charptr = &options->pid_file;
1126 goto parse_filename;
1127
1128 case sPermitRootLogin:
1129 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001130 multistate_ptr = multistate_permitrootlogin;
1131 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001132
1133 case sIgnoreRhosts:
1134 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001135 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001136 arg = strdelim(&cp);
1137 if (!arg || *arg == '\0')
1138 fatal("%s line %d: missing yes/no argument.",
1139 filename, linenum);
1140 value = 0; /* silence compiler */
1141 if (strcmp(arg, "yes") == 0)
1142 value = 1;
1143 else if (strcmp(arg, "no") == 0)
1144 value = 0;
1145 else
1146 fatal("%s line %d: Bad yes/no argument: %s",
1147 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001148 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001149 *intptr = value;
1150 break;
1151
1152 case sIgnoreUserKnownHosts:
1153 intptr = &options->ignore_user_known_hosts;
1154 goto parse_flag;
1155
Ben Lindstromade03f62001-12-06 18:22:17 +00001156 case sHostbasedAuthentication:
1157 intptr = &options->hostbased_authentication;
1158 goto parse_flag;
1159
1160 case sHostbasedUsesNameFromPacketOnly:
1161 intptr = &options->hostbased_uses_name_from_packet_only;
1162 goto parse_flag;
1163
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001164 case sHostbasedAcceptedKeyTypes:
1165 charptr = &options->hostbased_key_types;
1166 parse_keytypes:
1167 arg = strdelim(&cp);
1168 if (!arg || *arg == '\0')
1169 fatal("%s line %d: Missing argument.",
1170 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001171 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001172 fatal("%s line %d: Bad key types '%s'.",
1173 filename, linenum, arg ? arg : "<NONE>");
1174 if (*activep && *charptr == NULL)
1175 *charptr = xstrdup(arg);
1176 break;
1177
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001178 case sHostKeyAlgorithms:
1179 charptr = &options->hostkeyalgorithms;
1180 goto parse_keytypes;
1181
Ben Lindstromade03f62001-12-06 18:22:17 +00001182 case sPubkeyAuthentication:
1183 intptr = &options->pubkey_authentication;
1184 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001185
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001186 case sPubkeyAcceptedKeyTypes:
1187 charptr = &options->pubkey_key_types;
1188 goto parse_keytypes;
1189
Ben Lindstromade03f62001-12-06 18:22:17 +00001190 case sKerberosAuthentication:
1191 intptr = &options->kerberos_authentication;
1192 goto parse_flag;
1193
1194 case sKerberosOrLocalPasswd:
1195 intptr = &options->kerberos_or_local_passwd;
1196 goto parse_flag;
1197
1198 case sKerberosTicketCleanup:
1199 intptr = &options->kerberos_ticket_cleanup;
1200 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001201
Darren Tucker22ef5082003-12-31 11:37:34 +11001202 case sKerberosGetAFSToken:
1203 intptr = &options->kerberos_get_afs_token;
1204 goto parse_flag;
1205
Darren Tucker0efd1552003-08-26 11:49:55 +10001206 case sGssAuthentication:
1207 intptr = &options->gss_authentication;
1208 goto parse_flag;
1209
1210 case sGssCleanupCreds:
1211 intptr = &options->gss_cleanup_creds;
1212 goto parse_flag;
1213
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001214 case sGssStrictAcceptor:
1215 intptr = &options->gss_strict_acceptor;
1216 goto parse_flag;
1217
Ben Lindstromade03f62001-12-06 18:22:17 +00001218 case sPasswordAuthentication:
1219 intptr = &options->password_authentication;
1220 goto parse_flag;
1221
1222 case sKbdInteractiveAuthentication:
1223 intptr = &options->kbd_interactive_authentication;
1224 goto parse_flag;
1225
1226 case sChallengeResponseAuthentication:
1227 intptr = &options->challenge_response_authentication;
1228 goto parse_flag;
1229
1230 case sPrintMotd:
1231 intptr = &options->print_motd;
1232 goto parse_flag;
1233
1234 case sPrintLastLog:
1235 intptr = &options->print_lastlog;
1236 goto parse_flag;
1237
1238 case sX11Forwarding:
1239 intptr = &options->x11_forwarding;
1240 goto parse_flag;
1241
1242 case sX11DisplayOffset:
1243 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001244 parse_int:
1245 arg = strdelim(&cp);
1246 if (!arg || *arg == '\0')
1247 fatal("%s line %d: missing integer value.",
1248 filename, linenum);
1249 value = atoi(arg);
1250 if (*activep && *intptr == -1)
1251 *intptr = value;
1252 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001253
Damien Miller95c249f2002-02-05 12:11:34 +11001254 case sX11UseLocalhost:
1255 intptr = &options->x11_use_localhost;
1256 goto parse_flag;
1257
Ben Lindstromade03f62001-12-06 18:22:17 +00001258 case sXAuthLocation:
1259 charptr = &options->xauth_location;
1260 goto parse_filename;
1261
Damien Miller5ff30c62013-10-30 22:21:50 +11001262 case sPermitTTY:
1263 intptr = &options->permit_tty;
1264 goto parse_flag;
1265
Damien Miller72e6b5c2014-07-04 09:00:04 +10001266 case sPermitUserRC:
1267 intptr = &options->permit_user_rc;
1268 goto parse_flag;
1269
Ben Lindstromade03f62001-12-06 18:22:17 +00001270 case sStrictModes:
1271 intptr = &options->strict_modes;
1272 goto parse_flag;
1273
Damien Miller12c150e2003-12-17 16:31:10 +11001274 case sTCPKeepAlive:
1275 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001276 goto parse_flag;
1277
1278 case sEmptyPasswd:
1279 intptr = &options->permit_empty_passwd;
1280 goto parse_flag;
1281
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001282 case sPermitUserEnvironment:
1283 intptr = &options->permit_user_env;
1284 goto parse_flag;
1285
Ben Lindstromade03f62001-12-06 18:22:17 +00001286 case sUseLogin:
1287 intptr = &options->use_login;
1288 goto parse_flag;
1289
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001290 case sCompression:
1291 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001292 multistate_ptr = multistate_compression;
1293 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001294
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001295 case sRekeyLimit:
1296 arg = strdelim(&cp);
1297 if (!arg || *arg == '\0')
1298 fatal("%.200s line %d: Missing argument.", filename,
1299 linenum);
1300 if (strcmp(arg, "default") == 0) {
1301 val64 = 0;
1302 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001303 if (scan_scaled(arg, &val64) == -1)
1304 fatal("%.200s line %d: Bad number '%s': %s",
1305 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001306 if (val64 != 0 && val64 < 16)
1307 fatal("%.200s line %d: RekeyLimit too small",
1308 filename, linenum);
1309 }
1310 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001311 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001312 if (cp != NULL) { /* optional rekey interval present */
1313 if (strcmp(cp, "none") == 0) {
1314 (void)strdelim(&cp); /* discard */
1315 break;
1316 }
1317 intptr = &options->rekey_interval;
1318 goto parse_time;
1319 }
1320 break;
1321
Ben Lindstromade03f62001-12-06 18:22:17 +00001322 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001323 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001324 multistate_ptr = multistate_gatewayports;
1325 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001326
Damien Miller3a961dc2003-06-03 10:25:48 +10001327 case sUseDNS:
1328 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001329 goto parse_flag;
1330
1331 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001332 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001333 arg = strdelim(&cp);
1334 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001335 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001336 fatal("%.200s line %d: unsupported log facility '%s'",
1337 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001338 if (*log_facility_ptr == -1)
1339 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001340 break;
1341
1342 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001343 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001344 arg = strdelim(&cp);
1345 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001346 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001347 fatal("%.200s line %d: unsupported log level '%s'",
1348 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001349 if (*log_level_ptr == -1)
1350 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001351 break;
1352
1353 case sAllowTcpForwarding:
1354 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001355 multistate_ptr = multistate_tcpfwd;
1356 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001357
Damien Miller7acefbb2014-07-18 14:11:24 +10001358 case sAllowStreamLocalForwarding:
1359 intptr = &options->allow_streamlocal_forwarding;
1360 multistate_ptr = multistate_tcpfwd;
1361 goto parse_multistate;
1362
Damien Miller4f755cd2008-05-19 14:57:41 +10001363 case sAllowAgentForwarding:
1364 intptr = &options->allow_agent_forwarding;
1365 goto parse_flag;
1366
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001367 case sUsePrivilegeSeparation:
1368 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001369 multistate_ptr = multistate_privsep;
1370 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001371
Ben Lindstromade03f62001-12-06 18:22:17 +00001372 case sAllowUsers:
1373 while ((arg = strdelim(&cp)) && *arg != '\0') {
1374 if (options->num_allow_users >= MAX_ALLOW_USERS)
1375 fatal("%s line %d: too many allow users.",
1376 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001377 if (!*activep)
1378 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001379 options->allow_users[options->num_allow_users++] =
1380 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001381 }
1382 break;
1383
1384 case sDenyUsers:
1385 while ((arg = strdelim(&cp)) && *arg != '\0') {
1386 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001387 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001388 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001389 if (!*activep)
1390 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001391 options->deny_users[options->num_deny_users++] =
1392 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001393 }
1394 break;
1395
1396 case sAllowGroups:
1397 while ((arg = strdelim(&cp)) && *arg != '\0') {
1398 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1399 fatal("%s line %d: too many allow groups.",
1400 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001401 if (!*activep)
1402 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001403 options->allow_groups[options->num_allow_groups++] =
1404 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001405 }
1406 break;
1407
1408 case sDenyGroups:
1409 while ((arg = strdelim(&cp)) && *arg != '\0') {
1410 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1411 fatal("%s line %d: too many deny groups.",
1412 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001413 if (!*activep)
1414 continue;
1415 options->deny_groups[options->num_deny_groups++] =
1416 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001417 }
1418 break;
1419
1420 case sCiphers:
1421 arg = strdelim(&cp);
1422 if (!arg || *arg == '\0')
1423 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001424 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001425 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1426 filename, linenum, arg ? arg : "<NONE>");
1427 if (options->ciphers == NULL)
1428 options->ciphers = xstrdup(arg);
1429 break;
1430
1431 case sMacs:
1432 arg = strdelim(&cp);
1433 if (!arg || *arg == '\0')
1434 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001435 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001436 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1437 filename, linenum, arg ? arg : "<NONE>");
1438 if (options->macs == NULL)
1439 options->macs = xstrdup(arg);
1440 break;
1441
Damien Millerd5f62bf2010-09-24 22:11:14 +10001442 case sKexAlgorithms:
1443 arg = strdelim(&cp);
1444 if (!arg || *arg == '\0')
1445 fatal("%s line %d: Missing argument.",
1446 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001447 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001448 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1449 filename, linenum, arg ? arg : "<NONE>");
1450 if (options->kex_algorithms == NULL)
1451 options->kex_algorithms = xstrdup(arg);
1452 break;
1453
Ben Lindstromade03f62001-12-06 18:22:17 +00001454 case sSubsystem:
1455 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1456 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001457 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001458 }
1459 arg = strdelim(&cp);
1460 if (!arg || *arg == '\0')
1461 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001462 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001463 if (!*activep) {
1464 arg = strdelim(&cp);
1465 break;
1466 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001467 for (i = 0; i < options->num_subsystems; i++)
1468 if (strcmp(arg, options->subsystem_name[i]) == 0)
1469 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001470 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001471 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1472 arg = strdelim(&cp);
1473 if (!arg || *arg == '\0')
1474 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001475 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001476 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001477
1478 /* Collect arguments (separate to executable) */
1479 p = xstrdup(arg);
1480 len = strlen(p) + 1;
1481 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1482 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001483 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001484 strlcat(p, " ", len);
1485 strlcat(p, arg, len);
1486 }
1487 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001488 options->num_subsystems++;
1489 break;
1490
1491 case sMaxStartups:
1492 arg = strdelim(&cp);
1493 if (!arg || *arg == '\0')
1494 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001495 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001496 if ((n = sscanf(arg, "%d:%d:%d",
1497 &options->max_startups_begin,
1498 &options->max_startups_rate,
1499 &options->max_startups)) == 3) {
1500 if (options->max_startups_begin >
1501 options->max_startups ||
1502 options->max_startups_rate > 100 ||
1503 options->max_startups_rate < 1)
1504 fatal("%s line %d: Illegal MaxStartups spec.",
1505 filename, linenum);
1506 } else if (n != 1)
1507 fatal("%s line %d: Illegal MaxStartups spec.",
1508 filename, linenum);
1509 else
1510 options->max_startups = options->max_startups_begin;
1511 break;
1512
Darren Tucker89413db2004-05-24 10:36:23 +10001513 case sMaxAuthTries:
1514 intptr = &options->max_authtries;
1515 goto parse_int;
1516
Damien Miller7207f642008-05-19 15:34:50 +10001517 case sMaxSessions:
1518 intptr = &options->max_sessions;
1519 goto parse_int;
1520
Ben Lindstromade03f62001-12-06 18:22:17 +00001521 case sBanner:
1522 charptr = &options->banner;
1523 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001524
Ben Lindstromade03f62001-12-06 18:22:17 +00001525 /*
1526 * These options can contain %X options expanded at
1527 * connect time, so that you can specify paths like:
1528 *
1529 * AuthorizedKeysFile /etc/ssh_keys/%u
1530 */
1531 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001532 if (*activep && options->num_authkeys_files == 0) {
1533 while ((arg = strdelim(&cp)) && *arg != '\0') {
1534 if (options->num_authkeys_files >=
1535 MAX_AUTHKEYS_FILES)
1536 fatal("%s line %d: "
1537 "too many authorized keys files.",
1538 filename, linenum);
1539 options->authorized_keys_files[
1540 options->num_authkeys_files++] =
1541 tilde_expand_filename(arg, getuid());
1542 }
1543 }
1544 return 0;
1545
Damien Miller30da3442010-05-10 11:58:03 +10001546 case sAuthorizedPrincipalsFile:
1547 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001548 arg = strdelim(&cp);
1549 if (!arg || *arg == '\0')
1550 fatal("%s line %d: missing file name.",
1551 filename, linenum);
1552 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001553 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001554 /* increase optional counter */
1555 if (intptr != NULL)
1556 *intptr = *intptr + 1;
1557 }
1558 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001559
1560 case sClientAliveInterval:
1561 intptr = &options->client_alive_interval;
1562 goto parse_time;
1563
1564 case sClientAliveCountMax:
1565 intptr = &options->client_alive_count_max;
1566 goto parse_int;
1567
Darren Tucker46bc0752004-05-02 22:11:30 +10001568 case sAcceptEnv:
1569 while ((arg = strdelim(&cp)) && *arg != '\0') {
1570 if (strchr(arg, '=') != NULL)
1571 fatal("%s line %d: Invalid environment name.",
1572 filename, linenum);
1573 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1574 fatal("%s line %d: too many allow env.",
1575 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001576 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001577 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001578 options->accept_env[options->num_accept_env++] =
1579 xstrdup(arg);
1580 }
1581 break;
1582
Damien Millerd27b9472005-12-13 19:29:02 +11001583 case sPermitTunnel:
1584 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001585 arg = strdelim(&cp);
1586 if (!arg || *arg == '\0')
1587 fatal("%s line %d: Missing yes/point-to-point/"
1588 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001589 value = -1;
1590 for (i = 0; tunmode_desc[i].val != -1; i++)
1591 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1592 value = tunmode_desc[i].val;
1593 break;
1594 }
1595 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001596 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1597 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001598 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001599 *intptr = value;
1600 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001601
Darren Tucker45150472006-07-12 22:34:17 +10001602 case sMatch:
1603 if (cmdline)
1604 fatal("Match directive not supported as a command-line "
1605 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001606 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001607 if (value < 0)
1608 fatal("%s line %d: Bad Match condition", filename,
1609 linenum);
1610 *activep = value;
1611 break;
1612
Damien Miller9b439df2006-07-24 14:04:00 +10001613 case sPermitOpen:
1614 arg = strdelim(&cp);
1615 if (!arg || *arg == '\0')
1616 fatal("%s line %d: missing PermitOpen specification",
1617 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001618 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001619 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001620 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001621 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001622 options->num_permitted_opens = 0;
1623 }
Damien Miller9b439df2006-07-24 14:04:00 +10001624 break;
1625 }
Damien Millerc6081482012-04-22 11:18:53 +10001626 if (strcmp(arg, "none") == 0) {
1627 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001628 options->num_permitted_opens = 1;
1629 channel_disable_adm_local_opens();
1630 }
1631 break;
1632 }
Damien Millera29b95e2007-01-05 16:28:36 +11001633 if (*activep && n == -1)
1634 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001635 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1636 p = hpdelim(&arg);
1637 if (p == NULL)
1638 fatal("%s line %d: missing host in PermitOpen",
1639 filename, linenum);
1640 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001641 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001642 fatal("%s line %d: bad port number in "
1643 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001644 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001645 options->num_permitted_opens =
1646 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001647 }
Damien Miller9b439df2006-07-24 14:04:00 +10001648 break;
1649
Damien Millere2754432006-07-24 14:06:47 +10001650 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001651 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001652 fatal("%.200s line %d: Missing argument.", filename,
1653 linenum);
1654 len = strspn(cp, WHITESPACE);
1655 if (*activep && options->adm_forced_command == NULL)
1656 options->adm_forced_command = xstrdup(cp + len);
1657 return 0;
1658
Damien Millerd8cb1f12008-02-10 22:40:12 +11001659 case sChrootDirectory:
1660 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001661
1662 arg = strdelim(&cp);
1663 if (!arg || *arg == '\0')
1664 fatal("%s line %d: missing file name.",
1665 filename, linenum);
1666 if (*activep && *charptr == NULL)
1667 *charptr = xstrdup(arg);
1668 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001669
Damien Miller1aed65e2010-03-04 21:53:35 +11001670 case sTrustedUserCAKeys:
1671 charptr = &options->trusted_user_ca_keys;
1672 goto parse_filename;
1673
1674 case sRevokedKeys:
1675 charptr = &options->revoked_keys_file;
1676 goto parse_filename;
1677
Damien Miller0dac6fb2010-11-20 15:19:38 +11001678 case sIPQoS:
1679 arg = strdelim(&cp);
1680 if ((value = parse_ipqos(arg)) == -1)
1681 fatal("%s line %d: Bad IPQoS value: %s",
1682 filename, linenum, arg);
1683 arg = strdelim(&cp);
1684 if (arg == NULL)
1685 value2 = value;
1686 else if ((value2 = parse_ipqos(arg)) == -1)
1687 fatal("%s line %d: Bad IPQoS value: %s",
1688 filename, linenum, arg);
1689 if (*activep) {
1690 options->ip_qos_interactive = value;
1691 options->ip_qos_bulk = value2;
1692 }
1693 break;
1694
Damien Miller23528812012-04-22 11:24:43 +10001695 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001696 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001697 fatal("%.200s line %d: Missing argument.", filename,
1698 linenum);
1699 len = strspn(cp, WHITESPACE);
1700 if (*activep && options->version_addendum == NULL) {
1701 if (strcasecmp(cp + len, "none") == 0)
1702 options->version_addendum = xstrdup("");
1703 else if (strchr(cp + len, '\r') != NULL)
1704 fatal("%.200s line %d: Invalid argument",
1705 filename, linenum);
1706 else
1707 options->version_addendum = xstrdup(cp + len);
1708 }
1709 return 0;
1710
Damien Miller09d3e122012-10-31 08:58:58 +11001711 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001712 if (cp == NULL)
1713 fatal("%.200s line %d: Missing argument.", filename,
1714 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001715 len = strspn(cp, WHITESPACE);
1716 if (*activep && options->authorized_keys_command == NULL) {
1717 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1718 fatal("%.200s line %d: AuthorizedKeysCommand "
1719 "must be an absolute path",
1720 filename, linenum);
1721 options->authorized_keys_command = xstrdup(cp + len);
1722 }
1723 return 0;
1724
1725 case sAuthorizedKeysCommandUser:
1726 charptr = &options->authorized_keys_command_user;
1727
1728 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001729 if (!arg || *arg == '\0')
1730 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1731 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001732 if (*activep && *charptr == NULL)
1733 *charptr = xstrdup(arg);
1734 break;
1735
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001736 case sAuthorizedPrincipalsCommand:
1737 if (cp == NULL)
1738 fatal("%.200s line %d: Missing argument.", filename,
1739 linenum);
1740 len = strspn(cp, WHITESPACE);
1741 if (*activep &&
1742 options->authorized_principals_command == NULL) {
1743 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1744 fatal("%.200s line %d: "
1745 "AuthorizedPrincipalsCommand must be "
1746 "an absolute path", filename, linenum);
1747 options->authorized_principals_command =
1748 xstrdup(cp + len);
1749 }
1750 return 0;
1751
1752 case sAuthorizedPrincipalsCommandUser:
1753 charptr = &options->authorized_principals_command_user;
1754
1755 arg = strdelim(&cp);
1756 if (!arg || *arg == '\0')
1757 fatal("%s line %d: missing "
1758 "AuthorizedPrincipalsCommandUser argument.",
1759 filename, linenum);
1760 if (*activep && *charptr == NULL)
1761 *charptr = xstrdup(arg);
1762 break;
1763
Damien Millera6e3f012012-11-04 23:21:40 +11001764 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001765 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001766 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001767 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001768 while ((arg = strdelim(&cp)) && *arg != '\0') {
1769 if (options->num_auth_methods >=
1770 MAX_AUTH_METHODS)
1771 fatal("%s line %d: "
1772 "too many authentication methods.",
1773 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001774 if (strcmp(arg, "any") == 0) {
1775 if (options->num_auth_methods > 0) {
1776 fatal("%s line %d: \"any\" "
1777 "must appear alone in "
1778 "AuthenticationMethods",
1779 filename, linenum);
1780 }
1781 value = 1;
1782 } else if (value) {
1783 fatal("%s line %d: \"any\" must appear "
1784 "alone in AuthenticationMethods",
1785 filename, linenum);
1786 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001787 fatal("%s line %d: invalid "
1788 "authentication method list.",
1789 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001790 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001791 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001792 if (!*activep)
1793 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001794 options->auth_methods[
1795 options->num_auth_methods++] = xstrdup(arg);
1796 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001797 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001798 fatal("%s line %d: no AuthenticationMethods "
1799 "specified", filename, linenum);
1800 }
Damien Millera6e3f012012-11-04 23:21:40 +11001801 }
1802 return 0;
1803
Damien Miller7acefbb2014-07-18 14:11:24 +10001804 case sStreamLocalBindMask:
1805 arg = strdelim(&cp);
1806 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001807 fatal("%s line %d: missing StreamLocalBindMask "
1808 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001809 /* Parse mode in octal format */
1810 value = strtol(arg, &p, 8);
1811 if (arg == p || value < 0 || value > 0777)
1812 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001813 if (*activep)
1814 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001815 break;
1816
1817 case sStreamLocalBindUnlink:
1818 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1819 goto parse_flag;
1820
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001821 case sFingerprintHash:
1822 arg = strdelim(&cp);
1823 if (!arg || *arg == '\0')
1824 fatal("%.200s line %d: Missing argument.",
1825 filename, linenum);
1826 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1827 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1828 filename, linenum, arg);
1829 if (*activep)
1830 options->fingerprint_hash = value;
1831 break;
1832
Ben Lindstromade03f62001-12-06 18:22:17 +00001833 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001834 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001835 filename, linenum, arg);
1836 while (arg)
1837 arg = strdelim(&cp);
1838 break;
1839
Damien Millerf9b3feb2003-05-16 11:38:32 +10001840 case sUnsupported:
1841 logit("%s line %d: Unsupported option %s",
1842 filename, linenum, arg);
1843 while (arg)
1844 arg = strdelim(&cp);
1845 break;
1846
Ben Lindstromade03f62001-12-06 18:22:17 +00001847 default:
1848 fatal("%s line %d: Missing handler for opcode %s (%d)",
1849 filename, linenum, arg, opcode);
1850 }
1851 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1852 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1853 filename, linenum, arg);
1854 return 0;
1855}
1856
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001857/* Reads the server configuration file. */
1858
Damien Miller4af51302000-04-16 11:18:38 +10001859void
Darren Tucker645ab752004-06-25 13:33:20 +10001860load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001861{
Damien Miller46cb75a2012-07-31 12:22:37 +10001862 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001863 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001864 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001865
Darren Tucker645ab752004-06-25 13:33:20 +10001866 debug2("%s: filename %s", __func__, filename);
1867 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001868 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001869 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001870 }
Darren Tucker645ab752004-06-25 13:33:20 +10001871 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001872 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001873 lineno++;
1874 if (strlen(line) == sizeof(line) - 1)
1875 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001876 /*
1877 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001878 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001879 * line numbers later for error messages
1880 */
1881 if ((cp = strchr(line, '#')) != NULL)
1882 memcpy(cp, "\n", 2);
1883 cp = line + strspn(line, " \t\r");
1884
1885 buffer_append(conf, cp, strlen(cp));
1886 }
1887 buffer_append(conf, "\0", 1);
1888 fclose(f);
1889 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1890}
1891
1892void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001893parse_server_match_config(ServerOptions *options,
1894 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001895{
Darren Tucker45150472006-07-12 22:34:17 +10001896 ServerOptions mo;
1897
1898 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001899 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001900 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001901}
1902
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001903int parse_server_match_testspec(struct connection_info *ci, char *spec)
1904{
1905 char *p;
1906
1907 while ((p = strsep(&spec, ",")) && *p != '\0') {
1908 if (strncmp(p, "addr=", 5) == 0) {
1909 ci->address = xstrdup(p + 5);
1910 } else if (strncmp(p, "host=", 5) == 0) {
1911 ci->host = xstrdup(p + 5);
1912 } else if (strncmp(p, "user=", 5) == 0) {
1913 ci->user = xstrdup(p + 5);
1914 } else if (strncmp(p, "laddr=", 6) == 0) {
1915 ci->laddress = xstrdup(p + 6);
1916 } else if (strncmp(p, "lport=", 6) == 0) {
1917 ci->lport = a2port(p + 6);
1918 if (ci->lport == -1) {
1919 fprintf(stderr, "Invalid port '%s' in test mode"
1920 " specification %s\n", p+6, p);
1921 return -1;
1922 }
1923 } else {
1924 fprintf(stderr, "Invalid test mode specification %s\n",
1925 p);
1926 return -1;
1927 }
1928 }
1929 return 0;
1930}
1931
1932/*
1933 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1934 * empty spec.
1935 */
1936int server_match_spec_complete(struct connection_info *ci)
1937{
1938 if (ci->user && ci->host && ci->address)
1939 return 1; /* complete */
1940 if (!ci->user && !ci->host && !ci->address)
1941 return -1; /* empty */
1942 return 0; /* partial */
1943}
1944
Darren Tucker1629c072007-02-19 22:25:37 +11001945/*
1946 * Copy any supported values that are set.
1947 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001948 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001949 * array values that are not used pre-authentication, because any that we
1950 * do use must be explictly sent in mm_getpwnamallow().
1951 */
Darren Tucker45150472006-07-12 22:34:17 +10001952void
Darren Tucker1629c072007-02-19 22:25:37 +11001953copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001954{
Damien Miller534b2cc2013-12-05 14:07:27 +11001955#define M_CP_INTOPT(n) do {\
1956 if (src->n != -1) \
1957 dst->n = src->n; \
1958} while (0)
1959
Darren Tucker1629c072007-02-19 22:25:37 +11001960 M_CP_INTOPT(password_authentication);
1961 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11001962 M_CP_INTOPT(pubkey_authentication);
1963 M_CP_INTOPT(kerberos_authentication);
1964 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001965 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001966 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001967 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001968 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001969
1970 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001971 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001972 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001973 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001974 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001975 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11001976 M_CP_INTOPT(x11_display_offset);
1977 M_CP_INTOPT(x11_forwarding);
1978 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001979 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001980 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001981 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001982 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001983 M_CP_INTOPT(ip_qos_interactive);
1984 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001985 M_CP_INTOPT(rekey_limit);
1986 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001987
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001988 /*
1989 * The bind_mask is a mode_t that may be unsigned, so we can't use
1990 * M_CP_INTOPT - it does a signed comparison that causes compiler
1991 * warnings.
1992 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00001993 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001994 dst->fwd_opts.streamlocal_bind_mask =
1995 src->fwd_opts.streamlocal_bind_mask;
1996 }
1997
Damien Miller534b2cc2013-12-05 14:07:27 +11001998 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1999#define M_CP_STROPT(n) do {\
2000 if (src->n != NULL && dst->n != src->n) { \
2001 free(dst->n); \
2002 dst->n = src->n; \
2003 } \
2004} while(0)
2005#define M_CP_STRARRAYOPT(n, num_n) do {\
2006 if (src->num_n != 0) { \
2007 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2008 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2009 } \
2010} while(0)
2011
Damien Millerf2e407e2011-05-20 19:04:14 +10002012 /* See comment in servconf.h */
2013 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002014
djm@openbsd.orged085102015-10-29 08:05:01 +00002015 /* Arguments that accept '+...' need to be expanded */
2016 assemble_algorithms(dst);
2017
Damien Millerc2411902011-05-20 19:03:49 +10002018 /*
2019 * The only things that should be below this point are string options
2020 * which are only used after authentication.
2021 */
Damien Miller5d74e582011-05-20 19:03:31 +10002022 if (preauth)
2023 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002024
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002025 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002026 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002027 if (option_clear_or_none(dst->adm_forced_command)) {
2028 free(dst->adm_forced_command);
2029 dst->adm_forced_command = NULL;
2030 }
Damien Miller5d74e582011-05-20 19:03:31 +10002031 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002032 if (option_clear_or_none(dst->chroot_directory)) {
2033 free(dst->chroot_directory);
2034 dst->chroot_directory = NULL;
2035 }
Darren Tucker45150472006-07-12 22:34:17 +10002036}
2037
Darren Tucker1629c072007-02-19 22:25:37 +11002038#undef M_CP_INTOPT
2039#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002040#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002041
Darren Tucker45150472006-07-12 22:34:17 +10002042void
2043parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002044 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002045{
2046 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002047 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002048
2049 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2050
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002051 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2052 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002053 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002054 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002055 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002056 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002057 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002058 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002059 }
Darren Tuckera627d422013-06-02 07:31:17 +10002060 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002061 if (bad_options > 0)
2062 fatal("%s: terminating, %d bad configuration options",
2063 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002064 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002065}
Darren Tuckere7140f22008-06-10 23:01:51 +10002066
2067static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002068fmt_multistate_int(int val, const struct multistate *m)
2069{
2070 u_int i;
2071
2072 for (i = 0; m[i].key != NULL; i++) {
2073 if (m[i].value == val)
2074 return m[i].key;
2075 }
2076 return "UNKNOWN";
2077}
2078
2079static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002080fmt_intarg(ServerOpCodes code, int val)
2081{
Damien Miller82c55872011-06-23 08:20:30 +10002082 if (val == -1)
2083 return "unset";
2084 switch (code) {
2085 case sAddressFamily:
2086 return fmt_multistate_int(val, multistate_addressfamily);
2087 case sPermitRootLogin:
2088 return fmt_multistate_int(val, multistate_permitrootlogin);
2089 case sGatewayPorts:
2090 return fmt_multistate_int(val, multistate_gatewayports);
2091 case sCompression:
2092 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002093 case sUsePrivilegeSeparation:
2094 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002095 case sAllowTcpForwarding:
2096 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002097 case sAllowStreamLocalForwarding:
2098 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002099 case sFingerprintHash:
2100 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002101 default:
2102 switch (val) {
2103 case 0:
2104 return "no";
2105 case 1:
2106 return "yes";
2107 default:
2108 return "UNKNOWN";
2109 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002110 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002111}
2112
2113static const char *
2114lookup_opcode_name(ServerOpCodes code)
2115{
2116 u_int i;
2117
2118 for (i = 0; keywords[i].name != NULL; i++)
2119 if (keywords[i].opcode == code)
2120 return(keywords[i].name);
2121 return "UNKNOWN";
2122}
2123
2124static void
2125dump_cfg_int(ServerOpCodes code, int val)
2126{
2127 printf("%s %d\n", lookup_opcode_name(code), val);
2128}
2129
2130static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002131dump_cfg_oct(ServerOpCodes code, int val)
2132{
2133 printf("%s 0%o\n", lookup_opcode_name(code), val);
2134}
2135
2136static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002137dump_cfg_fmtint(ServerOpCodes code, int val)
2138{
2139 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2140}
2141
2142static void
2143dump_cfg_string(ServerOpCodes code, const char *val)
2144{
2145 if (val == NULL)
2146 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002147 printf("%s %s\n", lookup_opcode_name(code),
2148 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002149}
2150
2151static void
2152dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2153{
2154 u_int i;
2155
2156 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002157 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2158}
2159
2160static void
2161dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2162{
2163 u_int i;
2164
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002165 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002166 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002167 printf("%s", lookup_opcode_name(code));
2168 for (i = 0; i < count; i++)
2169 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002170 if (code == sAuthenticationMethods && count == 0)
2171 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002172 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002173}
2174
2175void
2176dump_config(ServerOptions *o)
2177{
2178 u_int i;
2179 int ret;
2180 struct addrinfo *ai;
2181 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002182 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002183
2184 /* these are usually at the top of the config */
2185 for (i = 0; i < o->num_ports; i++)
2186 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002187 dump_cfg_fmtint(sAddressFamily, o->address_family);
2188
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002189 /*
2190 * ListenAddress must be after Port. add_one_listen_addr pushes
2191 * addresses onto a stack, so to maintain ordering we need to
2192 * print these in reverse order.
2193 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002194 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2195 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2196 sizeof(addr), port, sizeof(port),
2197 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2198 error("getnameinfo failed: %.100s",
2199 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2200 strerror(errno));
2201 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002202 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002203 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002204 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2205 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002206 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002207 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2208 addr, port, laddr2);
2209 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002210 }
2211 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002212 printf("%s", laddr1);
2213 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002214
2215 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002216#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002217 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002218#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002219 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002220 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2221 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002222 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002223 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2224 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002225 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002226
2227 /* formatted integer arguments */
2228 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2229 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2230 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002231 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2232 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2233 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002234 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002235#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002236 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2237 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2238 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002239# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002240 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002241# endif
2242#endif
2243#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002244 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2245 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002246#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002247 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2248 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2249 o->kbd_interactive_authentication);
2250 dump_cfg_fmtint(sChallengeResponseAuthentication,
2251 o->challenge_response_authentication);
2252 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002253#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002254 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002255#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002256 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2257 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002258 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002259 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002260 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2261 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2262 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2263 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2264 dump_cfg_fmtint(sUseLogin, o->use_login);
2265 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002266 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002267 dump_cfg_fmtint(sUseDNS, o->use_dns);
2268 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002269 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002270 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002271 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
Darren Tuckere7140f22008-06-10 23:01:51 +10002272 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002273 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002274
2275 /* string arguments */
2276 dump_cfg_string(sPidFile, o->pid_file);
2277 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002278 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2279 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002280 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002282 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002283 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2284 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002285 dump_cfg_string(sAuthorizedPrincipalsFile,
2286 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002287 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2288 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002289 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2290 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002291 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2292 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002293 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002294 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002295 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002296 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2297 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002298 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2299 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002300 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2301 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002302
2303 /* string arguments requiring a lookup */
2304 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2305 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2306
2307 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002308 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2309 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002310 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2311 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002312 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002313 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002314 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2315 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2316 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2317 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2318 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002319 dump_cfg_strarray_oneline(sAuthenticationMethods,
2320 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002321
2322 /* other arguments */
2323 for (i = 0; i < o->num_subsystems; i++)
2324 printf("subsystem %s %s\n", o->subsystem_name[i],
2325 o->subsystem_args[i]);
2326
2327 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2328 o->max_startups_rate, o->max_startups);
2329
2330 for (i = 0; tunmode_desc[i].val != -1; i++)
2331 if (tunmode_desc[i].val == o->permit_tun) {
2332 s = tunmode_desc[i].text;
2333 break;
2334 }
2335 dump_cfg_string(sPermitTunnel, s);
2336
Damien Miller91475862011-05-05 14:14:34 +10002337 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2338 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002339
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002340 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002341 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002342
Darren Tuckere7140f22008-06-10 23:01:51 +10002343 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002344}