blob: ed1fc71cff63367a8813b515e7809da408cfa126 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org8f574952017-06-24 06:34:38 +00002/* $OpenBSD: servconf.c,v 1.309 2017/06/24 06:34:38 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;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000167 options->expose_userauth_info = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000168}
169
djm@openbsd.org161cf412014-12-22 07:55:51 +0000170/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
171static int
172option_clear_or_none(const char *o)
173{
174 return o == NULL || strcasecmp(o, "none") == 0;
175}
176
djm@openbsd.orged085102015-10-29 08:05:01 +0000177static void
178assemble_algorithms(ServerOptions *o)
179{
180 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
181 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
182 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
183 kex_assemble_names(KEX_DEFAULT_PK_ALG,
184 &o->hostkeyalgorithms) != 0 ||
185 kex_assemble_names(KEX_DEFAULT_PK_ALG,
186 &o->hostbased_key_types) != 0 ||
187 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
188 fatal("kex_assemble_names failed");
189}
190
Damien Miller4af51302000-04-16 11:18:38 +1000191void
Damien Miller95def091999-11-25 00:26:21 +1100192fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000193{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000194 int i;
195
Damien Miller726273e2001-11-12 11:40:11 +1100196 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000197 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000198 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100199
200 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100201 if (options->num_host_key_files == 0) {
202 /* fill default hostkeys for protocols */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000203 options->host_key_files[options->num_host_key_files++] =
204 _PATH_HOST_RSA_KEY_FILE;
205 options->host_key_files[options->num_host_key_files++] =
206 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100207#ifdef OPENSSL_HAS_ECC
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000208 options->host_key_files[options->num_host_key_files++] =
209 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100210#endif
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000211 options->host_key_files[options->num_host_key_files++] =
212 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100213 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100214 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100215 if (options->num_ports == 0)
216 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000217 if (options->address_family == -1)
218 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100219 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000220 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000221 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000222 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100223 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000224 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000225 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000226 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100227 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100228 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->ignore_user_known_hosts == -1)
230 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100231 if (options->print_motd == -1)
232 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000233 if (options->print_lastlog == -1)
234 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100235 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100236 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100237 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100238 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100239 if (options->x11_use_localhost == -1)
240 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000241 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000242 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100243 if (options->permit_tty == -1)
244 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000245 if (options->permit_user_rc == -1)
246 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100247 if (options->strict_modes == -1)
248 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100249 if (options->tcp_keep_alive == -1)
250 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100251 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100252 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100253 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000254 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000255 if (options->hostbased_authentication == -1)
256 options->hostbased_authentication = 0;
257 if (options->hostbased_uses_name_from_packet_only == -1)
258 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100259 if (options->pubkey_authentication == -1)
260 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100261 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000262 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100263 if (options->kerberos_or_local_passwd == -1)
264 options->kerberos_or_local_passwd = 1;
265 if (options->kerberos_ticket_cleanup == -1)
266 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100267 if (options->kerberos_get_afs_token == -1)
268 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000269 if (options->gss_authentication == -1)
270 options->gss_authentication = 0;
271 if (options->gss_cleanup_creds == -1)
272 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000273 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000274 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100275 if (options->password_authentication == -1)
276 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100277 if (options->kbd_interactive_authentication == -1)
278 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000279 if (options->challenge_response_authentication == -1)
280 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100281 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100282 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000283 if (options->permit_user_env == -1)
284 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000285 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000286 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000287 if (options->rekey_limit == -1)
288 options->rekey_limit = 0;
289 if (options->rekey_interval == -1)
290 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100291 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100292 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000293 if (options->allow_streamlocal_forwarding == -1)
294 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000295 if (options->allow_agent_forwarding == -1)
296 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000297 if (options->fwd_opts.gateway_ports == -1)
298 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000299 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100300 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000301 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100302 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000303 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100304 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000305 if (options->max_authtries == -1)
306 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000307 if (options->max_sessions == -1)
308 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000309 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000310 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000311 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100312 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000313 if (options->client_alive_count_max == -1)
314 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000315 if (options->num_authkeys_files == 0) {
316 options->authorized_keys_files[options->num_authkeys_files++] =
317 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
318 options->authorized_keys_files[options->num_authkeys_files++] =
319 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
320 }
Damien Millerd27b9472005-12-13 19:29:02 +1100321 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100322 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100323 if (options->ip_qos_interactive == -1)
324 options->ip_qos_interactive = IPTOS_LOWDELAY;
325 if (options->ip_qos_bulk == -1)
326 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000327 if (options->version_addendum == NULL)
328 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000329 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
330 options->fwd_opts.streamlocal_bind_mask = 0177;
331 if (options->fwd_opts.streamlocal_bind_unlink == -1)
332 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000333 if (options->fingerprint_hash == -1)
334 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000335 if (options->disable_forwarding == -1)
336 options->disable_forwarding = 0;
djm@openbsd.org8f574952017-06-24 06:34:38 +0000337 if (options->expose_userauth_info == -1)
338 options->expose_userauth_info = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000339
djm@openbsd.orged085102015-10-29 08:05:01 +0000340 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000341
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000342 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000343 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000344 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000345
djm@openbsd.org161cf412014-12-22 07:55:51 +0000346#define CLEAR_ON_NONE(v) \
347 do { \
348 if (option_clear_or_none(v)) { \
349 free(v); \
350 v = NULL; \
351 } \
352 } while(0)
353 CLEAR_ON_NONE(options->pid_file);
354 CLEAR_ON_NONE(options->xauth_location);
355 CLEAR_ON_NONE(options->banner);
356 CLEAR_ON_NONE(options->trusted_user_ca_keys);
357 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000358 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000359 CLEAR_ON_NONE(options->adm_forced_command);
360 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000361 for (i = 0; i < options->num_host_key_files; i++)
362 CLEAR_ON_NONE(options->host_key_files[i]);
363 for (i = 0; i < options->num_host_cert_files; i++)
364 CLEAR_ON_NONE(options->host_cert_files[i]);
365#undef CLEAR_ON_NONE
366
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000367 /* Similar handling for AuthenticationMethods=any */
368 if (options->num_auth_methods == 1 &&
369 strcmp(options->auth_methods[0], "any") == 0) {
370 free(options->auth_methods[0]);
371 options->auth_methods[0] = NULL;
372 options->num_auth_methods = 0;
373 }
374
Tim Rice40017b02002-07-14 13:36:49 -0700375#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000376 if (use_privsep && options->compression == 1) {
377 error("This platform does not support both privilege "
378 "separation and compression");
379 error("Compression disabled");
380 options->compression = 0;
381 }
382#endif
383
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000384}
385
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000386/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100387typedef enum {
388 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100389 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000390 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100391 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000392 sPort, sHostKeyFile, sLoginGraceTime,
393 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000394 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100395 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100396 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000397 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100398 sPasswordAuthentication, sKbdInteractiveAuthentication,
399 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000400 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100401 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100402 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000403 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000404 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000405 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000406 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
407 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000408 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000409 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000410 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000411 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000412 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
413 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100414 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100415 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100416 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000417 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000418 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000419 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100420 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000421 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000422 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000423 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.org8f574952017-06-24 06:34:38 +0000424 sExposeAuthInfo,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000425 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000426} ServerOpCodes;
427
Darren Tucker45150472006-07-12 22:34:17 +1000428#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
429#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
430#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
431
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000432/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100433static struct {
434 const char *name;
435 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000436 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100437} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100438 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000439#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000440 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000441#else
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000443#endif
Darren Tucker45150472006-07-12 22:34:17 +1000444 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100445 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "port", sPort, SSHCFG_GLOBAL },
447 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
448 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000449 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000450 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000451 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000452 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000453 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100454 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000455 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000456 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000457 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000458 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100459 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000460 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000461 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000462 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000463 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000465 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000466 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000467#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100468 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000469 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
470 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100471#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000472 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000473#else
Darren Tucker45150472006-07-12 22:34:17 +1000474 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100475#endif
476#else
Darren Tucker1629c072007-02-19 22:25:37 +1100477 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000478 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
479 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
480 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000481#endif
Darren Tucker45150472006-07-12 22:34:17 +1000482 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
483 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000484#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100485 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000487 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000488#else
Darren Tucker1629c072007-02-19 22:25:37 +1100489 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000490 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000491 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000492#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100493 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
494 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100495 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000496 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
497 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
498 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
499 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
500 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100501#ifdef DISABLE_LASTLOG
502 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
503#else
Darren Tucker45150472006-07-12 22:34:17 +1000504 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100505#endif
Darren Tucker45150472006-07-12 22:34:17 +1000506 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
507 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000508 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
509 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
510 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000511 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
512 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100513 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000515 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000516 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000517 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000518 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
519 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
520 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000521 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000522 { "allowusers", sAllowUsers, SSHCFG_ALL },
523 { "denyusers", sDenyUsers, SSHCFG_ALL },
524 { "allowgroups", sAllowGroups, SSHCFG_ALL },
525 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000526 { "ciphers", sCiphers, SSHCFG_GLOBAL },
527 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000528 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000529 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
530 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
531 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000532 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000533 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100534 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000535 { "usedns", sUseDNS, SSHCFG_GLOBAL },
536 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
537 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000538 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
539 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000540 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000541 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000542 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000543 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000544 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100545 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000546 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000547 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000548 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000549 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100550 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100551 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100552 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
553 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000554 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000555 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100556 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100557 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
558 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000559 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
560 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000561 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100562 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000563 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
564 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
565 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000566 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000567 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
djm@openbsd.org8f574952017-06-24 06:34:38 +0000568 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000569 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000570};
571
Darren Tuckere7140f22008-06-10 23:01:51 +1000572static struct {
573 int val;
574 char *text;
575} tunmode_desc[] = {
576 { SSH_TUNMODE_NO, "no" },
577 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
578 { SSH_TUNMODE_ETHERNET, "ethernet" },
579 { SSH_TUNMODE_YES, "yes" },
580 { -1, NULL }
581};
582
Damien Miller5428f641999-11-25 11:54:57 +1100583/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000584 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100585 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000586
Damien Miller4af51302000-04-16 11:18:38 +1000587static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100588parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000589 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000590{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000591 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000592
Damien Miller95def091999-11-25 00:26:21 +1100593 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000594 if (strcasecmp(cp, keywords[i].name) == 0) {
595 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100596 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000597 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000598
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000599 error("%s: line %d: Bad configuration option: %s",
600 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100601 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000602}
603
Darren Tucker88b6fb22010-01-13 22:44:29 +1100604char *
605derelativise_path(const char *path)
606{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000607 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100608
djm@openbsd.org161cf412014-12-22 07:55:51 +0000609 if (strcasecmp(path, "none") == 0)
610 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100611 expanded = tilde_expand_filename(path, getuid());
612 if (*expanded == '/')
613 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100614 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100615 fatal("%s: getcwd: %s", __func__, strerror(errno));
616 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000617 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100618 return ret;
619}
620
Ben Lindstrombba81212001-06-25 05:01:22 +0000621static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100622add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100623{
Damien Millereccb9de2005-06-17 12:59:34 +1000624 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100625
Ben Lindstrom19066a12001-04-12 23:39:26 +0000626 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000627 for (i = 0; i < options->num_ports; i++)
628 add_one_listen_addr(options, addr, options->ports[i]);
629 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000630 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000631}
632
Ben Lindstrombba81212001-06-25 05:01:22 +0000633static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100634add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000635{
636 struct addrinfo hints, *ai, *aitop;
637 char strport[NI_MAXSERV];
638 int gaierr;
639
640 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100641 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000642 hints.ai_socktype = SOCK_STREAM;
643 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100644 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000645 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
646 fatal("bad addr or host: %s (%s)",
647 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100648 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000649 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
650 ;
651 ai->ai_next = options->listen_addrs;
652 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100653}
654
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000655/*
656 * Queue a ListenAddress to be processed once we have all of the Ports
657 * and AddressFamily options.
658 */
659static void
660queue_listen_addr(ServerOptions *options, char *addr, int port)
661{
662 options->queued_listen_addrs = xreallocarray(
663 options->queued_listen_addrs, options->num_queued_listens + 1,
664 sizeof(addr));
665 options->queued_listen_ports = xreallocarray(
666 options->queued_listen_ports, options->num_queued_listens + 1,
667 sizeof(port));
668 options->queued_listen_addrs[options->num_queued_listens] =
669 xstrdup(addr);
670 options->queued_listen_ports[options->num_queued_listens] = port;
671 options->num_queued_listens++;
672}
673
674/*
675 * Process queued (text) ListenAddress entries.
676 */
677static void
678process_queued_listen_addrs(ServerOptions *options)
679{
680 u_int i;
681
682 if (options->num_ports == 0)
683 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
684 if (options->address_family == -1)
685 options->address_family = AF_UNSPEC;
686
687 for (i = 0; i < options->num_queued_listens; i++) {
688 add_listen_addr(options, options->queued_listen_addrs[i],
689 options->queued_listen_ports[i]);
690 free(options->queued_listen_addrs[i]);
691 options->queued_listen_addrs[i] = NULL;
692 }
693 free(options->queued_listen_addrs);
694 options->queued_listen_addrs = NULL;
695 free(options->queued_listen_ports);
696 options->queued_listen_ports = NULL;
697 options->num_queued_listens = 0;
698}
699
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000700struct connection_info *
701get_connection_info(int populate, int use_dns)
702{
djm@openbsd.org95767262016-03-07 19:02:43 +0000703 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000704 static struct connection_info ci;
705
706 if (!populate)
707 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000708 ci.host = auth_get_canonical_hostname(ssh, use_dns);
709 ci.address = ssh_remote_ipaddr(ssh);
710 ci.laddress = ssh_local_ipaddr(ssh);
711 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000712 return &ci;
713}
714
Darren Tucker45150472006-07-12 22:34:17 +1000715/*
716 * The strategy for the Match blocks is that the config file is parsed twice.
717 *
718 * The first time is at startup. activep is initialized to 1 and the
719 * directives in the global context are processed and acted on. Hitting a
720 * Match directive unsets activep and the directives inside the block are
721 * checked for syntax only.
722 *
723 * The second time is after a connection has been established but before
724 * authentication. activep is initialized to 2 and global config directives
725 * are ignored since they have already been processed. If the criteria in a
726 * Match block is met, activep is set and the subsequent directives
727 * processed and actioned until EOF or another Match block unsets it. Any
728 * options set are copied into the main server config.
729 *
730 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000731 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000732 *
733 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
734 * Match Address 192.168.0.*
735 * Tag trusted
736 * Match Group wheel
737 * Tag trusted
738 * Match Tag trusted
739 * AllowTcpForwarding yes
740 * GatewayPorts clientspecified
741 * [...]
742 *
743 * - Add a PermittedChannelRequests directive
744 * Match Group shell
745 * PermittedChannelRequests session,forwarded-tcpip
746 */
747
748static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000749match_cfg_line_group(const char *grps, int line, const char *user)
750{
751 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000752 struct passwd *pw;
753
Damien Miller565ca3f2006-08-19 00:23:15 +1000754 if (user == NULL)
755 goto out;
756
757 if ((pw = getpwnam(user)) == NULL) {
758 debug("Can't match group at line %d because user %.100s does "
759 "not exist", line, user);
760 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
761 debug("Can't Match group because user %.100s not in any group "
762 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000763 } else if (ga_match_pattern_list(grps) != 1) {
764 debug("user %.100s does not match group list %.100s at line %d",
765 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000766 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000767 debug("user %.100s matched group list %.100s at line %d", user,
768 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000769 result = 1;
770 }
771out:
772 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000773 return result;
774}
775
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000776/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000777 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100778 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000779 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000780 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000781static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000782match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000783{
Damien Millercf31f382013-10-24 21:02:56 +1100784 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000785 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000786
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000787 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000788 debug3("checking syntax for 'Match %s'", cp);
789 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000790 debug3("checking match for '%s' user %s host %s addr %s "
791 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
792 ci->host ? ci->host : "(null)",
793 ci->address ? ci->address : "(null)",
794 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000795
796 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100797 attributes++;
798 if (strcasecmp(attrib, "all") == 0) {
799 if (attributes != 1 ||
800 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
801 error("'all' cannot be combined with other "
802 "Match attributes");
803 return -1;
804 }
805 *condition = cp;
806 return 1;
807 }
Darren Tucker45150472006-07-12 22:34:17 +1000808 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
809 error("Missing Match criteria for %s", attrib);
810 return -1;
811 }
Darren Tucker45150472006-07-12 22:34:17 +1000812 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000813 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000814 result = 0;
815 continue;
816 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000817 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000818 result = 0;
819 else
820 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000821 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000822 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000823 if (ci == NULL || ci->user == NULL) {
824 result = 0;
825 continue;
826 }
827 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000828 case -1:
829 return -1;
830 case 0:
831 result = 0;
832 }
Darren Tucker45150472006-07-12 22:34:17 +1000833 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000834 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000835 result = 0;
836 continue;
837 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000838 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000839 result = 0;
840 else
841 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000842 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000843 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000844 if (ci == NULL || ci->address == NULL) {
845 result = 0;
846 continue;
847 }
848 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000849 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000850 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000851 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000852 break;
853 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000854 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000855 result = 0;
856 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000857 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000858 return -1;
859 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000860 } else if (strcasecmp(attrib, "localaddress") == 0){
861 if (ci == NULL || ci->laddress == NULL) {
862 result = 0;
863 continue;
864 }
865 switch (addr_match_list(ci->laddress, arg)) {
866 case 1:
867 debug("connection from %.100s matched "
868 "'LocalAddress %.100s' at line %d",
869 ci->laddress, arg, line);
870 break;
871 case 0:
872 case -1:
873 result = 0;
874 break;
875 case -2:
876 return -1;
877 }
878 } else if (strcasecmp(attrib, "localport") == 0) {
879 if ((port = a2port(arg)) == -1) {
880 error("Invalid LocalPort '%s' on Match line",
881 arg);
882 return -1;
883 }
884 if (ci == NULL || ci->lport == 0) {
885 result = 0;
886 continue;
887 }
888 /* TODO support port lists */
889 if (port == ci->lport)
890 debug("connection from %.100s matched "
891 "'LocalPort %d' at line %d",
892 ci->laddress, port, line);
893 else
894 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000895 } else {
896 error("Unsupported Match attribute %s", attrib);
897 return -1;
898 }
899 }
Damien Millercf31f382013-10-24 21:02:56 +1100900 if (attributes == 0) {
901 error("One or more attributes required for Match");
902 return -1;
903 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000904 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000905 debug3("match %sfound", result ? "" : "not ");
906 *condition = cp;
907 return result;
908}
909
Damien Millere2754432006-07-24 14:06:47 +1000910#define WHITESPACE " \t\r\n"
911
Damien Miller33322122011-06-20 14:43:11 +1000912/* Multistate option parsing */
913struct multistate {
914 char *key;
915 int value;
916};
917static const struct multistate multistate_addressfamily[] = {
918 { "inet", AF_INET },
919 { "inet6", AF_INET6 },
920 { "any", AF_UNSPEC },
921 { NULL, -1 }
922};
923static const struct multistate multistate_permitrootlogin[] = {
924 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000925 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000926 { "forced-commands-only", PERMIT_FORCED_ONLY },
927 { "yes", PERMIT_YES },
928 { "no", PERMIT_NO },
929 { NULL, -1 }
930};
931static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +0000932 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +0000933 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +1000934 { "no", COMP_NONE },
935 { NULL, -1 }
936};
937static const struct multistate multistate_gatewayports[] = {
938 { "clientspecified", 2 },
939 { "yes", 1 },
940 { "no", 0 },
941 { NULL, -1 }
942};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100943static const struct multistate multistate_tcpfwd[] = {
944 { "yes", FORWARD_ALLOW },
945 { "all", FORWARD_ALLOW },
946 { "no", FORWARD_DENY },
947 { "remote", FORWARD_REMOTE },
948 { "local", FORWARD_LOCAL },
949 { NULL, -1 }
950};
Damien Miller33322122011-06-20 14:43:11 +1000951
Ben Lindstromade03f62001-12-06 18:22:17 +0000952int
953process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000954 const char *filename, int linenum, int *activep,
955 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000956{
Darren Tucker09c0f032013-05-16 20:48:57 +1000957 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000958 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100959 SyslogFacility *log_facility_ptr;
960 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000961 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000962 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000963 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000964 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000965 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000966
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +0000967 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
968 if ((len = strlen(line)) == 0)
969 return 0;
970 for (len--; len > 0; len--) {
971 if (strchr(WHITESPACE "\f", line[len]) == NULL)
972 break;
973 line[len] = '\0';
974 }
975
Ben Lindstromade03f62001-12-06 18:22:17 +0000976 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100977 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100978 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000979 /* Ignore leading whitespace */
980 if (*arg == '\0')
981 arg = strdelim(&cp);
982 if (!arg || !*arg || *arg == '#')
983 return 0;
984 intptr = NULL;
985 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000986 opcode = parse_token(arg, filename, linenum, &flags);
987
988 if (activep == NULL) { /* We are processing a command line directive */
989 cmdline = 1;
990 activep = &cmdline;
991 }
992 if (*activep && opcode != sMatch)
993 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
994 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000995 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000996 fatal("%s line %d: Directive '%s' is not allowed "
997 "within a Match block", filename, linenum, arg);
998 } else { /* this is a directive we have already processed */
999 while (arg)
1000 arg = strdelim(&cp);
1001 return 0;
1002 }
1003 }
1004
Ben Lindstromade03f62001-12-06 18:22:17 +00001005 switch (opcode) {
1006 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001007 case sUsePAM:
1008 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001009 goto parse_flag;
1010
1011 /* Standard Options */
1012 case sBadOption:
1013 return -1;
1014 case sPort:
1015 /* ignore ports from configfile if cmdline specifies ports */
1016 if (options->ports_from_cmdline)
1017 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001018 if (options->num_ports >= MAX_PORTS)
1019 fatal("%s line %d: too many ports.",
1020 filename, linenum);
1021 arg = strdelim(&cp);
1022 if (!arg || *arg == '\0')
1023 fatal("%s line %d: missing port number.",
1024 filename, linenum);
1025 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001026 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001027 fatal("%s line %d: Badly formatted port number.",
1028 filename, linenum);
1029 break;
1030
Ben Lindstromade03f62001-12-06 18:22:17 +00001031 case sLoginGraceTime:
1032 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001033 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001034 arg = strdelim(&cp);
1035 if (!arg || *arg == '\0')
1036 fatal("%s line %d: missing time value.",
1037 filename, linenum);
1038 if ((value = convtime(arg)) == -1)
1039 fatal("%s line %d: invalid time value.",
1040 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001041 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001042 *intptr = value;
1043 break;
1044
Ben Lindstromade03f62001-12-06 18:22:17 +00001045 case sListenAddress:
1046 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001047 if (arg == NULL || *arg == '\0')
1048 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001049 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001050 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1051 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1052 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001053 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001054 break;
1055 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001056 p = hpdelim(&arg);
1057 if (p == NULL)
1058 fatal("%s line %d: bad address:port usage",
1059 filename, linenum);
1060 p = cleanhostname(p);
1061 if (arg == NULL)
1062 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001063 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001064 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001065
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001066 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001067
Ben Lindstromade03f62001-12-06 18:22:17 +00001068 break;
1069
Darren Tucker0f383232005-01-20 10:57:56 +11001070 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001071 intptr = &options->address_family;
1072 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001073 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001074 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001075 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001076 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001077 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001078 value = -1;
1079 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1080 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1081 value = multistate_ptr[i].value;
1082 break;
1083 }
1084 }
1085 if (value == -1)
1086 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001087 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001088 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001089 *intptr = value;
1090 break;
1091
Ben Lindstromade03f62001-12-06 18:22:17 +00001092 case sHostKeyFile:
1093 intptr = &options->num_host_key_files;
1094 if (*intptr >= MAX_HOSTKEYS)
1095 fatal("%s line %d: too many host keys specified (max %d).",
1096 filename, linenum, MAX_HOSTKEYS);
1097 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001098 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001099 arg = strdelim(&cp);
1100 if (!arg || *arg == '\0')
1101 fatal("%s line %d: missing file name.",
1102 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001103 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001104 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001105 /* increase optional counter */
1106 if (intptr != NULL)
1107 *intptr = *intptr + 1;
1108 }
1109 break;
1110
Damien Miller85b45e02013-07-20 13:21:52 +10001111 case sHostKeyAgent:
1112 charptr = &options->host_key_agent;
1113 arg = strdelim(&cp);
1114 if (!arg || *arg == '\0')
1115 fatal("%s line %d: missing socket name.",
1116 filename, linenum);
1117 if (*activep && *charptr == NULL)
1118 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1119 xstrdup(arg) : derelativise_path(arg);
1120 break;
1121
Damien Miller0a80ca12010-02-27 07:55:05 +11001122 case sHostCertificate:
1123 intptr = &options->num_host_cert_files;
1124 if (*intptr >= MAX_HOSTKEYS)
1125 fatal("%s line %d: too many host certificates "
1126 "specified (max %d).", filename, linenum,
1127 MAX_HOSTCERTS);
1128 charptr = &options->host_cert_files[*intptr];
1129 goto parse_filename;
Damien Miller0a80ca12010-02-27 07:55:05 +11001130
Ben Lindstromade03f62001-12-06 18:22:17 +00001131 case sPidFile:
1132 charptr = &options->pid_file;
1133 goto parse_filename;
1134
1135 case sPermitRootLogin:
1136 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001137 multistate_ptr = multistate_permitrootlogin;
1138 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001139
1140 case sIgnoreRhosts:
1141 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001142 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001143 arg = strdelim(&cp);
1144 if (!arg || *arg == '\0')
1145 fatal("%s line %d: missing yes/no argument.",
1146 filename, linenum);
1147 value = 0; /* silence compiler */
1148 if (strcmp(arg, "yes") == 0)
1149 value = 1;
1150 else if (strcmp(arg, "no") == 0)
1151 value = 0;
1152 else
1153 fatal("%s line %d: Bad yes/no argument: %s",
1154 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001155 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001156 *intptr = value;
1157 break;
1158
1159 case sIgnoreUserKnownHosts:
1160 intptr = &options->ignore_user_known_hosts;
1161 goto parse_flag;
1162
Ben Lindstromade03f62001-12-06 18:22:17 +00001163 case sHostbasedAuthentication:
1164 intptr = &options->hostbased_authentication;
1165 goto parse_flag;
1166
1167 case sHostbasedUsesNameFromPacketOnly:
1168 intptr = &options->hostbased_uses_name_from_packet_only;
1169 goto parse_flag;
1170
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001171 case sHostbasedAcceptedKeyTypes:
1172 charptr = &options->hostbased_key_types;
1173 parse_keytypes:
1174 arg = strdelim(&cp);
1175 if (!arg || *arg == '\0')
1176 fatal("%s line %d: Missing argument.",
1177 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001178 if (*arg != '-' &&
1179 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001180 fatal("%s line %d: Bad key types '%s'.",
1181 filename, linenum, arg ? arg : "<NONE>");
1182 if (*activep && *charptr == NULL)
1183 *charptr = xstrdup(arg);
1184 break;
1185
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001186 case sHostKeyAlgorithms:
1187 charptr = &options->hostkeyalgorithms;
1188 goto parse_keytypes;
1189
Ben Lindstromade03f62001-12-06 18:22:17 +00001190 case sPubkeyAuthentication:
1191 intptr = &options->pubkey_authentication;
1192 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001193
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001194 case sPubkeyAcceptedKeyTypes:
1195 charptr = &options->pubkey_key_types;
1196 goto parse_keytypes;
1197
Ben Lindstromade03f62001-12-06 18:22:17 +00001198 case sKerberosAuthentication:
1199 intptr = &options->kerberos_authentication;
1200 goto parse_flag;
1201
1202 case sKerberosOrLocalPasswd:
1203 intptr = &options->kerberos_or_local_passwd;
1204 goto parse_flag;
1205
1206 case sKerberosTicketCleanup:
1207 intptr = &options->kerberos_ticket_cleanup;
1208 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001209
Darren Tucker22ef5082003-12-31 11:37:34 +11001210 case sKerberosGetAFSToken:
1211 intptr = &options->kerberos_get_afs_token;
1212 goto parse_flag;
1213
Darren Tucker0efd1552003-08-26 11:49:55 +10001214 case sGssAuthentication:
1215 intptr = &options->gss_authentication;
1216 goto parse_flag;
1217
1218 case sGssCleanupCreds:
1219 intptr = &options->gss_cleanup_creds;
1220 goto parse_flag;
1221
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001222 case sGssStrictAcceptor:
1223 intptr = &options->gss_strict_acceptor;
1224 goto parse_flag;
1225
Ben Lindstromade03f62001-12-06 18:22:17 +00001226 case sPasswordAuthentication:
1227 intptr = &options->password_authentication;
1228 goto parse_flag;
1229
1230 case sKbdInteractiveAuthentication:
1231 intptr = &options->kbd_interactive_authentication;
1232 goto parse_flag;
1233
1234 case sChallengeResponseAuthentication:
1235 intptr = &options->challenge_response_authentication;
1236 goto parse_flag;
1237
1238 case sPrintMotd:
1239 intptr = &options->print_motd;
1240 goto parse_flag;
1241
1242 case sPrintLastLog:
1243 intptr = &options->print_lastlog;
1244 goto parse_flag;
1245
1246 case sX11Forwarding:
1247 intptr = &options->x11_forwarding;
1248 goto parse_flag;
1249
1250 case sX11DisplayOffset:
1251 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001252 parse_int:
1253 arg = strdelim(&cp);
1254 if (!arg || *arg == '\0')
1255 fatal("%s line %d: missing integer value.",
1256 filename, linenum);
1257 value = atoi(arg);
1258 if (*activep && *intptr == -1)
1259 *intptr = value;
1260 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001261
Damien Miller95c249f2002-02-05 12:11:34 +11001262 case sX11UseLocalhost:
1263 intptr = &options->x11_use_localhost;
1264 goto parse_flag;
1265
Ben Lindstromade03f62001-12-06 18:22:17 +00001266 case sXAuthLocation:
1267 charptr = &options->xauth_location;
1268 goto parse_filename;
1269
Damien Miller5ff30c62013-10-30 22:21:50 +11001270 case sPermitTTY:
1271 intptr = &options->permit_tty;
1272 goto parse_flag;
1273
Damien Miller72e6b5c2014-07-04 09:00:04 +10001274 case sPermitUserRC:
1275 intptr = &options->permit_user_rc;
1276 goto parse_flag;
1277
Ben Lindstromade03f62001-12-06 18:22:17 +00001278 case sStrictModes:
1279 intptr = &options->strict_modes;
1280 goto parse_flag;
1281
Damien Miller12c150e2003-12-17 16:31:10 +11001282 case sTCPKeepAlive:
1283 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001284 goto parse_flag;
1285
1286 case sEmptyPasswd:
1287 intptr = &options->permit_empty_passwd;
1288 goto parse_flag;
1289
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001290 case sPermitUserEnvironment:
1291 intptr = &options->permit_user_env;
1292 goto parse_flag;
1293
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001294 case sCompression:
1295 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001296 multistate_ptr = multistate_compression;
1297 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001298
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001299 case sRekeyLimit:
1300 arg = strdelim(&cp);
1301 if (!arg || *arg == '\0')
1302 fatal("%.200s line %d: Missing argument.", filename,
1303 linenum);
1304 if (strcmp(arg, "default") == 0) {
1305 val64 = 0;
1306 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001307 if (scan_scaled(arg, &val64) == -1)
1308 fatal("%.200s line %d: Bad number '%s': %s",
1309 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001310 if (val64 != 0 && val64 < 16)
1311 fatal("%.200s line %d: RekeyLimit too small",
1312 filename, linenum);
1313 }
1314 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001315 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001316 if (cp != NULL) { /* optional rekey interval present */
1317 if (strcmp(cp, "none") == 0) {
1318 (void)strdelim(&cp); /* discard */
1319 break;
1320 }
1321 intptr = &options->rekey_interval;
1322 goto parse_time;
1323 }
1324 break;
1325
Ben Lindstromade03f62001-12-06 18:22:17 +00001326 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001327 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001328 multistate_ptr = multistate_gatewayports;
1329 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001330
Damien Miller3a961dc2003-06-03 10:25:48 +10001331 case sUseDNS:
1332 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001333 goto parse_flag;
1334
1335 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001336 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001337 arg = strdelim(&cp);
1338 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001339 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001340 fatal("%.200s line %d: unsupported log facility '%s'",
1341 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001342 if (*log_facility_ptr == -1)
1343 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001344 break;
1345
1346 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001347 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001348 arg = strdelim(&cp);
1349 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001350 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001351 fatal("%.200s line %d: unsupported log level '%s'",
1352 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001353 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001354 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001355 break;
1356
1357 case sAllowTcpForwarding:
1358 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001359 multistate_ptr = multistate_tcpfwd;
1360 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001361
Damien Miller7acefbb2014-07-18 14:11:24 +10001362 case sAllowStreamLocalForwarding:
1363 intptr = &options->allow_streamlocal_forwarding;
1364 multistate_ptr = multistate_tcpfwd;
1365 goto parse_multistate;
1366
Damien Miller4f755cd2008-05-19 14:57:41 +10001367 case sAllowAgentForwarding:
1368 intptr = &options->allow_agent_forwarding;
1369 goto parse_flag;
1370
djm@openbsd.org7844f352016-11-30 03:00:05 +00001371 case sDisableForwarding:
1372 intptr = &options->disable_forwarding;
1373 goto parse_flag;
1374
Ben Lindstromade03f62001-12-06 18:22:17 +00001375 case sAllowUsers:
1376 while ((arg = strdelim(&cp)) && *arg != '\0') {
1377 if (options->num_allow_users >= MAX_ALLOW_USERS)
1378 fatal("%s line %d: too many allow users.",
1379 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001380 if (match_user(NULL, NULL, NULL, arg) == -1)
1381 fatal("%s line %d: invalid AllowUsers pattern: "
1382 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001383 if (!*activep)
1384 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001385 options->allow_users[options->num_allow_users++] =
1386 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001387 }
1388 break;
1389
1390 case sDenyUsers:
1391 while ((arg = strdelim(&cp)) && *arg != '\0') {
1392 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001393 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001394 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001395 if (match_user(NULL, NULL, NULL, arg) == -1)
1396 fatal("%s line %d: invalid DenyUsers pattern: "
1397 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001398 if (!*activep)
1399 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001400 options->deny_users[options->num_deny_users++] =
1401 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001402 }
1403 break;
1404
1405 case sAllowGroups:
1406 while ((arg = strdelim(&cp)) && *arg != '\0') {
1407 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1408 fatal("%s line %d: too many allow groups.",
1409 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001410 if (!*activep)
1411 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001412 options->allow_groups[options->num_allow_groups++] =
1413 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001414 }
1415 break;
1416
1417 case sDenyGroups:
1418 while ((arg = strdelim(&cp)) && *arg != '\0') {
1419 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1420 fatal("%s line %d: too many deny groups.",
1421 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001422 if (!*activep)
1423 continue;
1424 options->deny_groups[options->num_deny_groups++] =
1425 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001426 }
1427 break;
1428
1429 case sCiphers:
1430 arg = strdelim(&cp);
1431 if (!arg || *arg == '\0')
1432 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001433 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001434 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1435 filename, linenum, arg ? arg : "<NONE>");
1436 if (options->ciphers == NULL)
1437 options->ciphers = xstrdup(arg);
1438 break;
1439
1440 case sMacs:
1441 arg = strdelim(&cp);
1442 if (!arg || *arg == '\0')
1443 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001444 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001445 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1446 filename, linenum, arg ? arg : "<NONE>");
1447 if (options->macs == NULL)
1448 options->macs = xstrdup(arg);
1449 break;
1450
Damien Millerd5f62bf2010-09-24 22:11:14 +10001451 case sKexAlgorithms:
1452 arg = strdelim(&cp);
1453 if (!arg || *arg == '\0')
1454 fatal("%s line %d: Missing argument.",
1455 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001456 if (*arg != '-' &&
1457 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001458 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1459 filename, linenum, arg ? arg : "<NONE>");
1460 if (options->kex_algorithms == NULL)
1461 options->kex_algorithms = xstrdup(arg);
1462 break;
1463
Ben Lindstromade03f62001-12-06 18:22:17 +00001464 case sSubsystem:
1465 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1466 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001467 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001468 }
1469 arg = strdelim(&cp);
1470 if (!arg || *arg == '\0')
1471 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001472 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001473 if (!*activep) {
1474 arg = strdelim(&cp);
1475 break;
1476 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001477 for (i = 0; i < options->num_subsystems; i++)
1478 if (strcmp(arg, options->subsystem_name[i]) == 0)
1479 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001480 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001481 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1482 arg = strdelim(&cp);
1483 if (!arg || *arg == '\0')
1484 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001485 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001486 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001487
1488 /* Collect arguments (separate to executable) */
1489 p = xstrdup(arg);
1490 len = strlen(p) + 1;
1491 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1492 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001493 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001494 strlcat(p, " ", len);
1495 strlcat(p, arg, len);
1496 }
1497 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001498 options->num_subsystems++;
1499 break;
1500
1501 case sMaxStartups:
1502 arg = strdelim(&cp);
1503 if (!arg || *arg == '\0')
1504 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001505 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001506 if ((n = sscanf(arg, "%d:%d:%d",
1507 &options->max_startups_begin,
1508 &options->max_startups_rate,
1509 &options->max_startups)) == 3) {
1510 if (options->max_startups_begin >
1511 options->max_startups ||
1512 options->max_startups_rate > 100 ||
1513 options->max_startups_rate < 1)
1514 fatal("%s line %d: Illegal MaxStartups spec.",
1515 filename, linenum);
1516 } else if (n != 1)
1517 fatal("%s line %d: Illegal MaxStartups spec.",
1518 filename, linenum);
1519 else
1520 options->max_startups = options->max_startups_begin;
1521 break;
1522
Darren Tucker89413db2004-05-24 10:36:23 +10001523 case sMaxAuthTries:
1524 intptr = &options->max_authtries;
1525 goto parse_int;
1526
Damien Miller7207f642008-05-19 15:34:50 +10001527 case sMaxSessions:
1528 intptr = &options->max_sessions;
1529 goto parse_int;
1530
Ben Lindstromade03f62001-12-06 18:22:17 +00001531 case sBanner:
1532 charptr = &options->banner;
1533 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001534
Ben Lindstromade03f62001-12-06 18:22:17 +00001535 /*
1536 * These options can contain %X options expanded at
1537 * connect time, so that you can specify paths like:
1538 *
1539 * AuthorizedKeysFile /etc/ssh_keys/%u
1540 */
1541 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001542 if (*activep && options->num_authkeys_files == 0) {
1543 while ((arg = strdelim(&cp)) && *arg != '\0') {
1544 if (options->num_authkeys_files >=
1545 MAX_AUTHKEYS_FILES)
1546 fatal("%s line %d: "
1547 "too many authorized keys files.",
1548 filename, linenum);
1549 options->authorized_keys_files[
1550 options->num_authkeys_files++] =
1551 tilde_expand_filename(arg, getuid());
1552 }
1553 }
1554 return 0;
1555
Damien Miller30da3442010-05-10 11:58:03 +10001556 case sAuthorizedPrincipalsFile:
1557 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001558 arg = strdelim(&cp);
1559 if (!arg || *arg == '\0')
1560 fatal("%s line %d: missing file name.",
1561 filename, linenum);
1562 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001563 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001564 /* increase optional counter */
1565 if (intptr != NULL)
1566 *intptr = *intptr + 1;
1567 }
1568 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001569
1570 case sClientAliveInterval:
1571 intptr = &options->client_alive_interval;
1572 goto parse_time;
1573
1574 case sClientAliveCountMax:
1575 intptr = &options->client_alive_count_max;
1576 goto parse_int;
1577
Darren Tucker46bc0752004-05-02 22:11:30 +10001578 case sAcceptEnv:
1579 while ((arg = strdelim(&cp)) && *arg != '\0') {
1580 if (strchr(arg, '=') != NULL)
1581 fatal("%s line %d: Invalid environment name.",
1582 filename, linenum);
1583 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1584 fatal("%s line %d: too many allow env.",
1585 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001586 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001587 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001588 options->accept_env[options->num_accept_env++] =
1589 xstrdup(arg);
1590 }
1591 break;
1592
Damien Millerd27b9472005-12-13 19:29:02 +11001593 case sPermitTunnel:
1594 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001595 arg = strdelim(&cp);
1596 if (!arg || *arg == '\0')
1597 fatal("%s line %d: Missing yes/point-to-point/"
1598 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001599 value = -1;
1600 for (i = 0; tunmode_desc[i].val != -1; i++)
1601 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1602 value = tunmode_desc[i].val;
1603 break;
1604 }
1605 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001606 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1607 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001608 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001609 *intptr = value;
1610 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001611
Darren Tucker45150472006-07-12 22:34:17 +10001612 case sMatch:
1613 if (cmdline)
1614 fatal("Match directive not supported as a command-line "
1615 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001616 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001617 if (value < 0)
1618 fatal("%s line %d: Bad Match condition", filename,
1619 linenum);
1620 *activep = value;
1621 break;
1622
Damien Miller9b439df2006-07-24 14:04:00 +10001623 case sPermitOpen:
1624 arg = strdelim(&cp);
1625 if (!arg || *arg == '\0')
1626 fatal("%s line %d: missing PermitOpen specification",
1627 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001628 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001629 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001630 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001631 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001632 options->num_permitted_opens = 0;
1633 }
Damien Miller9b439df2006-07-24 14:04:00 +10001634 break;
1635 }
Damien Millerc6081482012-04-22 11:18:53 +10001636 if (strcmp(arg, "none") == 0) {
1637 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001638 options->num_permitted_opens = 1;
1639 channel_disable_adm_local_opens();
1640 }
1641 break;
1642 }
Damien Millera29b95e2007-01-05 16:28:36 +11001643 if (*activep && n == -1)
1644 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001645 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1646 p = hpdelim(&arg);
1647 if (p == NULL)
1648 fatal("%s line %d: missing host in PermitOpen",
1649 filename, linenum);
1650 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001651 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001652 fatal("%s line %d: bad port number in "
1653 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001654 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001655 options->num_permitted_opens =
1656 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001657 }
Damien Miller9b439df2006-07-24 14:04:00 +10001658 break;
1659
Damien Millere2754432006-07-24 14:06:47 +10001660 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001661 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001662 fatal("%.200s line %d: Missing argument.", filename,
1663 linenum);
1664 len = strspn(cp, WHITESPACE);
1665 if (*activep && options->adm_forced_command == NULL)
1666 options->adm_forced_command = xstrdup(cp + len);
1667 return 0;
1668
Damien Millerd8cb1f12008-02-10 22:40:12 +11001669 case sChrootDirectory:
1670 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001671
1672 arg = strdelim(&cp);
1673 if (!arg || *arg == '\0')
1674 fatal("%s line %d: missing file name.",
1675 filename, linenum);
1676 if (*activep && *charptr == NULL)
1677 *charptr = xstrdup(arg);
1678 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001679
Damien Miller1aed65e2010-03-04 21:53:35 +11001680 case sTrustedUserCAKeys:
1681 charptr = &options->trusted_user_ca_keys;
1682 goto parse_filename;
1683
1684 case sRevokedKeys:
1685 charptr = &options->revoked_keys_file;
1686 goto parse_filename;
1687
Damien Miller0dac6fb2010-11-20 15:19:38 +11001688 case sIPQoS:
1689 arg = strdelim(&cp);
1690 if ((value = parse_ipqos(arg)) == -1)
1691 fatal("%s line %d: Bad IPQoS value: %s",
1692 filename, linenum, arg);
1693 arg = strdelim(&cp);
1694 if (arg == NULL)
1695 value2 = value;
1696 else if ((value2 = parse_ipqos(arg)) == -1)
1697 fatal("%s line %d: Bad IPQoS value: %s",
1698 filename, linenum, arg);
1699 if (*activep) {
1700 options->ip_qos_interactive = value;
1701 options->ip_qos_bulk = value2;
1702 }
1703 break;
1704
Damien Miller23528812012-04-22 11:24:43 +10001705 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001706 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001707 fatal("%.200s line %d: Missing argument.", filename,
1708 linenum);
1709 len = strspn(cp, WHITESPACE);
1710 if (*activep && options->version_addendum == NULL) {
1711 if (strcasecmp(cp + len, "none") == 0)
1712 options->version_addendum = xstrdup("");
1713 else if (strchr(cp + len, '\r') != NULL)
1714 fatal("%.200s line %d: Invalid argument",
1715 filename, linenum);
1716 else
1717 options->version_addendum = xstrdup(cp + len);
1718 }
1719 return 0;
1720
Damien Miller09d3e122012-10-31 08:58:58 +11001721 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001722 if (cp == NULL)
1723 fatal("%.200s line %d: Missing argument.", filename,
1724 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001725 len = strspn(cp, WHITESPACE);
1726 if (*activep && options->authorized_keys_command == NULL) {
1727 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1728 fatal("%.200s line %d: AuthorizedKeysCommand "
1729 "must be an absolute path",
1730 filename, linenum);
1731 options->authorized_keys_command = xstrdup(cp + len);
1732 }
1733 return 0;
1734
1735 case sAuthorizedKeysCommandUser:
1736 charptr = &options->authorized_keys_command_user;
1737
1738 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001739 if (!arg || *arg == '\0')
1740 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1741 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001742 if (*activep && *charptr == NULL)
1743 *charptr = xstrdup(arg);
1744 break;
1745
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001746 case sAuthorizedPrincipalsCommand:
1747 if (cp == NULL)
1748 fatal("%.200s line %d: Missing argument.", filename,
1749 linenum);
1750 len = strspn(cp, WHITESPACE);
1751 if (*activep &&
1752 options->authorized_principals_command == NULL) {
1753 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1754 fatal("%.200s line %d: "
1755 "AuthorizedPrincipalsCommand must be "
1756 "an absolute path", filename, linenum);
1757 options->authorized_principals_command =
1758 xstrdup(cp + len);
1759 }
1760 return 0;
1761
1762 case sAuthorizedPrincipalsCommandUser:
1763 charptr = &options->authorized_principals_command_user;
1764
1765 arg = strdelim(&cp);
1766 if (!arg || *arg == '\0')
1767 fatal("%s line %d: missing "
1768 "AuthorizedPrincipalsCommandUser argument.",
1769 filename, linenum);
1770 if (*activep && *charptr == NULL)
1771 *charptr = xstrdup(arg);
1772 break;
1773
Damien Millera6e3f012012-11-04 23:21:40 +11001774 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001775 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001776 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001777 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001778 while ((arg = strdelim(&cp)) && *arg != '\0') {
1779 if (options->num_auth_methods >=
1780 MAX_AUTH_METHODS)
1781 fatal("%s line %d: "
1782 "too many authentication methods.",
1783 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001784 if (strcmp(arg, "any") == 0) {
1785 if (options->num_auth_methods > 0) {
1786 fatal("%s line %d: \"any\" "
1787 "must appear alone in "
1788 "AuthenticationMethods",
1789 filename, linenum);
1790 }
1791 value = 1;
1792 } else if (value) {
1793 fatal("%s line %d: \"any\" must appear "
1794 "alone in AuthenticationMethods",
1795 filename, linenum);
1796 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001797 fatal("%s line %d: invalid "
1798 "authentication method list.",
1799 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001800 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001801 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001802 if (!*activep)
1803 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001804 options->auth_methods[
1805 options->num_auth_methods++] = xstrdup(arg);
1806 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001807 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001808 fatal("%s line %d: no AuthenticationMethods "
1809 "specified", filename, linenum);
1810 }
Damien Millera6e3f012012-11-04 23:21:40 +11001811 }
1812 return 0;
1813
Damien Miller7acefbb2014-07-18 14:11:24 +10001814 case sStreamLocalBindMask:
1815 arg = strdelim(&cp);
1816 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001817 fatal("%s line %d: missing StreamLocalBindMask "
1818 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001819 /* Parse mode in octal format */
1820 value = strtol(arg, &p, 8);
1821 if (arg == p || value < 0 || value > 0777)
1822 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001823 if (*activep)
1824 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001825 break;
1826
1827 case sStreamLocalBindUnlink:
1828 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1829 goto parse_flag;
1830
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001831 case sFingerprintHash:
1832 arg = strdelim(&cp);
1833 if (!arg || *arg == '\0')
1834 fatal("%.200s line %d: Missing argument.",
1835 filename, linenum);
1836 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1837 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1838 filename, linenum, arg);
1839 if (*activep)
1840 options->fingerprint_hash = value;
1841 break;
1842
djm@openbsd.org8f574952017-06-24 06:34:38 +00001843 case sExposeAuthInfo:
1844 intptr = &options->expose_userauth_info;
1845 goto parse_flag;
1846
Ben Lindstromade03f62001-12-06 18:22:17 +00001847 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001848 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001849 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001850 do_log2(opcode == sIgnore ?
1851 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1852 "%s line %d: %s option %s", filename, linenum,
1853 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001854 while (arg)
1855 arg = strdelim(&cp);
1856 break;
1857
Ben Lindstromade03f62001-12-06 18:22:17 +00001858 default:
1859 fatal("%s line %d: Missing handler for opcode %s (%d)",
1860 filename, linenum, arg, opcode);
1861 }
1862 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1863 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1864 filename, linenum, arg);
1865 return 0;
1866}
1867
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001868/* Reads the server configuration file. */
1869
Damien Miller4af51302000-04-16 11:18:38 +10001870void
Darren Tucker645ab752004-06-25 13:33:20 +10001871load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001872{
Damien Miller46cb75a2012-07-31 12:22:37 +10001873 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001874 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001875 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001876
Darren Tucker645ab752004-06-25 13:33:20 +10001877 debug2("%s: filename %s", __func__, filename);
1878 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001879 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001880 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001881 }
Darren Tucker645ab752004-06-25 13:33:20 +10001882 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001883 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001884 lineno++;
1885 if (strlen(line) == sizeof(line) - 1)
1886 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001887 /*
1888 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001889 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001890 * line numbers later for error messages
1891 */
1892 if ((cp = strchr(line, '#')) != NULL)
1893 memcpy(cp, "\n", 2);
1894 cp = line + strspn(line, " \t\r");
1895
1896 buffer_append(conf, cp, strlen(cp));
1897 }
1898 buffer_append(conf, "\0", 1);
1899 fclose(f);
1900 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1901}
1902
1903void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001904parse_server_match_config(ServerOptions *options,
1905 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001906{
Darren Tucker45150472006-07-12 22:34:17 +10001907 ServerOptions mo;
1908
1909 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001910 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001911 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001912}
1913
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001914int parse_server_match_testspec(struct connection_info *ci, char *spec)
1915{
1916 char *p;
1917
1918 while ((p = strsep(&spec, ",")) && *p != '\0') {
1919 if (strncmp(p, "addr=", 5) == 0) {
1920 ci->address = xstrdup(p + 5);
1921 } else if (strncmp(p, "host=", 5) == 0) {
1922 ci->host = xstrdup(p + 5);
1923 } else if (strncmp(p, "user=", 5) == 0) {
1924 ci->user = xstrdup(p + 5);
1925 } else if (strncmp(p, "laddr=", 6) == 0) {
1926 ci->laddress = xstrdup(p + 6);
1927 } else if (strncmp(p, "lport=", 6) == 0) {
1928 ci->lport = a2port(p + 6);
1929 if (ci->lport == -1) {
1930 fprintf(stderr, "Invalid port '%s' in test mode"
1931 " specification %s\n", p+6, p);
1932 return -1;
1933 }
1934 } else {
1935 fprintf(stderr, "Invalid test mode specification %s\n",
1936 p);
1937 return -1;
1938 }
1939 }
1940 return 0;
1941}
1942
1943/*
1944 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1945 * empty spec.
1946 */
1947int server_match_spec_complete(struct connection_info *ci)
1948{
1949 if (ci->user && ci->host && ci->address)
1950 return 1; /* complete */
1951 if (!ci->user && !ci->host && !ci->address)
1952 return -1; /* empty */
1953 return 0; /* partial */
1954}
1955
Darren Tucker1629c072007-02-19 22:25:37 +11001956/*
1957 * Copy any supported values that are set.
1958 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001959 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001960 * array values that are not used pre-authentication, because any that we
1961 * do use must be explictly sent in mm_getpwnamallow().
1962 */
Darren Tucker45150472006-07-12 22:34:17 +10001963void
Darren Tucker1629c072007-02-19 22:25:37 +11001964copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001965{
Damien Miller534b2cc2013-12-05 14:07:27 +11001966#define M_CP_INTOPT(n) do {\
1967 if (src->n != -1) \
1968 dst->n = src->n; \
1969} while (0)
1970
Darren Tucker1629c072007-02-19 22:25:37 +11001971 M_CP_INTOPT(password_authentication);
1972 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11001973 M_CP_INTOPT(pubkey_authentication);
1974 M_CP_INTOPT(kerberos_authentication);
1975 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001976 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001977 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001978 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001979 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001980
1981 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001982 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001983 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00001984 M_CP_INTOPT(disable_forwarding);
djm@openbsd.org8f574952017-06-24 06:34:38 +00001985 M_CP_INTOPT(expose_userauth_info);
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);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002002 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11002003
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002004 /*
2005 * The bind_mask is a mode_t that may be unsigned, so we can't use
2006 * M_CP_INTOPT - it does a signed comparison that causes compiler
2007 * warnings.
2008 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00002009 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002010 dst->fwd_opts.streamlocal_bind_mask =
2011 src->fwd_opts.streamlocal_bind_mask;
2012 }
2013
Damien Miller534b2cc2013-12-05 14:07:27 +11002014 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2015#define M_CP_STROPT(n) do {\
2016 if (src->n != NULL && dst->n != src->n) { \
2017 free(dst->n); \
2018 dst->n = src->n; \
2019 } \
2020} while(0)
2021#define M_CP_STRARRAYOPT(n, num_n) do {\
2022 if (src->num_n != 0) { \
2023 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2024 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2025 } \
2026} while(0)
2027
Damien Millerf2e407e2011-05-20 19:04:14 +10002028 /* See comment in servconf.h */
2029 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002030
djm@openbsd.orged085102015-10-29 08:05:01 +00002031 /* Arguments that accept '+...' need to be expanded */
2032 assemble_algorithms(dst);
2033
Damien Millerc2411902011-05-20 19:03:49 +10002034 /*
2035 * The only things that should be below this point are string options
2036 * which are only used after authentication.
2037 */
Damien Miller5d74e582011-05-20 19:03:31 +10002038 if (preauth)
2039 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002040
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002041 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002042 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002043 if (option_clear_or_none(dst->adm_forced_command)) {
2044 free(dst->adm_forced_command);
2045 dst->adm_forced_command = NULL;
2046 }
Damien Miller5d74e582011-05-20 19:03:31 +10002047 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002048 if (option_clear_or_none(dst->chroot_directory)) {
2049 free(dst->chroot_directory);
2050 dst->chroot_directory = NULL;
2051 }
Darren Tucker45150472006-07-12 22:34:17 +10002052}
2053
Darren Tucker1629c072007-02-19 22:25:37 +11002054#undef M_CP_INTOPT
2055#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002056#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002057
Darren Tucker45150472006-07-12 22:34:17 +10002058void
2059parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002060 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002061{
2062 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002063 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002064
2065 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2066
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002067 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2068 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002069 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002070 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002071 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002072 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002073 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002074 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002075 }
Darren Tuckera627d422013-06-02 07:31:17 +10002076 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002077 if (bad_options > 0)
2078 fatal("%s: terminating, %d bad configuration options",
2079 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002080 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002081}
Darren Tuckere7140f22008-06-10 23:01:51 +10002082
2083static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002084fmt_multistate_int(int val, const struct multistate *m)
2085{
2086 u_int i;
2087
2088 for (i = 0; m[i].key != NULL; i++) {
2089 if (m[i].value == val)
2090 return m[i].key;
2091 }
2092 return "UNKNOWN";
2093}
2094
2095static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002096fmt_intarg(ServerOpCodes code, int val)
2097{
Damien Miller82c55872011-06-23 08:20:30 +10002098 if (val == -1)
2099 return "unset";
2100 switch (code) {
2101 case sAddressFamily:
2102 return fmt_multistate_int(val, multistate_addressfamily);
2103 case sPermitRootLogin:
2104 return fmt_multistate_int(val, multistate_permitrootlogin);
2105 case sGatewayPorts:
2106 return fmt_multistate_int(val, multistate_gatewayports);
2107 case sCompression:
2108 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002109 case sAllowTcpForwarding:
2110 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002111 case sAllowStreamLocalForwarding:
2112 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002113 case sFingerprintHash:
2114 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002115 default:
2116 switch (val) {
2117 case 0:
2118 return "no";
2119 case 1:
2120 return "yes";
2121 default:
2122 return "UNKNOWN";
2123 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002124 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002125}
2126
2127static const char *
2128lookup_opcode_name(ServerOpCodes code)
2129{
2130 u_int i;
2131
2132 for (i = 0; keywords[i].name != NULL; i++)
2133 if (keywords[i].opcode == code)
2134 return(keywords[i].name);
2135 return "UNKNOWN";
2136}
2137
2138static void
2139dump_cfg_int(ServerOpCodes code, int val)
2140{
2141 printf("%s %d\n", lookup_opcode_name(code), val);
2142}
2143
2144static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002145dump_cfg_oct(ServerOpCodes code, int val)
2146{
2147 printf("%s 0%o\n", lookup_opcode_name(code), val);
2148}
2149
2150static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002151dump_cfg_fmtint(ServerOpCodes code, int val)
2152{
2153 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2154}
2155
2156static void
2157dump_cfg_string(ServerOpCodes code, const char *val)
2158{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002159 printf("%s %s\n", lookup_opcode_name(code),
2160 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002161}
2162
2163static void
2164dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2165{
2166 u_int i;
2167
2168 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002169 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2170}
2171
2172static void
2173dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2174{
2175 u_int i;
2176
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002177 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002178 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002179 printf("%s", lookup_opcode_name(code));
2180 for (i = 0; i < count; i++)
2181 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002182 if (code == sAuthenticationMethods && count == 0)
2183 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002184 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002185}
2186
2187void
2188dump_config(ServerOptions *o)
2189{
2190 u_int i;
2191 int ret;
2192 struct addrinfo *ai;
2193 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002194 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002195
2196 /* these are usually at the top of the config */
2197 for (i = 0; i < o->num_ports; i++)
2198 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002199 dump_cfg_fmtint(sAddressFamily, o->address_family);
2200
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002201 /*
2202 * ListenAddress must be after Port. add_one_listen_addr pushes
2203 * addresses onto a stack, so to maintain ordering we need to
2204 * print these in reverse order.
2205 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002206 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2207 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2208 sizeof(addr), port, sizeof(port),
2209 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2210 error("getnameinfo failed: %.100s",
2211 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2212 strerror(errno));
2213 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002214 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002215 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002216 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2217 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002218 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002219 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2220 addr, port, laddr2);
2221 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002222 }
2223 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002224 printf("%s", laddr1);
2225 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002226
2227 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002228#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002229 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002230#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002231 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002232 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2233 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002234 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002235 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2236 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002237 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002238
2239 /* formatted integer arguments */
2240 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2241 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2242 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002243 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2244 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2245 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002246 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002247#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002248 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2249 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2250 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002251# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002252 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002253# endif
2254#endif
2255#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002256 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2257 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002258#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002259 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2260 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2261 o->kbd_interactive_authentication);
2262 dump_cfg_fmtint(sChallengeResponseAuthentication,
2263 o->challenge_response_authentication);
2264 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002265#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002266 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002267#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002268 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2269 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002270 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002271 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002272 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2273 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2274 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2275 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002276 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002277 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002278 dump_cfg_fmtint(sUseDNS, o->use_dns);
2279 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002280 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002281 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002282 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002283 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002284 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
djm@openbsd.org8f574952017-06-24 06:34:38 +00002285 dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
Darren Tuckere7140f22008-06-10 23:01:51 +10002286
2287 /* string arguments */
2288 dump_cfg_string(sPidFile, o->pid_file);
2289 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002290 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2291 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002292 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002293 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002294 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002295 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2296 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002297 dump_cfg_string(sAuthorizedPrincipalsFile,
2298 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002299 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2300 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002301 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2302 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002303 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2304 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002305 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002306 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002307 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002308 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2309 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002310 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2311 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002312 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2313 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002314
2315 /* string arguments requiring a lookup */
2316 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2317 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2318
2319 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002320 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2321 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002322 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2323 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002324 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002325 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002326 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2327 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2328 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2329 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2330 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002331 dump_cfg_strarray_oneline(sAuthenticationMethods,
2332 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002333
2334 /* other arguments */
2335 for (i = 0; i < o->num_subsystems; i++)
2336 printf("subsystem %s %s\n", o->subsystem_name[i],
2337 o->subsystem_args[i]);
2338
2339 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2340 o->max_startups_rate, o->max_startups);
2341
2342 for (i = 0; tunmode_desc[i].val != -1; i++)
2343 if (tunmode_desc[i].val == o->permit_tun) {
2344 s = tunmode_desc[i].text;
2345 break;
2346 }
2347 dump_cfg_string(sPermitTunnel, s);
2348
Damien Miller91475862011-05-05 14:14:34 +10002349 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2350 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002351
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002352 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002353 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002354
Darren Tuckere7140f22008-06-10 23:01:51 +10002355 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002356}