blob: a112798e496bacd4aba856c0988aa2792071f723 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00002/* $OpenBSD: servconf.c,v 1.308 2017/05/17 01:24:17 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerd7834352006-08-05 12:39:39 +100032#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100033#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100034#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100035#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100036#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100037
Damien Millerb84886b2008-05-19 15:05:07 +100038#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100042#include "buffer.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100043#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100045#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000047#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100048#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000049#include "kex.h"
50#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100051#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100052#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100053#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100054#include "canohost.h"
55#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110056#include "hostfile.h"
57#include "auth.h"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000058#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000059#include "digest.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000060
Damien Miller3dc71ad2009-01-28 16:31:22 +110061static void add_listen_addr(ServerOptions *, char *, int);
62static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110063
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000064/* Use of privilege separation or not */
65extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100066extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000067
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068/* Initializes the server options to their default values. */
69
Damien Miller4af51302000-04-16 11:18:38 +100070void
Damien Miller95def091999-11-25 00:26:21 +110071initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072{
Damien Miller95def091999-11-25 00:26:21 +110073 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100076 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110077
78 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110079 options->num_ports = 0;
80 options->ports_from_cmdline = 0;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +000081 options->queued_listen_addrs = NULL;
82 options->num_queued_listens = 0;
Damien Miller34132e52000-01-14 15:45:46 +110083 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110084 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110085 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110086 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100087 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100088 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110089 options->login_grace_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +000090 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110091 options->ignore_rhosts = -1;
92 options->ignore_user_known_hosts = -1;
93 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000094 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110095 options->x11_forwarding = -1;
96 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110097 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110098 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +100099 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000100 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100102 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100103 options->log_facility = SYSLOG_FACILITY_NOT_SET;
104 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000105 options->hostbased_authentication = -1;
106 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000107 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000108 options->hostkeyalgorithms = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100109 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000110 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->kerberos_authentication = -1;
112 options->kerberos_or_local_passwd = -1;
113 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100114 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000115 options->gss_authentication=-1;
116 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000117 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100118 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100119 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000120 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000122 options->permit_user_env = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000123 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000124 options->rekey_limit = -1;
125 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100126 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000127 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000128 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100129 options->num_allow_users = 0;
130 options->num_deny_users = 0;
131 options->num_allow_groups = 0;
132 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000133 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000134 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000135 options->kex_algorithms = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +1000136 options->fwd_opts.gateway_ports = -1;
137 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
138 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000139 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000140 options->max_startups_begin = -1;
141 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000142 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000143 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000144 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000145 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000146 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000147 options->client_alive_interval = -1;
148 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000149 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000150 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100151 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000152 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000153 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100154 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100155 options->authorized_keys_command = NULL;
156 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100157 options->revoked_keys_file = NULL;
158 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000159 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000160 options->authorized_principals_command = NULL;
161 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100162 options->ip_qos_interactive = -1;
163 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000164 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000165 options->fingerprint_hash = -1;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000166 options->disable_forwarding = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000167}
168
djm@openbsd.org161cf412014-12-22 07:55:51 +0000169/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
170static int
171option_clear_or_none(const char *o)
172{
173 return o == NULL || strcasecmp(o, "none") == 0;
174}
175
djm@openbsd.orged085102015-10-29 08:05:01 +0000176static void
177assemble_algorithms(ServerOptions *o)
178{
179 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
180 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
181 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
182 kex_assemble_names(KEX_DEFAULT_PK_ALG,
183 &o->hostkeyalgorithms) != 0 ||
184 kex_assemble_names(KEX_DEFAULT_PK_ALG,
185 &o->hostbased_key_types) != 0 ||
186 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
187 fatal("kex_assemble_names failed");
188}
189
Damien Miller4af51302000-04-16 11:18:38 +1000190void
Damien Miller95def091999-11-25 00:26:21 +1100191fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000192{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000193 int i;
194
Damien Miller726273e2001-11-12 11:40:11 +1100195 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000196 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000197 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100198
199 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100200 if (options->num_host_key_files == 0) {
201 /* fill default hostkeys for protocols */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000202 options->host_key_files[options->num_host_key_files++] =
203 _PATH_HOST_RSA_KEY_FILE;
204 options->host_key_files[options->num_host_key_files++] =
205 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100206#ifdef OPENSSL_HAS_ECC
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000207 options->host_key_files[options->num_host_key_files++] =
208 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100209#endif
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000210 options->host_key_files[options->num_host_key_files++] =
211 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100212 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100213 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100214 if (options->num_ports == 0)
215 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000216 if (options->address_family == -1)
217 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100218 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000219 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000220 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000221 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000223 options->login_grace_time = 120;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000224 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000225 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100227 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->ignore_user_known_hosts == -1)
229 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->print_motd == -1)
231 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000232 if (options->print_lastlog == -1)
233 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100235 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100237 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100238 if (options->x11_use_localhost == -1)
239 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000240 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000241 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100242 if (options->permit_tty == -1)
243 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000244 if (options->permit_user_rc == -1)
245 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->strict_modes == -1)
247 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100248 if (options->tcp_keep_alive == -1)
249 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100250 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100251 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100252 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000253 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000254 if (options->hostbased_authentication == -1)
255 options->hostbased_authentication = 0;
256 if (options->hostbased_uses_name_from_packet_only == -1)
257 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100258 if (options->pubkey_authentication == -1)
259 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100260 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000261 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->kerberos_or_local_passwd == -1)
263 options->kerberos_or_local_passwd = 1;
264 if (options->kerberos_ticket_cleanup == -1)
265 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100266 if (options->kerberos_get_afs_token == -1)
267 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000268 if (options->gss_authentication == -1)
269 options->gss_authentication = 0;
270 if (options->gss_cleanup_creds == -1)
271 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000272 if (options->gss_strict_acceptor == -1)
djm@openbsd.org13bd2e22017-01-06 03:45:41 +0000273 options->gss_strict_acceptor = 1;
Damien Miller95def091999-11-25 00:26:21 +1100274 if (options->password_authentication == -1)
275 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100276 if (options->kbd_interactive_authentication == -1)
277 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000278 if (options->challenge_response_authentication == -1)
279 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100281 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000282 if (options->permit_user_env == -1)
283 options->permit_user_env = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000284 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000285 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000286 if (options->rekey_limit == -1)
287 options->rekey_limit = 0;
288 if (options->rekey_interval == -1)
289 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100290 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100291 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000292 if (options->allow_streamlocal_forwarding == -1)
293 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000294 if (options->allow_agent_forwarding == -1)
295 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000296 if (options->fwd_opts.gateway_ports == -1)
297 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000298 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100299 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000300 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100301 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000302 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100303 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000304 if (options->max_authtries == -1)
305 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000306 if (options->max_sessions == -1)
307 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000308 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000309 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000310 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100311 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000312 if (options->client_alive_count_max == -1)
313 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000314 if (options->num_authkeys_files == 0) {
315 options->authorized_keys_files[options->num_authkeys_files++] =
316 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
317 options->authorized_keys_files[options->num_authkeys_files++] =
318 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
319 }
Damien Millerd27b9472005-12-13 19:29:02 +1100320 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100321 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100322 if (options->ip_qos_interactive == -1)
323 options->ip_qos_interactive = IPTOS_LOWDELAY;
324 if (options->ip_qos_bulk == -1)
325 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000326 if (options->version_addendum == NULL)
327 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000328 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
329 options->fwd_opts.streamlocal_bind_mask = 0177;
330 if (options->fwd_opts.streamlocal_bind_unlink == -1)
331 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000332 if (options->fingerprint_hash == -1)
333 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org7844f352016-11-30 03:00:05 +0000334 if (options->disable_forwarding == -1)
335 options->disable_forwarding = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000336
djm@openbsd.orged085102015-10-29 08:05:01 +0000337 assemble_algorithms(options);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000338
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000339 /* Turn privilege separation and sandboxing on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000340 if (use_privsep == -1)
djm@openbsd.orgc5c3f322016-02-17 05:29:04 +0000341 use_privsep = PRIVSEP_ON;
Damien Miller4903eb42002-06-21 16:20:44 +1000342
djm@openbsd.org161cf412014-12-22 07:55:51 +0000343#define CLEAR_ON_NONE(v) \
344 do { \
345 if (option_clear_or_none(v)) { \
346 free(v); \
347 v = NULL; \
348 } \
349 } while(0)
350 CLEAR_ON_NONE(options->pid_file);
351 CLEAR_ON_NONE(options->xauth_location);
352 CLEAR_ON_NONE(options->banner);
353 CLEAR_ON_NONE(options->trusted_user_ca_keys);
354 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000355 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org9fd04682015-11-13 04:38:06 +0000356 CLEAR_ON_NONE(options->adm_forced_command);
357 CLEAR_ON_NONE(options->chroot_directory);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000358 for (i = 0; i < options->num_host_key_files; i++)
359 CLEAR_ON_NONE(options->host_key_files[i]);
360 for (i = 0; i < options->num_host_cert_files; i++)
361 CLEAR_ON_NONE(options->host_cert_files[i]);
362#undef CLEAR_ON_NONE
363
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +0000364 /* Similar handling for AuthenticationMethods=any */
365 if (options->num_auth_methods == 1 &&
366 strcmp(options->auth_methods[0], "any") == 0) {
367 free(options->auth_methods[0]);
368 options->auth_methods[0] = NULL;
369 options->num_auth_methods = 0;
370 }
371
Tim Rice40017b02002-07-14 13:36:49 -0700372#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000373 if (use_privsep && options->compression == 1) {
374 error("This platform does not support both privilege "
375 "separation and compression");
376 error("Compression disabled");
377 options->compression = 0;
378 }
379#endif
380
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381}
382
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100384typedef enum {
385 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100386 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000387 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100388 /* Standard Options */
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000389 sPort, sHostKeyFile, sLoginGraceTime,
390 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000391 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100392 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100393 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000394 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100395 sPasswordAuthentication, sKbdInteractiveAuthentication,
396 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000397 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100398 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100399 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
djm@openbsd.org83b58182016-08-19 03:18:06 +0000400 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000401 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000402 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000403 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
404 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000405 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000406 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000407 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000408 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000409 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
410 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100411 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100412 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100413 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000414 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000415 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000416 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100417 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000418 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000419 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org7844f352016-11-30 03:00:05 +0000420 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000421 sDeprecated, sIgnore, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422} ServerOpCodes;
423
Darren Tucker45150472006-07-12 22:34:17 +1000424#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
425#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
426#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
427
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000428/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100429static struct {
430 const char *name;
431 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000432 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100433} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100434 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000435#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000436 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000437#else
Darren Tucker45150472006-07-12 22:34:17 +1000438 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000439#endif
Darren Tucker45150472006-07-12 22:34:17 +1000440 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100441 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "port", sPort, SSHCFG_GLOBAL },
443 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
444 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000445 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "pidfile", sPidFile, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000447 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000448 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000449 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100450 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
djm@openbsd.org54cd41a2017-05-17 01:24:17 +0000452 { "loglevel", sLogLevel, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000453 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000454 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100455 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000456 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000457 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000458 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +0000459 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100460 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000461 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000462 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000463#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000465 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
466 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100467#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000468 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000469#else
Darren Tucker45150472006-07-12 22:34:17 +1000470 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100471#endif
472#else
Darren Tucker1629c072007-02-19 22:25:37 +1100473 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000474 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
475 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
476 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000477#endif
Darren Tucker45150472006-07-12 22:34:17 +1000478 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
479 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000480#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100481 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000482 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000483 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000484#else
Darren Tucker1629c072007-02-19 22:25:37 +1100485 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000487 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000488#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100489 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
490 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100491 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000492 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
493 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
494 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
495 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
496 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100497#ifdef DISABLE_LASTLOG
498 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
499#else
Darren Tucker45150472006-07-12 22:34:17 +1000500 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100501#endif
Darren Tucker45150472006-07-12 22:34:17 +1000502 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
503 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000504 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
505 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
506 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000507 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
508 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100509 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000510 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
djm@openbsd.org83b58182016-08-19 03:18:06 +0000511 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000513 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000514 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
515 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
516 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000517 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000518 { "allowusers", sAllowUsers, SSHCFG_ALL },
519 { "denyusers", sDenyUsers, SSHCFG_ALL },
520 { "allowgroups", sAllowGroups, SSHCFG_ALL },
521 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000522 { "ciphers", sCiphers, SSHCFG_GLOBAL },
523 { "macs", sMacs, SSHCFG_GLOBAL },
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000524 { "protocol", sIgnore, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000525 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
526 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
527 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000528 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000529 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100530 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000531 { "usedns", sUseDNS, SSHCFG_GLOBAL },
532 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
533 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +0000534 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
535 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000536 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000537 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
djm@openbsd.org66705942017-03-14 07:19:07 +0000538 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000539 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000540 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100541 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000542 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000543 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000544 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000545 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100546 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100547 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100548 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
549 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000550 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000551 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100552 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100553 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
554 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000555 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
556 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000557 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100558 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000559 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
560 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
561 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000562 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
djm@openbsd.org7844f352016-11-30 03:00:05 +0000563 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000564 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000565};
566
Darren Tuckere7140f22008-06-10 23:01:51 +1000567static struct {
568 int val;
569 char *text;
570} tunmode_desc[] = {
571 { SSH_TUNMODE_NO, "no" },
572 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
573 { SSH_TUNMODE_ETHERNET, "ethernet" },
574 { SSH_TUNMODE_YES, "yes" },
575 { -1, NULL }
576};
577
Damien Miller5428f641999-11-25 11:54:57 +1100578/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000579 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100580 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000581
Damien Miller4af51302000-04-16 11:18:38 +1000582static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100583parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000584 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000585{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000586 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000587
Damien Miller95def091999-11-25 00:26:21 +1100588 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000589 if (strcasecmp(cp, keywords[i].name) == 0) {
590 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100591 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000592 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000593
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000594 error("%s: line %d: Bad configuration option: %s",
595 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100596 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000597}
598
Darren Tucker88b6fb22010-01-13 22:44:29 +1100599char *
600derelativise_path(const char *path)
601{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000602 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100603
djm@openbsd.org161cf412014-12-22 07:55:51 +0000604 if (strcasecmp(path, "none") == 0)
605 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100606 expanded = tilde_expand_filename(path, getuid());
607 if (*expanded == '/')
608 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100609 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100610 fatal("%s: getcwd: %s", __func__, strerror(errno));
611 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000612 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100613 return ret;
614}
615
Ben Lindstrombba81212001-06-25 05:01:22 +0000616static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100617add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100618{
Damien Millereccb9de2005-06-17 12:59:34 +1000619 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100620
Ben Lindstrom19066a12001-04-12 23:39:26 +0000621 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000622 for (i = 0; i < options->num_ports; i++)
623 add_one_listen_addr(options, addr, options->ports[i]);
624 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000625 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000626}
627
Ben Lindstrombba81212001-06-25 05:01:22 +0000628static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100629add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000630{
631 struct addrinfo hints, *ai, *aitop;
632 char strport[NI_MAXSERV];
633 int gaierr;
634
635 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100636 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000637 hints.ai_socktype = SOCK_STREAM;
638 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100639 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000640 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
641 fatal("bad addr or host: %s (%s)",
642 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100643 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000644 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
645 ;
646 ai->ai_next = options->listen_addrs;
647 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100648}
649
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000650/*
651 * Queue a ListenAddress to be processed once we have all of the Ports
652 * and AddressFamily options.
653 */
654static void
655queue_listen_addr(ServerOptions *options, char *addr, int port)
656{
657 options->queued_listen_addrs = xreallocarray(
658 options->queued_listen_addrs, options->num_queued_listens + 1,
659 sizeof(addr));
660 options->queued_listen_ports = xreallocarray(
661 options->queued_listen_ports, options->num_queued_listens + 1,
662 sizeof(port));
663 options->queued_listen_addrs[options->num_queued_listens] =
664 xstrdup(addr);
665 options->queued_listen_ports[options->num_queued_listens] = port;
666 options->num_queued_listens++;
667}
668
669/*
670 * Process queued (text) ListenAddress entries.
671 */
672static void
673process_queued_listen_addrs(ServerOptions *options)
674{
675 u_int i;
676
677 if (options->num_ports == 0)
678 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
679 if (options->address_family == -1)
680 options->address_family = AF_UNSPEC;
681
682 for (i = 0; i < options->num_queued_listens; i++) {
683 add_listen_addr(options, options->queued_listen_addrs[i],
684 options->queued_listen_ports[i]);
685 free(options->queued_listen_addrs[i]);
686 options->queued_listen_addrs[i] = NULL;
687 }
688 free(options->queued_listen_addrs);
689 options->queued_listen_addrs = NULL;
690 free(options->queued_listen_ports);
691 options->queued_listen_ports = NULL;
692 options->num_queued_listens = 0;
693}
694
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695struct connection_info *
696get_connection_info(int populate, int use_dns)
697{
djm@openbsd.org95767262016-03-07 19:02:43 +0000698 struct ssh *ssh = active_state; /* XXX */
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000699 static struct connection_info ci;
700
701 if (!populate)
702 return &ci;
djm@openbsd.org95767262016-03-07 19:02:43 +0000703 ci.host = auth_get_canonical_hostname(ssh, use_dns);
704 ci.address = ssh_remote_ipaddr(ssh);
705 ci.laddress = ssh_local_ipaddr(ssh);
706 ci.lport = ssh_local_port(ssh);
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000707 return &ci;
708}
709
Darren Tucker45150472006-07-12 22:34:17 +1000710/*
711 * The strategy for the Match blocks is that the config file is parsed twice.
712 *
713 * The first time is at startup. activep is initialized to 1 and the
714 * directives in the global context are processed and acted on. Hitting a
715 * Match directive unsets activep and the directives inside the block are
716 * checked for syntax only.
717 *
718 * The second time is after a connection has been established but before
719 * authentication. activep is initialized to 2 and global config directives
720 * are ignored since they have already been processed. If the criteria in a
721 * Match block is met, activep is set and the subsequent directives
722 * processed and actioned until EOF or another Match block unsets it. Any
723 * options set are copied into the main server config.
724 *
725 * Potential additions/improvements:
djm@openbsd.orgae363d72016-08-25 23:57:54 +0000726 * - Add Match support for pre-kex directives, eg. Ciphers.
Darren Tucker45150472006-07-12 22:34:17 +1000727 *
728 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
729 * Match Address 192.168.0.*
730 * Tag trusted
731 * Match Group wheel
732 * Tag trusted
733 * Match Tag trusted
734 * AllowTcpForwarding yes
735 * GatewayPorts clientspecified
736 * [...]
737 *
738 * - Add a PermittedChannelRequests directive
739 * Match Group shell
740 * PermittedChannelRequests session,forwarded-tcpip
741 */
742
743static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000744match_cfg_line_group(const char *grps, int line, const char *user)
745{
746 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000747 struct passwd *pw;
748
Damien Miller565ca3f2006-08-19 00:23:15 +1000749 if (user == NULL)
750 goto out;
751
752 if ((pw = getpwnam(user)) == NULL) {
753 debug("Can't match group at line %d because user %.100s does "
754 "not exist", line, user);
755 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
756 debug("Can't Match group because user %.100s not in any group "
757 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000758 } else if (ga_match_pattern_list(grps) != 1) {
759 debug("user %.100s does not match group list %.100s at line %d",
760 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000761 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000762 debug("user %.100s matched group list %.100s at line %d", user,
763 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000764 result = 1;
765 }
766out:
767 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000768 return result;
769}
770
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000771/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000772 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100773 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000774 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000775 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000776static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000777match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000778{
Damien Millercf31f382013-10-24 21:02:56 +1100779 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000780 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000781
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000782 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000783 debug3("checking syntax for 'Match %s'", cp);
784 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000785 debug3("checking match for '%s' user %s host %s addr %s "
786 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
787 ci->host ? ci->host : "(null)",
788 ci->address ? ci->address : "(null)",
789 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000790
791 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100792 attributes++;
793 if (strcasecmp(attrib, "all") == 0) {
794 if (attributes != 1 ||
795 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
796 error("'all' cannot be combined with other "
797 "Match attributes");
798 return -1;
799 }
800 *condition = cp;
801 return 1;
802 }
Darren Tucker45150472006-07-12 22:34:17 +1000803 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
804 error("Missing Match criteria for %s", attrib);
805 return -1;
806 }
Darren Tucker45150472006-07-12 22:34:17 +1000807 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000808 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000809 result = 0;
810 continue;
811 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000812 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000813 result = 0;
814 else
815 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000816 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000817 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000818 if (ci == NULL || ci->user == NULL) {
819 result = 0;
820 continue;
821 }
822 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000823 case -1:
824 return -1;
825 case 0:
826 result = 0;
827 }
Darren Tucker45150472006-07-12 22:34:17 +1000828 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000829 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000830 result = 0;
831 continue;
832 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000833 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000834 result = 0;
835 else
836 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000837 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000838 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000839 if (ci == NULL || ci->address == NULL) {
840 result = 0;
841 continue;
842 }
843 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000844 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000845 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000846 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000847 break;
848 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000849 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000850 result = 0;
851 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000852 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000853 return -1;
854 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000855 } else if (strcasecmp(attrib, "localaddress") == 0){
856 if (ci == NULL || ci->laddress == NULL) {
857 result = 0;
858 continue;
859 }
860 switch (addr_match_list(ci->laddress, arg)) {
861 case 1:
862 debug("connection from %.100s matched "
863 "'LocalAddress %.100s' at line %d",
864 ci->laddress, arg, line);
865 break;
866 case 0:
867 case -1:
868 result = 0;
869 break;
870 case -2:
871 return -1;
872 }
873 } else if (strcasecmp(attrib, "localport") == 0) {
874 if ((port = a2port(arg)) == -1) {
875 error("Invalid LocalPort '%s' on Match line",
876 arg);
877 return -1;
878 }
879 if (ci == NULL || ci->lport == 0) {
880 result = 0;
881 continue;
882 }
883 /* TODO support port lists */
884 if (port == ci->lport)
885 debug("connection from %.100s matched "
886 "'LocalPort %d' at line %d",
887 ci->laddress, port, line);
888 else
889 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000890 } else {
891 error("Unsupported Match attribute %s", attrib);
892 return -1;
893 }
894 }
Damien Millercf31f382013-10-24 21:02:56 +1100895 if (attributes == 0) {
896 error("One or more attributes required for Match");
897 return -1;
898 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000899 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000900 debug3("match %sfound", result ? "" : "not ");
901 *condition = cp;
902 return result;
903}
904
Damien Millere2754432006-07-24 14:06:47 +1000905#define WHITESPACE " \t\r\n"
906
Damien Miller33322122011-06-20 14:43:11 +1000907/* Multistate option parsing */
908struct multistate {
909 char *key;
910 int value;
911};
912static const struct multistate multistate_addressfamily[] = {
913 { "inet", AF_INET },
914 { "inet6", AF_INET6 },
915 { "any", AF_UNSPEC },
916 { NULL, -1 }
917};
918static const struct multistate multistate_permitrootlogin[] = {
919 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000920 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000921 { "forced-commands-only", PERMIT_FORCED_ONLY },
922 { "yes", PERMIT_YES },
923 { "no", PERMIT_NO },
924 { NULL, -1 }
925};
926static const struct multistate multistate_compression[] = {
djm@openbsd.org0082fba2016-09-28 16:33:06 +0000927 { "yes", COMP_DELAYED },
djm@openbsd.org4577ade2016-09-28 20:32:42 +0000928 { "delayed", COMP_DELAYED },
Damien Miller33322122011-06-20 14:43:11 +1000929 { "no", COMP_NONE },
930 { NULL, -1 }
931};
932static const struct multistate multistate_gatewayports[] = {
933 { "clientspecified", 2 },
934 { "yes", 1 },
935 { "no", 0 },
936 { NULL, -1 }
937};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100938static const struct multistate multistate_tcpfwd[] = {
939 { "yes", FORWARD_ALLOW },
940 { "all", FORWARD_ALLOW },
941 { "no", FORWARD_DENY },
942 { "remote", FORWARD_REMOTE },
943 { "local", FORWARD_LOCAL },
944 { NULL, -1 }
945};
Damien Miller33322122011-06-20 14:43:11 +1000946
Ben Lindstromade03f62001-12-06 18:22:17 +0000947int
948process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000949 const char *filename, int linenum, int *activep,
950 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000951{
Darren Tucker09c0f032013-05-16 20:48:57 +1000952 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000953 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100954 SyslogFacility *log_facility_ptr;
955 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000956 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000957 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000958 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000959 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000960 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000961
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +0000962 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
963 if ((len = strlen(line)) == 0)
964 return 0;
965 for (len--; len > 0; len--) {
966 if (strchr(WHITESPACE "\f", line[len]) == NULL)
967 break;
968 line[len] = '\0';
969 }
970
Ben Lindstromade03f62001-12-06 18:22:17 +0000971 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100972 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100973 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000974 /* Ignore leading whitespace */
975 if (*arg == '\0')
976 arg = strdelim(&cp);
977 if (!arg || !*arg || *arg == '#')
978 return 0;
979 intptr = NULL;
980 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000981 opcode = parse_token(arg, filename, linenum, &flags);
982
983 if (activep == NULL) { /* We are processing a command line directive */
984 cmdline = 1;
985 activep = &cmdline;
986 }
987 if (*activep && opcode != sMatch)
988 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
989 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000990 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000991 fatal("%s line %d: Directive '%s' is not allowed "
992 "within a Match block", filename, linenum, arg);
993 } else { /* this is a directive we have already processed */
994 while (arg)
995 arg = strdelim(&cp);
996 return 0;
997 }
998 }
999
Ben Lindstromade03f62001-12-06 18:22:17 +00001000 switch (opcode) {
1001 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001002 case sUsePAM:
1003 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001004 goto parse_flag;
1005
1006 /* Standard Options */
1007 case sBadOption:
1008 return -1;
1009 case sPort:
1010 /* ignore ports from configfile if cmdline specifies ports */
1011 if (options->ports_from_cmdline)
1012 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001013 if (options->num_ports >= MAX_PORTS)
1014 fatal("%s line %d: too many ports.",
1015 filename, linenum);
1016 arg = strdelim(&cp);
1017 if (!arg || *arg == '\0')
1018 fatal("%s line %d: missing port number.",
1019 filename, linenum);
1020 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001021 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001022 fatal("%s line %d: Badly formatted port number.",
1023 filename, linenum);
1024 break;
1025
Ben Lindstromade03f62001-12-06 18:22:17 +00001026 case sLoginGraceTime:
1027 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001028 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001029 arg = strdelim(&cp);
1030 if (!arg || *arg == '\0')
1031 fatal("%s line %d: missing time value.",
1032 filename, linenum);
1033 if ((value = convtime(arg)) == -1)
1034 fatal("%s line %d: invalid time value.",
1035 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001036 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001037 *intptr = value;
1038 break;
1039
Ben Lindstromade03f62001-12-06 18:22:17 +00001040 case sListenAddress:
1041 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001042 if (arg == NULL || *arg == '\0')
1043 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001045 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1046 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1047 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001048 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001049 break;
1050 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001051 p = hpdelim(&arg);
1052 if (p == NULL)
1053 fatal("%s line %d: bad address:port usage",
1054 filename, linenum);
1055 p = cleanhostname(p);
1056 if (arg == NULL)
1057 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001058 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001059 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001060
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001061 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001062
Ben Lindstromade03f62001-12-06 18:22:17 +00001063 break;
1064
Darren Tucker0f383232005-01-20 10:57:56 +11001065 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001066 intptr = &options->address_family;
1067 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001068 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001069 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001070 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001071 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001072 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001073 value = -1;
1074 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1075 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1076 value = multistate_ptr[i].value;
1077 break;
1078 }
1079 }
1080 if (value == -1)
1081 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001082 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001083 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001084 *intptr = value;
1085 break;
1086
Ben Lindstromade03f62001-12-06 18:22:17 +00001087 case sHostKeyFile:
1088 intptr = &options->num_host_key_files;
1089 if (*intptr >= MAX_HOSTKEYS)
1090 fatal("%s line %d: too many host keys specified (max %d).",
1091 filename, linenum, MAX_HOSTKEYS);
1092 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001093 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001094 arg = strdelim(&cp);
1095 if (!arg || *arg == '\0')
1096 fatal("%s line %d: missing file name.",
1097 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001098 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001099 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001100 /* increase optional counter */
1101 if (intptr != NULL)
1102 *intptr = *intptr + 1;
1103 }
1104 break;
1105
Damien Miller85b45e02013-07-20 13:21:52 +10001106 case sHostKeyAgent:
1107 charptr = &options->host_key_agent;
1108 arg = strdelim(&cp);
1109 if (!arg || *arg == '\0')
1110 fatal("%s line %d: missing socket name.",
1111 filename, linenum);
1112 if (*activep && *charptr == NULL)
1113 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1114 xstrdup(arg) : derelativise_path(arg);
1115 break;
1116
Damien Miller0a80ca12010-02-27 07:55:05 +11001117 case sHostCertificate:
1118 intptr = &options->num_host_cert_files;
1119 if (*intptr >= MAX_HOSTKEYS)
1120 fatal("%s line %d: too many host certificates "
1121 "specified (max %d).", filename, linenum,
1122 MAX_HOSTCERTS);
1123 charptr = &options->host_cert_files[*intptr];
1124 goto parse_filename;
Damien Miller0a80ca12010-02-27 07:55:05 +11001125
Ben Lindstromade03f62001-12-06 18:22:17 +00001126 case sPidFile:
1127 charptr = &options->pid_file;
1128 goto parse_filename;
1129
1130 case sPermitRootLogin:
1131 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001132 multistate_ptr = multistate_permitrootlogin;
1133 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001134
1135 case sIgnoreRhosts:
1136 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001137 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001138 arg = strdelim(&cp);
1139 if (!arg || *arg == '\0')
1140 fatal("%s line %d: missing yes/no argument.",
1141 filename, linenum);
1142 value = 0; /* silence compiler */
1143 if (strcmp(arg, "yes") == 0)
1144 value = 1;
1145 else if (strcmp(arg, "no") == 0)
1146 value = 0;
1147 else
1148 fatal("%s line %d: Bad yes/no argument: %s",
1149 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001150 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001151 *intptr = value;
1152 break;
1153
1154 case sIgnoreUserKnownHosts:
1155 intptr = &options->ignore_user_known_hosts;
1156 goto parse_flag;
1157
Ben Lindstromade03f62001-12-06 18:22:17 +00001158 case sHostbasedAuthentication:
1159 intptr = &options->hostbased_authentication;
1160 goto parse_flag;
1161
1162 case sHostbasedUsesNameFromPacketOnly:
1163 intptr = &options->hostbased_uses_name_from_packet_only;
1164 goto parse_flag;
1165
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001166 case sHostbasedAcceptedKeyTypes:
1167 charptr = &options->hostbased_key_types;
1168 parse_keytypes:
1169 arg = strdelim(&cp);
1170 if (!arg || *arg == '\0')
1171 fatal("%s line %d: Missing argument.",
1172 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001173 if (*arg != '-' &&
1174 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001175 fatal("%s line %d: Bad key types '%s'.",
1176 filename, linenum, arg ? arg : "<NONE>");
1177 if (*activep && *charptr == NULL)
1178 *charptr = xstrdup(arg);
1179 break;
1180
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001181 case sHostKeyAlgorithms:
1182 charptr = &options->hostkeyalgorithms;
1183 goto parse_keytypes;
1184
Ben Lindstromade03f62001-12-06 18:22:17 +00001185 case sPubkeyAuthentication:
1186 intptr = &options->pubkey_authentication;
1187 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001188
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001189 case sPubkeyAcceptedKeyTypes:
1190 charptr = &options->pubkey_key_types;
1191 goto parse_keytypes;
1192
Ben Lindstromade03f62001-12-06 18:22:17 +00001193 case sKerberosAuthentication:
1194 intptr = &options->kerberos_authentication;
1195 goto parse_flag;
1196
1197 case sKerberosOrLocalPasswd:
1198 intptr = &options->kerberos_or_local_passwd;
1199 goto parse_flag;
1200
1201 case sKerberosTicketCleanup:
1202 intptr = &options->kerberos_ticket_cleanup;
1203 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001204
Darren Tucker22ef5082003-12-31 11:37:34 +11001205 case sKerberosGetAFSToken:
1206 intptr = &options->kerberos_get_afs_token;
1207 goto parse_flag;
1208
Darren Tucker0efd1552003-08-26 11:49:55 +10001209 case sGssAuthentication:
1210 intptr = &options->gss_authentication;
1211 goto parse_flag;
1212
1213 case sGssCleanupCreds:
1214 intptr = &options->gss_cleanup_creds;
1215 goto parse_flag;
1216
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001217 case sGssStrictAcceptor:
1218 intptr = &options->gss_strict_acceptor;
1219 goto parse_flag;
1220
Ben Lindstromade03f62001-12-06 18:22:17 +00001221 case sPasswordAuthentication:
1222 intptr = &options->password_authentication;
1223 goto parse_flag;
1224
1225 case sKbdInteractiveAuthentication:
1226 intptr = &options->kbd_interactive_authentication;
1227 goto parse_flag;
1228
1229 case sChallengeResponseAuthentication:
1230 intptr = &options->challenge_response_authentication;
1231 goto parse_flag;
1232
1233 case sPrintMotd:
1234 intptr = &options->print_motd;
1235 goto parse_flag;
1236
1237 case sPrintLastLog:
1238 intptr = &options->print_lastlog;
1239 goto parse_flag;
1240
1241 case sX11Forwarding:
1242 intptr = &options->x11_forwarding;
1243 goto parse_flag;
1244
1245 case sX11DisplayOffset:
1246 intptr = &options->x11_display_offset;
naddy@openbsd.orgc38ea632016-08-15 12:27:56 +00001247 parse_int:
1248 arg = strdelim(&cp);
1249 if (!arg || *arg == '\0')
1250 fatal("%s line %d: missing integer value.",
1251 filename, linenum);
1252 value = atoi(arg);
1253 if (*activep && *intptr == -1)
1254 *intptr = value;
1255 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001256
Damien Miller95c249f2002-02-05 12:11:34 +11001257 case sX11UseLocalhost:
1258 intptr = &options->x11_use_localhost;
1259 goto parse_flag;
1260
Ben Lindstromade03f62001-12-06 18:22:17 +00001261 case sXAuthLocation:
1262 charptr = &options->xauth_location;
1263 goto parse_filename;
1264
Damien Miller5ff30c62013-10-30 22:21:50 +11001265 case sPermitTTY:
1266 intptr = &options->permit_tty;
1267 goto parse_flag;
1268
Damien Miller72e6b5c2014-07-04 09:00:04 +10001269 case sPermitUserRC:
1270 intptr = &options->permit_user_rc;
1271 goto parse_flag;
1272
Ben Lindstromade03f62001-12-06 18:22:17 +00001273 case sStrictModes:
1274 intptr = &options->strict_modes;
1275 goto parse_flag;
1276
Damien Miller12c150e2003-12-17 16:31:10 +11001277 case sTCPKeepAlive:
1278 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001279 goto parse_flag;
1280
1281 case sEmptyPasswd:
1282 intptr = &options->permit_empty_passwd;
1283 goto parse_flag;
1284
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001285 case sPermitUserEnvironment:
1286 intptr = &options->permit_user_env;
1287 goto parse_flag;
1288
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001289 case sCompression:
1290 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001291 multistate_ptr = multistate_compression;
1292 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001293
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001294 case sRekeyLimit:
1295 arg = strdelim(&cp);
1296 if (!arg || *arg == '\0')
1297 fatal("%.200s line %d: Missing argument.", filename,
1298 linenum);
1299 if (strcmp(arg, "default") == 0) {
1300 val64 = 0;
1301 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001302 if (scan_scaled(arg, &val64) == -1)
1303 fatal("%.200s line %d: Bad number '%s': %s",
1304 filename, linenum, arg, strerror(errno));
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001305 if (val64 != 0 && val64 < 16)
1306 fatal("%.200s line %d: RekeyLimit too small",
1307 filename, linenum);
1308 }
1309 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001310 options->rekey_limit = val64;
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001311 if (cp != NULL) { /* optional rekey interval present */
1312 if (strcmp(cp, "none") == 0) {
1313 (void)strdelim(&cp); /* discard */
1314 break;
1315 }
1316 intptr = &options->rekey_interval;
1317 goto parse_time;
1318 }
1319 break;
1320
Ben Lindstromade03f62001-12-06 18:22:17 +00001321 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001322 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001323 multistate_ptr = multistate_gatewayports;
1324 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001325
Damien Miller3a961dc2003-06-03 10:25:48 +10001326 case sUseDNS:
1327 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001328 goto parse_flag;
1329
1330 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001331 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001332 arg = strdelim(&cp);
1333 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001334 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001335 fatal("%.200s line %d: unsupported log facility '%s'",
1336 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001337 if (*log_facility_ptr == -1)
1338 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001339 break;
1340
1341 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001342 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001343 arg = strdelim(&cp);
1344 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001345 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001346 fatal("%.200s line %d: unsupported log level '%s'",
1347 filename, linenum, arg ? arg : "<NONE>");
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001348 if (*activep && *log_level_ptr == -1)
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001349 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001350 break;
1351
1352 case sAllowTcpForwarding:
1353 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001354 multistate_ptr = multistate_tcpfwd;
1355 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001356
Damien Miller7acefbb2014-07-18 14:11:24 +10001357 case sAllowStreamLocalForwarding:
1358 intptr = &options->allow_streamlocal_forwarding;
1359 multistate_ptr = multistate_tcpfwd;
1360 goto parse_multistate;
1361
Damien Miller4f755cd2008-05-19 14:57:41 +10001362 case sAllowAgentForwarding:
1363 intptr = &options->allow_agent_forwarding;
1364 goto parse_flag;
1365
djm@openbsd.org7844f352016-11-30 03:00:05 +00001366 case sDisableForwarding:
1367 intptr = &options->disable_forwarding;
1368 goto parse_flag;
1369
Ben Lindstromade03f62001-12-06 18:22:17 +00001370 case sAllowUsers:
1371 while ((arg = strdelim(&cp)) && *arg != '\0') {
1372 if (options->num_allow_users >= MAX_ALLOW_USERS)
1373 fatal("%s line %d: too many allow users.",
1374 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001375 if (match_user(NULL, NULL, NULL, arg) == -1)
1376 fatal("%s line %d: invalid AllowUsers pattern: "
1377 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001378 if (!*activep)
1379 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001380 options->allow_users[options->num_allow_users++] =
1381 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001382 }
1383 break;
1384
1385 case sDenyUsers:
1386 while ((arg = strdelim(&cp)) && *arg != '\0') {
1387 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001388 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001389 filename, linenum);
djm@openbsd.org010359b2016-11-06 05:46:37 +00001390 if (match_user(NULL, NULL, NULL, arg) == -1)
1391 fatal("%s line %d: invalid DenyUsers pattern: "
1392 "\"%.100s\"", filename, linenum, arg);
Damien Millerc24da772012-06-20 21:53:58 +10001393 if (!*activep)
1394 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001395 options->deny_users[options->num_deny_users++] =
1396 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001397 }
1398 break;
1399
1400 case sAllowGroups:
1401 while ((arg = strdelim(&cp)) && *arg != '\0') {
1402 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1403 fatal("%s line %d: too many allow groups.",
1404 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001405 if (!*activep)
1406 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001407 options->allow_groups[options->num_allow_groups++] =
1408 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001409 }
1410 break;
1411
1412 case sDenyGroups:
1413 while ((arg = strdelim(&cp)) && *arg != '\0') {
1414 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1415 fatal("%s line %d: too many deny groups.",
1416 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001417 if (!*activep)
1418 continue;
1419 options->deny_groups[options->num_deny_groups++] =
1420 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001421 }
1422 break;
1423
1424 case sCiphers:
1425 arg = strdelim(&cp);
1426 if (!arg || *arg == '\0')
1427 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001428 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001429 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1430 filename, linenum, arg ? arg : "<NONE>");
1431 if (options->ciphers == NULL)
1432 options->ciphers = xstrdup(arg);
1433 break;
1434
1435 case sMacs:
1436 arg = strdelim(&cp);
1437 if (!arg || *arg == '\0')
1438 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001439 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001440 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1441 filename, linenum, arg ? arg : "<NONE>");
1442 if (options->macs == NULL)
1443 options->macs = xstrdup(arg);
1444 break;
1445
Damien Millerd5f62bf2010-09-24 22:11:14 +10001446 case sKexAlgorithms:
1447 arg = strdelim(&cp);
1448 if (!arg || *arg == '\0')
1449 fatal("%s line %d: Missing argument.",
1450 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001451 if (*arg != '-' &&
1452 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001453 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1454 filename, linenum, arg ? arg : "<NONE>");
1455 if (options->kex_algorithms == NULL)
1456 options->kex_algorithms = xstrdup(arg);
1457 break;
1458
Ben Lindstromade03f62001-12-06 18:22:17 +00001459 case sSubsystem:
1460 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1461 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001462 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001463 }
1464 arg = strdelim(&cp);
1465 if (!arg || *arg == '\0')
1466 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001467 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001468 if (!*activep) {
1469 arg = strdelim(&cp);
1470 break;
1471 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001472 for (i = 0; i < options->num_subsystems; i++)
1473 if (strcmp(arg, options->subsystem_name[i]) == 0)
1474 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001475 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001476 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1477 arg = strdelim(&cp);
1478 if (!arg || *arg == '\0')
1479 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001480 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001481 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001482
1483 /* Collect arguments (separate to executable) */
1484 p = xstrdup(arg);
1485 len = strlen(p) + 1;
1486 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1487 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001488 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001489 strlcat(p, " ", len);
1490 strlcat(p, arg, len);
1491 }
1492 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001493 options->num_subsystems++;
1494 break;
1495
1496 case sMaxStartups:
1497 arg = strdelim(&cp);
1498 if (!arg || *arg == '\0')
1499 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001500 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001501 if ((n = sscanf(arg, "%d:%d:%d",
1502 &options->max_startups_begin,
1503 &options->max_startups_rate,
1504 &options->max_startups)) == 3) {
1505 if (options->max_startups_begin >
1506 options->max_startups ||
1507 options->max_startups_rate > 100 ||
1508 options->max_startups_rate < 1)
1509 fatal("%s line %d: Illegal MaxStartups spec.",
1510 filename, linenum);
1511 } else if (n != 1)
1512 fatal("%s line %d: Illegal MaxStartups spec.",
1513 filename, linenum);
1514 else
1515 options->max_startups = options->max_startups_begin;
1516 break;
1517
Darren Tucker89413db2004-05-24 10:36:23 +10001518 case sMaxAuthTries:
1519 intptr = &options->max_authtries;
1520 goto parse_int;
1521
Damien Miller7207f642008-05-19 15:34:50 +10001522 case sMaxSessions:
1523 intptr = &options->max_sessions;
1524 goto parse_int;
1525
Ben Lindstromade03f62001-12-06 18:22:17 +00001526 case sBanner:
1527 charptr = &options->banner;
1528 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001529
Ben Lindstromade03f62001-12-06 18:22:17 +00001530 /*
1531 * These options can contain %X options expanded at
1532 * connect time, so that you can specify paths like:
1533 *
1534 * AuthorizedKeysFile /etc/ssh_keys/%u
1535 */
1536 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001537 if (*activep && options->num_authkeys_files == 0) {
1538 while ((arg = strdelim(&cp)) && *arg != '\0') {
1539 if (options->num_authkeys_files >=
1540 MAX_AUTHKEYS_FILES)
1541 fatal("%s line %d: "
1542 "too many authorized keys files.",
1543 filename, linenum);
1544 options->authorized_keys_files[
1545 options->num_authkeys_files++] =
1546 tilde_expand_filename(arg, getuid());
1547 }
1548 }
1549 return 0;
1550
Damien Miller30da3442010-05-10 11:58:03 +10001551 case sAuthorizedPrincipalsFile:
1552 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001553 arg = strdelim(&cp);
1554 if (!arg || *arg == '\0')
1555 fatal("%s line %d: missing file name.",
1556 filename, linenum);
1557 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001558 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001559 /* increase optional counter */
1560 if (intptr != NULL)
1561 *intptr = *intptr + 1;
1562 }
1563 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001564
1565 case sClientAliveInterval:
1566 intptr = &options->client_alive_interval;
1567 goto parse_time;
1568
1569 case sClientAliveCountMax:
1570 intptr = &options->client_alive_count_max;
1571 goto parse_int;
1572
Darren Tucker46bc0752004-05-02 22:11:30 +10001573 case sAcceptEnv:
1574 while ((arg = strdelim(&cp)) && *arg != '\0') {
1575 if (strchr(arg, '=') != NULL)
1576 fatal("%s line %d: Invalid environment name.",
1577 filename, linenum);
1578 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1579 fatal("%s line %d: too many allow env.",
1580 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001581 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001582 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001583 options->accept_env[options->num_accept_env++] =
1584 xstrdup(arg);
1585 }
1586 break;
1587
Damien Millerd27b9472005-12-13 19:29:02 +11001588 case sPermitTunnel:
1589 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001590 arg = strdelim(&cp);
1591 if (!arg || *arg == '\0')
1592 fatal("%s line %d: Missing yes/point-to-point/"
1593 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001594 value = -1;
1595 for (i = 0; tunmode_desc[i].val != -1; i++)
1596 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1597 value = tunmode_desc[i].val;
1598 break;
1599 }
1600 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001601 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1602 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001603 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001604 *intptr = value;
1605 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001606
Darren Tucker45150472006-07-12 22:34:17 +10001607 case sMatch:
1608 if (cmdline)
1609 fatal("Match directive not supported as a command-line "
1610 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001611 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001612 if (value < 0)
1613 fatal("%s line %d: Bad Match condition", filename,
1614 linenum);
1615 *activep = value;
1616 break;
1617
Damien Miller9b439df2006-07-24 14:04:00 +10001618 case sPermitOpen:
1619 arg = strdelim(&cp);
1620 if (!arg || *arg == '\0')
1621 fatal("%s line %d: missing PermitOpen specification",
1622 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001623 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001624 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001625 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001626 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001627 options->num_permitted_opens = 0;
1628 }
Damien Miller9b439df2006-07-24 14:04:00 +10001629 break;
1630 }
Damien Millerc6081482012-04-22 11:18:53 +10001631 if (strcmp(arg, "none") == 0) {
1632 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001633 options->num_permitted_opens = 1;
1634 channel_disable_adm_local_opens();
1635 }
1636 break;
1637 }
Damien Millera29b95e2007-01-05 16:28:36 +11001638 if (*activep && n == -1)
1639 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001640 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1641 p = hpdelim(&arg);
1642 if (p == NULL)
1643 fatal("%s line %d: missing host in PermitOpen",
1644 filename, linenum);
1645 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001646 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001647 fatal("%s line %d: bad port number in "
1648 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001649 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001650 options->num_permitted_opens =
1651 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001652 }
Damien Miller9b439df2006-07-24 14:04:00 +10001653 break;
1654
Damien Millere2754432006-07-24 14:06:47 +10001655 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001656 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001657 fatal("%.200s line %d: Missing argument.", filename,
1658 linenum);
1659 len = strspn(cp, WHITESPACE);
1660 if (*activep && options->adm_forced_command == NULL)
1661 options->adm_forced_command = xstrdup(cp + len);
1662 return 0;
1663
Damien Millerd8cb1f12008-02-10 22:40:12 +11001664 case sChrootDirectory:
1665 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001666
1667 arg = strdelim(&cp);
1668 if (!arg || *arg == '\0')
1669 fatal("%s line %d: missing file name.",
1670 filename, linenum);
1671 if (*activep && *charptr == NULL)
1672 *charptr = xstrdup(arg);
1673 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001674
Damien Miller1aed65e2010-03-04 21:53:35 +11001675 case sTrustedUserCAKeys:
1676 charptr = &options->trusted_user_ca_keys;
1677 goto parse_filename;
1678
1679 case sRevokedKeys:
1680 charptr = &options->revoked_keys_file;
1681 goto parse_filename;
1682
Damien Miller0dac6fb2010-11-20 15:19:38 +11001683 case sIPQoS:
1684 arg = strdelim(&cp);
1685 if ((value = parse_ipqos(arg)) == -1)
1686 fatal("%s line %d: Bad IPQoS value: %s",
1687 filename, linenum, arg);
1688 arg = strdelim(&cp);
1689 if (arg == NULL)
1690 value2 = value;
1691 else if ((value2 = parse_ipqos(arg)) == -1)
1692 fatal("%s line %d: Bad IPQoS value: %s",
1693 filename, linenum, arg);
1694 if (*activep) {
1695 options->ip_qos_interactive = value;
1696 options->ip_qos_bulk = value2;
1697 }
1698 break;
1699
Damien Miller23528812012-04-22 11:24:43 +10001700 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001701 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001702 fatal("%.200s line %d: Missing argument.", filename,
1703 linenum);
1704 len = strspn(cp, WHITESPACE);
1705 if (*activep && options->version_addendum == NULL) {
1706 if (strcasecmp(cp + len, "none") == 0)
1707 options->version_addendum = xstrdup("");
1708 else if (strchr(cp + len, '\r') != NULL)
1709 fatal("%.200s line %d: Invalid argument",
1710 filename, linenum);
1711 else
1712 options->version_addendum = xstrdup(cp + len);
1713 }
1714 return 0;
1715
Damien Miller09d3e122012-10-31 08:58:58 +11001716 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001717 if (cp == NULL)
1718 fatal("%.200s line %d: Missing argument.", filename,
1719 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001720 len = strspn(cp, WHITESPACE);
1721 if (*activep && options->authorized_keys_command == NULL) {
1722 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1723 fatal("%.200s line %d: AuthorizedKeysCommand "
1724 "must be an absolute path",
1725 filename, linenum);
1726 options->authorized_keys_command = xstrdup(cp + len);
1727 }
1728 return 0;
1729
1730 case sAuthorizedKeysCommandUser:
1731 charptr = &options->authorized_keys_command_user;
1732
1733 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001734 if (!arg || *arg == '\0')
1735 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1736 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001737 if (*activep && *charptr == NULL)
1738 *charptr = xstrdup(arg);
1739 break;
1740
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001741 case sAuthorizedPrincipalsCommand:
1742 if (cp == NULL)
1743 fatal("%.200s line %d: Missing argument.", filename,
1744 linenum);
1745 len = strspn(cp, WHITESPACE);
1746 if (*activep &&
1747 options->authorized_principals_command == NULL) {
1748 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1749 fatal("%.200s line %d: "
1750 "AuthorizedPrincipalsCommand must be "
1751 "an absolute path", filename, linenum);
1752 options->authorized_principals_command =
1753 xstrdup(cp + len);
1754 }
1755 return 0;
1756
1757 case sAuthorizedPrincipalsCommandUser:
1758 charptr = &options->authorized_principals_command_user;
1759
1760 arg = strdelim(&cp);
1761 if (!arg || *arg == '\0')
1762 fatal("%s line %d: missing "
1763 "AuthorizedPrincipalsCommandUser argument.",
1764 filename, linenum);
1765 if (*activep && *charptr == NULL)
1766 *charptr = xstrdup(arg);
1767 break;
1768
Damien Millera6e3f012012-11-04 23:21:40 +11001769 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001770 if (options->num_auth_methods == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001771 value = 0; /* seen "any" pseudo-method */
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001772 value2 = 0; /* sucessfully parsed any method */
Damien Millera6e3f012012-11-04 23:21:40 +11001773 while ((arg = strdelim(&cp)) && *arg != '\0') {
1774 if (options->num_auth_methods >=
1775 MAX_AUTH_METHODS)
1776 fatal("%s line %d: "
1777 "too many authentication methods.",
1778 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001779 if (strcmp(arg, "any") == 0) {
1780 if (options->num_auth_methods > 0) {
1781 fatal("%s line %d: \"any\" "
1782 "must appear alone in "
1783 "AuthenticationMethods",
1784 filename, linenum);
1785 }
1786 value = 1;
1787 } else if (value) {
1788 fatal("%s line %d: \"any\" must appear "
1789 "alone in AuthenticationMethods",
1790 filename, linenum);
1791 } else if (auth2_methods_valid(arg, 0) != 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001792 fatal("%s line %d: invalid "
1793 "authentication method list.",
1794 filename, linenum);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001795 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001796 value2 = 1;
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001797 if (!*activep)
1798 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001799 options->auth_methods[
1800 options->num_auth_methods++] = xstrdup(arg);
1801 }
djm@openbsd.org46ecd192016-06-23 05:17:51 +00001802 if (value2 == 0) {
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00001803 fatal("%s line %d: no AuthenticationMethods "
1804 "specified", filename, linenum);
1805 }
Damien Millera6e3f012012-11-04 23:21:40 +11001806 }
1807 return 0;
1808
Damien Miller7acefbb2014-07-18 14:11:24 +10001809 case sStreamLocalBindMask:
1810 arg = strdelim(&cp);
1811 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001812 fatal("%s line %d: missing StreamLocalBindMask "
1813 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001814 /* Parse mode in octal format */
1815 value = strtol(arg, &p, 8);
1816 if (arg == p || value < 0 || value > 0777)
1817 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001818 if (*activep)
1819 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001820 break;
1821
1822 case sStreamLocalBindUnlink:
1823 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1824 goto parse_flag;
1825
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001826 case sFingerprintHash:
1827 arg = strdelim(&cp);
1828 if (!arg || *arg == '\0')
1829 fatal("%.200s line %d: Missing argument.",
1830 filename, linenum);
1831 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1832 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1833 filename, linenum, arg);
1834 if (*activep)
1835 options->fingerprint_hash = value;
1836 break;
1837
Ben Lindstromade03f62001-12-06 18:22:17 +00001838 case sDeprecated:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001839 case sIgnore:
Damien Millerf9b3feb2003-05-16 11:38:32 +10001840 case sUnsupported:
djm@openbsd.orgae363d72016-08-25 23:57:54 +00001841 do_log2(opcode == sIgnore ?
1842 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1843 "%s line %d: %s option %s", filename, linenum,
1844 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
Damien Millerf9b3feb2003-05-16 11:38:32 +10001845 while (arg)
1846 arg = strdelim(&cp);
1847 break;
1848
Ben Lindstromade03f62001-12-06 18:22:17 +00001849 default:
1850 fatal("%s line %d: Missing handler for opcode %s (%d)",
1851 filename, linenum, arg, opcode);
1852 }
1853 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1854 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1855 filename, linenum, arg);
1856 return 0;
1857}
1858
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001859/* Reads the server configuration file. */
1860
Damien Miller4af51302000-04-16 11:18:38 +10001861void
Darren Tucker645ab752004-06-25 13:33:20 +10001862load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001863{
Damien Miller46cb75a2012-07-31 12:22:37 +10001864 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001865 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001866 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001867
Darren Tucker645ab752004-06-25 13:33:20 +10001868 debug2("%s: filename %s", __func__, filename);
1869 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001870 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001871 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001872 }
Darren Tucker645ab752004-06-25 13:33:20 +10001873 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001874 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001875 lineno++;
1876 if (strlen(line) == sizeof(line) - 1)
1877 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001878 /*
1879 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001880 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001881 * line numbers later for error messages
1882 */
1883 if ((cp = strchr(line, '#')) != NULL)
1884 memcpy(cp, "\n", 2);
1885 cp = line + strspn(line, " \t\r");
1886
1887 buffer_append(conf, cp, strlen(cp));
1888 }
1889 buffer_append(conf, "\0", 1);
1890 fclose(f);
1891 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1892}
1893
1894void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001895parse_server_match_config(ServerOptions *options,
1896 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001897{
Darren Tucker45150472006-07-12 22:34:17 +10001898 ServerOptions mo;
1899
1900 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001901 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001902 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001903}
1904
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001905int parse_server_match_testspec(struct connection_info *ci, char *spec)
1906{
1907 char *p;
1908
1909 while ((p = strsep(&spec, ",")) && *p != '\0') {
1910 if (strncmp(p, "addr=", 5) == 0) {
1911 ci->address = xstrdup(p + 5);
1912 } else if (strncmp(p, "host=", 5) == 0) {
1913 ci->host = xstrdup(p + 5);
1914 } else if (strncmp(p, "user=", 5) == 0) {
1915 ci->user = xstrdup(p + 5);
1916 } else if (strncmp(p, "laddr=", 6) == 0) {
1917 ci->laddress = xstrdup(p + 6);
1918 } else if (strncmp(p, "lport=", 6) == 0) {
1919 ci->lport = a2port(p + 6);
1920 if (ci->lport == -1) {
1921 fprintf(stderr, "Invalid port '%s' in test mode"
1922 " specification %s\n", p+6, p);
1923 return -1;
1924 }
1925 } else {
1926 fprintf(stderr, "Invalid test mode specification %s\n",
1927 p);
1928 return -1;
1929 }
1930 }
1931 return 0;
1932}
1933
1934/*
1935 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1936 * empty spec.
1937 */
1938int server_match_spec_complete(struct connection_info *ci)
1939{
1940 if (ci->user && ci->host && ci->address)
1941 return 1; /* complete */
1942 if (!ci->user && !ci->host && !ci->address)
1943 return -1; /* empty */
1944 return 0; /* partial */
1945}
1946
Darren Tucker1629c072007-02-19 22:25:37 +11001947/*
1948 * Copy any supported values that are set.
1949 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001950 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001951 * array values that are not used pre-authentication, because any that we
1952 * do use must be explictly sent in mm_getpwnamallow().
1953 */
Darren Tucker45150472006-07-12 22:34:17 +10001954void
Darren Tucker1629c072007-02-19 22:25:37 +11001955copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001956{
Damien Miller534b2cc2013-12-05 14:07:27 +11001957#define M_CP_INTOPT(n) do {\
1958 if (src->n != -1) \
1959 dst->n = src->n; \
1960} while (0)
1961
Darren Tucker1629c072007-02-19 22:25:37 +11001962 M_CP_INTOPT(password_authentication);
1963 M_CP_INTOPT(gss_authentication);
Darren Tucker1629c072007-02-19 22:25:37 +11001964 M_CP_INTOPT(pubkey_authentication);
1965 M_CP_INTOPT(kerberos_authentication);
1966 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001967 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001968 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001969 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001970 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001971
1972 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001973 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001974 M_CP_INTOPT(allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00001975 M_CP_INTOPT(disable_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001976 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001977 M_CP_INTOPT(fwd_opts.gateway_ports);
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001978 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
Darren Tucker1629c072007-02-19 22:25:37 +11001979 M_CP_INTOPT(x11_display_offset);
1980 M_CP_INTOPT(x11_forwarding);
1981 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001982 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001983 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001984 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001985 M_CP_INTOPT(max_authtries);
markus@openbsd.orgf0ddede2016-11-23 23:14:15 +00001986 M_CP_INTOPT(client_alive_count_max);
1987 M_CP_INTOPT(client_alive_interval);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001988 M_CP_INTOPT(ip_qos_interactive);
1989 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001990 M_CP_INTOPT(rekey_limit);
1991 M_CP_INTOPT(rekey_interval);
djm@openbsd.org54cd41a2017-05-17 01:24:17 +00001992 M_CP_INTOPT(log_level);
Darren Tucker1629c072007-02-19 22:25:37 +11001993
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00001994 /*
1995 * The bind_mask is a mode_t that may be unsigned, so we can't use
1996 * M_CP_INTOPT - it does a signed comparison that causes compiler
1997 * warnings.
1998 */
dtucker@openbsd.org9faae502016-05-04 14:00:09 +00001999 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
djm@openbsd.orgcfefbce2016-05-03 15:57:39 +00002000 dst->fwd_opts.streamlocal_bind_mask =
2001 src->fwd_opts.streamlocal_bind_mask;
2002 }
2003
Damien Miller534b2cc2013-12-05 14:07:27 +11002004 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2005#define M_CP_STROPT(n) do {\
2006 if (src->n != NULL && dst->n != src->n) { \
2007 free(dst->n); \
2008 dst->n = src->n; \
2009 } \
2010} while(0)
2011#define M_CP_STRARRAYOPT(n, num_n) do {\
2012 if (src->num_n != 0) { \
2013 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2014 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2015 } \
2016} while(0)
2017
Damien Millerf2e407e2011-05-20 19:04:14 +10002018 /* See comment in servconf.h */
2019 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002020
djm@openbsd.orged085102015-10-29 08:05:01 +00002021 /* Arguments that accept '+...' need to be expanded */
2022 assemble_algorithms(dst);
2023
Damien Millerc2411902011-05-20 19:03:49 +10002024 /*
2025 * The only things that should be below this point are string options
2026 * which are only used after authentication.
2027 */
Damien Miller5d74e582011-05-20 19:03:31 +10002028 if (preauth)
2029 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002030
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002031 /* These options may be "none" to clear a global setting */
Damien Miller5d74e582011-05-20 19:03:31 +10002032 M_CP_STROPT(adm_forced_command);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002033 if (option_clear_or_none(dst->adm_forced_command)) {
2034 free(dst->adm_forced_command);
2035 dst->adm_forced_command = NULL;
2036 }
Damien Miller5d74e582011-05-20 19:03:31 +10002037 M_CP_STROPT(chroot_directory);
djm@openbsd.org9fd04682015-11-13 04:38:06 +00002038 if (option_clear_or_none(dst->chroot_directory)) {
2039 free(dst->chroot_directory);
2040 dst->chroot_directory = NULL;
2041 }
Darren Tucker45150472006-07-12 22:34:17 +10002042}
2043
Darren Tucker1629c072007-02-19 22:25:37 +11002044#undef M_CP_INTOPT
2045#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002046#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002047
Darren Tucker45150472006-07-12 22:34:17 +10002048void
2049parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002050 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002051{
2052 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002053 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002054
2055 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2056
djm@openbsd.org1a31d022016-05-02 08:49:03 +00002057 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2058 fatal("%s: sshbuf_dup_string failed", __func__);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002059 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002060 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002061 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002062 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002063 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002064 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002065 }
Darren Tuckera627d422013-06-02 07:31:17 +10002066 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002067 if (bad_options > 0)
2068 fatal("%s: terminating, %d bad configuration options",
2069 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002070 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002071}
Darren Tuckere7140f22008-06-10 23:01:51 +10002072
2073static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002074fmt_multistate_int(int val, const struct multistate *m)
2075{
2076 u_int i;
2077
2078 for (i = 0; m[i].key != NULL; i++) {
2079 if (m[i].value == val)
2080 return m[i].key;
2081 }
2082 return "UNKNOWN";
2083}
2084
2085static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002086fmt_intarg(ServerOpCodes code, int val)
2087{
Damien Miller82c55872011-06-23 08:20:30 +10002088 if (val == -1)
2089 return "unset";
2090 switch (code) {
2091 case sAddressFamily:
2092 return fmt_multistate_int(val, multistate_addressfamily);
2093 case sPermitRootLogin:
2094 return fmt_multistate_int(val, multistate_permitrootlogin);
2095 case sGatewayPorts:
2096 return fmt_multistate_int(val, multistate_gatewayports);
2097 case sCompression:
2098 return fmt_multistate_int(val, multistate_compression);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002099 case sAllowTcpForwarding:
2100 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002101 case sAllowStreamLocalForwarding:
2102 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002103 case sFingerprintHash:
2104 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002105 default:
2106 switch (val) {
2107 case 0:
2108 return "no";
2109 case 1:
2110 return "yes";
2111 default:
2112 return "UNKNOWN";
2113 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002114 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002115}
2116
2117static const char *
2118lookup_opcode_name(ServerOpCodes code)
2119{
2120 u_int i;
2121
2122 for (i = 0; keywords[i].name != NULL; i++)
2123 if (keywords[i].opcode == code)
2124 return(keywords[i].name);
2125 return "UNKNOWN";
2126}
2127
2128static void
2129dump_cfg_int(ServerOpCodes code, int val)
2130{
2131 printf("%s %d\n", lookup_opcode_name(code), val);
2132}
2133
2134static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002135dump_cfg_oct(ServerOpCodes code, int val)
2136{
2137 printf("%s 0%o\n", lookup_opcode_name(code), val);
2138}
2139
2140static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002141dump_cfg_fmtint(ServerOpCodes code, int val)
2142{
2143 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2144}
2145
2146static void
2147dump_cfg_string(ServerOpCodes code, const char *val)
2148{
djm@openbsd.org161cf412014-12-22 07:55:51 +00002149 printf("%s %s\n", lookup_opcode_name(code),
2150 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002151}
2152
2153static void
2154dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2155{
2156 u_int i;
2157
2158 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002159 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2160}
2161
2162static void
2163dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2164{
2165 u_int i;
2166
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002167 if (count <= 0 && code != sAuthenticationMethods)
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002168 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002169 printf("%s", lookup_opcode_name(code));
2170 for (i = 0; i < count; i++)
2171 printf(" %s", vals[i]);
djm@openbsd.orgb64faeb2016-06-17 05:03:40 +00002172 if (code == sAuthenticationMethods && count == 0)
2173 printf(" any");
Damien Millerd8478b62011-05-29 21:39:36 +10002174 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002175}
2176
2177void
2178dump_config(ServerOptions *o)
2179{
2180 u_int i;
2181 int ret;
2182 struct addrinfo *ai;
2183 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002184 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002185
2186 /* these are usually at the top of the config */
2187 for (i = 0; i < o->num_ports; i++)
2188 printf("port %d\n", o->ports[i]);
Darren Tuckere7140f22008-06-10 23:01:51 +10002189 dump_cfg_fmtint(sAddressFamily, o->address_family);
2190
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002191 /*
2192 * ListenAddress must be after Port. add_one_listen_addr pushes
2193 * addresses onto a stack, so to maintain ordering we need to
2194 * print these in reverse order.
2195 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002196 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2197 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2198 sizeof(addr), port, sizeof(port),
2199 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2200 error("getnameinfo failed: %.100s",
2201 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2202 strerror(errno));
2203 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002204 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002205 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002206 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2207 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002208 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002209 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2210 addr, port, laddr2);
2211 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002212 }
2213 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002214 printf("%s", laddr1);
2215 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002216
2217 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002218#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002219 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002220#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002221 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
Darren Tuckere7140f22008-06-10 23:01:51 +10002222 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2223 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002224 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002225 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2226 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002227 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002228
2229 /* formatted integer arguments */
2230 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2231 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2232 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
Darren Tuckere7140f22008-06-10 23:01:51 +10002233 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2234 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2235 o->hostbased_uses_name_from_packet_only);
Darren Tuckere7140f22008-06-10 23:01:51 +10002236 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002237#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002238 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2239 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2240 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002241# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002242 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002243# endif
2244#endif
2245#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002246 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2247 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002248#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002249 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2250 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2251 o->kbd_interactive_authentication);
2252 dump_cfg_fmtint(sChallengeResponseAuthentication,
2253 o->challenge_response_authentication);
2254 dump_cfg_fmtint(sPrintMotd, o->print_motd);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002255#ifndef DISABLE_LASTLOG
Darren Tuckere7140f22008-06-10 23:01:51 +10002256 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Darren Tuckerfd4e4f22016-02-24 10:44:25 +11002257#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002258 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2259 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002260 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002261 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002262 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2263 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2264 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2265 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
Darren Tuckere7140f22008-06-10 23:01:51 +10002266 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002267 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002268 dump_cfg_fmtint(sUseDNS, o->use_dns);
2269 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002270 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
djm@openbsd.org7844f352016-11-30 03:00:05 +00002271 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002272 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
djm@openbsd.org771c2f52016-05-03 15:25:06 +00002273 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002274 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002275
2276 /* string arguments */
2277 dump_cfg_string(sPidFile, o->pid_file);
2278 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002279 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2280 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002281 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002282 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002283 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002284 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2285 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002286 dump_cfg_string(sAuthorizedPrincipalsFile,
2287 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002288 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2289 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002290 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2291 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002292 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2293 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002294 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002295 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002296 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002297 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2298 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002299 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2300 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002301 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2302 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002303
2304 /* string arguments requiring a lookup */
2305 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2306 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2307
2308 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002309 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2310 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002311 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2312 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002313 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002314 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002315 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2316 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2317 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2318 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2319 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002320 dump_cfg_strarray_oneline(sAuthenticationMethods,
2321 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002322
2323 /* other arguments */
2324 for (i = 0; i < o->num_subsystems; i++)
2325 printf("subsystem %s %s\n", o->subsystem_name[i],
2326 o->subsystem_args[i]);
2327
2328 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2329 o->max_startups_rate, o->max_startups);
2330
2331 for (i = 0; tunmode_desc[i].val != -1; i++)
2332 if (tunmode_desc[i].val == o->permit_tun) {
2333 s = tunmode_desc[i].text;
2334 break;
2335 }
2336 dump_cfg_string(sPermitTunnel, s);
2337
Damien Miller91475862011-05-05 14:14:34 +10002338 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2339 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002340
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002341 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
Damien Millera6d6c1f2013-08-21 02:40:01 +10002342 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002343
Darren Tuckere7140f22008-06-10 23:01:51 +10002344 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002345}