blob: f9be7f0930cbd162eef8cc5b92f5ea8d1d94617b [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
djm@openbsd.org6310f602015-08-21 23:52:30 +00002/* $OpenBSD: servconf.c,v 1.281 2015/08/21 23:52:30 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->server_key_bits = -1;
90 options->login_grace_time = -1;
91 options->key_regeneration_time = -1;
chris@openbsd.org3d5728a2015-07-31 15:38:09 +000092 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110093 options->ignore_rhosts = -1;
94 options->ignore_user_known_hosts = -1;
95 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000096 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110097 options->x11_forwarding = -1;
98 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110099 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +1100100 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000101 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +1000102 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100104 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100105 options->log_facility = SYSLOG_FACILITY_NOT_SET;
106 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000108 options->hostbased_authentication = -1;
109 options->hostbased_uses_name_from_packet_only = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000110 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000111 options->hostkeyalgorithms = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100113 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000114 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100115 options->kerberos_authentication = -1;
116 options->kerberos_or_local_passwd = -1;
117 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100118 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000119 options->gss_authentication=-1;
120 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000121 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100122 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100123 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000124 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100125 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000126 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100127 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000128 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000129 options->rekey_limit = -1;
130 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100131 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000132 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000133 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100134 options->num_allow_users = 0;
135 options->num_deny_users = 0;
136 options->num_allow_groups = 0;
137 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000138 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000139 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000140 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000141 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller7acefbb2014-07-18 14:11:24 +1000142 options->fwd_opts.gateway_ports = -1;
143 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
144 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000145 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000146 options->max_startups_begin = -1;
147 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000148 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000149 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000150 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000151 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000152 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000153 options->client_alive_interval = -1;
154 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000155 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000156 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100157 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000158 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000159 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100160 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100161 options->authorized_keys_command = NULL;
162 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100163 options->revoked_keys_file = NULL;
164 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000165 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000166 options->authorized_principals_command = NULL;
167 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100168 options->ip_qos_interactive = -1;
169 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000170 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000171 options->fingerprint_hash = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000172}
173
djm@openbsd.org161cf412014-12-22 07:55:51 +0000174/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
175static int
176option_clear_or_none(const char *o)
177{
178 return o == NULL || strcasecmp(o, "none") == 0;
179}
180
Damien Miller4af51302000-04-16 11:18:38 +1000181void
Damien Miller95def091999-11-25 00:26:21 +1100182fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000183{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000184 int i;
185
Damien Miller726273e2001-11-12 11:40:11 +1100186 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000187 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000188 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100189
190 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100191 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100192 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100193 if (options->num_host_key_files == 0) {
194 /* fill default hostkeys for protocols */
195 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100196 options->host_key_files[options->num_host_key_files++] =
197 _PATH_HOST_KEY_FILE;
198 if (options->protocol & SSH_PROTO_2) {
199 options->host_key_files[options->num_host_key_files++] =
200 _PATH_HOST_RSA_KEY_FILE;
201 options->host_key_files[options->num_host_key_files++] =
202 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100203#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000204 options->host_key_files[options->num_host_key_files++] =
205 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100206#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100207 options->host_key_files[options->num_host_key_files++] =
208 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100209 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100210 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100211 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100212 if (options->num_ports == 0)
213 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000214 if (options->address_family == -1)
215 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100216 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000217 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000218 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000219 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000221 options->server_key_bits = 1024;
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;
Damien Miller95def091999-11-25 00:26:21 +1100224 if (options->key_regeneration_time == -1)
225 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000226 if (options->permit_root_login == PERMIT_NOT_SET)
chris@openbsd.org3d5728a2015-07-31 15:38:09 +0000227 options->permit_root_login = PERMIT_NO_PASSWD;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100229 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->ignore_user_known_hosts == -1)
231 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100232 if (options->print_motd == -1)
233 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000234 if (options->print_lastlog == -1)
235 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100237 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100238 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100239 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100240 if (options->x11_use_localhost == -1)
241 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000242 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000243 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100244 if (options->permit_tty == -1)
245 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000246 if (options->permit_user_rc == -1)
247 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100248 if (options->strict_modes == -1)
249 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100250 if (options->tcp_keep_alive == -1)
251 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100252 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100253 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100254 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000255 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100256 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100257 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000258 if (options->hostbased_authentication == -1)
259 options->hostbased_authentication = 0;
260 if (options->hostbased_uses_name_from_packet_only == -1)
261 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->rsa_authentication == -1)
263 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100264 if (options->pubkey_authentication == -1)
265 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100266 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000267 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100268 if (options->kerberos_or_local_passwd == -1)
269 options->kerberos_or_local_passwd = 1;
270 if (options->kerberos_ticket_cleanup == -1)
271 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100272 if (options->kerberos_get_afs_token == -1)
273 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000274 if (options->gss_authentication == -1)
275 options->gss_authentication = 0;
276 if (options->gss_cleanup_creds == -1)
277 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000278 if (options->gss_strict_acceptor == -1)
279 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100280 if (options->password_authentication == -1)
281 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100282 if (options->kbd_interactive_authentication == -1)
283 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000284 if (options->challenge_response_authentication == -1)
285 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100286 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100287 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000288 if (options->permit_user_env == -1)
289 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100290 if (options->use_login == -1)
291 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000292 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000293 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000294 if (options->rekey_limit == -1)
295 options->rekey_limit = 0;
296 if (options->rekey_interval == -1)
297 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100298 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100299 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000300 if (options->allow_streamlocal_forwarding == -1)
301 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000302 if (options->allow_agent_forwarding == -1)
303 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000304 if (options->fwd_opts.gateway_ports == -1)
305 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000306 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100307 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000308 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100309 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000310 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100311 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000312 if (options->max_authtries == -1)
313 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000314 if (options->max_sessions == -1)
315 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000316 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000317 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000318 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100319 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000320 if (options->client_alive_count_max == -1)
321 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000322 if (options->num_authkeys_files == 0) {
323 options->authorized_keys_files[options->num_authkeys_files++] =
324 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
325 options->authorized_keys_files[options->num_authkeys_files++] =
326 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
327 }
Damien Millerd27b9472005-12-13 19:29:02 +1100328 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100329 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100330 if (options->ip_qos_interactive == -1)
331 options->ip_qos_interactive = IPTOS_LOWDELAY;
332 if (options->ip_qos_bulk == -1)
333 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000334 if (options->version_addendum == NULL)
335 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000336 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
337 options->fwd_opts.streamlocal_bind_mask = 0177;
338 if (options->fwd_opts.streamlocal_bind_unlink == -1)
339 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000340 if (options->fingerprint_hash == -1)
341 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000342
343 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &options->ciphers) != 0 ||
344 kex_assemble_names(KEX_SERVER_MAC, &options->macs) != 0 ||
345 kex_assemble_names(KEX_SERVER_KEX, &options->kex_algorithms) != 0 ||
346 kex_assemble_names(KEX_DEFAULT_PK_ALG,
djm@openbsd.org6310f602015-08-21 23:52:30 +0000347 &options->hostkeyalgorithms) != 0 ||
348 kex_assemble_names(KEX_DEFAULT_PK_ALG,
djm@openbsd.orgf9eca242015-07-30 00:01:34 +0000349 &options->hostbased_key_types) != 0 ||
350 kex_assemble_names(KEX_DEFAULT_PK_ALG,
351 &options->pubkey_key_types) != 0)
352 fatal("%s: kex_assemble_names failed", __func__);
353
Ben Lindstromfb62a692002-06-06 19:47:11 +0000354 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000355 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000356 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000357
djm@openbsd.org161cf412014-12-22 07:55:51 +0000358#define CLEAR_ON_NONE(v) \
359 do { \
360 if (option_clear_or_none(v)) { \
361 free(v); \
362 v = NULL; \
363 } \
364 } while(0)
365 CLEAR_ON_NONE(options->pid_file);
366 CLEAR_ON_NONE(options->xauth_location);
367 CLEAR_ON_NONE(options->banner);
368 CLEAR_ON_NONE(options->trusted_user_ca_keys);
369 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000370 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000371 for (i = 0; i < options->num_host_key_files; i++)
372 CLEAR_ON_NONE(options->host_key_files[i]);
373 for (i = 0; i < options->num_host_cert_files; i++)
374 CLEAR_ON_NONE(options->host_cert_files[i]);
375#undef CLEAR_ON_NONE
376
Tim Rice40017b02002-07-14 13:36:49 -0700377#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000378 if (use_privsep && options->compression == 1) {
379 error("This platform does not support both privilege "
380 "separation and compression");
381 error("Compression disabled");
382 options->compression = 0;
383 }
384#endif
385
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000386}
387
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000388/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100389typedef enum {
390 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100391 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000392 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100393 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000394 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
395 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000396 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100397 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100398 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000399 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100400 sPasswordAuthentication, sKbdInteractiveAuthentication,
401 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000402 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100403 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100404 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000405 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000406 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000407 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000408 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
409 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000410 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000411 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000412 sHostKeyAlgorithms,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000413 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000414 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
415 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100416 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100417 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100418 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000419 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000420 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000421 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100422 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000423 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000424 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000425 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000426 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000427} ServerOpCodes;
428
Darren Tucker45150472006-07-12 22:34:17 +1000429#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
430#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
431#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
432
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000433/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100434static struct {
435 const char *name;
436 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000437 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100438} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100439 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000440#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000441 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000442#else
Darren Tucker45150472006-07-12 22:34:17 +1000443 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000444#endif
Darren Tucker45150472006-07-12 22:34:17 +1000445 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100446 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000447 { "port", sPort, SSHCFG_GLOBAL },
448 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
449 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000450 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "pidfile", sPidFile, SSHCFG_GLOBAL },
452 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
453 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
454 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100455 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000456 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
457 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
458 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100459 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
460 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000461 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000462 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000463 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100464 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
465 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000466 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000467 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000468#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100469 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000470 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
471 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100472#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000473 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000474#else
Darren Tucker45150472006-07-12 22:34:17 +1000475 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100476#endif
477#else
Darren Tucker1629c072007-02-19 22:25:37 +1100478 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000479 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
480 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
481 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000482#endif
Darren Tucker45150472006-07-12 22:34:17 +1000483 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
484 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000485#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100486 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000487 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000488 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000489#else
Darren Tucker1629c072007-02-19 22:25:37 +1100490 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000491 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000492 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000493#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100494 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
495 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100496 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000497 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
498 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
499 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
500 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
501 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100502#ifdef DISABLE_LASTLOG
503 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
504#else
Darren Tucker45150472006-07-12 22:34:17 +1000505 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
Damien Millerac908c12015-10-22 09:35:24 +1100506#endif
Darren Tucker45150472006-07-12 22:34:17 +1000507 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
508 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000509 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
510 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
511 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
513 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100514 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000515 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
516 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
517 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000518 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000519 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
520 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
521 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000522 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000523 { "allowusers", sAllowUsers, SSHCFG_ALL },
524 { "denyusers", sDenyUsers, SSHCFG_ALL },
525 { "allowgroups", sAllowGroups, SSHCFG_ALL },
526 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000527 { "ciphers", sCiphers, SSHCFG_GLOBAL },
528 { "macs", sMacs, SSHCFG_GLOBAL },
529 { "protocol", sProtocol, SSHCFG_GLOBAL },
530 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
531 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
532 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000533 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000534 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100535 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000536 { "usedns", sUseDNS, SSHCFG_GLOBAL },
537 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
538 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
539 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
540 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000541 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000542 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000543 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000544 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000545 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100546 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000547 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000548 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000549 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000550 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100551 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100552 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100553 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
554 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000555 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000556 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100557 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100558 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
559 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000560 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
561 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000562 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100563 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000564 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
565 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
566 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000567 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000568 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000569};
570
Darren Tuckere7140f22008-06-10 23:01:51 +1000571static struct {
572 int val;
573 char *text;
574} tunmode_desc[] = {
575 { SSH_TUNMODE_NO, "no" },
576 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
577 { SSH_TUNMODE_ETHERNET, "ethernet" },
578 { SSH_TUNMODE_YES, "yes" },
579 { -1, NULL }
580};
581
Damien Miller5428f641999-11-25 11:54:57 +1100582/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000583 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100584 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000585
Damien Miller4af51302000-04-16 11:18:38 +1000586static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100587parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000588 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000589{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000590 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000591
Damien Miller95def091999-11-25 00:26:21 +1100592 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000593 if (strcasecmp(cp, keywords[i].name) == 0) {
594 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100595 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000596 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000597
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000598 error("%s: line %d: Bad configuration option: %s",
599 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100600 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000601}
602
Darren Tucker88b6fb22010-01-13 22:44:29 +1100603char *
604derelativise_path(const char *path)
605{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000606 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100607
djm@openbsd.org161cf412014-12-22 07:55:51 +0000608 if (strcasecmp(path, "none") == 0)
609 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100610 expanded = tilde_expand_filename(path, getuid());
611 if (*expanded == '/')
612 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100613 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100614 fatal("%s: getcwd: %s", __func__, strerror(errno));
615 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000616 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100617 return ret;
618}
619
Ben Lindstrombba81212001-06-25 05:01:22 +0000620static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100621add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100622{
Damien Millereccb9de2005-06-17 12:59:34 +1000623 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100624
Ben Lindstrom19066a12001-04-12 23:39:26 +0000625 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000626 for (i = 0; i < options->num_ports; i++)
627 add_one_listen_addr(options, addr, options->ports[i]);
628 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000629 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000630}
631
Ben Lindstrombba81212001-06-25 05:01:22 +0000632static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100633add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000634{
635 struct addrinfo hints, *ai, *aitop;
636 char strport[NI_MAXSERV];
637 int gaierr;
638
639 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100640 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000641 hints.ai_socktype = SOCK_STREAM;
642 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100643 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000644 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
645 fatal("bad addr or host: %s (%s)",
646 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100647 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000648 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
649 ;
650 ai->ai_next = options->listen_addrs;
651 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100652}
653
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000654/*
655 * Queue a ListenAddress to be processed once we have all of the Ports
656 * and AddressFamily options.
657 */
658static void
659queue_listen_addr(ServerOptions *options, char *addr, int port)
660{
661 options->queued_listen_addrs = xreallocarray(
662 options->queued_listen_addrs, options->num_queued_listens + 1,
663 sizeof(addr));
664 options->queued_listen_ports = xreallocarray(
665 options->queued_listen_ports, options->num_queued_listens + 1,
666 sizeof(port));
667 options->queued_listen_addrs[options->num_queued_listens] =
668 xstrdup(addr);
669 options->queued_listen_ports[options->num_queued_listens] = port;
670 options->num_queued_listens++;
671}
672
673/*
674 * Process queued (text) ListenAddress entries.
675 */
676static void
677process_queued_listen_addrs(ServerOptions *options)
678{
679 u_int i;
680
681 if (options->num_ports == 0)
682 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
683 if (options->address_family == -1)
684 options->address_family = AF_UNSPEC;
685
686 for (i = 0; i < options->num_queued_listens; i++) {
687 add_listen_addr(options, options->queued_listen_addrs[i],
688 options->queued_listen_ports[i]);
689 free(options->queued_listen_addrs[i]);
690 options->queued_listen_addrs[i] = NULL;
691 }
692 free(options->queued_listen_addrs);
693 options->queued_listen_addrs = NULL;
694 free(options->queued_listen_ports);
695 options->queued_listen_ports = NULL;
696 options->num_queued_listens = 0;
697}
698
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000699struct connection_info *
700get_connection_info(int populate, int use_dns)
701{
702 static struct connection_info ci;
703
704 if (!populate)
705 return &ci;
706 ci.host = get_canonical_hostname(use_dns);
707 ci.address = get_remote_ipaddr();
708 ci.laddress = get_local_ipaddr(packet_get_connection_in());
709 ci.lport = get_local_port();
710 return &ci;
711}
712
Darren Tucker45150472006-07-12 22:34:17 +1000713/*
714 * The strategy for the Match blocks is that the config file is parsed twice.
715 *
716 * The first time is at startup. activep is initialized to 1 and the
717 * directives in the global context are processed and acted on. Hitting a
718 * Match directive unsets activep and the directives inside the block are
719 * checked for syntax only.
720 *
721 * The second time is after a connection has been established but before
722 * authentication. activep is initialized to 2 and global config directives
723 * are ignored since they have already been processed. If the criteria in a
724 * Match block is met, activep is set and the subsequent directives
725 * processed and actioned until EOF or another Match block unsets it. Any
726 * options set are copied into the main server config.
727 *
728 * Potential additions/improvements:
729 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
730 *
731 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
732 * Match Address 192.168.0.*
733 * Tag trusted
734 * Match Group wheel
735 * Tag trusted
736 * Match Tag trusted
737 * AllowTcpForwarding yes
738 * GatewayPorts clientspecified
739 * [...]
740 *
741 * - Add a PermittedChannelRequests directive
742 * Match Group shell
743 * PermittedChannelRequests session,forwarded-tcpip
744 */
745
746static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000747match_cfg_line_group(const char *grps, int line, const char *user)
748{
749 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000750 struct passwd *pw;
751
Damien Miller565ca3f2006-08-19 00:23:15 +1000752 if (user == NULL)
753 goto out;
754
755 if ((pw = getpwnam(user)) == NULL) {
756 debug("Can't match group at line %d because user %.100s does "
757 "not exist", line, user);
758 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
759 debug("Can't Match group because user %.100s not in any group "
760 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000761 } else if (ga_match_pattern_list(grps) != 1) {
762 debug("user %.100s does not match group list %.100s at line %d",
763 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000764 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000765 debug("user %.100s matched group list %.100s at line %d", user,
766 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000767 result = 1;
768 }
769out:
770 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000771 return result;
772}
773
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000774/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000775 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100776 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000777 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000778 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000779static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000780match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000781{
Damien Millercf31f382013-10-24 21:02:56 +1100782 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000783 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000784
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000785 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000786 debug3("checking syntax for 'Match %s'", cp);
787 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000788 debug3("checking match for '%s' user %s host %s addr %s "
789 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
790 ci->host ? ci->host : "(null)",
791 ci->address ? ci->address : "(null)",
792 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000793
794 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100795 attributes++;
796 if (strcasecmp(attrib, "all") == 0) {
797 if (attributes != 1 ||
798 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
799 error("'all' cannot be combined with other "
800 "Match attributes");
801 return -1;
802 }
803 *condition = cp;
804 return 1;
805 }
Darren Tucker45150472006-07-12 22:34:17 +1000806 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
807 error("Missing Match criteria for %s", attrib);
808 return -1;
809 }
Darren Tucker45150472006-07-12 22:34:17 +1000810 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000811 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000812 result = 0;
813 continue;
814 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000815 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000816 result = 0;
817 else
818 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000819 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000820 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000821 if (ci == NULL || ci->user == NULL) {
822 result = 0;
823 continue;
824 }
825 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000826 case -1:
827 return -1;
828 case 0:
829 result = 0;
830 }
Darren Tucker45150472006-07-12 22:34:17 +1000831 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000832 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000833 result = 0;
834 continue;
835 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000836 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000837 result = 0;
838 else
839 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000840 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000841 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000842 if (ci == NULL || ci->address == NULL) {
843 result = 0;
844 continue;
845 }
846 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000847 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000848 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000849 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000850 break;
851 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000852 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000853 result = 0;
854 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000855 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000856 return -1;
857 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000858 } else if (strcasecmp(attrib, "localaddress") == 0){
859 if (ci == NULL || ci->laddress == NULL) {
860 result = 0;
861 continue;
862 }
863 switch (addr_match_list(ci->laddress, arg)) {
864 case 1:
865 debug("connection from %.100s matched "
866 "'LocalAddress %.100s' at line %d",
867 ci->laddress, arg, line);
868 break;
869 case 0:
870 case -1:
871 result = 0;
872 break;
873 case -2:
874 return -1;
875 }
876 } else if (strcasecmp(attrib, "localport") == 0) {
877 if ((port = a2port(arg)) == -1) {
878 error("Invalid LocalPort '%s' on Match line",
879 arg);
880 return -1;
881 }
882 if (ci == NULL || ci->lport == 0) {
883 result = 0;
884 continue;
885 }
886 /* TODO support port lists */
887 if (port == ci->lport)
888 debug("connection from %.100s matched "
889 "'LocalPort %d' at line %d",
890 ci->laddress, port, line);
891 else
892 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000893 } else {
894 error("Unsupported Match attribute %s", attrib);
895 return -1;
896 }
897 }
Damien Millercf31f382013-10-24 21:02:56 +1100898 if (attributes == 0) {
899 error("One or more attributes required for Match");
900 return -1;
901 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000902 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000903 debug3("match %sfound", result ? "" : "not ");
904 *condition = cp;
905 return result;
906}
907
Damien Millere2754432006-07-24 14:06:47 +1000908#define WHITESPACE " \t\r\n"
909
Damien Miller33322122011-06-20 14:43:11 +1000910/* Multistate option parsing */
911struct multistate {
912 char *key;
913 int value;
914};
915static const struct multistate multistate_addressfamily[] = {
916 { "inet", AF_INET },
917 { "inet6", AF_INET6 },
918 { "any", AF_UNSPEC },
919 { NULL, -1 }
920};
921static const struct multistate multistate_permitrootlogin[] = {
922 { "without-password", PERMIT_NO_PASSWD },
deraadt@openbsd.org1dc8d932015-08-06 14:53:21 +0000923 { "prohibit-password", PERMIT_NO_PASSWD },
Damien Miller33322122011-06-20 14:43:11 +1000924 { "forced-commands-only", PERMIT_FORCED_ONLY },
925 { "yes", PERMIT_YES },
926 { "no", PERMIT_NO },
927 { NULL, -1 }
928};
929static const struct multistate multistate_compression[] = {
930 { "delayed", COMP_DELAYED },
931 { "yes", COMP_ZLIB },
932 { "no", COMP_NONE },
933 { NULL, -1 }
934};
935static const struct multistate multistate_gatewayports[] = {
936 { "clientspecified", 2 },
937 { "yes", 1 },
938 { "no", 0 },
939 { NULL, -1 }
940};
Damien Miller69ff1df2011-06-23 08:30:03 +1000941static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000942 { "yes", PRIVSEP_NOSANDBOX },
943 { "sandbox", PRIVSEP_ON },
944 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000945 { "no", PRIVSEP_OFF },
946 { NULL, -1 }
947};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100948static const struct multistate multistate_tcpfwd[] = {
949 { "yes", FORWARD_ALLOW },
950 { "all", FORWARD_ALLOW },
951 { "no", FORWARD_DENY },
952 { "remote", FORWARD_REMOTE },
953 { "local", FORWARD_LOCAL },
954 { NULL, -1 }
955};
Damien Miller33322122011-06-20 14:43:11 +1000956
Ben Lindstromade03f62001-12-06 18:22:17 +0000957int
958process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000959 const char *filename, int linenum, int *activep,
960 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000961{
Darren Tucker09c0f032013-05-16 20:48:57 +1000962 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000963 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100964 SyslogFacility *log_facility_ptr;
965 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000966 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000967 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000968 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000969 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000970 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000971
972 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100973 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100974 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000975 /* Ignore leading whitespace */
976 if (*arg == '\0')
977 arg = strdelim(&cp);
978 if (!arg || !*arg || *arg == '#')
979 return 0;
980 intptr = NULL;
981 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000982 opcode = parse_token(arg, filename, linenum, &flags);
983
984 if (activep == NULL) { /* We are processing a command line directive */
985 cmdline = 1;
986 activep = &cmdline;
987 }
988 if (*activep && opcode != sMatch)
989 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
990 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000991 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000992 fatal("%s line %d: Directive '%s' is not allowed "
993 "within a Match block", filename, linenum, arg);
994 } else { /* this is a directive we have already processed */
995 while (arg)
996 arg = strdelim(&cp);
997 return 0;
998 }
999 }
1000
Ben Lindstromade03f62001-12-06 18:22:17 +00001001 switch (opcode) {
1002 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +10001003 case sUsePAM:
1004 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +00001005 goto parse_flag;
1006
1007 /* Standard Options */
1008 case sBadOption:
1009 return -1;
1010 case sPort:
1011 /* ignore ports from configfile if cmdline specifies ports */
1012 if (options->ports_from_cmdline)
1013 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +00001014 if (options->num_ports >= MAX_PORTS)
1015 fatal("%s line %d: too many ports.",
1016 filename, linenum);
1017 arg = strdelim(&cp);
1018 if (!arg || *arg == '\0')
1019 fatal("%s line %d: missing port number.",
1020 filename, linenum);
1021 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001022 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001023 fatal("%s line %d: Badly formatted port number.",
1024 filename, linenum);
1025 break;
1026
1027 case sServerKeyBits:
1028 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001029 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001030 arg = strdelim(&cp);
1031 if (!arg || *arg == '\0')
1032 fatal("%s line %d: missing integer value.",
1033 filename, linenum);
1034 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001035 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 *intptr = value;
1037 break;
1038
1039 case sLoginGraceTime:
1040 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001041 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001042 arg = strdelim(&cp);
1043 if (!arg || *arg == '\0')
1044 fatal("%s line %d: missing time value.",
1045 filename, linenum);
1046 if ((value = convtime(arg)) == -1)
1047 fatal("%s line %d: invalid time value.",
1048 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001049 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001050 *intptr = value;
1051 break;
1052
1053 case sKeyRegenerationTime:
1054 intptr = &options->key_regeneration_time;
1055 goto parse_time;
1056
1057 case sListenAddress:
1058 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001059 if (arg == NULL || *arg == '\0')
1060 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001061 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001062 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1063 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1064 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001065 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001066 break;
1067 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001068 p = hpdelim(&arg);
1069 if (p == NULL)
1070 fatal("%s line %d: bad address:port usage",
1071 filename, linenum);
1072 p = cleanhostname(p);
1073 if (arg == NULL)
1074 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001075 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001076 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001077
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001078 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001079
Ben Lindstromade03f62001-12-06 18:22:17 +00001080 break;
1081
Darren Tucker0f383232005-01-20 10:57:56 +11001082 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001083 intptr = &options->address_family;
1084 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001085 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001086 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001087 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001088 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001089 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001090 value = -1;
1091 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1092 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1093 value = multistate_ptr[i].value;
1094 break;
1095 }
1096 }
1097 if (value == -1)
1098 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001099 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001100 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001101 *intptr = value;
1102 break;
1103
Ben Lindstromade03f62001-12-06 18:22:17 +00001104 case sHostKeyFile:
1105 intptr = &options->num_host_key_files;
1106 if (*intptr >= MAX_HOSTKEYS)
1107 fatal("%s line %d: too many host keys specified (max %d).",
1108 filename, linenum, MAX_HOSTKEYS);
1109 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001110 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001111 arg = strdelim(&cp);
1112 if (!arg || *arg == '\0')
1113 fatal("%s line %d: missing file name.",
1114 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001115 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001116 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001117 /* increase optional counter */
1118 if (intptr != NULL)
1119 *intptr = *intptr + 1;
1120 }
1121 break;
1122
Damien Miller85b45e02013-07-20 13:21:52 +10001123 case sHostKeyAgent:
1124 charptr = &options->host_key_agent;
1125 arg = strdelim(&cp);
1126 if (!arg || *arg == '\0')
1127 fatal("%s line %d: missing socket name.",
1128 filename, linenum);
1129 if (*activep && *charptr == NULL)
1130 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1131 xstrdup(arg) : derelativise_path(arg);
1132 break;
1133
Damien Miller0a80ca12010-02-27 07:55:05 +11001134 case sHostCertificate:
1135 intptr = &options->num_host_cert_files;
1136 if (*intptr >= MAX_HOSTKEYS)
1137 fatal("%s line %d: too many host certificates "
1138 "specified (max %d).", filename, linenum,
1139 MAX_HOSTCERTS);
1140 charptr = &options->host_cert_files[*intptr];
1141 goto parse_filename;
1142 break;
1143
Ben Lindstromade03f62001-12-06 18:22:17 +00001144 case sPidFile:
1145 charptr = &options->pid_file;
1146 goto parse_filename;
1147
1148 case sPermitRootLogin:
1149 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001150 multistate_ptr = multistate_permitrootlogin;
1151 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001152
1153 case sIgnoreRhosts:
1154 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001155 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001156 arg = strdelim(&cp);
1157 if (!arg || *arg == '\0')
1158 fatal("%s line %d: missing yes/no argument.",
1159 filename, linenum);
1160 value = 0; /* silence compiler */
1161 if (strcmp(arg, "yes") == 0)
1162 value = 1;
1163 else if (strcmp(arg, "no") == 0)
1164 value = 0;
1165 else
1166 fatal("%s line %d: Bad yes/no argument: %s",
1167 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001168 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001169 *intptr = value;
1170 break;
1171
1172 case sIgnoreUserKnownHosts:
1173 intptr = &options->ignore_user_known_hosts;
1174 goto parse_flag;
1175
Ben Lindstromade03f62001-12-06 18:22:17 +00001176 case sRhostsRSAAuthentication:
1177 intptr = &options->rhosts_rsa_authentication;
1178 goto parse_flag;
1179
1180 case sHostbasedAuthentication:
1181 intptr = &options->hostbased_authentication;
1182 goto parse_flag;
1183
1184 case sHostbasedUsesNameFromPacketOnly:
1185 intptr = &options->hostbased_uses_name_from_packet_only;
1186 goto parse_flag;
1187
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001188 case sHostbasedAcceptedKeyTypes:
1189 charptr = &options->hostbased_key_types;
1190 parse_keytypes:
1191 arg = strdelim(&cp);
1192 if (!arg || *arg == '\0')
1193 fatal("%s line %d: Missing argument.",
1194 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001195 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001196 fatal("%s line %d: Bad key types '%s'.",
1197 filename, linenum, arg ? arg : "<NONE>");
1198 if (*activep && *charptr == NULL)
1199 *charptr = xstrdup(arg);
1200 break;
1201
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001202 case sHostKeyAlgorithms:
1203 charptr = &options->hostkeyalgorithms;
1204 goto parse_keytypes;
1205
Ben Lindstromade03f62001-12-06 18:22:17 +00001206 case sRSAAuthentication:
1207 intptr = &options->rsa_authentication;
1208 goto parse_flag;
1209
1210 case sPubkeyAuthentication:
1211 intptr = &options->pubkey_authentication;
1212 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001213
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001214 case sPubkeyAcceptedKeyTypes:
1215 charptr = &options->pubkey_key_types;
1216 goto parse_keytypes;
1217
Ben Lindstromade03f62001-12-06 18:22:17 +00001218 case sKerberosAuthentication:
1219 intptr = &options->kerberos_authentication;
1220 goto parse_flag;
1221
1222 case sKerberosOrLocalPasswd:
1223 intptr = &options->kerberos_or_local_passwd;
1224 goto parse_flag;
1225
1226 case sKerberosTicketCleanup:
1227 intptr = &options->kerberos_ticket_cleanup;
1228 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001229
Darren Tucker22ef5082003-12-31 11:37:34 +11001230 case sKerberosGetAFSToken:
1231 intptr = &options->kerberos_get_afs_token;
1232 goto parse_flag;
1233
Darren Tucker0efd1552003-08-26 11:49:55 +10001234 case sGssAuthentication:
1235 intptr = &options->gss_authentication;
1236 goto parse_flag;
1237
1238 case sGssCleanupCreds:
1239 intptr = &options->gss_cleanup_creds;
1240 goto parse_flag;
1241
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001242 case sGssStrictAcceptor:
1243 intptr = &options->gss_strict_acceptor;
1244 goto parse_flag;
1245
Ben Lindstromade03f62001-12-06 18:22:17 +00001246 case sPasswordAuthentication:
1247 intptr = &options->password_authentication;
1248 goto parse_flag;
1249
1250 case sKbdInteractiveAuthentication:
1251 intptr = &options->kbd_interactive_authentication;
1252 goto parse_flag;
1253
1254 case sChallengeResponseAuthentication:
1255 intptr = &options->challenge_response_authentication;
1256 goto parse_flag;
1257
1258 case sPrintMotd:
1259 intptr = &options->print_motd;
1260 goto parse_flag;
1261
1262 case sPrintLastLog:
1263 intptr = &options->print_lastlog;
1264 goto parse_flag;
1265
1266 case sX11Forwarding:
1267 intptr = &options->x11_forwarding;
1268 goto parse_flag;
1269
1270 case sX11DisplayOffset:
1271 intptr = &options->x11_display_offset;
1272 goto parse_int;
1273
Damien Miller95c249f2002-02-05 12:11:34 +11001274 case sX11UseLocalhost:
1275 intptr = &options->x11_use_localhost;
1276 goto parse_flag;
1277
Ben Lindstromade03f62001-12-06 18:22:17 +00001278 case sXAuthLocation:
1279 charptr = &options->xauth_location;
1280 goto parse_filename;
1281
Damien Miller5ff30c62013-10-30 22:21:50 +11001282 case sPermitTTY:
1283 intptr = &options->permit_tty;
1284 goto parse_flag;
1285
Damien Miller72e6b5c2014-07-04 09:00:04 +10001286 case sPermitUserRC:
1287 intptr = &options->permit_user_rc;
1288 goto parse_flag;
1289
Ben Lindstromade03f62001-12-06 18:22:17 +00001290 case sStrictModes:
1291 intptr = &options->strict_modes;
1292 goto parse_flag;
1293
Damien Miller12c150e2003-12-17 16:31:10 +11001294 case sTCPKeepAlive:
1295 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001296 goto parse_flag;
1297
1298 case sEmptyPasswd:
1299 intptr = &options->permit_empty_passwd;
1300 goto parse_flag;
1301
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001302 case sPermitUserEnvironment:
1303 intptr = &options->permit_user_env;
1304 goto parse_flag;
1305
Ben Lindstromade03f62001-12-06 18:22:17 +00001306 case sUseLogin:
1307 intptr = &options->use_login;
1308 goto parse_flag;
1309
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001310 case sCompression:
1311 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001312 multistate_ptr = multistate_compression;
1313 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001314
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001315 case sRekeyLimit:
1316 arg = strdelim(&cp);
1317 if (!arg || *arg == '\0')
1318 fatal("%.200s line %d: Missing argument.", filename,
1319 linenum);
1320 if (strcmp(arg, "default") == 0) {
1321 val64 = 0;
1322 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001323 if (scan_scaled(arg, &val64) == -1)
1324 fatal("%.200s line %d: Bad number '%s': %s",
1325 filename, linenum, arg, strerror(errno));
1326 /* check for too-large or too-small limits */
1327 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001328 fatal("%.200s line %d: RekeyLimit too large",
1329 filename, linenum);
1330 if (val64 != 0 && val64 < 16)
1331 fatal("%.200s line %d: RekeyLimit too small",
1332 filename, linenum);
1333 }
1334 if (*activep && options->rekey_limit == -1)
1335 options->rekey_limit = (u_int32_t)val64;
1336 if (cp != NULL) { /* optional rekey interval present */
1337 if (strcmp(cp, "none") == 0) {
1338 (void)strdelim(&cp); /* discard */
1339 break;
1340 }
1341 intptr = &options->rekey_interval;
1342 goto parse_time;
1343 }
1344 break;
1345
Ben Lindstromade03f62001-12-06 18:22:17 +00001346 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001347 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001348 multistate_ptr = multistate_gatewayports;
1349 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001350
Damien Miller3a961dc2003-06-03 10:25:48 +10001351 case sUseDNS:
1352 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 goto parse_flag;
1354
1355 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001356 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001357 arg = strdelim(&cp);
1358 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001359 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001360 fatal("%.200s line %d: unsupported log facility '%s'",
1361 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001362 if (*log_facility_ptr == -1)
1363 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 break;
1365
1366 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001367 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001368 arg = strdelim(&cp);
1369 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001370 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 fatal("%.200s line %d: unsupported log level '%s'",
1372 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001373 if (*log_level_ptr == -1)
1374 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001375 break;
1376
1377 case sAllowTcpForwarding:
1378 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001379 multistate_ptr = multistate_tcpfwd;
1380 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001381
Damien Miller7acefbb2014-07-18 14:11:24 +10001382 case sAllowStreamLocalForwarding:
1383 intptr = &options->allow_streamlocal_forwarding;
1384 multistate_ptr = multistate_tcpfwd;
1385 goto parse_multistate;
1386
Damien Miller4f755cd2008-05-19 14:57:41 +10001387 case sAllowAgentForwarding:
1388 intptr = &options->allow_agent_forwarding;
1389 goto parse_flag;
1390
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001391 case sUsePrivilegeSeparation:
1392 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001393 multistate_ptr = multistate_privsep;
1394 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001395
Ben Lindstromade03f62001-12-06 18:22:17 +00001396 case sAllowUsers:
1397 while ((arg = strdelim(&cp)) && *arg != '\0') {
1398 if (options->num_allow_users >= MAX_ALLOW_USERS)
1399 fatal("%s line %d: too many allow users.",
1400 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001401 if (!*activep)
1402 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001403 options->allow_users[options->num_allow_users++] =
1404 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001405 }
1406 break;
1407
1408 case sDenyUsers:
1409 while ((arg = strdelim(&cp)) && *arg != '\0') {
1410 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001411 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001412 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001413 if (!*activep)
1414 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001415 options->deny_users[options->num_deny_users++] =
1416 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001417 }
1418 break;
1419
1420 case sAllowGroups:
1421 while ((arg = strdelim(&cp)) && *arg != '\0') {
1422 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1423 fatal("%s line %d: too many allow groups.",
1424 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001425 if (!*activep)
1426 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001427 options->allow_groups[options->num_allow_groups++] =
1428 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001429 }
1430 break;
1431
1432 case sDenyGroups:
1433 while ((arg = strdelim(&cp)) && *arg != '\0') {
1434 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1435 fatal("%s line %d: too many deny groups.",
1436 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001437 if (!*activep)
1438 continue;
1439 options->deny_groups[options->num_deny_groups++] =
1440 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001441 }
1442 break;
1443
1444 case sCiphers:
1445 arg = strdelim(&cp);
1446 if (!arg || *arg == '\0')
1447 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001448 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001449 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1450 filename, linenum, arg ? arg : "<NONE>");
1451 if (options->ciphers == NULL)
1452 options->ciphers = xstrdup(arg);
1453 break;
1454
1455 case sMacs:
1456 arg = strdelim(&cp);
1457 if (!arg || *arg == '\0')
1458 fatal("%s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001459 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstromade03f62001-12-06 18:22:17 +00001460 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1461 filename, linenum, arg ? arg : "<NONE>");
1462 if (options->macs == NULL)
1463 options->macs = xstrdup(arg);
1464 break;
1465
Damien Millerd5f62bf2010-09-24 22:11:14 +10001466 case sKexAlgorithms:
1467 arg = strdelim(&cp);
1468 if (!arg || *arg == '\0')
1469 fatal("%s line %d: Missing argument.",
1470 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001471 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001472 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1473 filename, linenum, arg ? arg : "<NONE>");
1474 if (options->kex_algorithms == NULL)
1475 options->kex_algorithms = xstrdup(arg);
1476 break;
1477
Ben Lindstromade03f62001-12-06 18:22:17 +00001478 case sProtocol:
1479 intptr = &options->protocol;
1480 arg = strdelim(&cp);
1481 if (!arg || *arg == '\0')
1482 fatal("%s line %d: Missing argument.", filename, linenum);
1483 value = proto_spec(arg);
1484 if (value == SSH_PROTO_UNKNOWN)
1485 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001486 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001487 if (*intptr == SSH_PROTO_UNKNOWN)
1488 *intptr = value;
1489 break;
1490
1491 case sSubsystem:
1492 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1493 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001494 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001495 }
1496 arg = strdelim(&cp);
1497 if (!arg || *arg == '\0')
1498 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001499 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001500 if (!*activep) {
1501 arg = strdelim(&cp);
1502 break;
1503 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001504 for (i = 0; i < options->num_subsystems; i++)
1505 if (strcmp(arg, options->subsystem_name[i]) == 0)
1506 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001507 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001508 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1509 arg = strdelim(&cp);
1510 if (!arg || *arg == '\0')
1511 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001512 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001513 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001514
1515 /* Collect arguments (separate to executable) */
1516 p = xstrdup(arg);
1517 len = strlen(p) + 1;
1518 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1519 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001520 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001521 strlcat(p, " ", len);
1522 strlcat(p, arg, len);
1523 }
1524 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001525 options->num_subsystems++;
1526 break;
1527
1528 case sMaxStartups:
1529 arg = strdelim(&cp);
1530 if (!arg || *arg == '\0')
1531 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001532 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001533 if ((n = sscanf(arg, "%d:%d:%d",
1534 &options->max_startups_begin,
1535 &options->max_startups_rate,
1536 &options->max_startups)) == 3) {
1537 if (options->max_startups_begin >
1538 options->max_startups ||
1539 options->max_startups_rate > 100 ||
1540 options->max_startups_rate < 1)
1541 fatal("%s line %d: Illegal MaxStartups spec.",
1542 filename, linenum);
1543 } else if (n != 1)
1544 fatal("%s line %d: Illegal MaxStartups spec.",
1545 filename, linenum);
1546 else
1547 options->max_startups = options->max_startups_begin;
1548 break;
1549
Darren Tucker89413db2004-05-24 10:36:23 +10001550 case sMaxAuthTries:
1551 intptr = &options->max_authtries;
1552 goto parse_int;
1553
Damien Miller7207f642008-05-19 15:34:50 +10001554 case sMaxSessions:
1555 intptr = &options->max_sessions;
1556 goto parse_int;
1557
Ben Lindstromade03f62001-12-06 18:22:17 +00001558 case sBanner:
1559 charptr = &options->banner;
1560 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001561
Ben Lindstromade03f62001-12-06 18:22:17 +00001562 /*
1563 * These options can contain %X options expanded at
1564 * connect time, so that you can specify paths like:
1565 *
1566 * AuthorizedKeysFile /etc/ssh_keys/%u
1567 */
1568 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001569 if (*activep && options->num_authkeys_files == 0) {
1570 while ((arg = strdelim(&cp)) && *arg != '\0') {
1571 if (options->num_authkeys_files >=
1572 MAX_AUTHKEYS_FILES)
1573 fatal("%s line %d: "
1574 "too many authorized keys files.",
1575 filename, linenum);
1576 options->authorized_keys_files[
1577 options->num_authkeys_files++] =
1578 tilde_expand_filename(arg, getuid());
1579 }
1580 }
1581 return 0;
1582
Damien Miller30da3442010-05-10 11:58:03 +10001583 case sAuthorizedPrincipalsFile:
1584 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001585 arg = strdelim(&cp);
1586 if (!arg || *arg == '\0')
1587 fatal("%s line %d: missing file name.",
1588 filename, linenum);
1589 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001590 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001591 /* increase optional counter */
1592 if (intptr != NULL)
1593 *intptr = *intptr + 1;
1594 }
1595 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001596
1597 case sClientAliveInterval:
1598 intptr = &options->client_alive_interval;
1599 goto parse_time;
1600
1601 case sClientAliveCountMax:
1602 intptr = &options->client_alive_count_max;
1603 goto parse_int;
1604
Darren Tucker46bc0752004-05-02 22:11:30 +10001605 case sAcceptEnv:
1606 while ((arg = strdelim(&cp)) && *arg != '\0') {
1607 if (strchr(arg, '=') != NULL)
1608 fatal("%s line %d: Invalid environment name.",
1609 filename, linenum);
1610 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1611 fatal("%s line %d: too many allow env.",
1612 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001613 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001614 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001615 options->accept_env[options->num_accept_env++] =
1616 xstrdup(arg);
1617 }
1618 break;
1619
Damien Millerd27b9472005-12-13 19:29:02 +11001620 case sPermitTunnel:
1621 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001622 arg = strdelim(&cp);
1623 if (!arg || *arg == '\0')
1624 fatal("%s line %d: Missing yes/point-to-point/"
1625 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001626 value = -1;
1627 for (i = 0; tunmode_desc[i].val != -1; i++)
1628 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1629 value = tunmode_desc[i].val;
1630 break;
1631 }
1632 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001633 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1634 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001635 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001636 *intptr = value;
1637 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001638
Darren Tucker45150472006-07-12 22:34:17 +10001639 case sMatch:
1640 if (cmdline)
1641 fatal("Match directive not supported as a command-line "
1642 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001643 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001644 if (value < 0)
1645 fatal("%s line %d: Bad Match condition", filename,
1646 linenum);
1647 *activep = value;
1648 break;
1649
Damien Miller9b439df2006-07-24 14:04:00 +10001650 case sPermitOpen:
1651 arg = strdelim(&cp);
1652 if (!arg || *arg == '\0')
1653 fatal("%s line %d: missing PermitOpen specification",
1654 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001655 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001656 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001657 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001658 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001659 options->num_permitted_opens = 0;
1660 }
Damien Miller9b439df2006-07-24 14:04:00 +10001661 break;
1662 }
Damien Millerc6081482012-04-22 11:18:53 +10001663 if (strcmp(arg, "none") == 0) {
1664 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001665 options->num_permitted_opens = 1;
1666 channel_disable_adm_local_opens();
1667 }
1668 break;
1669 }
Damien Millera29b95e2007-01-05 16:28:36 +11001670 if (*activep && n == -1)
1671 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001672 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1673 p = hpdelim(&arg);
1674 if (p == NULL)
1675 fatal("%s line %d: missing host in PermitOpen",
1676 filename, linenum);
1677 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001678 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001679 fatal("%s line %d: bad port number in "
1680 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001681 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001682 options->num_permitted_opens =
1683 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001684 }
Damien Miller9b439df2006-07-24 14:04:00 +10001685 break;
1686
Damien Millere2754432006-07-24 14:06:47 +10001687 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001688 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001689 fatal("%.200s line %d: Missing argument.", filename,
1690 linenum);
1691 len = strspn(cp, WHITESPACE);
1692 if (*activep && options->adm_forced_command == NULL)
1693 options->adm_forced_command = xstrdup(cp + len);
1694 return 0;
1695
Damien Millerd8cb1f12008-02-10 22:40:12 +11001696 case sChrootDirectory:
1697 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001698
1699 arg = strdelim(&cp);
1700 if (!arg || *arg == '\0')
1701 fatal("%s line %d: missing file name.",
1702 filename, linenum);
1703 if (*activep && *charptr == NULL)
1704 *charptr = xstrdup(arg);
1705 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001706
Damien Miller1aed65e2010-03-04 21:53:35 +11001707 case sTrustedUserCAKeys:
1708 charptr = &options->trusted_user_ca_keys;
1709 goto parse_filename;
1710
1711 case sRevokedKeys:
1712 charptr = &options->revoked_keys_file;
1713 goto parse_filename;
1714
Damien Miller0dac6fb2010-11-20 15:19:38 +11001715 case sIPQoS:
1716 arg = strdelim(&cp);
1717 if ((value = parse_ipqos(arg)) == -1)
1718 fatal("%s line %d: Bad IPQoS value: %s",
1719 filename, linenum, arg);
1720 arg = strdelim(&cp);
1721 if (arg == NULL)
1722 value2 = value;
1723 else if ((value2 = parse_ipqos(arg)) == -1)
1724 fatal("%s line %d: Bad IPQoS value: %s",
1725 filename, linenum, arg);
1726 if (*activep) {
1727 options->ip_qos_interactive = value;
1728 options->ip_qos_bulk = value2;
1729 }
1730 break;
1731
Damien Miller23528812012-04-22 11:24:43 +10001732 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001733 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001734 fatal("%.200s line %d: Missing argument.", filename,
1735 linenum);
1736 len = strspn(cp, WHITESPACE);
1737 if (*activep && options->version_addendum == NULL) {
1738 if (strcasecmp(cp + len, "none") == 0)
1739 options->version_addendum = xstrdup("");
1740 else if (strchr(cp + len, '\r') != NULL)
1741 fatal("%.200s line %d: Invalid argument",
1742 filename, linenum);
1743 else
1744 options->version_addendum = xstrdup(cp + len);
1745 }
1746 return 0;
1747
Damien Miller09d3e122012-10-31 08:58:58 +11001748 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001749 if (cp == NULL)
1750 fatal("%.200s line %d: Missing argument.", filename,
1751 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001752 len = strspn(cp, WHITESPACE);
1753 if (*activep && options->authorized_keys_command == NULL) {
1754 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1755 fatal("%.200s line %d: AuthorizedKeysCommand "
1756 "must be an absolute path",
1757 filename, linenum);
1758 options->authorized_keys_command = xstrdup(cp + len);
1759 }
1760 return 0;
1761
1762 case sAuthorizedKeysCommandUser:
1763 charptr = &options->authorized_keys_command_user;
1764
1765 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001766 if (!arg || *arg == '\0')
1767 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1768 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001769 if (*activep && *charptr == NULL)
1770 *charptr = xstrdup(arg);
1771 break;
1772
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001773 case sAuthorizedPrincipalsCommand:
1774 if (cp == NULL)
1775 fatal("%.200s line %d: Missing argument.", filename,
1776 linenum);
1777 len = strspn(cp, WHITESPACE);
1778 if (*activep &&
1779 options->authorized_principals_command == NULL) {
1780 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1781 fatal("%.200s line %d: "
1782 "AuthorizedPrincipalsCommand must be "
1783 "an absolute path", filename, linenum);
1784 options->authorized_principals_command =
1785 xstrdup(cp + len);
1786 }
1787 return 0;
1788
1789 case sAuthorizedPrincipalsCommandUser:
1790 charptr = &options->authorized_principals_command_user;
1791
1792 arg = strdelim(&cp);
1793 if (!arg || *arg == '\0')
1794 fatal("%s line %d: missing "
1795 "AuthorizedPrincipalsCommandUser argument.",
1796 filename, linenum);
1797 if (*activep && *charptr == NULL)
1798 *charptr = xstrdup(arg);
1799 break;
1800
Damien Millera6e3f012012-11-04 23:21:40 +11001801 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001802 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001803 while ((arg = strdelim(&cp)) && *arg != '\0') {
1804 if (options->num_auth_methods >=
1805 MAX_AUTH_METHODS)
1806 fatal("%s line %d: "
1807 "too many authentication methods.",
1808 filename, linenum);
1809 if (auth2_methods_valid(arg, 0) != 0)
1810 fatal("%s line %d: invalid "
1811 "authentication method list.",
1812 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001813 if (!*activep)
1814 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001815 options->auth_methods[
1816 options->num_auth_methods++] = xstrdup(arg);
1817 }
1818 }
1819 return 0;
1820
Damien Miller7acefbb2014-07-18 14:11:24 +10001821 case sStreamLocalBindMask:
1822 arg = strdelim(&cp);
1823 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001824 fatal("%s line %d: missing StreamLocalBindMask "
1825 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001826 /* Parse mode in octal format */
1827 value = strtol(arg, &p, 8);
1828 if (arg == p || value < 0 || value > 0777)
1829 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001830 if (*activep)
1831 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001832 break;
1833
1834 case sStreamLocalBindUnlink:
1835 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1836 goto parse_flag;
1837
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001838 case sFingerprintHash:
1839 arg = strdelim(&cp);
1840 if (!arg || *arg == '\0')
1841 fatal("%.200s line %d: Missing argument.",
1842 filename, linenum);
1843 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1844 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1845 filename, linenum, arg);
1846 if (*activep)
1847 options->fingerprint_hash = value;
1848 break;
1849
Ben Lindstromade03f62001-12-06 18:22:17 +00001850 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001851 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001852 filename, linenum, arg);
1853 while (arg)
1854 arg = strdelim(&cp);
1855 break;
1856
Damien Millerf9b3feb2003-05-16 11:38:32 +10001857 case sUnsupported:
1858 logit("%s line %d: Unsupported option %s",
1859 filename, linenum, arg);
1860 while (arg)
1861 arg = strdelim(&cp);
1862 break;
1863
Ben Lindstromade03f62001-12-06 18:22:17 +00001864 default:
1865 fatal("%s line %d: Missing handler for opcode %s (%d)",
1866 filename, linenum, arg, opcode);
1867 }
1868 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1869 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1870 filename, linenum, arg);
1871 return 0;
1872}
1873
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001874/* Reads the server configuration file. */
1875
Damien Miller4af51302000-04-16 11:18:38 +10001876void
Darren Tucker645ab752004-06-25 13:33:20 +10001877load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001878{
Damien Miller46cb75a2012-07-31 12:22:37 +10001879 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001880 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001881 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001882
Darren Tucker645ab752004-06-25 13:33:20 +10001883 debug2("%s: filename %s", __func__, filename);
1884 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001885 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001886 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001887 }
Darren Tucker645ab752004-06-25 13:33:20 +10001888 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001889 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001890 lineno++;
1891 if (strlen(line) == sizeof(line) - 1)
1892 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001893 /*
1894 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001895 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001896 * line numbers later for error messages
1897 */
1898 if ((cp = strchr(line, '#')) != NULL)
1899 memcpy(cp, "\n", 2);
1900 cp = line + strspn(line, " \t\r");
1901
1902 buffer_append(conf, cp, strlen(cp));
1903 }
1904 buffer_append(conf, "\0", 1);
1905 fclose(f);
1906 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1907}
1908
1909void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001910parse_server_match_config(ServerOptions *options,
1911 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001912{
Darren Tucker45150472006-07-12 22:34:17 +10001913 ServerOptions mo;
1914
1915 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001916 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001917 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001918}
1919
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001920int parse_server_match_testspec(struct connection_info *ci, char *spec)
1921{
1922 char *p;
1923
1924 while ((p = strsep(&spec, ",")) && *p != '\0') {
1925 if (strncmp(p, "addr=", 5) == 0) {
1926 ci->address = xstrdup(p + 5);
1927 } else if (strncmp(p, "host=", 5) == 0) {
1928 ci->host = xstrdup(p + 5);
1929 } else if (strncmp(p, "user=", 5) == 0) {
1930 ci->user = xstrdup(p + 5);
1931 } else if (strncmp(p, "laddr=", 6) == 0) {
1932 ci->laddress = xstrdup(p + 6);
1933 } else if (strncmp(p, "lport=", 6) == 0) {
1934 ci->lport = a2port(p + 6);
1935 if (ci->lport == -1) {
1936 fprintf(stderr, "Invalid port '%s' in test mode"
1937 " specification %s\n", p+6, p);
1938 return -1;
1939 }
1940 } else {
1941 fprintf(stderr, "Invalid test mode specification %s\n",
1942 p);
1943 return -1;
1944 }
1945 }
1946 return 0;
1947}
1948
1949/*
1950 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1951 * empty spec.
1952 */
1953int server_match_spec_complete(struct connection_info *ci)
1954{
1955 if (ci->user && ci->host && ci->address)
1956 return 1; /* complete */
1957 if (!ci->user && !ci->host && !ci->address)
1958 return -1; /* empty */
1959 return 0; /* partial */
1960}
1961
Darren Tucker1629c072007-02-19 22:25:37 +11001962/*
1963 * Copy any supported values that are set.
1964 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001965 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001966 * array values that are not used pre-authentication, because any that we
1967 * do use must be explictly sent in mm_getpwnamallow().
1968 */
Darren Tucker45150472006-07-12 22:34:17 +10001969void
Darren Tucker1629c072007-02-19 22:25:37 +11001970copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001971{
Damien Miller534b2cc2013-12-05 14:07:27 +11001972#define M_CP_INTOPT(n) do {\
1973 if (src->n != -1) \
1974 dst->n = src->n; \
1975} while (0)
1976
Darren Tucker1629c072007-02-19 22:25:37 +11001977 M_CP_INTOPT(password_authentication);
1978 M_CP_INTOPT(gss_authentication);
1979 M_CP_INTOPT(rsa_authentication);
1980 M_CP_INTOPT(pubkey_authentication);
1981 M_CP_INTOPT(kerberos_authentication);
1982 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001983 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001984 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001985 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001986 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001987
1988 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001989 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001990 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001991 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001992 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001993 M_CP_INTOPT(x11_display_offset);
1994 M_CP_INTOPT(x11_forwarding);
1995 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001996 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001997 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001998 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001999 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11002000 M_CP_INTOPT(ip_qos_interactive);
2001 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002002 M_CP_INTOPT(rekey_limit);
2003 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11002004
Damien Miller534b2cc2013-12-05 14:07:27 +11002005 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2006#define M_CP_STROPT(n) do {\
2007 if (src->n != NULL && dst->n != src->n) { \
2008 free(dst->n); \
2009 dst->n = src->n; \
2010 } \
2011} while(0)
2012#define M_CP_STRARRAYOPT(n, num_n) do {\
2013 if (src->num_n != 0) { \
2014 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2015 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2016 } \
2017} while(0)
2018
Damien Millerf2e407e2011-05-20 19:04:14 +10002019 /* See comment in servconf.h */
2020 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002021
Damien Millerc2411902011-05-20 19:03:49 +10002022 /*
2023 * The only things that should be below this point are string options
2024 * which are only used after authentication.
2025 */
Damien Miller5d74e582011-05-20 19:03:31 +10002026 if (preauth)
2027 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002028
Damien Miller5d74e582011-05-20 19:03:31 +10002029 M_CP_STROPT(adm_forced_command);
2030 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10002031}
2032
Darren Tucker1629c072007-02-19 22:25:37 +11002033#undef M_CP_INTOPT
2034#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002035#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002036
Darren Tucker45150472006-07-12 22:34:17 +10002037void
2038parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002039 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002040{
2041 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002042 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002043
2044 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2045
Darren Tucker9fbac712004-08-12 22:41:44 +10002046 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002047 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002048 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002049 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002050 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002051 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002052 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002053 }
Darren Tuckera627d422013-06-02 07:31:17 +10002054 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002055 if (bad_options > 0)
2056 fatal("%s: terminating, %d bad configuration options",
2057 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002058 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002059}
Darren Tuckere7140f22008-06-10 23:01:51 +10002060
2061static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002062fmt_multistate_int(int val, const struct multistate *m)
2063{
2064 u_int i;
2065
2066 for (i = 0; m[i].key != NULL; i++) {
2067 if (m[i].value == val)
2068 return m[i].key;
2069 }
2070 return "UNKNOWN";
2071}
2072
2073static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002074fmt_intarg(ServerOpCodes code, int val)
2075{
Damien Miller82c55872011-06-23 08:20:30 +10002076 if (val == -1)
2077 return "unset";
2078 switch (code) {
2079 case sAddressFamily:
2080 return fmt_multistate_int(val, multistate_addressfamily);
2081 case sPermitRootLogin:
2082 return fmt_multistate_int(val, multistate_permitrootlogin);
2083 case sGatewayPorts:
2084 return fmt_multistate_int(val, multistate_gatewayports);
2085 case sCompression:
2086 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002087 case sUsePrivilegeSeparation:
2088 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002089 case sAllowTcpForwarding:
2090 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002091 case sAllowStreamLocalForwarding:
2092 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002093 case sFingerprintHash:
2094 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002095 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002096 switch (val) {
2097 case SSH_PROTO_1:
2098 return "1";
2099 case SSH_PROTO_2:
2100 return "2";
2101 case (SSH_PROTO_1|SSH_PROTO_2):
2102 return "2,1";
2103 default:
2104 return "UNKNOWN";
2105 }
Damien Miller82c55872011-06-23 08:20:30 +10002106 default:
2107 switch (val) {
2108 case 0:
2109 return "no";
2110 case 1:
2111 return "yes";
2112 default:
2113 return "UNKNOWN";
2114 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002115 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002116}
2117
2118static const char *
2119lookup_opcode_name(ServerOpCodes code)
2120{
2121 u_int i;
2122
2123 for (i = 0; keywords[i].name != NULL; i++)
2124 if (keywords[i].opcode == code)
2125 return(keywords[i].name);
2126 return "UNKNOWN";
2127}
2128
2129static void
2130dump_cfg_int(ServerOpCodes code, int val)
2131{
2132 printf("%s %d\n", lookup_opcode_name(code), val);
2133}
2134
2135static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002136dump_cfg_oct(ServerOpCodes code, int val)
2137{
2138 printf("%s 0%o\n", lookup_opcode_name(code), val);
2139}
2140
2141static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002142dump_cfg_fmtint(ServerOpCodes code, int val)
2143{
2144 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2145}
2146
2147static void
2148dump_cfg_string(ServerOpCodes code, const char *val)
2149{
2150 if (val == NULL)
2151 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002152 printf("%s %s\n", lookup_opcode_name(code),
2153 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002154}
2155
2156static void
2157dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2158{
2159 u_int i;
2160
2161 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002162 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2163}
2164
2165static void
2166dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2167{
2168 u_int i;
2169
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002170 if (count <= 0)
2171 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002172 printf("%s", lookup_opcode_name(code));
2173 for (i = 0; i < count; i++)
2174 printf(" %s", vals[i]);
2175 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002176}
2177
2178void
2179dump_config(ServerOptions *o)
2180{
2181 u_int i;
2182 int ret;
2183 struct addrinfo *ai;
2184 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002185 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002186
2187 /* these are usually at the top of the config */
2188 for (i = 0; i < o->num_ports; i++)
2189 printf("port %d\n", o->ports[i]);
2190 dump_cfg_fmtint(sProtocol, o->protocol);
2191 dump_cfg_fmtint(sAddressFamily, o->address_family);
2192
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002193 /*
2194 * ListenAddress must be after Port. add_one_listen_addr pushes
2195 * addresses onto a stack, so to maintain ordering we need to
2196 * print these in reverse order.
2197 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002198 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2199 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2200 sizeof(addr), port, sizeof(port),
2201 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2202 error("getnameinfo failed: %.100s",
2203 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2204 strerror(errno));
2205 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002206 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002207 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002208 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2209 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002210 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002211 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2212 addr, port, laddr2);
2213 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002214 }
2215 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002216 printf("%s", laddr1);
2217 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002218
2219 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002220#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002221 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002222#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002223 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2224 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2225 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2226 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2227 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002228 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002229 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2230 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002231 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002232
2233 /* formatted integer arguments */
2234 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2235 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2236 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2237 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2238 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2239 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2240 o->hostbased_uses_name_from_packet_only);
2241 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2242 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002243#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002244 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2245 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2246 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002247# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002248 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002249# endif
2250#endif
2251#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002252 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2253 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002254#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002255 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2256 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2257 o->kbd_interactive_authentication);
2258 dump_cfg_fmtint(sChallengeResponseAuthentication,
2259 o->challenge_response_authentication);
2260 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2261 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2262 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2263 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002264 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002265 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002266 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2267 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2268 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2269 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2270 dump_cfg_fmtint(sUseLogin, o->use_login);
2271 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002272 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002273 dump_cfg_fmtint(sUseDNS, o->use_dns);
2274 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002275 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002276 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002277 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002278 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002279
2280 /* string arguments */
2281 dump_cfg_string(sPidFile, o->pid_file);
2282 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002283 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2284 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002285 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002286 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002287 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002288 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2289 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002290 dump_cfg_string(sAuthorizedPrincipalsFile,
2291 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002292 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2293 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002294 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2295 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002296 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2297 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002298 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002299 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002300 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002301 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2302 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00002303 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2304 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002305 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2306 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002307
2308 /* string arguments requiring a lookup */
2309 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2310 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2311
2312 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002313 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2314 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002315 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2316 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002317 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002318 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002319 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2320 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2321 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2322 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2323 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002324 dump_cfg_strarray_oneline(sAuthenticationMethods,
2325 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002326
2327 /* other arguments */
2328 for (i = 0; i < o->num_subsystems; i++)
2329 printf("subsystem %s %s\n", o->subsystem_name[i],
2330 o->subsystem_args[i]);
2331
2332 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2333 o->max_startups_rate, o->max_startups);
2334
2335 for (i = 0; tunmode_desc[i].val != -1; i++)
2336 if (tunmode_desc[i].val == o->permit_tun) {
2337 s = tunmode_desc[i].text;
2338 break;
2339 }
2340 dump_cfg_string(sPermitTunnel, s);
2341
Damien Miller91475862011-05-05 14:14:34 +10002342 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2343 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002344
Damien Millera6d6c1f2013-08-21 02:40:01 +10002345 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2346 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002347
Darren Tuckere7140f22008-06-10 23:01:51 +10002348 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002349}