blob: 1880b8cfdc9058c16a7afa853cd3a6021cc66613 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +00002/* $OpenBSD: servconf.c,v 1.303 2017/02/03 05:05:56 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;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000166 options->disable_forwarding = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000167}
168
djm@openbsd.org161cf412014-12-22 07:55:51 +0000169/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
170static int
171option_clear_or_none(const char *o)
172{
173 return o == NULL || strcasecmp(o, "none") == 0;
174}
175
djm@openbsd.orged085102015-10-29 08:05:01 +0000176static void
177assemble_algorithms(ServerOptions *o)
178{
179 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
180 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
181 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
182 kex_assemble_names(KEX_DEFAULT_PK_ALG,
183 &o->hostkeyalgorithms) != 0 ||
184 kex_assemble_names(KEX_DEFAULT_PK_ALG,
185 &o->hostbased_key_types) != 0 ||
186 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
187 fatal("kex_assemble_names failed");
188}
189
Damien Miller4af51302000-04-16 11:18:38 +1000190void
Damien Miller95def091999-11-25 00:26:21 +1100191fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000192{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000193 int i;
194
Damien Miller726273e2001-11-12 11:40:11 +1100195 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000196 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000197 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100198
199 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100200 if (options->num_host_key_files == 0) {
201 /* fill default hostkeys for protocols */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000202 options->host_key_files[options->num_host_key_files++] =
203 _PATH_HOST_RSA_KEY_FILE;
204 options->host_key_files[options->num_host_key_files++] =
205 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100206#ifdef OPENSSL_HAS_ECC
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000207 options->host_key_files[options->num_host_key_files++] =
208 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100209#endif
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000210 options->host_key_files[options->num_host_key_files++] =
211 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100212 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100213 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100214 if (options->num_ports == 0)
215 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000216 if (options->address_family == -1)
217 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100218 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000219 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000220 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000221 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000223 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000224 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000225 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100227 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->ignore_user_known_hosts == -1)
229 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->print_motd == -1)
231 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000232 if (options->print_lastlog == -1)
233 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100235 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100237 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100238 if (options->x11_use_localhost == -1)
239 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000240 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000241 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100242 if (options->permit_tty == -1)
243 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000244 if (options->permit_user_rc == -1)
245 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->strict_modes == -1)
247 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100248 if (options->tcp_keep_alive == -1)
249 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100250 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100251 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100252 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000253 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000254 if (options->hostbased_authentication == -1)
255 options->hostbased_authentication = 0;
256 if (options->hostbased_uses_name_from_packet_only == -1)
257 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100258 if (options->pubkey_authentication == -1)
259 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100260 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000261 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->kerberos_or_local_passwd == -1)
263 options->kerberos_or_local_passwd = 1;
264 if (options->kerberos_ticket_cleanup == -1)
265 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100266 if (options->kerberos_get_afs_token == -1)
267 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000268 if (options->gss_authentication == -1)
269 options->gss_authentication = 0;
270 if (options->gss_cleanup_creds == -1)
271 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000272 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000273 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100274 if (options->password_authentication == -1)
275 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100276 if (options->kbd_interactive_authentication == -1)
277 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000278 if (options->challenge_response_authentication == -1)
279 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100281 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000282 if (options->permit_user_env == -1)
283 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000284 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000285 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000286 if (options->rekey_limit == -1)
287 options->rekey_limit = 0;
288 if (options->rekey_interval == -1)
289 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100290 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100291 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000292 if (options->allow_streamlocal_forwarding == -1)
293 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000294 if (options->allow_agent_forwarding == -1)
295 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000296 if (options->fwd_opts.gateway_ports == -1)
297 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000298 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100299 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000300 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100301 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000302 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100303 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000304 if (options->max_authtries == -1)
305 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000306 if (options->max_sessions == -1)
307 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000308 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000309 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000310 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100311 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000312 if (options->client_alive_count_max == -1)
313 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000314 if (options->num_authkeys_files == 0) {
315 options->authorized_keys_files[options->num_authkeys_files++] =
316 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
317 options->authorized_keys_files[options->num_authkeys_files++] =
318 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
319 }
Damien Millerd27b9472005-12-13 19:29:02 +1100320 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100321 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100322 if (options->ip_qos_interactive == -1)
323 options->ip_qos_interactive = IPTOS_LOWDELAY;
324 if (options->ip_qos_bulk == -1)
325 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000326 if (options->version_addendum == NULL)
327 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000328 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
329 options->fwd_opts.streamlocal_bind_mask = 0177;
330 if (options->fwd_opts.streamlocal_bind_unlink == -1)
331 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000332 if (options->fingerprint_hash == -1)
333 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000334 if (options->disable_forwarding == -1)
335 options->disable_forwarding = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000336
djm@openbsd.orged085102015-10-29 08:05:01 +0000337 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000338
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000339 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000340 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000341 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000342
djm@openbsd.org161cf412014-12-22 07:55:51 +0000343#define CLEAR_ON_NONE(v) \
344 do { \
345 if (option_clear_or_none(v)) { \
346 free(v); \
347 v = NULL; \
348 } \
349 } while(0)
350 CLEAR_ON_NONE(options->pid_file);
351 CLEAR_ON_NONE(options->xauth_location);
352 CLEAR_ON_NONE(options->banner);
353 CLEAR_ON_NONE(options->trusted_user_ca_keys);
354 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000355 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000356 CLEAR_ON_NONE(options->adm_forced_command);
357 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000358 for (i = 0; i < options->num_host_key_files; i++)
359 CLEAR_ON_NONE(options->host_key_files[i]);
360 for (i = 0; i < options->num_host_cert_files; i++)
361 CLEAR_ON_NONE(options->host_cert_files[i]);
362#undef CLEAR_ON_NONE
363
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000364 /* Similar handling for AuthenticationMethods=any */
365 if (options->num_auth_methods == 1 &&
366 strcmp(options->auth_methods[0], "any") == 0) {
367 free(options->auth_methods[0]);
368 options->auth_methods[0] = NULL;
369 options->num_auth_methods = 0;
370 }
371
Tim Rice40017b02002-07-14 13:36:49 -0700372#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000373 if (use_privsep && options->compression == 1) {
374 error("This platform does not support both privilege "
375 "separation and compression");
376 error("Compression disabled");
377 options->compression = 0;
378 }
379#endif
380
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381}
382
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100384typedef enum {
385 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100386 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000387 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100388 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000389 sPort, sHostKeyFile, sLoginGraceTime,
390 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000391 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100392 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100393 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000394 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100395 sPasswordAuthentication, sKbdInteractiveAuthentication,
396 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000397 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100398 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100399 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000400 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000401 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000402 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000403 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
404 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000405 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000406 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000407 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000408 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000409 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
410 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100411 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100412 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100413 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000414 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000415 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000416 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100417 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000418 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000419 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000420 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000421 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422} ServerOpCodes;
423
Darren Tucker45150472006-07-12 22:34:17 +1000424#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
425#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
426#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
427
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000428/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100429static struct {
430 const char *name;
431 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000432 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100433} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100434 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000435#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000436 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000437#else
Darren Tucker45150472006-07-12 22:34:17 +1000438 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000439#endif
Darren Tucker45150472006-07-12 22:34:17 +1000440 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100441 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "port", sPort, SSHCFG_GLOBAL },
443 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
444 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000445 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000447 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000448 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000449 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100450 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
452 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
453 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000454 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100455 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000456 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000457 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000458 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000459 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100460 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000461 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000462 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000463#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000465 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
466 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100467#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000468 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000469#else
Darren Tucker45150472006-07-12 22:34:17 +1000470 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100471#endif
472#else
Darren Tucker1629c072007-02-19 22:25:37 +1100473 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000474 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
475 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
476 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000477#endif
Darren Tucker45150472006-07-12 22:34:17 +1000478 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
479 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000480#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100481 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000482 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000483 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000484#else
Darren Tucker1629c072007-02-19 22:25:37 +1100485 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000487 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000488#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100489 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
490 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100491 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000492 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
493 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
494 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
495 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
496 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100497#ifdef DISABLE_LASTLOG
498 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
499#else
Darren Tucker45150472006-07-12 22:34:17 +1000500 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100501#endif
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
503 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000504 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
505 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
506 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000507 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
508 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100509 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000510 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000511 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000513 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
515 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
516 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000517 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000518 { "allowusers", sAllowUsers, SSHCFG_ALL },
519 { "denyusers", sDenyUsers, SSHCFG_ALL },
520 { "allowgroups", sAllowGroups, SSHCFG_ALL },
521 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "ciphers", sCiphers, SSHCFG_GLOBAL },
523 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000524 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
526 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
527 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000528 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000529 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100530 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000531 { "usedns", sUseDNS, SSHCFG_GLOBAL },
532 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
533 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000534 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
535 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000536 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000537 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000538 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000539 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000540 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100541 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000542 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000543 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000544 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000545 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100546 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100547 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100548 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
549 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000550 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000551 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100552 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100553 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
554 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000555 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
556 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000557 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100558 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000559 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
560 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
561 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000562 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000563 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000564 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000565};
566
Darren Tuckere7140f22008-06-10 23:01:51 +1000567static struct {
568 int val;
569 char *text;
570} tunmode_desc[] = {
571 { SSH_TUNMODE_NO, "no" },
572 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
573 { SSH_TUNMODE_ETHERNET, "ethernet" },
574 { SSH_TUNMODE_YES, "yes" },
575 { -1, NULL }
576};
577
Damien Miller5428f641999-11-25 11:54:57 +1100578/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000579 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100580 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581
Damien Miller4af51302000-04-16 11:18:38 +1000582static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100583parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000584 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000585{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000586 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000587
Damien Miller95def091999-11-25 00:26:21 +1100588 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000589 if (strcasecmp(cp, keywords[i].name) == 0) {
590 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100591 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000592 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000593
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000594 error("%s: line %d: Bad configuration option: %s",
595 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100596 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000597}
598
Darren Tucker88b6fb22010-01-13 22:44:29 +1100599char *
600derelativise_path(const char *path)
601{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000602 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100603
djm@openbsd.org161cf412014-12-22 07:55:51 +0000604 if (strcasecmp(path, "none") == 0)
605 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100606 expanded = tilde_expand_filename(path, getuid());
607 if (*expanded == '/')
608 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100609 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100610 fatal("%s: getcwd: %s", __func__, strerror(errno));
611 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000612 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100613 return ret;
614}
615
Ben Lindstrombba81212001-06-25 05:01:22 +0000616static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100617add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100618{
Damien Millereccb9de2005-06-17 12:59:34 +1000619 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100620
Ben Lindstrom19066a12001-04-12 23:39:26 +0000621 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000622 for (i = 0; i < options->num_ports; i++)
623 add_one_listen_addr(options, addr, options->ports[i]);
624 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000625 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000626}
627
Ben Lindstrombba81212001-06-25 05:01:22 +0000628static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100629add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000630{
631 struct addrinfo hints, *ai, *aitop;
632 char strport[NI_MAXSERV];
633 int gaierr;
634
635 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100636 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000637 hints.ai_socktype = SOCK_STREAM;
638 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100639 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000640 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
641 fatal("bad addr or host: %s (%s)",
642 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100643 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000644 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
645 ;
646 ai->ai_next = options->listen_addrs;
647 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100648}
649
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000650/*
651 * Queue a ListenAddress to be processed once we have all of the Ports
652 * and AddressFamily options.
653 */
654static void
655queue_listen_addr(ServerOptions *options, char *addr, int port)
656{
657 options->queued_listen_addrs = xreallocarray(
658 options->queued_listen_addrs, options->num_queued_listens + 1,
659 sizeof(addr));
660 options->queued_listen_ports = xreallocarray(
661 options->queued_listen_ports, options->num_queued_listens + 1,
662 sizeof(port));
663 options->queued_listen_addrs[options->num_queued_listens] =
664 xstrdup(addr);
665 options->queued_listen_ports[options->num_queued_listens] = port;
666 options->num_queued_listens++;
667}
668
669/*
670 * Process queued (text) ListenAddress entries.
671 */
672static void
673process_queued_listen_addrs(ServerOptions *options)
674{
675 u_int i;
676
677 if (options->num_ports == 0)
678 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
679 if (options->address_family == -1)
680 options->address_family = AF_UNSPEC;
681
682 for (i = 0; i < options->num_queued_listens; i++) {
683 add_listen_addr(options, options->queued_listen_addrs[i],
684 options->queued_listen_ports[i]);
685 free(options->queued_listen_addrs[i]);
686 options->queued_listen_addrs[i] = NULL;
687 }
688 free(options->queued_listen_addrs);
689 options->queued_listen_addrs = NULL;
690 free(options->queued_listen_ports);
691 options->queued_listen_ports = NULL;
692 options->num_queued_listens = 0;
693}
694
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695struct connection_info *
696get_connection_info(int populate, int use_dns)
697{
djm@openbsd.org95767262016-03-07 19:02:43 +0000698 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000699 static struct connection_info ci;
700
701 if (!populate)
702 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000703 ci.host = auth_get_canonical_hostname(ssh, use_dns);
704 ci.address = ssh_remote_ipaddr(ssh);
705 ci.laddress = ssh_local_ipaddr(ssh);
706 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000707 return &ci;
708}
709
Darren Tucker45150472006-07-12 22:34:17 +1000710/*
711 * The strategy for the Match blocks is that the config file is parsed twice.
712 *
713 * The first time is at startup. activep is initialized to 1 and the
714 * directives in the global context are processed and acted on. Hitting a
715 * Match directive unsets activep and the directives inside the block are
716 * checked for syntax only.
717 *
718 * The second time is after a connection has been established but before
719 * authentication. activep is initialized to 2 and global config directives
720 * are ignored since they have already been processed. If the criteria in a
721 * Match block is met, activep is set and the subsequent directives
722 * processed and actioned until EOF or another Match block unsets it. Any
723 * options set are copied into the main server config.
724 *
725 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000726 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000727 *
728 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
729 * Match Address 192.168.0.*
730 * Tag trusted
731 * Match Group wheel
732 * Tag trusted
733 * Match Tag trusted
734 * AllowTcpForwarding yes
735 * GatewayPorts clientspecified
736 * [...]
737 *
738 * - Add a PermittedChannelRequests directive
739 * Match Group shell
740 * PermittedChannelRequests session,forwarded-tcpip
741 */
742
743static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000744match_cfg_line_group(const char *grps, int line, const char *user)
745{
746 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000747 struct passwd *pw;
748
Damien Miller565ca3f2006-08-19 00:23:15 +1000749 if (user == NULL)
750 goto out;
751
752 if ((pw = getpwnam(user)) == NULL) {
753 debug("Can't match group at line %d because user %.100s does "
754 "not exist", line, user);
755 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
756 debug("Can't Match group because user %.100s not in any group "
757 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000758 } else if (ga_match_pattern_list(grps) != 1) {
759 debug("user %.100s does not match group list %.100s at line %d",
760 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000761 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000762 debug("user %.100s matched group list %.100s at line %d", user,
763 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000764 result = 1;
765 }
766out:
767 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000768 return result;
769}
770
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000771/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000772 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100773 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000774 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000775 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000776static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000777match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000778{
Damien Millercf31f382013-10-24 21:02:56 +1100779 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000780 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000781
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000782 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000783 debug3("checking syntax for 'Match %s'", cp);
784 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000785 debug3("checking match for '%s' user %s host %s addr %s "
786 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
787 ci->host ? ci->host : "(null)",
788 ci->address ? ci->address : "(null)",
789 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000790
791 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100792 attributes++;
793 if (strcasecmp(attrib, "all") == 0) {
794 if (attributes != 1 ||
795 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
796 error("'all' cannot be combined with other "
797 "Match attributes");
798 return -1;
799 }
800 *condition = cp;
801 return 1;
802 }
Darren Tucker45150472006-07-12 22:34:17 +1000803 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
804 error("Missing Match criteria for %s", attrib);
805 return -1;
806 }
Darren Tucker45150472006-07-12 22:34:17 +1000807 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000808 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000809 result = 0;
810 continue;
811 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000812 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000813 result = 0;
814 else
815 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000816 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000817 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000818 if (ci == NULL || ci->user == NULL) {
819 result = 0;
820 continue;
821 }
822 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000823 case -1:
824 return -1;
825 case 0:
826 result = 0;
827 }
Darren Tucker45150472006-07-12 22:34:17 +1000828 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000829 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000830 result = 0;
831 continue;
832 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000833 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000834 result = 0;
835 else
836 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000837 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000838 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000839 if (ci == NULL || ci->address == NULL) {
840 result = 0;
841 continue;
842 }
843 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000844 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000845 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000846 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000847 break;
848 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000849 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000850 result = 0;
851 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000852 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000853 return -1;
854 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000855 } else if (strcasecmp(attrib, "localaddress") == 0){
856 if (ci == NULL || ci->laddress == NULL) {
857 result = 0;
858 continue;
859 }
860 switch (addr_match_list(ci->laddress, arg)) {
861 case 1:
862 debug("connection from %.100s matched "
863 "'LocalAddress %.100s' at line %d",
864 ci->laddress, arg, line);
865 break;
866 case 0:
867 case -1:
868 result = 0;
869 break;
870 case -2:
871 return -1;
872 }
873 } else if (strcasecmp(attrib, "localport") == 0) {
874 if ((port = a2port(arg)) == -1) {
875 error("Invalid LocalPort '%s' on Match line",
876 arg);
877 return -1;
878 }
879 if (ci == NULL || ci->lport == 0) {
880 result = 0;
881 continue;
882 }
883 /* TODO support port lists */
884 if (port == ci->lport)
885 debug("connection from %.100s matched "
886 "'LocalPort %d' at line %d",
887 ci->laddress, port, line);
888 else
889 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000890 } else {
891 error("Unsupported Match attribute %s", attrib);
892 return -1;
893 }
894 }
Damien Millercf31f382013-10-24 21:02:56 +1100895 if (attributes == 0) {
896 error("One or more attributes required for Match");
897 return -1;
898 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000899 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000900 debug3("match %sfound", result ? "" : "not ");
901 *condition = cp;
902 return result;
903}
904
Damien Millere2754432006-07-24 14:06:47 +1000905#define WHITESPACE " \t\r\n"
906
Damien Miller33322122011-06-20 14:43:11 +1000907/* Multistate option parsing */
908struct multistate {
909 char *key;
910 int value;
911};
912static const struct multistate multistate_addressfamily[] = {
913 { "inet", AF_INET },
914 { "inet6", AF_INET6 },
915 { "any", AF_UNSPEC },
916 { NULL, -1 }
917};
918static const struct multistate multistate_permitrootlogin[] = {
919 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000920 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000921 { "forced-commands-only", PERMIT_FORCED_ONLY },
922 { "yes", PERMIT_YES },
923 { "no", PERMIT_NO },
924 { NULL, -1 }
925};
926static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +0000927 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +0000928 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +1000929 { "no", COMP_NONE },
930 { NULL, -1 }
931};
932static const struct multistate multistate_gatewayports[] = {
933 { "clientspecified", 2 },
934 { "yes", 1 },
935 { "no", 0 },
936 { NULL, -1 }
937};
Damien Miller69ff1df2011-06-23 08:30:03 +1000938static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000939 { "yes", PRIVSEP_NOSANDBOX },
940 { "sandbox", PRIVSEP_ON },
941 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000942 { "no", PRIVSEP_OFF },
943 { NULL, -1 }
944};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100945static const struct multistate multistate_tcpfwd[] = {
946 { "yes", FORWARD_ALLOW },
947 { "all", FORWARD_ALLOW },
948 { "no", FORWARD_DENY },
949 { "remote", FORWARD_REMOTE },
950 { "local", FORWARD_LOCAL },
951 { NULL, -1 }
952};
Damien Miller33322122011-06-20 14:43:11 +1000953
Ben Lindstromade03f62001-12-06 18:22:17 +0000954int
955process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000956 const char *filename, int linenum, int *activep,
957 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000958{
Darren Tucker09c0f032013-05-16 20:48:57 +1000959 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000960 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100961 SyslogFacility *log_facility_ptr;
962 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000963 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000964 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000965 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000966 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000967 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000968
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +0000969 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
970 if ((len = strlen(line)) == 0)
971 return 0;
972 for (len--; len > 0; len--) {
973 if (strchr(WHITESPACE "\f", line[len]) == NULL)
974 break;
975 line[len] = '\0';
976 }
977
Ben Lindstromade03f62001-12-06 18:22:17 +0000978 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100979 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100980 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000981 /* Ignore leading whitespace */
982 if (*arg == '\0')
983 arg = strdelim(&cp);
984 if (!arg || !*arg || *arg == '#')
985 return 0;
986 intptr = NULL;
987 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000988 opcode = parse_token(arg, filename, linenum, &flags);
989
990 if (activep == NULL) { /* We are processing a command line directive */
991 cmdline = 1;
992 activep = &cmdline;
993 }
994 if (*activep && opcode != sMatch)
995 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
996 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000997 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000998 fatal("%s line %d: Directive '%s' is not allowed "
999 "within a Match block", filename, linenum, arg);
1000 } else { /* this is a directive we have already processed */
1001 while (arg)
1002 arg = strdelim(&cp);
1003 return 0;
1004 }
1005 }
1006
Ben Lindstromade03f62001-12-06 18:22:17 +00001007 switch (opcode) {
1008 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001009 case sUsePAM:
1010 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001011 goto parse_flag;
1012
1013 /* Standard Options */
1014 case sBadOption:
1015 return -1;
1016 case sPort:
1017 /* ignore ports from configfile if cmdline specifies ports */
1018 if (options->ports_from_cmdline)
1019 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001020 if (options->num_ports >= MAX_PORTS)
1021 fatal("%s line %d: too many ports.",
1022 filename, linenum);
1023 arg = strdelim(&cp);
1024 if (!arg || *arg == '\0')
1025 fatal("%s line %d: missing port number.",
1026 filename, linenum);
1027 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001028 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001029 fatal("%s line %d: Badly formatted port number.",
1030 filename, linenum);
1031 break;
1032
Ben Lindstromade03f62001-12-06 18:22:17 +00001033 case sLoginGraceTime:
1034 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001035 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 arg = strdelim(&cp);
1037 if (!arg || *arg == '\0')
1038 fatal("%s line %d: missing time value.",
1039 filename, linenum);
1040 if ((value = convtime(arg)) == -1)
1041 fatal("%s line %d: invalid time value.",
1042 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001043 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 *intptr = value;
1045 break;
1046
Ben Lindstromade03f62001-12-06 18:22:17 +00001047 case sListenAddress:
1048 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001049 if (arg == NULL || *arg == '\0')
1050 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001051 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001052 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1053 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1054 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001055 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001056 break;
1057 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001058 p = hpdelim(&arg);
1059 if (p == NULL)
1060 fatal("%s line %d: bad address:port usage",
1061 filename, linenum);
1062 p = cleanhostname(p);
1063 if (arg == NULL)
1064 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001065 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001066 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001067
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001068 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001069
Ben Lindstromade03f62001-12-06 18:22:17 +00001070 break;
1071
Darren Tucker0f383232005-01-20 10:57:56 +11001072 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001073 intptr = &options->address_family;
1074 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001075 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001076 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001077 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001078 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001079 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001080 value = -1;
1081 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1082 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1083 value = multistate_ptr[i].value;
1084 break;
1085 }
1086 }
1087 if (value == -1)
1088 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001089 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001090 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001091 *intptr = value;
1092 break;
1093
Ben Lindstromade03f62001-12-06 18:22:17 +00001094 case sHostKeyFile:
1095 intptr = &options->num_host_key_files;
1096 if (*intptr >= MAX_HOSTKEYS)
1097 fatal("%s line %d: too many host keys specified (max %d).",
1098 filename, linenum, MAX_HOSTKEYS);
1099 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001100 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001101 arg = strdelim(&cp);
1102 if (!arg || *arg == '\0')
1103 fatal("%s line %d: missing file name.",
1104 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001105 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001106 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001107 /* increase optional counter */
1108 if (intptr != NULL)
1109 *intptr = *intptr + 1;
1110 }
1111 break;
1112
Damien Miller85b45e02013-07-20 13:21:52 +10001113 case sHostKeyAgent:
1114 charptr = &options->host_key_agent;
1115 arg = strdelim(&cp);
1116 if (!arg || *arg == '\0')
1117 fatal("%s line %d: missing socket name.",
1118 filename, linenum);
1119 if (*activep && *charptr == NULL)
1120 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1121 xstrdup(arg) : derelativise_path(arg);
1122 break;
1123
Damien Miller0a80ca12010-02-27 07:55:05 +11001124 case sHostCertificate:
1125 intptr = &options->num_host_cert_files;
1126 if (*intptr >= MAX_HOSTKEYS)
1127 fatal("%s line %d: too many host certificates "
1128 "specified (max %d).", filename, linenum,
1129 MAX_HOSTCERTS);
1130 charptr = &options->host_cert_files[*intptr];
1131 goto parse_filename;
Damien Miller0a80ca12010-02-27 07:55:05 +11001132
Ben Lindstromade03f62001-12-06 18:22:17 +00001133 case sPidFile:
1134 charptr = &options->pid_file;
1135 goto parse_filename;
1136
1137 case sPermitRootLogin:
1138 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001139 multistate_ptr = multistate_permitrootlogin;
1140 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001141
1142 case sIgnoreRhosts:
1143 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001144 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001145 arg = strdelim(&cp);
1146 if (!arg || *arg == '\0')
1147 fatal("%s line %d: missing yes/no argument.",
1148 filename, linenum);
1149 value = 0; /* silence compiler */
1150 if (strcmp(arg, "yes") == 0)
1151 value = 1;
1152 else if (strcmp(arg, "no") == 0)
1153 value = 0;
1154 else
1155 fatal("%s line %d: Bad yes/no argument: %s",
1156 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001157 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001158 *intptr = value;
1159 break;
1160
1161 case sIgnoreUserKnownHosts:
1162 intptr = &options->ignore_user_known_hosts;
1163 goto parse_flag;
1164
Ben Lindstromade03f62001-12-06 18:22:17 +00001165 case sHostbasedAuthentication:
1166 intptr = &options->hostbased_authentication;
1167 goto parse_flag;
1168
1169 case sHostbasedUsesNameFromPacketOnly:
1170 intptr = &options->hostbased_uses_name_from_packet_only;
1171 goto parse_flag;
1172
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001173 case sHostbasedAcceptedKeyTypes:
1174 charptr = &options->hostbased_key_types;
1175 parse_keytypes:
1176 arg = strdelim(&cp);
1177 if (!arg || *arg == '\0')
1178 fatal("%s line %d: Missing argument.",
1179 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001180 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001181 fatal("%s line %d: Bad key types '%s'.",
1182 filename, linenum, arg ? arg : "<NONE>");
1183 if (*activep && *charptr == NULL)
1184 *charptr = xstrdup(arg);
1185 break;
1186
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001187 case sHostKeyAlgorithms:
1188 charptr = &options->hostkeyalgorithms;
1189 goto parse_keytypes;
1190
Ben Lindstromade03f62001-12-06 18:22:17 +00001191 case sPubkeyAuthentication:
1192 intptr = &options->pubkey_authentication;
1193 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001194
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001195 case sPubkeyAcceptedKeyTypes:
1196 charptr = &options->pubkey_key_types;
1197 goto parse_keytypes;
1198
Ben Lindstromade03f62001-12-06 18:22:17 +00001199 case sKerberosAuthentication:
1200 intptr = &options->kerberos_authentication;
1201 goto parse_flag;
1202
1203 case sKerberosOrLocalPasswd:
1204 intptr = &options->kerberos_or_local_passwd;
1205 goto parse_flag;
1206
1207 case sKerberosTicketCleanup:
1208 intptr = &options->kerberos_ticket_cleanup;
1209 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001210
Darren Tucker22ef5082003-12-31 11:37:34 +11001211 case sKerberosGetAFSToken:
1212 intptr = &options->kerberos_get_afs_token;
1213 goto parse_flag;
1214
Darren Tucker0efd1552003-08-26 11:49:55 +10001215 case sGssAuthentication:
1216 intptr = &options->gss_authentication;
1217 goto parse_flag;
1218
1219 case sGssCleanupCreds:
1220 intptr = &options->gss_cleanup_creds;
1221 goto parse_flag;
1222
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001223 case sGssStrictAcceptor:
1224 intptr = &options->gss_strict_acceptor;
1225 goto parse_flag;
1226
Ben Lindstromade03f62001-12-06 18:22:17 +00001227 case sPasswordAuthentication:
1228 intptr = &options->password_authentication;
1229 goto parse_flag;
1230
1231 case sKbdInteractiveAuthentication:
1232 intptr = &options->kbd_interactive_authentication;
1233 goto parse_flag;
1234
1235 case sChallengeResponseAuthentication:
1236 intptr = &options->challenge_response_authentication;
1237 goto parse_flag;
1238
1239 case sPrintMotd:
1240 intptr = &options->print_motd;
1241 goto parse_flag;
1242
1243 case sPrintLastLog:
1244 intptr = &options->print_lastlog;
1245 goto parse_flag;
1246
1247 case sX11Forwarding:
1248 intptr = &options->x11_forwarding;
1249 goto parse_flag;
1250
1251 case sX11DisplayOffset:
1252 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001253 parse_int:
1254 arg = strdelim(&cp);
1255 if (!arg || *arg == '\0')
1256 fatal("%s line %d: missing integer value.",
1257 filename, linenum);
1258 value = atoi(arg);
1259 if (*activep && *intptr == -1)
1260 *intptr = value;
1261 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001262
Damien Miller95c249f2002-02-05 12:11:34 +11001263 case sX11UseLocalhost:
1264 intptr = &options->x11_use_localhost;
1265 goto parse_flag;
1266
Ben Lindstromade03f62001-12-06 18:22:17 +00001267 case sXAuthLocation:
1268 charptr = &options->xauth_location;
1269 goto parse_filename;
1270
Damien Miller5ff30c62013-10-30 22:21:50 +11001271 case sPermitTTY:
1272 intptr = &options->permit_tty;
1273 goto parse_flag;
1274
Damien Miller72e6b5c2014-07-04 09:00:04 +10001275 case sPermitUserRC:
1276 intptr = &options->permit_user_rc;
1277 goto parse_flag;
1278
Ben Lindstromade03f62001-12-06 18:22:17 +00001279 case sStrictModes:
1280 intptr = &options->strict_modes;
1281 goto parse_flag;
1282
Damien Miller12c150e2003-12-17 16:31:10 +11001283 case sTCPKeepAlive:
1284 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001285 goto parse_flag;
1286
1287 case sEmptyPasswd:
1288 intptr = &options->permit_empty_passwd;
1289 goto parse_flag;
1290
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001291 case sPermitUserEnvironment:
1292 intptr = &options->permit_user_env;
1293 goto parse_flag;
1294
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001295 case sCompression:
1296 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001297 multistate_ptr = multistate_compression;
1298 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001299
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001300 case sRekeyLimit:
1301 arg = strdelim(&cp);
1302 if (!arg || *arg == '\0')
1303 fatal("%.200s line %d: Missing argument.", filename,
1304 linenum);
1305 if (strcmp(arg, "default") == 0) {
1306 val64 = 0;
1307 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001308 if (scan_scaled(arg, &val64) == -1)
1309 fatal("%.200s line %d: Bad number '%s': %s",
1310 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001311 if (val64 != 0 && val64 < 16)
1312 fatal("%.200s line %d: RekeyLimit too small",
1313 filename, linenum);
1314 }
1315 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001316 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001317 if (cp != NULL) { /* optional rekey interval present */
1318 if (strcmp(cp, "none") == 0) {
1319 (void)strdelim(&cp); /* discard */
1320 break;
1321 }
1322 intptr = &options->rekey_interval;
1323 goto parse_time;
1324 }
1325 break;
1326
Ben Lindstromade03f62001-12-06 18:22:17 +00001327 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001328 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001329 multistate_ptr = multistate_gatewayports;
1330 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001331
Damien Miller3a961dc2003-06-03 10:25:48 +10001332 case sUseDNS:
1333 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001334 goto parse_flag;
1335
1336 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001337 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001338 arg = strdelim(&cp);
1339 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001340 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001341 fatal("%.200s line %d: unsupported log facility '%s'",
1342 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001343 if (*log_facility_ptr == -1)
1344 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001345 break;
1346
1347 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001348 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001349 arg = strdelim(&cp);
1350 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001351 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001352 fatal("%.200s line %d: unsupported log level '%s'",
1353 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001354 if (*log_level_ptr == -1)
1355 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001356 break;
1357
1358 case sAllowTcpForwarding:
1359 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001360 multistate_ptr = multistate_tcpfwd;
1361 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001362
Damien Miller7acefbb2014-07-18 14:11:24 +10001363 case sAllowStreamLocalForwarding:
1364 intptr = &options->allow_streamlocal_forwarding;
1365 multistate_ptr = multistate_tcpfwd;
1366 goto parse_multistate;
1367
Damien Miller4f755cd2008-05-19 14:57:41 +10001368 case sAllowAgentForwarding:
1369 intptr = &options->allow_agent_forwarding;
1370 goto parse_flag;
1371
djm@openbsd.org7844f352016-11-30 03:00:05 +00001372 case sDisableForwarding:
1373 intptr = &options->disable_forwarding;
1374 goto parse_flag;
1375
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001376 case sUsePrivilegeSeparation:
1377 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001378 multistate_ptr = multistate_privsep;
1379 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001380
Ben Lindstromade03f62001-12-06 18:22:17 +00001381 case sAllowUsers:
1382 while ((arg = strdelim(&cp)) && *arg != '\0') {
1383 if (options->num_allow_users >= MAX_ALLOW_USERS)
1384 fatal("%s line %d: too many allow users.",
1385 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001386 if (match_user(NULL, NULL, NULL, arg) == -1)
1387 fatal("%s line %d: invalid AllowUsers pattern: "
1388 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001389 if (!*activep)
1390 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001391 options->allow_users[options->num_allow_users++] =
1392 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001393 }
1394 break;
1395
1396 case sDenyUsers:
1397 while ((arg = strdelim(&cp)) && *arg != '\0') {
1398 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001399 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001400 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001401 if (match_user(NULL, NULL, NULL, arg) == -1)
1402 fatal("%s line %d: invalid DenyUsers pattern: "
1403 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001404 if (!*activep)
1405 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001406 options->deny_users[options->num_deny_users++] =
1407 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001408 }
1409 break;
1410
1411 case sAllowGroups:
1412 while ((arg = strdelim(&cp)) && *arg != '\0') {
1413 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1414 fatal("%s line %d: too many allow groups.",
1415 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001416 if (!*activep)
1417 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001418 options->allow_groups[options->num_allow_groups++] =
1419 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001420 }
1421 break;
1422
1423 case sDenyGroups:
1424 while ((arg = strdelim(&cp)) && *arg != '\0') {
1425 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1426 fatal("%s line %d: too many deny groups.",
1427 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001428 if (!*activep)
1429 continue;
1430 options->deny_groups[options->num_deny_groups++] =
1431 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001432 }
1433 break;
1434
1435 case sCiphers:
1436 arg = strdelim(&cp);
1437 if (!arg || *arg == '\0')
1438 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001439 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001440 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1441 filename, linenum, arg ? arg : "<NONE>");
1442 if (options->ciphers == NULL)
1443 options->ciphers = xstrdup(arg);
1444 break;
1445
1446 case sMacs:
1447 arg = strdelim(&cp);
1448 if (!arg || *arg == '\0')
1449 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001450 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001451 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1452 filename, linenum, arg ? arg : "<NONE>");
1453 if (options->macs == NULL)
1454 options->macs = xstrdup(arg);
1455 break;
1456
Damien Millerd5f62bf2010-09-24 22:11:14 +10001457 case sKexAlgorithms:
1458 arg = strdelim(&cp);
1459 if (!arg || *arg == '\0')
1460 fatal("%s line %d: Missing argument.",
1461 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001462 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001463 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1464 filename, linenum, arg ? arg : "<NONE>");
1465 if (options->kex_algorithms == NULL)
1466 options->kex_algorithms = xstrdup(arg);
1467 break;
1468
Ben Lindstromade03f62001-12-06 18:22:17 +00001469 case sSubsystem:
1470 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1471 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001472 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001473 }
1474 arg = strdelim(&cp);
1475 if (!arg || *arg == '\0')
1476 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001477 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001478 if (!*activep) {
1479 arg = strdelim(&cp);
1480 break;
1481 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001482 for (i = 0; i < options->num_subsystems; i++)
1483 if (strcmp(arg, options->subsystem_name[i]) == 0)
1484 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001485 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001486 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1487 arg = strdelim(&cp);
1488 if (!arg || *arg == '\0')
1489 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001490 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001491 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001492
1493 /* Collect arguments (separate to executable) */
1494 p = xstrdup(arg);
1495 len = strlen(p) + 1;
1496 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1497 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001498 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001499 strlcat(p, " ", len);
1500 strlcat(p, arg, len);
1501 }
1502 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001503 options->num_subsystems++;
1504 break;
1505
1506 case sMaxStartups:
1507 arg = strdelim(&cp);
1508 if (!arg || *arg == '\0')
1509 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001510 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001511 if ((n = sscanf(arg, "%d:%d:%d",
1512 &options->max_startups_begin,
1513 &options->max_startups_rate,
1514 &options->max_startups)) == 3) {
1515 if (options->max_startups_begin >
1516 options->max_startups ||
1517 options->max_startups_rate > 100 ||
1518 options->max_startups_rate < 1)
1519 fatal("%s line %d: Illegal MaxStartups spec.",
1520 filename, linenum);
1521 } else if (n != 1)
1522 fatal("%s line %d: Illegal MaxStartups spec.",
1523 filename, linenum);
1524 else
1525 options->max_startups = options->max_startups_begin;
1526 break;
1527
Darren Tucker89413db2004-05-24 10:36:23 +10001528 case sMaxAuthTries:
1529 intptr = &options->max_authtries;
1530 goto parse_int;
1531
Damien Miller7207f642008-05-19 15:34:50 +10001532 case sMaxSessions:
1533 intptr = &options->max_sessions;
1534 goto parse_int;
1535
Ben Lindstromade03f62001-12-06 18:22:17 +00001536 case sBanner:
1537 charptr = &options->banner;
1538 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001539
Ben Lindstromade03f62001-12-06 18:22:17 +00001540 /*
1541 * These options can contain %X options expanded at
1542 * connect time, so that you can specify paths like:
1543 *
1544 * AuthorizedKeysFile /etc/ssh_keys/%u
1545 */
1546 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001547 if (*activep && options->num_authkeys_files == 0) {
1548 while ((arg = strdelim(&cp)) && *arg != '\0') {
1549 if (options->num_authkeys_files >=
1550 MAX_AUTHKEYS_FILES)
1551 fatal("%s line %d: "
1552 "too many authorized keys files.",
1553 filename, linenum);
1554 options->authorized_keys_files[
1555 options->num_authkeys_files++] =
1556 tilde_expand_filename(arg, getuid());
1557 }
1558 }
1559 return 0;
1560
Damien Miller30da3442010-05-10 11:58:03 +10001561 case sAuthorizedPrincipalsFile:
1562 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001563 arg = strdelim(&cp);
1564 if (!arg || *arg == '\0')
1565 fatal("%s line %d: missing file name.",
1566 filename, linenum);
1567 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001568 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001569 /* increase optional counter */
1570 if (intptr != NULL)
1571 *intptr = *intptr + 1;
1572 }
1573 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001574
1575 case sClientAliveInterval:
1576 intptr = &options->client_alive_interval;
1577 goto parse_time;
1578
1579 case sClientAliveCountMax:
1580 intptr = &options->client_alive_count_max;
1581 goto parse_int;
1582
Darren Tucker46bc0752004-05-02 22:11:30 +10001583 case sAcceptEnv:
1584 while ((arg = strdelim(&cp)) && *arg != '\0') {
1585 if (strchr(arg, '=') != NULL)
1586 fatal("%s line %d: Invalid environment name.",
1587 filename, linenum);
1588 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1589 fatal("%s line %d: too many allow env.",
1590 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001591 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001592 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001593 options->accept_env[options->num_accept_env++] =
1594 xstrdup(arg);
1595 }
1596 break;
1597
Damien Millerd27b9472005-12-13 19:29:02 +11001598 case sPermitTunnel:
1599 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001600 arg = strdelim(&cp);
1601 if (!arg || *arg == '\0')
1602 fatal("%s line %d: Missing yes/point-to-point/"
1603 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001604 value = -1;
1605 for (i = 0; tunmode_desc[i].val != -1; i++)
1606 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1607 value = tunmode_desc[i].val;
1608 break;
1609 }
1610 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001611 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1612 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001613 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001614 *intptr = value;
1615 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001616
Darren Tucker45150472006-07-12 22:34:17 +10001617 case sMatch:
1618 if (cmdline)
1619 fatal("Match directive not supported as a command-line "
1620 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001621 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001622 if (value < 0)
1623 fatal("%s line %d: Bad Match condition", filename,
1624 linenum);
1625 *activep = value;
1626 break;
1627
Damien Miller9b439df2006-07-24 14:04:00 +10001628 case sPermitOpen:
1629 arg = strdelim(&cp);
1630 if (!arg || *arg == '\0')
1631 fatal("%s line %d: missing PermitOpen specification",
1632 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001633 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001634 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001635 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001636 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001637 options->num_permitted_opens = 0;
1638 }
Damien Miller9b439df2006-07-24 14:04:00 +10001639 break;
1640 }
Damien Millerc6081482012-04-22 11:18:53 +10001641 if (strcmp(arg, "none") == 0) {
1642 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001643 options->num_permitted_opens = 1;
1644 channel_disable_adm_local_opens();
1645 }
1646 break;
1647 }
Damien Millera29b95e2007-01-05 16:28:36 +11001648 if (*activep && n == -1)
1649 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001650 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1651 p = hpdelim(&arg);
1652 if (p == NULL)
1653 fatal("%s line %d: missing host in PermitOpen",
1654 filename, linenum);
1655 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001656 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001657 fatal("%s line %d: bad port number in "
1658 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001659 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001660 options->num_permitted_opens =
1661 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001662 }
Damien Miller9b439df2006-07-24 14:04:00 +10001663 break;
1664
Damien Millere2754432006-07-24 14:06:47 +10001665 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001666 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001667 fatal("%.200s line %d: Missing argument.", filename,
1668 linenum);
1669 len = strspn(cp, WHITESPACE);
1670 if (*activep && options->adm_forced_command == NULL)
1671 options->adm_forced_command = xstrdup(cp + len);
1672 return 0;
1673
Damien Millerd8cb1f12008-02-10 22:40:12 +11001674 case sChrootDirectory:
1675 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001676
1677 arg = strdelim(&cp);
1678 if (!arg || *arg == '\0')
1679 fatal("%s line %d: missing file name.",
1680 filename, linenum);
1681 if (*activep && *charptr == NULL)
1682 *charptr = xstrdup(arg);
1683 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001684
Damien Miller1aed65e2010-03-04 21:53:35 +11001685 case sTrustedUserCAKeys:
1686 charptr = &options->trusted_user_ca_keys;
1687 goto parse_filename;
1688
1689 case sRevokedKeys:
1690 charptr = &options->revoked_keys_file;
1691 goto parse_filename;
1692
Damien Miller0dac6fb2010-11-20 15:19:38 +11001693 case sIPQoS:
1694 arg = strdelim(&cp);
1695 if ((value = parse_ipqos(arg)) == -1)
1696 fatal("%s line %d: Bad IPQoS value: %s",
1697 filename, linenum, arg);
1698 arg = strdelim(&cp);
1699 if (arg == NULL)
1700 value2 = value;
1701 else if ((value2 = parse_ipqos(arg)) == -1)
1702 fatal("%s line %d: Bad IPQoS value: %s",
1703 filename, linenum, arg);
1704 if (*activep) {
1705 options->ip_qos_interactive = value;
1706 options->ip_qos_bulk = value2;
1707 }
1708 break;
1709
Damien Miller23528812012-04-22 11:24:43 +10001710 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001711 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001712 fatal("%.200s line %d: Missing argument.", filename,
1713 linenum);
1714 len = strspn(cp, WHITESPACE);
1715 if (*activep && options->version_addendum == NULL) {
1716 if (strcasecmp(cp + len, "none") == 0)
1717 options->version_addendum = xstrdup("");
1718 else if (strchr(cp + len, '\r') != NULL)
1719 fatal("%.200s line %d: Invalid argument",
1720 filename, linenum);
1721 else
1722 options->version_addendum = xstrdup(cp + len);
1723 }
1724 return 0;
1725
Damien Miller09d3e122012-10-31 08:58:58 +11001726 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001727 if (cp == NULL)
1728 fatal("%.200s line %d: Missing argument.", filename,
1729 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001730 len = strspn(cp, WHITESPACE);
1731 if (*activep && options->authorized_keys_command == NULL) {
1732 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1733 fatal("%.200s line %d: AuthorizedKeysCommand "
1734 "must be an absolute path",
1735 filename, linenum);
1736 options->authorized_keys_command = xstrdup(cp + len);
1737 }
1738 return 0;
1739
1740 case sAuthorizedKeysCommandUser:
1741 charptr = &options->authorized_keys_command_user;
1742
1743 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001744 if (!arg || *arg == '\0')
1745 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1746 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001747 if (*activep && *charptr == NULL)
1748 *charptr = xstrdup(arg);
1749 break;
1750
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001751 case sAuthorizedPrincipalsCommand:
1752 if (cp == NULL)
1753 fatal("%.200s line %d: Missing argument.", filename,
1754 linenum);
1755 len = strspn(cp, WHITESPACE);
1756 if (*activep &&
1757 options->authorized_principals_command == NULL) {
1758 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1759 fatal("%.200s line %d: "
1760 "AuthorizedPrincipalsCommand must be "
1761 "an absolute path", filename, linenum);
1762 options->authorized_principals_command =
1763 xstrdup(cp + len);
1764 }
1765 return 0;
1766
1767 case sAuthorizedPrincipalsCommandUser:
1768 charptr = &options->authorized_principals_command_user;
1769
1770 arg = strdelim(&cp);
1771 if (!arg || *arg == '\0')
1772 fatal("%s line %d: missing "
1773 "AuthorizedPrincipalsCommandUser argument.",
1774 filename, linenum);
1775 if (*activep && *charptr == NULL)
1776 *charptr = xstrdup(arg);
1777 break;
1778
Damien Millera6e3f012012-11-04 23:21:40 +11001779 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001780 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001781 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001782 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001783 while ((arg = strdelim(&cp)) && *arg != '\0') {
1784 if (options->num_auth_methods >=
1785 MAX_AUTH_METHODS)
1786 fatal("%s line %d: "
1787 "too many authentication methods.",
1788 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001789 if (strcmp(arg, "any") == 0) {
1790 if (options->num_auth_methods > 0) {
1791 fatal("%s line %d: \"any\" "
1792 "must appear alone in "
1793 "AuthenticationMethods",
1794 filename, linenum);
1795 }
1796 value = 1;
1797 } else if (value) {
1798 fatal("%s line %d: \"any\" must appear "
1799 "alone in AuthenticationMethods",
1800 filename, linenum);
1801 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001802 fatal("%s line %d: invalid "
1803 "authentication method list.",
1804 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001805 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001806 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001807 if (!*activep)
1808 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001809 options->auth_methods[
1810 options->num_auth_methods++] = xstrdup(arg);
1811 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001812 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001813 fatal("%s line %d: no AuthenticationMethods "
1814 "specified", filename, linenum);
1815 }
Damien Millera6e3f012012-11-04 23:21:40 +11001816 }
1817 return 0;
1818
Damien Miller7acefbb2014-07-18 14:11:24 +10001819 case sStreamLocalBindMask:
1820 arg = strdelim(&cp);
1821 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001822 fatal("%s line %d: missing StreamLocalBindMask "
1823 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001824 /* Parse mode in octal format */
1825 value = strtol(arg, &p, 8);
1826 if (arg == p || value < 0 || value > 0777)
1827 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001828 if (*activep)
1829 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001830 break;
1831
1832 case sStreamLocalBindUnlink:
1833 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1834 goto parse_flag;
1835
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001836 case sFingerprintHash:
1837 arg = strdelim(&cp);
1838 if (!arg || *arg == '\0')
1839 fatal("%.200s line %d: Missing argument.",
1840 filename, linenum);
1841 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1842 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1843 filename, linenum, arg);
1844 if (*activep)
1845 options->fingerprint_hash = value;
1846 break;
1847
Ben Lindstromade03f62001-12-06 18:22:17 +00001848 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001849 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001850 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001851 do_log2(opcode == sIgnore ?
1852 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1853 "%s line %d: %s option %s", filename, linenum,
1854 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001855 while (arg)
1856 arg = strdelim(&cp);
1857 break;
1858
Ben Lindstromade03f62001-12-06 18:22:17 +00001859 default:
1860 fatal("%s line %d: Missing handler for opcode %s (%d)",
1861 filename, linenum, arg, opcode);
1862 }
1863 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1864 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1865 filename, linenum, arg);
1866 return 0;
1867}
1868
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001869/* Reads the server configuration file. */
1870
Damien Miller4af51302000-04-16 11:18:38 +10001871void
Darren Tucker645ab752004-06-25 13:33:20 +10001872load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001873{
Damien Miller46cb75a2012-07-31 12:22:37 +10001874 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001875 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001876 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001877
Darren Tucker645ab752004-06-25 13:33:20 +10001878 debug2("%s: filename %s", __func__, filename);
1879 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001880 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001881 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001882 }
Darren Tucker645ab752004-06-25 13:33:20 +10001883 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001884 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001885 lineno++;
1886 if (strlen(line) == sizeof(line) - 1)
1887 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001888 /*
1889 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001890 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001891 * line numbers later for error messages
1892 */
1893 if ((cp = strchr(line, '#')) != NULL)
1894 memcpy(cp, "\n", 2);
1895 cp = line + strspn(line, " \t\r");
1896
1897 buffer_append(conf, cp, strlen(cp));
1898 }
1899 buffer_append(conf, "\0", 1);
1900 fclose(f);
1901 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1902}
1903
1904void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001905parse_server_match_config(ServerOptions *options,
1906 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001907{
Darren Tucker45150472006-07-12 22:34:17 +10001908 ServerOptions mo;
1909
1910 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001911 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001912 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001913}
1914
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001915int parse_server_match_testspec(struct connection_info *ci, char *spec)
1916{
1917 char *p;
1918
1919 while ((p = strsep(&spec, ",")) && *p != '\0') {
1920 if (strncmp(p, "addr=", 5) == 0) {
1921 ci->address = xstrdup(p + 5);
1922 } else if (strncmp(p, "host=", 5) == 0) {
1923 ci->host = xstrdup(p + 5);
1924 } else if (strncmp(p, "user=", 5) == 0) {
1925 ci->user = xstrdup(p + 5);
1926 } else if (strncmp(p, "laddr=", 6) == 0) {
1927 ci->laddress = xstrdup(p + 6);
1928 } else if (strncmp(p, "lport=", 6) == 0) {
1929 ci->lport = a2port(p + 6);
1930 if (ci->lport == -1) {
1931 fprintf(stderr, "Invalid port '%s' in test mode"
1932 " specification %s\n", p+6, p);
1933 return -1;
1934 }
1935 } else {
1936 fprintf(stderr, "Invalid test mode specification %s\n",
1937 p);
1938 return -1;
1939 }
1940 }
1941 return 0;
1942}
1943
1944/*
1945 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1946 * empty spec.
1947 */
1948int server_match_spec_complete(struct connection_info *ci)
1949{
1950 if (ci->user && ci->host && ci->address)
1951 return 1; /* complete */
1952 if (!ci->user && !ci->host && !ci->address)
1953 return -1; /* empty */
1954 return 0; /* partial */
1955}
1956
Darren Tucker1629c072007-02-19 22:25:37 +11001957/*
1958 * Copy any supported values that are set.
1959 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001960 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001961 * array values that are not used pre-authentication, because any that we
1962 * do use must be explictly sent in mm_getpwnamallow().
1963 */
Darren Tucker45150472006-07-12 22:34:17 +10001964void
Darren Tucker1629c072007-02-19 22:25:37 +11001965copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001966{
Damien Miller534b2cc2013-12-05 14:07:27 +11001967#define M_CP_INTOPT(n) do {\
1968 if (src->n != -1) \
1969 dst->n = src->n; \
1970} while (0)
1971
Darren Tucker1629c072007-02-19 22:25:37 +11001972 M_CP_INTOPT(password_authentication);
1973 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11001974 M_CP_INTOPT(pubkey_authentication);
1975 M_CP_INTOPT(kerberos_authentication);
1976 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001977 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001978 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001979 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001980 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001981
1982 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001983 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001984 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00001985 M_CP_INTOPT(disable_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001986 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001987 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001988 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11001989 M_CP_INTOPT(x11_display_offset);
1990 M_CP_INTOPT(x11_forwarding);
1991 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001992 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001993 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001994 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001995 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00001996 M_CP_INTOPT(client_alive_count_max);
1997 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001998 M_CP_INTOPT(ip_qos_interactive);
1999 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002000 M_CP_INTOPT(rekey_limit);
2001 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002002
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002003 /*
2004 * The bind_mask is a mode_t that may be unsigned, so we can't use
2005 * M_CP_INTOPT - it does a signed comparison that causes compiler
2006 * warnings.
2007 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002008 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002009 dst->fwd_opts.streamlocal_bind_mask =
2010 src->fwd_opts.streamlocal_bind_mask;
2011 }
2012
Damien Miller534b2cc2013-12-05 14:07:27 +11002013 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2014#define M_CP_STROPT(n) do {\
2015 if (src->n != NULL && dst->n != src->n) { \
2016 free(dst->n); \
2017 dst->n = src->n; \
2018 } \
2019} while(0)
2020#define M_CP_STRARRAYOPT(n, num_n) do {\
2021 if (src->num_n != 0) { \
2022 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2023 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2024 } \
2025} while(0)
2026
Damien Millerf2e407e2011-05-20 19:04:14 +10002027 /* See comment in servconf.h */
2028 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002029
djm@openbsd.orged085102015-10-29 08:05:01 +00002030 /* Arguments that accept '+...' need to be expanded */
2031 assemble_algorithms(dst);
2032
Damien Millerc2411902011-05-20 19:03:49 +10002033 /*
2034 * The only things that should be below this point are string options
2035 * which are only used after authentication.
2036 */
Damien Miller5d74e582011-05-20 19:03:31 +10002037 if (preauth)
2038 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002039
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002040 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002041 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002042 if (option_clear_or_none(dst->adm_forced_command)) {
2043 free(dst->adm_forced_command);
2044 dst->adm_forced_command = NULL;
2045 }
Damien Miller5d74e582011-05-20 19:03:31 +10002046 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002047 if (option_clear_or_none(dst->chroot_directory)) {
2048 free(dst->chroot_directory);
2049 dst->chroot_directory = NULL;
2050 }
Darren Tucker45150472006-07-12 22:34:17 +10002051}
2052
Darren Tucker1629c072007-02-19 22:25:37 +11002053#undef M_CP_INTOPT
2054#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002055#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002056
Darren Tucker45150472006-07-12 22:34:17 +10002057void
2058parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002059 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002060{
2061 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002062 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002063
2064 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2065
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002066 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2067 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002068 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002069 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002070 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002071 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002072 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002073 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002074 }
Darren Tuckera627d422013-06-02 07:31:17 +10002075 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002076 if (bad_options > 0)
2077 fatal("%s: terminating, %d bad configuration options",
2078 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002079 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002080}
Darren Tuckere7140f22008-06-10 23:01:51 +10002081
2082static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002083fmt_multistate_int(int val, const struct multistate *m)
2084{
2085 u_int i;
2086
2087 for (i = 0; m[i].key != NULL; i++) {
2088 if (m[i].value == val)
2089 return m[i].key;
2090 }
2091 return "UNKNOWN";
2092}
2093
2094static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002095fmt_intarg(ServerOpCodes code, int val)
2096{
Damien Miller82c55872011-06-23 08:20:30 +10002097 if (val == -1)
2098 return "unset";
2099 switch (code) {
2100 case sAddressFamily:
2101 return fmt_multistate_int(val, multistate_addressfamily);
2102 case sPermitRootLogin:
2103 return fmt_multistate_int(val, multistate_permitrootlogin);
2104 case sGatewayPorts:
2105 return fmt_multistate_int(val, multistate_gatewayports);
2106 case sCompression:
2107 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002108 case sUsePrivilegeSeparation:
2109 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002110 case sAllowTcpForwarding:
2111 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002112 case sAllowStreamLocalForwarding:
2113 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002114 case sFingerprintHash:
2115 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002116 default:
2117 switch (val) {
2118 case 0:
2119 return "no";
2120 case 1:
2121 return "yes";
2122 default:
2123 return "UNKNOWN";
2124 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002125 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002126}
2127
2128static const char *
2129lookup_opcode_name(ServerOpCodes code)
2130{
2131 u_int i;
2132
2133 for (i = 0; keywords[i].name != NULL; i++)
2134 if (keywords[i].opcode == code)
2135 return(keywords[i].name);
2136 return "UNKNOWN";
2137}
2138
2139static void
2140dump_cfg_int(ServerOpCodes code, int val)
2141{
2142 printf("%s %d\n", lookup_opcode_name(code), val);
2143}
2144
2145static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002146dump_cfg_oct(ServerOpCodes code, int val)
2147{
2148 printf("%s 0%o\n", lookup_opcode_name(code), val);
2149}
2150
2151static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002152dump_cfg_fmtint(ServerOpCodes code, int val)
2153{
2154 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2155}
2156
2157static void
2158dump_cfg_string(ServerOpCodes code, const char *val)
2159{
2160 if (val == NULL)
2161 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002162 printf("%s %s\n", lookup_opcode_name(code),
2163 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002164}
2165
2166static void
2167dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2168{
2169 u_int i;
2170
2171 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002172 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2173}
2174
2175static void
2176dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2177{
2178 u_int i;
2179
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002180 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002181 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002182 printf("%s", lookup_opcode_name(code));
2183 for (i = 0; i < count; i++)
2184 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002185 if (code == sAuthenticationMethods && count == 0)
2186 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002187 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002188}
2189
2190void
2191dump_config(ServerOptions *o)
2192{
2193 u_int i;
2194 int ret;
2195 struct addrinfo *ai;
2196 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002197 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002198
2199 /* these are usually at the top of the config */
2200 for (i = 0; i < o->num_ports; i++)
2201 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002202 dump_cfg_fmtint(sAddressFamily, o->address_family);
2203
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002204 /*
2205 * ListenAddress must be after Port. add_one_listen_addr pushes
2206 * addresses onto a stack, so to maintain ordering we need to
2207 * print these in reverse order.
2208 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002209 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2210 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2211 sizeof(addr), port, sizeof(port),
2212 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2213 error("getnameinfo failed: %.100s",
2214 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2215 strerror(errno));
2216 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002217 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002218 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002219 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2220 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002221 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002222 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2223 addr, port, laddr2);
2224 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002225 }
2226 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002227 printf("%s", laddr1);
2228 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002229
2230 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002231#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002232 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002233#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002234 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002235 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2236 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002237 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002238 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2239 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002240 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002241
2242 /* formatted integer arguments */
2243 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2244 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2245 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002246 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2247 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2248 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002249 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002250#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002251 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2252 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2253 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002254# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002255 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002256# endif
2257#endif
2258#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002259 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2260 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002261#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002262 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2263 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2264 o->kbd_interactive_authentication);
2265 dump_cfg_fmtint(sChallengeResponseAuthentication,
2266 o->challenge_response_authentication);
2267 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002268#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002269 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002270#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002271 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2272 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002273 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002274 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002275 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2276 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2277 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2278 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002279 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002280 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_fmtint(sUseDNS, o->use_dns);
2282 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002283 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002284 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002285 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002286 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
Darren Tuckere7140f22008-06-10 23:01:51 +10002287 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002288 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002289
2290 /* string arguments */
2291 dump_cfg_string(sPidFile, o->pid_file);
2292 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002293 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2294 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002295 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002296 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002297 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002298 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2299 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002300 dump_cfg_string(sAuthorizedPrincipalsFile,
2301 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002302 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2303 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002304 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2305 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002306 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2307 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002308 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002309 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002310 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002311 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2312 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002313 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2314 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002315 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2316 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002317
2318 /* string arguments requiring a lookup */
2319 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2320 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2321
2322 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002323 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2324 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002325 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2326 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002327 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002328 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002329 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2330 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2331 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2332 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2333 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002334 dump_cfg_strarray_oneline(sAuthenticationMethods,
2335 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002336
2337 /* other arguments */
2338 for (i = 0; i < o->num_subsystems; i++)
2339 printf("subsystem %s %s\n", o->subsystem_name[i],
2340 o->subsystem_args[i]);
2341
2342 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2343 o->max_startups_rate, o->max_startups);
2344
2345 for (i = 0; tunmode_desc[i].val != -1; i++)
2346 if (tunmode_desc[i].val == o->permit_tun) {
2347 s = tunmode_desc[i].text;
2348 break;
2349 }
2350 dump_cfg_string(sPermitTunnel, s);
2351
Damien Miller91475862011-05-05 14:14:34 +10002352 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2353 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002354
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002355 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002356 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002357
Darren Tuckere7140f22008-06-10 23:01:51 +10002358 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002359}