blob: a18ebb59746114e4793d8f6c7cf19b86283ba377 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org010359b2016-11-06 05:46:37 +00002/* $OpenBSD: servconf.c,v 1.299 2016/11/06 05:46:37 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100032#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100033#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100034#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100035#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100036#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100037
Damien Millerb84886b2008-05-19 15:05:07 +100038#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100042#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100043#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100045#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000049#include "kex.h"
50#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100051#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100052#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100053#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100054#include "canohost.h"
55#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110056#include "hostfile.h"
57#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000058#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000059#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000060
Damien Miller3dc71ad2009-01-28 16:31:22 +110061static void add_listen_addr(ServerOptions *, char *, int);
62static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110063
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000064/* Use of privilege separation or not */
65extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100066extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068/* Initializes the server options to their default values. */
69
Damien Miller4af51302000-04-16 11:18:38 +100070void
Damien Miller95def091999-11-25 00:26:21 +110071initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072{
Damien Miller95def091999-11-25 00:26:21 +110073 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100076 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110077
78 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110079 options->num_ports = 0;
80 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000081 options->queued_listen_addrs = NULL;
82 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110083 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110084 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110085 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110086 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100087 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100088 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110089 options->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;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000123 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000124 options->rekey_limit = -1;
125 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100126 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000127 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000128 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100129 options->num_allow_users = 0;
130 options->num_deny_users = 0;
131 options->num_allow_groups = 0;
132 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000133 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000134 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000135 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000136 options->fwd_opts.gateway_ports = -1;
137 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
138 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000139 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000140 options->max_startups_begin = -1;
141 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000142 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000143 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000144 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000145 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000146 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000147 options->client_alive_interval = -1;
148 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000149 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000150 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100151 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000152 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000153 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100154 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100155 options->authorized_keys_command = NULL;
156 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100157 options->revoked_keys_file = NULL;
158 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000159 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000160 options->authorized_principals_command = NULL;
161 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100162 options->ip_qos_interactive = -1;
163 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000164 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000165 options->fingerprint_hash = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000166}
167
djm@openbsd.org161cf412014-12-22 07:55:51 +0000168/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
169static int
170option_clear_or_none(const char *o)
171{
172 return o == NULL || strcasecmp(o, "none") == 0;
173}
174
djm@openbsd.orged085102015-10-29 08:05:01 +0000175static void
176assemble_algorithms(ServerOptions *o)
177{
178 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
179 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
180 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
181 kex_assemble_names(KEX_DEFAULT_PK_ALG,
182 &o->hostkeyalgorithms) != 0 ||
183 kex_assemble_names(KEX_DEFAULT_PK_ALG,
184 &o->hostbased_key_types) != 0 ||
185 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
186 fatal("kex_assemble_names failed");
187}
188
Damien Miller4af51302000-04-16 11:18:38 +1000189void
Damien Miller95def091999-11-25 00:26:21 +1100190fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000191{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000192 int i;
193
Damien Miller726273e2001-11-12 11:40:11 +1100194 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000195 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000196 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100197
198 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100199 if (options->num_host_key_files == 0) {
200 /* fill default hostkeys for protocols */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000201 options->host_key_files[options->num_host_key_files++] =
202 _PATH_HOST_RSA_KEY_FILE;
203 options->host_key_files[options->num_host_key_files++] =
204 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100205#ifdef OPENSSL_HAS_ECC
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000206 options->host_key_files[options->num_host_key_files++] =
207 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100208#endif
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000209 options->host_key_files[options->num_host_key_files++] =
210 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100211 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100212 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100213 if (options->num_ports == 0)
214 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000215 if (options->address_family == -1)
216 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100217 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000218 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000219 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000220 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100221 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000222 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000223 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000224 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100225 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100226 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100227 if (options->ignore_user_known_hosts == -1)
228 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->print_motd == -1)
230 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000231 if (options->print_lastlog == -1)
232 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100233 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100234 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100235 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100236 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100237 if (options->x11_use_localhost == -1)
238 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000239 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000240 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100241 if (options->permit_tty == -1)
242 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000243 if (options->permit_user_rc == -1)
244 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100245 if (options->strict_modes == -1)
246 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100247 if (options->tcp_keep_alive == -1)
248 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100249 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100250 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100251 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000252 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000253 if (options->hostbased_authentication == -1)
254 options->hostbased_authentication = 0;
255 if (options->hostbased_uses_name_from_packet_only == -1)
256 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100257 if (options->pubkey_authentication == -1)
258 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100259 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000260 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100261 if (options->kerberos_or_local_passwd == -1)
262 options->kerberos_or_local_passwd = 1;
263 if (options->kerberos_ticket_cleanup == -1)
264 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100265 if (options->kerberos_get_afs_token == -1)
266 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000267 if (options->gss_authentication == -1)
268 options->gss_authentication = 0;
269 if (options->gss_cleanup_creds == -1)
270 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000271 if (options->gss_strict_acceptor == -1)
272 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100273 if (options->password_authentication == -1)
274 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100275 if (options->kbd_interactive_authentication == -1)
276 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000277 if (options->challenge_response_authentication == -1)
278 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100279 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100280 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000281 if (options->permit_user_env == -1)
282 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000283 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000284 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000285 if (options->rekey_limit == -1)
286 options->rekey_limit = 0;
287 if (options->rekey_interval == -1)
288 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100289 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100290 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000291 if (options->allow_streamlocal_forwarding == -1)
292 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000293 if (options->allow_agent_forwarding == -1)
294 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000295 if (options->fwd_opts.gateway_ports == -1)
296 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000297 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100298 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000299 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100300 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000301 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100302 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000303 if (options->max_authtries == -1)
304 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000305 if (options->max_sessions == -1)
306 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000307 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000308 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000309 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100310 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000311 if (options->client_alive_count_max == -1)
312 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000313 if (options->num_authkeys_files == 0) {
314 options->authorized_keys_files[options->num_authkeys_files++] =
315 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
316 options->authorized_keys_files[options->num_authkeys_files++] =
317 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
318 }
Damien Millerd27b9472005-12-13 19:29:02 +1100319 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100320 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100321 if (options->ip_qos_interactive == -1)
322 options->ip_qos_interactive = IPTOS_LOWDELAY;
323 if (options->ip_qos_bulk == -1)
324 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000325 if (options->version_addendum == NULL)
326 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000327 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
328 options->fwd_opts.streamlocal_bind_mask = 0177;
329 if (options->fwd_opts.streamlocal_bind_unlink == -1)
330 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000331 if (options->fingerprint_hash == -1)
332 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000333
djm@openbsd.orged085102015-10-29 08:05:01 +0000334 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000335
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000336 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000337 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000338 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000339
djm@openbsd.org161cf412014-12-22 07:55:51 +0000340#define CLEAR_ON_NONE(v) \
341 do { \
342 if (option_clear_or_none(v)) { \
343 free(v); \
344 v = NULL; \
345 } \
346 } while(0)
347 CLEAR_ON_NONE(options->pid_file);
348 CLEAR_ON_NONE(options->xauth_location);
349 CLEAR_ON_NONE(options->banner);
350 CLEAR_ON_NONE(options->trusted_user_ca_keys);
351 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000352 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000353 CLEAR_ON_NONE(options->adm_forced_command);
354 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000355 for (i = 0; i < options->num_host_key_files; i++)
356 CLEAR_ON_NONE(options->host_key_files[i]);
357 for (i = 0; i < options->num_host_cert_files; i++)
358 CLEAR_ON_NONE(options->host_cert_files[i]);
359#undef CLEAR_ON_NONE
360
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000361 /* Similar handling for AuthenticationMethods=any */
362 if (options->num_auth_methods == 1 &&
363 strcmp(options->auth_methods[0], "any") == 0) {
364 free(options->auth_methods[0]);
365 options->auth_methods[0] = NULL;
366 options->num_auth_methods = 0;
367 }
368
Tim Rice40017b02002-07-14 13:36:49 -0700369#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000370 if (use_privsep && options->compression == 1) {
371 error("This platform does not support both privilege "
372 "separation and compression");
373 error("Compression disabled");
374 options->compression = 0;
375 }
376#endif
377
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000378}
379
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000380/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100381typedef enum {
382 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100383 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000384 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100385 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000386 sPort, sHostKeyFile, sLoginGraceTime,
387 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000388 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100389 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100390 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000391 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100392 sPasswordAuthentication, sKbdInteractiveAuthentication,
393 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000394 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100395 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100396 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000397 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000398 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000399 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000400 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
401 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000402 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000403 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000404 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000405 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000406 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
407 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100408 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100409 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100410 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000411 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000412 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000413 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100414 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000415 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000416 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000417 sAllowStreamLocalForwarding, sFingerprintHash,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000418 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000419} ServerOpCodes;
420
Darren Tucker45150472006-07-12 22:34:17 +1000421#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
422#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
423#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
424
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000425/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100426static struct {
427 const char *name;
428 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000429 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100430} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100431 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000432#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000433 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000434#else
Darren Tucker45150472006-07-12 22:34:17 +1000435 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000436#endif
Darren Tucker45150472006-07-12 22:34:17 +1000437 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100438 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000439 { "port", sPort, SSHCFG_GLOBAL },
440 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
441 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000442 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000443 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000444 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000445 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000446 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100447 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000448 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
449 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
450 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000451 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100452 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000453 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000454 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000455 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000456 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100457 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000458 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000459 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000460#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100461 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000462 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
463 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100464#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000465 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000466#else
Darren Tucker45150472006-07-12 22:34:17 +1000467 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100468#endif
469#else
Darren Tucker1629c072007-02-19 22:25:37 +1100470 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000471 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
472 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
473 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000474#endif
Darren Tucker45150472006-07-12 22:34:17 +1000475 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
476 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000477#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100478 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000479 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000480 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000481#else
Darren Tucker1629c072007-02-19 22:25:37 +1100482 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000483 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000484 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000485#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100486 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
487 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100488 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000489 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
490 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
491 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
492 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
493 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100494#ifdef DISABLE_LASTLOG
495 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
496#else
Darren Tucker45150472006-07-12 22:34:17 +1000497 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100498#endif
Darren Tucker45150472006-07-12 22:34:17 +1000499 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
500 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000501 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
502 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
503 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000504 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
505 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100506 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000507 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000508 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000509 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000510 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
512 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
513 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000514 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000515 { "allowusers", sAllowUsers, SSHCFG_ALL },
516 { "denyusers", sDenyUsers, SSHCFG_ALL },
517 { "allowgroups", sAllowGroups, SSHCFG_ALL },
518 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000519 { "ciphers", sCiphers, SSHCFG_GLOBAL },
520 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000521 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
523 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
524 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000525 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000526 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100527 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000528 { "usedns", sUseDNS, SSHCFG_GLOBAL },
529 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
530 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
531 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
532 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000533 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000534 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000535 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000536 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000537 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100538 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000539 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000540 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000541 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000542 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100543 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100544 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100545 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
546 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000547 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000548 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100549 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100550 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
551 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000552 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
553 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000554 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100555 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000556 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
557 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
558 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000559 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000560 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000561};
562
Darren Tuckere7140f22008-06-10 23:01:51 +1000563static struct {
564 int val;
565 char *text;
566} tunmode_desc[] = {
567 { SSH_TUNMODE_NO, "no" },
568 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
569 { SSH_TUNMODE_ETHERNET, "ethernet" },
570 { SSH_TUNMODE_YES, "yes" },
571 { -1, NULL }
572};
573
Damien Miller5428f641999-11-25 11:54:57 +1100574/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000575 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100576 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000577
Damien Miller4af51302000-04-16 11:18:38 +1000578static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100579parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000580 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000582 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000583
Damien Miller95def091999-11-25 00:26:21 +1100584 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000585 if (strcasecmp(cp, keywords[i].name) == 0) {
586 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100587 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000588 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000589
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000590 error("%s: line %d: Bad configuration option: %s",
591 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100592 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000593}
594
Darren Tucker88b6fb22010-01-13 22:44:29 +1100595char *
596derelativise_path(const char *path)
597{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000598 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100599
djm@openbsd.org161cf412014-12-22 07:55:51 +0000600 if (strcasecmp(path, "none") == 0)
601 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100602 expanded = tilde_expand_filename(path, getuid());
603 if (*expanded == '/')
604 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100605 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100606 fatal("%s: getcwd: %s", __func__, strerror(errno));
607 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000608 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100609 return ret;
610}
611
Ben Lindstrombba81212001-06-25 05:01:22 +0000612static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100613add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100614{
Damien Millereccb9de2005-06-17 12:59:34 +1000615 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100616
Ben Lindstrom19066a12001-04-12 23:39:26 +0000617 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000618 for (i = 0; i < options->num_ports; i++)
619 add_one_listen_addr(options, addr, options->ports[i]);
620 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000621 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000622}
623
Ben Lindstrombba81212001-06-25 05:01:22 +0000624static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100625add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000626{
627 struct addrinfo hints, *ai, *aitop;
628 char strport[NI_MAXSERV];
629 int gaierr;
630
631 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100632 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000633 hints.ai_socktype = SOCK_STREAM;
634 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100635 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000636 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
637 fatal("bad addr or host: %s (%s)",
638 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100639 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000640 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
641 ;
642 ai->ai_next = options->listen_addrs;
643 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100644}
645
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000646/*
647 * Queue a ListenAddress to be processed once we have all of the Ports
648 * and AddressFamily options.
649 */
650static void
651queue_listen_addr(ServerOptions *options, char *addr, int port)
652{
653 options->queued_listen_addrs = xreallocarray(
654 options->queued_listen_addrs, options->num_queued_listens + 1,
655 sizeof(addr));
656 options->queued_listen_ports = xreallocarray(
657 options->queued_listen_ports, options->num_queued_listens + 1,
658 sizeof(port));
659 options->queued_listen_addrs[options->num_queued_listens] =
660 xstrdup(addr);
661 options->queued_listen_ports[options->num_queued_listens] = port;
662 options->num_queued_listens++;
663}
664
665/*
666 * Process queued (text) ListenAddress entries.
667 */
668static void
669process_queued_listen_addrs(ServerOptions *options)
670{
671 u_int i;
672
673 if (options->num_ports == 0)
674 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
675 if (options->address_family == -1)
676 options->address_family = AF_UNSPEC;
677
678 for (i = 0; i < options->num_queued_listens; i++) {
679 add_listen_addr(options, options->queued_listen_addrs[i],
680 options->queued_listen_ports[i]);
681 free(options->queued_listen_addrs[i]);
682 options->queued_listen_addrs[i] = NULL;
683 }
684 free(options->queued_listen_addrs);
685 options->queued_listen_addrs = NULL;
686 free(options->queued_listen_ports);
687 options->queued_listen_ports = NULL;
688 options->num_queued_listens = 0;
689}
690
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000691struct connection_info *
692get_connection_info(int populate, int use_dns)
693{
djm@openbsd.org95767262016-03-07 19:02:43 +0000694 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695 static struct connection_info ci;
696
697 if (!populate)
698 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000699 ci.host = auth_get_canonical_hostname(ssh, use_dns);
700 ci.address = ssh_remote_ipaddr(ssh);
701 ci.laddress = ssh_local_ipaddr(ssh);
702 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000703 return &ci;
704}
705
Darren Tucker45150472006-07-12 22:34:17 +1000706/*
707 * The strategy for the Match blocks is that the config file is parsed twice.
708 *
709 * The first time is at startup. activep is initialized to 1 and the
710 * directives in the global context are processed and acted on. Hitting a
711 * Match directive unsets activep and the directives inside the block are
712 * checked for syntax only.
713 *
714 * The second time is after a connection has been established but before
715 * authentication. activep is initialized to 2 and global config directives
716 * are ignored since they have already been processed. If the criteria in a
717 * Match block is met, activep is set and the subsequent directives
718 * processed and actioned until EOF or another Match block unsets it. Any
719 * options set are copied into the main server config.
720 *
721 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000722 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000723 *
724 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
725 * Match Address 192.168.0.*
726 * Tag trusted
727 * Match Group wheel
728 * Tag trusted
729 * Match Tag trusted
730 * AllowTcpForwarding yes
731 * GatewayPorts clientspecified
732 * [...]
733 *
734 * - Add a PermittedChannelRequests directive
735 * Match Group shell
736 * PermittedChannelRequests session,forwarded-tcpip
737 */
738
739static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000740match_cfg_line_group(const char *grps, int line, const char *user)
741{
742 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000743 struct passwd *pw;
744
Damien Miller565ca3f2006-08-19 00:23:15 +1000745 if (user == NULL)
746 goto out;
747
748 if ((pw = getpwnam(user)) == NULL) {
749 debug("Can't match group at line %d because user %.100s does "
750 "not exist", line, user);
751 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
752 debug("Can't Match group because user %.100s not in any group "
753 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000754 } else if (ga_match_pattern_list(grps) != 1) {
755 debug("user %.100s does not match group list %.100s at line %d",
756 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000757 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000758 debug("user %.100s matched group list %.100s at line %d", user,
759 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000760 result = 1;
761 }
762out:
763 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000764 return result;
765}
766
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000767/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000768 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100769 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000770 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000771 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000772static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000773match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000774{
Damien Millercf31f382013-10-24 21:02:56 +1100775 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000776 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000777
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000778 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000779 debug3("checking syntax for 'Match %s'", cp);
780 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000781 debug3("checking match for '%s' user %s host %s addr %s "
782 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
783 ci->host ? ci->host : "(null)",
784 ci->address ? ci->address : "(null)",
785 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000786
787 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100788 attributes++;
789 if (strcasecmp(attrib, "all") == 0) {
790 if (attributes != 1 ||
791 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
792 error("'all' cannot be combined with other "
793 "Match attributes");
794 return -1;
795 }
796 *condition = cp;
797 return 1;
798 }
Darren Tucker45150472006-07-12 22:34:17 +1000799 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
800 error("Missing Match criteria for %s", attrib);
801 return -1;
802 }
Darren Tucker45150472006-07-12 22:34:17 +1000803 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000804 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000805 result = 0;
806 continue;
807 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000808 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000809 result = 0;
810 else
811 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000812 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000813 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000814 if (ci == NULL || ci->user == NULL) {
815 result = 0;
816 continue;
817 }
818 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000819 case -1:
820 return -1;
821 case 0:
822 result = 0;
823 }
Darren Tucker45150472006-07-12 22:34:17 +1000824 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000825 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000826 result = 0;
827 continue;
828 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000829 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000830 result = 0;
831 else
832 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000833 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000834 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000835 if (ci == NULL || ci->address == NULL) {
836 result = 0;
837 continue;
838 }
839 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000840 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000841 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000842 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000843 break;
844 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000845 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000846 result = 0;
847 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000848 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000849 return -1;
850 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000851 } else if (strcasecmp(attrib, "localaddress") == 0){
852 if (ci == NULL || ci->laddress == NULL) {
853 result = 0;
854 continue;
855 }
856 switch (addr_match_list(ci->laddress, arg)) {
857 case 1:
858 debug("connection from %.100s matched "
859 "'LocalAddress %.100s' at line %d",
860 ci->laddress, arg, line);
861 break;
862 case 0:
863 case -1:
864 result = 0;
865 break;
866 case -2:
867 return -1;
868 }
869 } else if (strcasecmp(attrib, "localport") == 0) {
870 if ((port = a2port(arg)) == -1) {
871 error("Invalid LocalPort '%s' on Match line",
872 arg);
873 return -1;
874 }
875 if (ci == NULL || ci->lport == 0) {
876 result = 0;
877 continue;
878 }
879 /* TODO support port lists */
880 if (port == ci->lport)
881 debug("connection from %.100s matched "
882 "'LocalPort %d' at line %d",
883 ci->laddress, port, line);
884 else
885 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000886 } else {
887 error("Unsupported Match attribute %s", attrib);
888 return -1;
889 }
890 }
Damien Millercf31f382013-10-24 21:02:56 +1100891 if (attributes == 0) {
892 error("One or more attributes required for Match");
893 return -1;
894 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000895 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000896 debug3("match %sfound", result ? "" : "not ");
897 *condition = cp;
898 return result;
899}
900
Damien Millere2754432006-07-24 14:06:47 +1000901#define WHITESPACE " \t\r\n"
902
Damien Miller33322122011-06-20 14:43:11 +1000903/* Multistate option parsing */
904struct multistate {
905 char *key;
906 int value;
907};
908static const struct multistate multistate_addressfamily[] = {
909 { "inet", AF_INET },
910 { "inet6", AF_INET6 },
911 { "any", AF_UNSPEC },
912 { NULL, -1 }
913};
914static const struct multistate multistate_permitrootlogin[] = {
915 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000916 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000917 { "forced-commands-only", PERMIT_FORCED_ONLY },
918 { "yes", PERMIT_YES },
919 { "no", PERMIT_NO },
920 { NULL, -1 }
921};
922static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +0000923 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +0000924 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +1000925 { "no", COMP_NONE },
926 { NULL, -1 }
927};
928static const struct multistate multistate_gatewayports[] = {
929 { "clientspecified", 2 },
930 { "yes", 1 },
931 { "no", 0 },
932 { NULL, -1 }
933};
Damien Miller69ff1df2011-06-23 08:30:03 +1000934static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000935 { "yes", PRIVSEP_NOSANDBOX },
936 { "sandbox", PRIVSEP_ON },
937 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000938 { "no", PRIVSEP_OFF },
939 { NULL, -1 }
940};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100941static const struct multistate multistate_tcpfwd[] = {
942 { "yes", FORWARD_ALLOW },
943 { "all", FORWARD_ALLOW },
944 { "no", FORWARD_DENY },
945 { "remote", FORWARD_REMOTE },
946 { "local", FORWARD_LOCAL },
947 { NULL, -1 }
948};
Damien Miller33322122011-06-20 14:43:11 +1000949
Ben Lindstromade03f62001-12-06 18:22:17 +0000950int
951process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000952 const char *filename, int linenum, int *activep,
953 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000954{
Darren Tucker09c0f032013-05-16 20:48:57 +1000955 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000956 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100957 SyslogFacility *log_facility_ptr;
958 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000959 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000960 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000961 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000962 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000963 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000964
965 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100966 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100967 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000968 /* Ignore leading whitespace */
969 if (*arg == '\0')
970 arg = strdelim(&cp);
971 if (!arg || !*arg || *arg == '#')
972 return 0;
973 intptr = NULL;
974 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000975 opcode = parse_token(arg, filename, linenum, &flags);
976
977 if (activep == NULL) { /* We are processing a command line directive */
978 cmdline = 1;
979 activep = &cmdline;
980 }
981 if (*activep && opcode != sMatch)
982 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
983 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000984 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000985 fatal("%s line %d: Directive '%s' is not allowed "
986 "within a Match block", filename, linenum, arg);
987 } else { /* this is a directive we have already processed */
988 while (arg)
989 arg = strdelim(&cp);
990 return 0;
991 }
992 }
993
Ben Lindstromade03f62001-12-06 18:22:17 +0000994 switch (opcode) {
995 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000996 case sUsePAM:
997 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000998 goto parse_flag;
999
1000 /* Standard Options */
1001 case sBadOption:
1002 return -1;
1003 case sPort:
1004 /* ignore ports from configfile if cmdline specifies ports */
1005 if (options->ports_from_cmdline)
1006 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001007 if (options->num_ports >= MAX_PORTS)
1008 fatal("%s line %d: too many ports.",
1009 filename, linenum);
1010 arg = strdelim(&cp);
1011 if (!arg || *arg == '\0')
1012 fatal("%s line %d: missing port number.",
1013 filename, linenum);
1014 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001015 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001016 fatal("%s line %d: Badly formatted port number.",
1017 filename, linenum);
1018 break;
1019
Ben Lindstromade03f62001-12-06 18:22:17 +00001020 case sLoginGraceTime:
1021 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001022 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001023 arg = strdelim(&cp);
1024 if (!arg || *arg == '\0')
1025 fatal("%s line %d: missing time value.",
1026 filename, linenum);
1027 if ((value = convtime(arg)) == -1)
1028 fatal("%s line %d: invalid time value.",
1029 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001030 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001031 *intptr = value;
1032 break;
1033
Ben Lindstromade03f62001-12-06 18:22:17 +00001034 case sListenAddress:
1035 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001036 if (arg == NULL || *arg == '\0')
1037 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001039 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1040 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1041 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001042 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001043 break;
1044 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001045 p = hpdelim(&arg);
1046 if (p == NULL)
1047 fatal("%s line %d: bad address:port usage",
1048 filename, linenum);
1049 p = cleanhostname(p);
1050 if (arg == NULL)
1051 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001052 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001053 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001054
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001055 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001056
Ben Lindstromade03f62001-12-06 18:22:17 +00001057 break;
1058
Darren Tucker0f383232005-01-20 10:57:56 +11001059 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001060 intptr = &options->address_family;
1061 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001062 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001063 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001064 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001065 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001066 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001067 value = -1;
1068 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1069 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1070 value = multistate_ptr[i].value;
1071 break;
1072 }
1073 }
1074 if (value == -1)
1075 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001076 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001077 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001078 *intptr = value;
1079 break;
1080
Ben Lindstromade03f62001-12-06 18:22:17 +00001081 case sHostKeyFile:
1082 intptr = &options->num_host_key_files;
1083 if (*intptr >= MAX_HOSTKEYS)
1084 fatal("%s line %d: too many host keys specified (max %d).",
1085 filename, linenum, MAX_HOSTKEYS);
1086 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001087 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001088 arg = strdelim(&cp);
1089 if (!arg || *arg == '\0')
1090 fatal("%s line %d: missing file name.",
1091 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001092 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001093 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001094 /* increase optional counter */
1095 if (intptr != NULL)
1096 *intptr = *intptr + 1;
1097 }
1098 break;
1099
Damien Miller85b45e02013-07-20 13:21:52 +10001100 case sHostKeyAgent:
1101 charptr = &options->host_key_agent;
1102 arg = strdelim(&cp);
1103 if (!arg || *arg == '\0')
1104 fatal("%s line %d: missing socket name.",
1105 filename, linenum);
1106 if (*activep && *charptr == NULL)
1107 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1108 xstrdup(arg) : derelativise_path(arg);
1109 break;
1110
Damien Miller0a80ca12010-02-27 07:55:05 +11001111 case sHostCertificate:
1112 intptr = &options->num_host_cert_files;
1113 if (*intptr >= MAX_HOSTKEYS)
1114 fatal("%s line %d: too many host certificates "
1115 "specified (max %d).", filename, linenum,
1116 MAX_HOSTCERTS);
1117 charptr = &options->host_cert_files[*intptr];
1118 goto parse_filename;
Damien Miller0a80ca12010-02-27 07:55:05 +11001119
Ben Lindstromade03f62001-12-06 18:22:17 +00001120 case sPidFile:
1121 charptr = &options->pid_file;
1122 goto parse_filename;
1123
1124 case sPermitRootLogin:
1125 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001126 multistate_ptr = multistate_permitrootlogin;
1127 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001128
1129 case sIgnoreRhosts:
1130 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001131 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001132 arg = strdelim(&cp);
1133 if (!arg || *arg == '\0')
1134 fatal("%s line %d: missing yes/no argument.",
1135 filename, linenum);
1136 value = 0; /* silence compiler */
1137 if (strcmp(arg, "yes") == 0)
1138 value = 1;
1139 else if (strcmp(arg, "no") == 0)
1140 value = 0;
1141 else
1142 fatal("%s line %d: Bad yes/no argument: %s",
1143 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001144 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001145 *intptr = value;
1146 break;
1147
1148 case sIgnoreUserKnownHosts:
1149 intptr = &options->ignore_user_known_hosts;
1150 goto parse_flag;
1151
Ben Lindstromade03f62001-12-06 18:22:17 +00001152 case sHostbasedAuthentication:
1153 intptr = &options->hostbased_authentication;
1154 goto parse_flag;
1155
1156 case sHostbasedUsesNameFromPacketOnly:
1157 intptr = &options->hostbased_uses_name_from_packet_only;
1158 goto parse_flag;
1159
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001160 case sHostbasedAcceptedKeyTypes:
1161 charptr = &options->hostbased_key_types;
1162 parse_keytypes:
1163 arg = strdelim(&cp);
1164 if (!arg || *arg == '\0')
1165 fatal("%s line %d: Missing argument.",
1166 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001167 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001168 fatal("%s line %d: Bad key types '%s'.",
1169 filename, linenum, arg ? arg : "<NONE>");
1170 if (*activep && *charptr == NULL)
1171 *charptr = xstrdup(arg);
1172 break;
1173
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001174 case sHostKeyAlgorithms:
1175 charptr = &options->hostkeyalgorithms;
1176 goto parse_keytypes;
1177
Ben Lindstromade03f62001-12-06 18:22:17 +00001178 case sPubkeyAuthentication:
1179 intptr = &options->pubkey_authentication;
1180 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001181
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001182 case sPubkeyAcceptedKeyTypes:
1183 charptr = &options->pubkey_key_types;
1184 goto parse_keytypes;
1185
Ben Lindstromade03f62001-12-06 18:22:17 +00001186 case sKerberosAuthentication:
1187 intptr = &options->kerberos_authentication;
1188 goto parse_flag;
1189
1190 case sKerberosOrLocalPasswd:
1191 intptr = &options->kerberos_or_local_passwd;
1192 goto parse_flag;
1193
1194 case sKerberosTicketCleanup:
1195 intptr = &options->kerberos_ticket_cleanup;
1196 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001197
Darren Tucker22ef5082003-12-31 11:37:34 +11001198 case sKerberosGetAFSToken:
1199 intptr = &options->kerberos_get_afs_token;
1200 goto parse_flag;
1201
Darren Tucker0efd1552003-08-26 11:49:55 +10001202 case sGssAuthentication:
1203 intptr = &options->gss_authentication;
1204 goto parse_flag;
1205
1206 case sGssCleanupCreds:
1207 intptr = &options->gss_cleanup_creds;
1208 goto parse_flag;
1209
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001210 case sGssStrictAcceptor:
1211 intptr = &options->gss_strict_acceptor;
1212 goto parse_flag;
1213
Ben Lindstromade03f62001-12-06 18:22:17 +00001214 case sPasswordAuthentication:
1215 intptr = &options->password_authentication;
1216 goto parse_flag;
1217
1218 case sKbdInteractiveAuthentication:
1219 intptr = &options->kbd_interactive_authentication;
1220 goto parse_flag;
1221
1222 case sChallengeResponseAuthentication:
1223 intptr = &options->challenge_response_authentication;
1224 goto parse_flag;
1225
1226 case sPrintMotd:
1227 intptr = &options->print_motd;
1228 goto parse_flag;
1229
1230 case sPrintLastLog:
1231 intptr = &options->print_lastlog;
1232 goto parse_flag;
1233
1234 case sX11Forwarding:
1235 intptr = &options->x11_forwarding;
1236 goto parse_flag;
1237
1238 case sX11DisplayOffset:
1239 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001240 parse_int:
1241 arg = strdelim(&cp);
1242 if (!arg || *arg == '\0')
1243 fatal("%s line %d: missing integer value.",
1244 filename, linenum);
1245 value = atoi(arg);
1246 if (*activep && *intptr == -1)
1247 *intptr = value;
1248 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001249
Damien Miller95c249f2002-02-05 12:11:34 +11001250 case sX11UseLocalhost:
1251 intptr = &options->x11_use_localhost;
1252 goto parse_flag;
1253
Ben Lindstromade03f62001-12-06 18:22:17 +00001254 case sXAuthLocation:
1255 charptr = &options->xauth_location;
1256 goto parse_filename;
1257
Damien Miller5ff30c62013-10-30 22:21:50 +11001258 case sPermitTTY:
1259 intptr = &options->permit_tty;
1260 goto parse_flag;
1261
Damien Miller72e6b5c2014-07-04 09:00:04 +10001262 case sPermitUserRC:
1263 intptr = &options->permit_user_rc;
1264 goto parse_flag;
1265
Ben Lindstromade03f62001-12-06 18:22:17 +00001266 case sStrictModes:
1267 intptr = &options->strict_modes;
1268 goto parse_flag;
1269
Damien Miller12c150e2003-12-17 16:31:10 +11001270 case sTCPKeepAlive:
1271 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001272 goto parse_flag;
1273
1274 case sEmptyPasswd:
1275 intptr = &options->permit_empty_passwd;
1276 goto parse_flag;
1277
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001278 case sPermitUserEnvironment:
1279 intptr = &options->permit_user_env;
1280 goto parse_flag;
1281
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001282 case sCompression:
1283 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001284 multistate_ptr = multistate_compression;
1285 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001286
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001287 case sRekeyLimit:
1288 arg = strdelim(&cp);
1289 if (!arg || *arg == '\0')
1290 fatal("%.200s line %d: Missing argument.", filename,
1291 linenum);
1292 if (strcmp(arg, "default") == 0) {
1293 val64 = 0;
1294 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001295 if (scan_scaled(arg, &val64) == -1)
1296 fatal("%.200s line %d: Bad number '%s': %s",
1297 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001298 if (val64 != 0 && val64 < 16)
1299 fatal("%.200s line %d: RekeyLimit too small",
1300 filename, linenum);
1301 }
1302 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001303 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001304 if (cp != NULL) { /* optional rekey interval present */
1305 if (strcmp(cp, "none") == 0) {
1306 (void)strdelim(&cp); /* discard */
1307 break;
1308 }
1309 intptr = &options->rekey_interval;
1310 goto parse_time;
1311 }
1312 break;
1313
Ben Lindstromade03f62001-12-06 18:22:17 +00001314 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001315 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001316 multistate_ptr = multistate_gatewayports;
1317 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001318
Damien Miller3a961dc2003-06-03 10:25:48 +10001319 case sUseDNS:
1320 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001321 goto parse_flag;
1322
1323 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001324 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001325 arg = strdelim(&cp);
1326 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001327 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001328 fatal("%.200s line %d: unsupported log facility '%s'",
1329 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001330 if (*log_facility_ptr == -1)
1331 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001332 break;
1333
1334 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001335 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001336 arg = strdelim(&cp);
1337 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001338 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001339 fatal("%.200s line %d: unsupported log level '%s'",
1340 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001341 if (*log_level_ptr == -1)
1342 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001343 break;
1344
1345 case sAllowTcpForwarding:
1346 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001347 multistate_ptr = multistate_tcpfwd;
1348 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001349
Damien Miller7acefbb2014-07-18 14:11:24 +10001350 case sAllowStreamLocalForwarding:
1351 intptr = &options->allow_streamlocal_forwarding;
1352 multistate_ptr = multistate_tcpfwd;
1353 goto parse_multistate;
1354
Damien Miller4f755cd2008-05-19 14:57:41 +10001355 case sAllowAgentForwarding:
1356 intptr = &options->allow_agent_forwarding;
1357 goto parse_flag;
1358
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001359 case sUsePrivilegeSeparation:
1360 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001361 multistate_ptr = multistate_privsep;
1362 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001363
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 case sAllowUsers:
1365 while ((arg = strdelim(&cp)) && *arg != '\0') {
1366 if (options->num_allow_users >= MAX_ALLOW_USERS)
1367 fatal("%s line %d: too many allow users.",
1368 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001369 if (match_user(NULL, NULL, NULL, arg) == -1)
1370 fatal("%s line %d: invalid AllowUsers pattern: "
1371 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001372 if (!*activep)
1373 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001374 options->allow_users[options->num_allow_users++] =
1375 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001376 }
1377 break;
1378
1379 case sDenyUsers:
1380 while ((arg = strdelim(&cp)) && *arg != '\0') {
1381 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001382 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001383 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001384 if (match_user(NULL, NULL, NULL, arg) == -1)
1385 fatal("%s line %d: invalid DenyUsers pattern: "
1386 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001387 if (!*activep)
1388 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001389 options->deny_users[options->num_deny_users++] =
1390 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001391 }
1392 break;
1393
1394 case sAllowGroups:
1395 while ((arg = strdelim(&cp)) && *arg != '\0') {
1396 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1397 fatal("%s line %d: too many allow groups.",
1398 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001399 if (!*activep)
1400 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001401 options->allow_groups[options->num_allow_groups++] =
1402 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001403 }
1404 break;
1405
1406 case sDenyGroups:
1407 while ((arg = strdelim(&cp)) && *arg != '\0') {
1408 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1409 fatal("%s line %d: too many deny groups.",
1410 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001411 if (!*activep)
1412 continue;
1413 options->deny_groups[options->num_deny_groups++] =
1414 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001415 }
1416 break;
1417
1418 case sCiphers:
1419 arg = strdelim(&cp);
1420 if (!arg || *arg == '\0')
1421 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001422 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001423 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1424 filename, linenum, arg ? arg : "<NONE>");
1425 if (options->ciphers == NULL)
1426 options->ciphers = xstrdup(arg);
1427 break;
1428
1429 case sMacs:
1430 arg = strdelim(&cp);
1431 if (!arg || *arg == '\0')
1432 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001433 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001434 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1435 filename, linenum, arg ? arg : "<NONE>");
1436 if (options->macs == NULL)
1437 options->macs = xstrdup(arg);
1438 break;
1439
Damien Millerd5f62bf2010-09-24 22:11:14 +10001440 case sKexAlgorithms:
1441 arg = strdelim(&cp);
1442 if (!arg || *arg == '\0')
1443 fatal("%s line %d: Missing argument.",
1444 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001445 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001446 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1447 filename, linenum, arg ? arg : "<NONE>");
1448 if (options->kex_algorithms == NULL)
1449 options->kex_algorithms = xstrdup(arg);
1450 break;
1451
Ben Lindstromade03f62001-12-06 18:22:17 +00001452 case sSubsystem:
1453 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1454 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001455 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001456 }
1457 arg = strdelim(&cp);
1458 if (!arg || *arg == '\0')
1459 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001460 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001461 if (!*activep) {
1462 arg = strdelim(&cp);
1463 break;
1464 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001465 for (i = 0; i < options->num_subsystems; i++)
1466 if (strcmp(arg, options->subsystem_name[i]) == 0)
1467 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001468 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001469 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1470 arg = strdelim(&cp);
1471 if (!arg || *arg == '\0')
1472 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001473 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001474 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001475
1476 /* Collect arguments (separate to executable) */
1477 p = xstrdup(arg);
1478 len = strlen(p) + 1;
1479 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1480 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001481 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001482 strlcat(p, " ", len);
1483 strlcat(p, arg, len);
1484 }
1485 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001486 options->num_subsystems++;
1487 break;
1488
1489 case sMaxStartups:
1490 arg = strdelim(&cp);
1491 if (!arg || *arg == '\0')
1492 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001493 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001494 if ((n = sscanf(arg, "%d:%d:%d",
1495 &options->max_startups_begin,
1496 &options->max_startups_rate,
1497 &options->max_startups)) == 3) {
1498 if (options->max_startups_begin >
1499 options->max_startups ||
1500 options->max_startups_rate > 100 ||
1501 options->max_startups_rate < 1)
1502 fatal("%s line %d: Illegal MaxStartups spec.",
1503 filename, linenum);
1504 } else if (n != 1)
1505 fatal("%s line %d: Illegal MaxStartups spec.",
1506 filename, linenum);
1507 else
1508 options->max_startups = options->max_startups_begin;
1509 break;
1510
Darren Tucker89413db2004-05-24 10:36:23 +10001511 case sMaxAuthTries:
1512 intptr = &options->max_authtries;
1513 goto parse_int;
1514
Damien Miller7207f642008-05-19 15:34:50 +10001515 case sMaxSessions:
1516 intptr = &options->max_sessions;
1517 goto parse_int;
1518
Ben Lindstromade03f62001-12-06 18:22:17 +00001519 case sBanner:
1520 charptr = &options->banner;
1521 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001522
Ben Lindstromade03f62001-12-06 18:22:17 +00001523 /*
1524 * These options can contain %X options expanded at
1525 * connect time, so that you can specify paths like:
1526 *
1527 * AuthorizedKeysFile /etc/ssh_keys/%u
1528 */
1529 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001530 if (*activep && options->num_authkeys_files == 0) {
1531 while ((arg = strdelim(&cp)) && *arg != '\0') {
1532 if (options->num_authkeys_files >=
1533 MAX_AUTHKEYS_FILES)
1534 fatal("%s line %d: "
1535 "too many authorized keys files.",
1536 filename, linenum);
1537 options->authorized_keys_files[
1538 options->num_authkeys_files++] =
1539 tilde_expand_filename(arg, getuid());
1540 }
1541 }
1542 return 0;
1543
Damien Miller30da3442010-05-10 11:58:03 +10001544 case sAuthorizedPrincipalsFile:
1545 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001546 arg = strdelim(&cp);
1547 if (!arg || *arg == '\0')
1548 fatal("%s line %d: missing file name.",
1549 filename, linenum);
1550 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001551 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001552 /* increase optional counter */
1553 if (intptr != NULL)
1554 *intptr = *intptr + 1;
1555 }
1556 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001557
1558 case sClientAliveInterval:
1559 intptr = &options->client_alive_interval;
1560 goto parse_time;
1561
1562 case sClientAliveCountMax:
1563 intptr = &options->client_alive_count_max;
1564 goto parse_int;
1565
Darren Tucker46bc0752004-05-02 22:11:30 +10001566 case sAcceptEnv:
1567 while ((arg = strdelim(&cp)) && *arg != '\0') {
1568 if (strchr(arg, '=') != NULL)
1569 fatal("%s line %d: Invalid environment name.",
1570 filename, linenum);
1571 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1572 fatal("%s line %d: too many allow env.",
1573 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001574 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001575 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001576 options->accept_env[options->num_accept_env++] =
1577 xstrdup(arg);
1578 }
1579 break;
1580
Damien Millerd27b9472005-12-13 19:29:02 +11001581 case sPermitTunnel:
1582 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001583 arg = strdelim(&cp);
1584 if (!arg || *arg == '\0')
1585 fatal("%s line %d: Missing yes/point-to-point/"
1586 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001587 value = -1;
1588 for (i = 0; tunmode_desc[i].val != -1; i++)
1589 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1590 value = tunmode_desc[i].val;
1591 break;
1592 }
1593 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001594 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1595 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001596 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001597 *intptr = value;
1598 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001599
Darren Tucker45150472006-07-12 22:34:17 +10001600 case sMatch:
1601 if (cmdline)
1602 fatal("Match directive not supported as a command-line "
1603 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001604 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001605 if (value < 0)
1606 fatal("%s line %d: Bad Match condition", filename,
1607 linenum);
1608 *activep = value;
1609 break;
1610
Damien Miller9b439df2006-07-24 14:04:00 +10001611 case sPermitOpen:
1612 arg = strdelim(&cp);
1613 if (!arg || *arg == '\0')
1614 fatal("%s line %d: missing PermitOpen specification",
1615 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001616 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001617 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001618 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001619 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001620 options->num_permitted_opens = 0;
1621 }
Damien Miller9b439df2006-07-24 14:04:00 +10001622 break;
1623 }
Damien Millerc6081482012-04-22 11:18:53 +10001624 if (strcmp(arg, "none") == 0) {
1625 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001626 options->num_permitted_opens = 1;
1627 channel_disable_adm_local_opens();
1628 }
1629 break;
1630 }
Damien Millera29b95e2007-01-05 16:28:36 +11001631 if (*activep && n == -1)
1632 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001633 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1634 p = hpdelim(&arg);
1635 if (p == NULL)
1636 fatal("%s line %d: missing host in PermitOpen",
1637 filename, linenum);
1638 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001639 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001640 fatal("%s line %d: bad port number in "
1641 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001642 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001643 options->num_permitted_opens =
1644 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001645 }
Damien Miller9b439df2006-07-24 14:04:00 +10001646 break;
1647
Damien Millere2754432006-07-24 14:06:47 +10001648 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001649 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001650 fatal("%.200s line %d: Missing argument.", filename,
1651 linenum);
1652 len = strspn(cp, WHITESPACE);
1653 if (*activep && options->adm_forced_command == NULL)
1654 options->adm_forced_command = xstrdup(cp + len);
1655 return 0;
1656
Damien Millerd8cb1f12008-02-10 22:40:12 +11001657 case sChrootDirectory:
1658 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001659
1660 arg = strdelim(&cp);
1661 if (!arg || *arg == '\0')
1662 fatal("%s line %d: missing file name.",
1663 filename, linenum);
1664 if (*activep && *charptr == NULL)
1665 *charptr = xstrdup(arg);
1666 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001667
Damien Miller1aed65e2010-03-04 21:53:35 +11001668 case sTrustedUserCAKeys:
1669 charptr = &options->trusted_user_ca_keys;
1670 goto parse_filename;
1671
1672 case sRevokedKeys:
1673 charptr = &options->revoked_keys_file;
1674 goto parse_filename;
1675
Damien Miller0dac6fb2010-11-20 15:19:38 +11001676 case sIPQoS:
1677 arg = strdelim(&cp);
1678 if ((value = parse_ipqos(arg)) == -1)
1679 fatal("%s line %d: Bad IPQoS value: %s",
1680 filename, linenum, arg);
1681 arg = strdelim(&cp);
1682 if (arg == NULL)
1683 value2 = value;
1684 else if ((value2 = parse_ipqos(arg)) == -1)
1685 fatal("%s line %d: Bad IPQoS value: %s",
1686 filename, linenum, arg);
1687 if (*activep) {
1688 options->ip_qos_interactive = value;
1689 options->ip_qos_bulk = value2;
1690 }
1691 break;
1692
Damien Miller23528812012-04-22 11:24:43 +10001693 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001694 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001695 fatal("%.200s line %d: Missing argument.", filename,
1696 linenum);
1697 len = strspn(cp, WHITESPACE);
1698 if (*activep && options->version_addendum == NULL) {
1699 if (strcasecmp(cp + len, "none") == 0)
1700 options->version_addendum = xstrdup("");
1701 else if (strchr(cp + len, '\r') != NULL)
1702 fatal("%.200s line %d: Invalid argument",
1703 filename, linenum);
1704 else
1705 options->version_addendum = xstrdup(cp + len);
1706 }
1707 return 0;
1708
Damien Miller09d3e122012-10-31 08:58:58 +11001709 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001710 if (cp == NULL)
1711 fatal("%.200s line %d: Missing argument.", filename,
1712 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001713 len = strspn(cp, WHITESPACE);
1714 if (*activep && options->authorized_keys_command == NULL) {
1715 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1716 fatal("%.200s line %d: AuthorizedKeysCommand "
1717 "must be an absolute path",
1718 filename, linenum);
1719 options->authorized_keys_command = xstrdup(cp + len);
1720 }
1721 return 0;
1722
1723 case sAuthorizedKeysCommandUser:
1724 charptr = &options->authorized_keys_command_user;
1725
1726 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001727 if (!arg || *arg == '\0')
1728 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1729 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001730 if (*activep && *charptr == NULL)
1731 *charptr = xstrdup(arg);
1732 break;
1733
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001734 case sAuthorizedPrincipalsCommand:
1735 if (cp == NULL)
1736 fatal("%.200s line %d: Missing argument.", filename,
1737 linenum);
1738 len = strspn(cp, WHITESPACE);
1739 if (*activep &&
1740 options->authorized_principals_command == NULL) {
1741 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1742 fatal("%.200s line %d: "
1743 "AuthorizedPrincipalsCommand must be "
1744 "an absolute path", filename, linenum);
1745 options->authorized_principals_command =
1746 xstrdup(cp + len);
1747 }
1748 return 0;
1749
1750 case sAuthorizedPrincipalsCommandUser:
1751 charptr = &options->authorized_principals_command_user;
1752
1753 arg = strdelim(&cp);
1754 if (!arg || *arg == '\0')
1755 fatal("%s line %d: missing "
1756 "AuthorizedPrincipalsCommandUser argument.",
1757 filename, linenum);
1758 if (*activep && *charptr == NULL)
1759 *charptr = xstrdup(arg);
1760 break;
1761
Damien Millera6e3f012012-11-04 23:21:40 +11001762 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001763 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001764 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001765 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001766 while ((arg = strdelim(&cp)) && *arg != '\0') {
1767 if (options->num_auth_methods >=
1768 MAX_AUTH_METHODS)
1769 fatal("%s line %d: "
1770 "too many authentication methods.",
1771 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001772 if (strcmp(arg, "any") == 0) {
1773 if (options->num_auth_methods > 0) {
1774 fatal("%s line %d: \"any\" "
1775 "must appear alone in "
1776 "AuthenticationMethods",
1777 filename, linenum);
1778 }
1779 value = 1;
1780 } else if (value) {
1781 fatal("%s line %d: \"any\" must appear "
1782 "alone in AuthenticationMethods",
1783 filename, linenum);
1784 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001785 fatal("%s line %d: invalid "
1786 "authentication method list.",
1787 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001788 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001789 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001790 if (!*activep)
1791 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001792 options->auth_methods[
1793 options->num_auth_methods++] = xstrdup(arg);
1794 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001795 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001796 fatal("%s line %d: no AuthenticationMethods "
1797 "specified", filename, linenum);
1798 }
Damien Millera6e3f012012-11-04 23:21:40 +11001799 }
1800 return 0;
1801
Damien Miller7acefbb2014-07-18 14:11:24 +10001802 case sStreamLocalBindMask:
1803 arg = strdelim(&cp);
1804 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001805 fatal("%s line %d: missing StreamLocalBindMask "
1806 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001807 /* Parse mode in octal format */
1808 value = strtol(arg, &p, 8);
1809 if (arg == p || value < 0 || value > 0777)
1810 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001811 if (*activep)
1812 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001813 break;
1814
1815 case sStreamLocalBindUnlink:
1816 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1817 goto parse_flag;
1818
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001819 case sFingerprintHash:
1820 arg = strdelim(&cp);
1821 if (!arg || *arg == '\0')
1822 fatal("%.200s line %d: Missing argument.",
1823 filename, linenum);
1824 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1825 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1826 filename, linenum, arg);
1827 if (*activep)
1828 options->fingerprint_hash = value;
1829 break;
1830
Ben Lindstromade03f62001-12-06 18:22:17 +00001831 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001832 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001833 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001834 do_log2(opcode == sIgnore ?
1835 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1836 "%s line %d: %s option %s", filename, linenum,
1837 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001838 while (arg)
1839 arg = strdelim(&cp);
1840 break;
1841
Ben Lindstromade03f62001-12-06 18:22:17 +00001842 default:
1843 fatal("%s line %d: Missing handler for opcode %s (%d)",
1844 filename, linenum, arg, opcode);
1845 }
1846 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1847 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1848 filename, linenum, arg);
1849 return 0;
1850}
1851
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001852/* Reads the server configuration file. */
1853
Damien Miller4af51302000-04-16 11:18:38 +10001854void
Darren Tucker645ab752004-06-25 13:33:20 +10001855load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001856{
Damien Miller46cb75a2012-07-31 12:22:37 +10001857 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001858 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001859 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001860
Darren Tucker645ab752004-06-25 13:33:20 +10001861 debug2("%s: filename %s", __func__, filename);
1862 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001863 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001864 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001865 }
Darren Tucker645ab752004-06-25 13:33:20 +10001866 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001867 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001868 lineno++;
1869 if (strlen(line) == sizeof(line) - 1)
1870 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001871 /*
1872 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001873 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001874 * line numbers later for error messages
1875 */
1876 if ((cp = strchr(line, '#')) != NULL)
1877 memcpy(cp, "\n", 2);
1878 cp = line + strspn(line, " \t\r");
1879
1880 buffer_append(conf, cp, strlen(cp));
1881 }
1882 buffer_append(conf, "\0", 1);
1883 fclose(f);
1884 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1885}
1886
1887void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001888parse_server_match_config(ServerOptions *options,
1889 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001890{
Darren Tucker45150472006-07-12 22:34:17 +10001891 ServerOptions mo;
1892
1893 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001894 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001895 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001896}
1897
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001898int parse_server_match_testspec(struct connection_info *ci, char *spec)
1899{
1900 char *p;
1901
1902 while ((p = strsep(&spec, ",")) && *p != '\0') {
1903 if (strncmp(p, "addr=", 5) == 0) {
1904 ci->address = xstrdup(p + 5);
1905 } else if (strncmp(p, "host=", 5) == 0) {
1906 ci->host = xstrdup(p + 5);
1907 } else if (strncmp(p, "user=", 5) == 0) {
1908 ci->user = xstrdup(p + 5);
1909 } else if (strncmp(p, "laddr=", 6) == 0) {
1910 ci->laddress = xstrdup(p + 6);
1911 } else if (strncmp(p, "lport=", 6) == 0) {
1912 ci->lport = a2port(p + 6);
1913 if (ci->lport == -1) {
1914 fprintf(stderr, "Invalid port '%s' in test mode"
1915 " specification %s\n", p+6, p);
1916 return -1;
1917 }
1918 } else {
1919 fprintf(stderr, "Invalid test mode specification %s\n",
1920 p);
1921 return -1;
1922 }
1923 }
1924 return 0;
1925}
1926
1927/*
1928 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1929 * empty spec.
1930 */
1931int server_match_spec_complete(struct connection_info *ci)
1932{
1933 if (ci->user && ci->host && ci->address)
1934 return 1; /* complete */
1935 if (!ci->user && !ci->host && !ci->address)
1936 return -1; /* empty */
1937 return 0; /* partial */
1938}
1939
Darren Tucker1629c072007-02-19 22:25:37 +11001940/*
1941 * Copy any supported values that are set.
1942 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001943 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001944 * array values that are not used pre-authentication, because any that we
1945 * do use must be explictly sent in mm_getpwnamallow().
1946 */
Darren Tucker45150472006-07-12 22:34:17 +10001947void
Darren Tucker1629c072007-02-19 22:25:37 +11001948copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001949{
Damien Miller534b2cc2013-12-05 14:07:27 +11001950#define M_CP_INTOPT(n) do {\
1951 if (src->n != -1) \
1952 dst->n = src->n; \
1953} while (0)
1954
Darren Tucker1629c072007-02-19 22:25:37 +11001955 M_CP_INTOPT(password_authentication);
1956 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11001957 M_CP_INTOPT(pubkey_authentication);
1958 M_CP_INTOPT(kerberos_authentication);
1959 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001960 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001961 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001962 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001963 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001964
1965 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001966 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001967 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001968 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001969 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001970 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11001971 M_CP_INTOPT(x11_display_offset);
1972 M_CP_INTOPT(x11_forwarding);
1973 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001974 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001975 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001976 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001977 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001978 M_CP_INTOPT(ip_qos_interactive);
1979 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001980 M_CP_INTOPT(rekey_limit);
1981 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001982
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001983 /*
1984 * The bind_mask is a mode_t that may be unsigned, so we can't use
1985 * M_CP_INTOPT - it does a signed comparison that causes compiler
1986 * warnings.
1987 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00001988 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001989 dst->fwd_opts.streamlocal_bind_mask =
1990 src->fwd_opts.streamlocal_bind_mask;
1991 }
1992
Damien Miller534b2cc2013-12-05 14:07:27 +11001993 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1994#define M_CP_STROPT(n) do {\
1995 if (src->n != NULL && dst->n != src->n) { \
1996 free(dst->n); \
1997 dst->n = src->n; \
1998 } \
1999} while(0)
2000#define M_CP_STRARRAYOPT(n, num_n) do {\
2001 if (src->num_n != 0) { \
2002 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2003 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2004 } \
2005} while(0)
2006
Damien Millerf2e407e2011-05-20 19:04:14 +10002007 /* See comment in servconf.h */
2008 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002009
djm@openbsd.orged085102015-10-29 08:05:01 +00002010 /* Arguments that accept '+...' need to be expanded */
2011 assemble_algorithms(dst);
2012
Damien Millerc2411902011-05-20 19:03:49 +10002013 /*
2014 * The only things that should be below this point are string options
2015 * which are only used after authentication.
2016 */
Damien Miller5d74e582011-05-20 19:03:31 +10002017 if (preauth)
2018 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002019
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002020 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002021 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002022 if (option_clear_or_none(dst->adm_forced_command)) {
2023 free(dst->adm_forced_command);
2024 dst->adm_forced_command = NULL;
2025 }
Damien Miller5d74e582011-05-20 19:03:31 +10002026 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002027 if (option_clear_or_none(dst->chroot_directory)) {
2028 free(dst->chroot_directory);
2029 dst->chroot_directory = NULL;
2030 }
Darren Tucker45150472006-07-12 22:34:17 +10002031}
2032
Darren Tucker1629c072007-02-19 22:25:37 +11002033#undef M_CP_INTOPT
2034#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002035#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002036
Darren Tucker45150472006-07-12 22:34:17 +10002037void
2038parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002039 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002040{
2041 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002042 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002043
2044 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2045
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002046 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2047 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002048 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002049 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002050 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002051 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002052 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002053 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002054 }
Darren Tuckera627d422013-06-02 07:31:17 +10002055 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002056 if (bad_options > 0)
2057 fatal("%s: terminating, %d bad configuration options",
2058 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002059 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002060}
Darren Tuckere7140f22008-06-10 23:01:51 +10002061
2062static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002063fmt_multistate_int(int val, const struct multistate *m)
2064{
2065 u_int i;
2066
2067 for (i = 0; m[i].key != NULL; i++) {
2068 if (m[i].value == val)
2069 return m[i].key;
2070 }
2071 return "UNKNOWN";
2072}
2073
2074static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002075fmt_intarg(ServerOpCodes code, int val)
2076{
Damien Miller82c55872011-06-23 08:20:30 +10002077 if (val == -1)
2078 return "unset";
2079 switch (code) {
2080 case sAddressFamily:
2081 return fmt_multistate_int(val, multistate_addressfamily);
2082 case sPermitRootLogin:
2083 return fmt_multistate_int(val, multistate_permitrootlogin);
2084 case sGatewayPorts:
2085 return fmt_multistate_int(val, multistate_gatewayports);
2086 case sCompression:
2087 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002088 case sUsePrivilegeSeparation:
2089 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002090 case sAllowTcpForwarding:
2091 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002092 case sAllowStreamLocalForwarding:
2093 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002094 case sFingerprintHash:
2095 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002096 default:
2097 switch (val) {
2098 case 0:
2099 return "no";
2100 case 1:
2101 return "yes";
2102 default:
2103 return "UNKNOWN";
2104 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002105 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002106}
2107
2108static const char *
2109lookup_opcode_name(ServerOpCodes code)
2110{
2111 u_int i;
2112
2113 for (i = 0; keywords[i].name != NULL; i++)
2114 if (keywords[i].opcode == code)
2115 return(keywords[i].name);
2116 return "UNKNOWN";
2117}
2118
2119static void
2120dump_cfg_int(ServerOpCodes code, int val)
2121{
2122 printf("%s %d\n", lookup_opcode_name(code), val);
2123}
2124
2125static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002126dump_cfg_oct(ServerOpCodes code, int val)
2127{
2128 printf("%s 0%o\n", lookup_opcode_name(code), val);
2129}
2130
2131static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002132dump_cfg_fmtint(ServerOpCodes code, int val)
2133{
2134 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2135}
2136
2137static void
2138dump_cfg_string(ServerOpCodes code, const char *val)
2139{
2140 if (val == NULL)
2141 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002142 printf("%s %s\n", lookup_opcode_name(code),
2143 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002144}
2145
2146static void
2147dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2148{
2149 u_int i;
2150
2151 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002152 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2153}
2154
2155static void
2156dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2157{
2158 u_int i;
2159
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002160 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002161 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002162 printf("%s", lookup_opcode_name(code));
2163 for (i = 0; i < count; i++)
2164 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002165 if (code == sAuthenticationMethods && count == 0)
2166 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002167 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002168}
2169
2170void
2171dump_config(ServerOptions *o)
2172{
2173 u_int i;
2174 int ret;
2175 struct addrinfo *ai;
2176 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002177 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002178
2179 /* these are usually at the top of the config */
2180 for (i = 0; i < o->num_ports; i++)
2181 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002182 dump_cfg_fmtint(sAddressFamily, o->address_family);
2183
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002184 /*
2185 * ListenAddress must be after Port. add_one_listen_addr pushes
2186 * addresses onto a stack, so to maintain ordering we need to
2187 * print these in reverse order.
2188 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002189 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2190 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2191 sizeof(addr), port, sizeof(port),
2192 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2193 error("getnameinfo failed: %.100s",
2194 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2195 strerror(errno));
2196 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002197 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002198 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002199 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2200 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002201 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002202 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2203 addr, port, laddr2);
2204 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002205 }
2206 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002207 printf("%s", laddr1);
2208 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002209
2210 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002211#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002212 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002213#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002214 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002215 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2216 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002217 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002218 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2219 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002220 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002221
2222 /* formatted integer arguments */
2223 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2224 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2225 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002226 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2227 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2228 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002229 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002230#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002231 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2232 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2233 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002234# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002235 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002236# endif
2237#endif
2238#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002239 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2240 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002241#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002242 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2243 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2244 o->kbd_interactive_authentication);
2245 dump_cfg_fmtint(sChallengeResponseAuthentication,
2246 o->challenge_response_authentication);
2247 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002248#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002249 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002250#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002251 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2252 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002253 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002254 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002255 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2256 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2257 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2258 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002259 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002260 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002261 dump_cfg_fmtint(sUseDNS, o->use_dns);
2262 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002263 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002264 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002265 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
Darren Tuckere7140f22008-06-10 23:01:51 +10002266 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002267 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002268
2269 /* string arguments */
2270 dump_cfg_string(sPidFile, o->pid_file);
2271 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002272 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2273 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002274 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002275 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002276 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002277 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2278 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002279 dump_cfg_string(sAuthorizedPrincipalsFile,
2280 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002281 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2282 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002283 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2284 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002285 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2286 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002287 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002288 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002289 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002290 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2291 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002292 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2293 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002294 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2295 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002296
2297 /* string arguments requiring a lookup */
2298 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2299 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2300
2301 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002302 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2303 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002304 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2305 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002306 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002307 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002308 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2309 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2310 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2311 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2312 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002313 dump_cfg_strarray_oneline(sAuthenticationMethods,
2314 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002315
2316 /* other arguments */
2317 for (i = 0; i < o->num_subsystems; i++)
2318 printf("subsystem %s %s\n", o->subsystem_name[i],
2319 o->subsystem_args[i]);
2320
2321 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2322 o->max_startups_rate, o->max_startups);
2323
2324 for (i = 0; tunmode_desc[i].val != -1; i++)
2325 if (tunmode_desc[i].val == o->permit_tun) {
2326 s = tunmode_desc[i].text;
2327 break;
2328 }
2329 dump_cfg_string(sPermitTunnel, s);
2330
Damien Miller91475862011-05-05 14:14:34 +10002331 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2332 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002333
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002334 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002335 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002336
Darren Tuckere7140f22008-06-10 23:01:51 +10002337 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002338}