blob: 80465ecc116ce6f1bae5794fa6a78121e237f647 [file] [log] [blame]
djm@openbsd.org868109b2015-07-01 02:39:06 +00001
2/* $OpenBSD: servconf.c,v 1.275 2015/07/01 02:39:06 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;
Ben Lindstromd8a90212001-02-15 03:08:27 +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;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100112 options->pubkey_authentication = -1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000113 options->pubkey_key_types = NULL;
Damien Miller95def091999-11-25 00:26:21 +1100114 options->kerberos_authentication = -1;
115 options->kerberos_or_local_passwd = -1;
116 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100117 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000118 options->gss_authentication=-1;
119 options->gss_cleanup_creds = -1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000120 options->gss_strict_acceptor = -1;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100122 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000123 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100124 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000125 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100126 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000127 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000128 options->rekey_limit = -1;
129 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100130 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000131 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000132 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100133 options->num_allow_users = 0;
134 options->num_deny_users = 0;
135 options->num_allow_groups = 0;
136 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000137 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000138 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000139 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000140 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller7acefbb2014-07-18 14:11:24 +1000141 options->fwd_opts.gateway_ports = -1;
142 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
143 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000144 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000145 options->max_startups_begin = -1;
146 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000147 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000148 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000149 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000150 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000151 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000152 options->client_alive_interval = -1;
153 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000154 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000155 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100156 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000157 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000158 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100159 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100160 options->authorized_keys_command = NULL;
161 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100162 options->revoked_keys_file = NULL;
163 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000164 options->authorized_principals_file = NULL;
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000165 options->authorized_principals_command = NULL;
166 options->authorized_principals_command_user = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100167 options->ip_qos_interactive = -1;
168 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000169 options->version_addendum = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000170 options->fingerprint_hash = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000171}
172
djm@openbsd.org161cf412014-12-22 07:55:51 +0000173/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
174static int
175option_clear_or_none(const char *o)
176{
177 return o == NULL || strcasecmp(o, "none") == 0;
178}
179
Damien Miller4af51302000-04-16 11:18:38 +1000180void
Damien Miller95def091999-11-25 00:26:21 +1100181fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000182{
djm@openbsd.org161cf412014-12-22 07:55:51 +0000183 int i;
184
Damien Miller726273e2001-11-12 11:40:11 +1100185 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000186 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000187 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100188
189 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100190 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100191 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100192 if (options->num_host_key_files == 0) {
193 /* fill default hostkeys for protocols */
194 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100195 options->host_key_files[options->num_host_key_files++] =
196 _PATH_HOST_KEY_FILE;
197 if (options->protocol & SSH_PROTO_2) {
198 options->host_key_files[options->num_host_key_files++] =
199 _PATH_HOST_RSA_KEY_FILE;
200 options->host_key_files[options->num_host_key_files++] =
201 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100202#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000203 options->host_key_files[options->num_host_key_files++] =
204 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100205#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100206 options->host_key_files[options->num_host_key_files++] =
207 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100208 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100209 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100210 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100211 if (options->num_ports == 0)
212 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000213 if (options->address_family == -1)
214 options->address_family = AF_UNSPEC;
Damien Miller34132e52000-01-14 15:45:46 +1100215 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000216 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000217 if (options->pid_file == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000218 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
Damien Miller95def091999-11-25 00:26:21 +1100219 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000220 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100221 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000222 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100223 if (options->key_regeneration_time == -1)
224 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000225 if (options->permit_root_login == PERMIT_NOT_SET)
djm@openbsd.org868109b2015-07-01 02:39:06 +0000226 options->permit_root_login = PERMIT_NO;
Damien Miller95def091999-11-25 00:26:21 +1100227 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100228 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->ignore_user_known_hosts == -1)
230 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100231 if (options->print_motd == -1)
232 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000233 if (options->print_lastlog == -1)
234 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100235 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100236 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100237 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100238 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100239 if (options->x11_use_localhost == -1)
240 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000241 if (options->xauth_location == NULL)
djm@openbsd.org161cf412014-12-22 07:55:51 +0000242 options->xauth_location = xstrdup(_PATH_XAUTH);
Damien Miller5ff30c62013-10-30 22:21:50 +1100243 if (options->permit_tty == -1)
244 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000245 if (options->permit_user_rc == -1)
246 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100247 if (options->strict_modes == -1)
248 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100249 if (options->tcp_keep_alive == -1)
250 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100251 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100252 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100253 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000254 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100255 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100256 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000257 if (options->hostbased_authentication == -1)
258 options->hostbased_authentication = 0;
259 if (options->hostbased_uses_name_from_packet_only == -1)
260 options->hostbased_uses_name_from_packet_only = 0;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000261 if (options->hostbased_key_types == NULL)
262 options->hostbased_key_types = xstrdup("*");
Damien Miller95def091999-11-25 00:26:21 +1100263 if (options->rsa_authentication == -1)
264 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100265 if (options->pubkey_authentication == -1)
266 options->pubkey_authentication = 1;
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000267 if (options->pubkey_key_types == NULL)
268 options->pubkey_key_types = xstrdup("*");
Damien Miller95def091999-11-25 00:26:21 +1100269 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000270 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100271 if (options->kerberos_or_local_passwd == -1)
272 options->kerberos_or_local_passwd = 1;
273 if (options->kerberos_ticket_cleanup == -1)
274 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100275 if (options->kerberos_get_afs_token == -1)
276 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000277 if (options->gss_authentication == -1)
278 options->gss_authentication = 0;
279 if (options->gss_cleanup_creds == -1)
280 options->gss_cleanup_creds = 1;
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000281 if (options->gss_strict_acceptor == -1)
282 options->gss_strict_acceptor = 0;
Damien Miller95def091999-11-25 00:26:21 +1100283 if (options->password_authentication == -1)
284 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100285 if (options->kbd_interactive_authentication == -1)
286 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000287 if (options->challenge_response_authentication == -1)
288 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100289 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100290 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000291 if (options->permit_user_env == -1)
292 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100293 if (options->use_login == -1)
294 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000295 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000296 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000297 if (options->rekey_limit == -1)
298 options->rekey_limit = 0;
299 if (options->rekey_interval == -1)
300 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100301 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100302 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000303 if (options->allow_streamlocal_forwarding == -1)
304 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000305 if (options->allow_agent_forwarding == -1)
306 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000307 if (options->fwd_opts.gateway_ports == -1)
308 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000309 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100310 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000311 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100312 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000313 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100314 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000315 if (options->max_authtries == -1)
316 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000317 if (options->max_sessions == -1)
318 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000319 if (options->use_dns == -1)
deraadt@openbsd.org3cd51032015-02-02 01:57:44 +0000320 options->use_dns = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000321 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100322 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000323 if (options->client_alive_count_max == -1)
324 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000325 if (options->num_authkeys_files == 0) {
326 options->authorized_keys_files[options->num_authkeys_files++] =
327 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
328 options->authorized_keys_files[options->num_authkeys_files++] =
329 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
330 }
Damien Millerd27b9472005-12-13 19:29:02 +1100331 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100332 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100333 if (options->ip_qos_interactive == -1)
334 options->ip_qos_interactive = IPTOS_LOWDELAY;
335 if (options->ip_qos_bulk == -1)
336 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000337 if (options->version_addendum == NULL)
338 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000339 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
340 options->fwd_opts.streamlocal_bind_mask = 0177;
341 if (options->fwd_opts.streamlocal_bind_unlink == -1)
342 options->fwd_opts.streamlocal_bind_unlink = 0;
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000343 if (options->fingerprint_hash == -1)
344 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
Ben Lindstromfb62a692002-06-06 19:47:11 +0000345 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000346 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000347 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000348
djm@openbsd.org161cf412014-12-22 07:55:51 +0000349#define CLEAR_ON_NONE(v) \
350 do { \
351 if (option_clear_or_none(v)) { \
352 free(v); \
353 v = NULL; \
354 } \
355 } while(0)
356 CLEAR_ON_NONE(options->pid_file);
357 CLEAR_ON_NONE(options->xauth_location);
358 CLEAR_ON_NONE(options->banner);
359 CLEAR_ON_NONE(options->trusted_user_ca_keys);
360 CLEAR_ON_NONE(options->revoked_keys_file);
djm@openbsd.org7e8528c2015-05-01 04:17:51 +0000361 CLEAR_ON_NONE(options->authorized_principals_file);
djm@openbsd.org161cf412014-12-22 07:55:51 +0000362 for (i = 0; i < options->num_host_key_files; i++)
363 CLEAR_ON_NONE(options->host_key_files[i]);
364 for (i = 0; i < options->num_host_cert_files; i++)
365 CLEAR_ON_NONE(options->host_cert_files[i]);
366#undef CLEAR_ON_NONE
367
Tim Rice40017b02002-07-14 13:36:49 -0700368#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000369 if (use_privsep && options->compression == 1) {
370 error("This platform does not support both privilege "
371 "separation and compression");
372 error("Compression disabled");
373 options->compression = 0;
374 }
375#endif
376
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000377}
378
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100380typedef enum {
381 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100382 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000383 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100384 /* Standard Options */
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000385 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
386 sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000387 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100388 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100389 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000390 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100391 sPasswordAuthentication, sKbdInteractiveAuthentication,
392 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000393 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100394 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100395 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000396 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000397 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000398 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000399 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
400 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000401 sBanner, sUseDNS, sHostbasedAuthentication,
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000402 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
403 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000404 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
405 sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100406 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100407 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100408 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000409 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000410 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
Damien Miller23528812012-04-22 11:24:43 +1000411 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100412 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000413 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000414 sStreamLocalBindMask, sStreamLocalBindUnlink,
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000415 sAllowStreamLocalForwarding, sFingerprintHash,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000416 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000417} ServerOpCodes;
418
Darren Tucker45150472006-07-12 22:34:17 +1000419#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
420#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
421#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
422
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000423/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100424static struct {
425 const char *name;
426 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000427 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100428} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100429 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000430#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000431 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000432#else
Darren Tucker45150472006-07-12 22:34:17 +1000433 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000434#endif
Darren Tucker45150472006-07-12 22:34:17 +1000435 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100436 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000437 { "port", sPort, SSHCFG_GLOBAL },
438 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
439 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000440 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000441 { "pidfile", sPidFile, SSHCFG_GLOBAL },
442 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
443 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
444 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100445 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
447 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
448 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100449 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
450 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000451 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000452 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100453 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
454 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
djm@openbsd.org1f729f02015-01-13 07:39:19 +0000455 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000456 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000457#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100458 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000459 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
460 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100461#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000462 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000463#else
Darren Tucker45150472006-07-12 22:34:17 +1000464 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100465#endif
466#else
Darren Tucker1629c072007-02-19 22:25:37 +1100467 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000468 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
469 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
470 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000471#endif
Darren Tucker45150472006-07-12 22:34:17 +1000472 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
473 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000474#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100475 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000476 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000477 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000478#else
Darren Tucker1629c072007-02-19 22:25:37 +1100479 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000480 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +0000481 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000482#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100483 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
484 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100485 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000486 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
487 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
488 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
489 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
490 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
491 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
492 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
493 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000494 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
495 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
496 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000497 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
498 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100499 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000500 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
501 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
502 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000503 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000504 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
505 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
506 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000507 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000508 { "allowusers", sAllowUsers, SSHCFG_ALL },
509 { "denyusers", sDenyUsers, SSHCFG_ALL },
510 { "allowgroups", sAllowGroups, SSHCFG_ALL },
511 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000512 { "ciphers", sCiphers, SSHCFG_GLOBAL },
513 { "macs", sMacs, SSHCFG_GLOBAL },
514 { "protocol", sProtocol, SSHCFG_GLOBAL },
515 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
516 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
517 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000518 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000519 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100520 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000521 { "usedns", sUseDNS, SSHCFG_GLOBAL },
522 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
523 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
524 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
525 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000526 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000527 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000528 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000529 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000530 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100531 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000532 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000533 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000534 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000535 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100536 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100537 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100538 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
539 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000540 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000541 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100542 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100543 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
544 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +0000545 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
546 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000547 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100548 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000549 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
550 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
551 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000552 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000553 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000554};
555
Darren Tuckere7140f22008-06-10 23:01:51 +1000556static struct {
557 int val;
558 char *text;
559} tunmode_desc[] = {
560 { SSH_TUNMODE_NO, "no" },
561 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
562 { SSH_TUNMODE_ETHERNET, "ethernet" },
563 { SSH_TUNMODE_YES, "yes" },
564 { -1, NULL }
565};
566
Damien Miller5428f641999-11-25 11:54:57 +1100567/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000568 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100569 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000570
Damien Miller4af51302000-04-16 11:18:38 +1000571static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100572parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000573 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000574{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000575 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000576
Damien Miller95def091999-11-25 00:26:21 +1100577 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000578 if (strcasecmp(cp, keywords[i].name) == 0) {
579 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100580 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000581 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000582
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000583 error("%s: line %d: Bad configuration option: %s",
584 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100585 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000586}
587
Darren Tucker88b6fb22010-01-13 22:44:29 +1100588char *
589derelativise_path(const char *path)
590{
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +0000591 char *expanded, *ret, cwd[PATH_MAX];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100592
djm@openbsd.org161cf412014-12-22 07:55:51 +0000593 if (strcasecmp(path, "none") == 0)
594 return xstrdup("none");
Darren Tucker88b6fb22010-01-13 22:44:29 +1100595 expanded = tilde_expand_filename(path, getuid());
596 if (*expanded == '/')
597 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100598 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100599 fatal("%s: getcwd: %s", __func__, strerror(errno));
600 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000601 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100602 return ret;
603}
604
Ben Lindstrombba81212001-06-25 05:01:22 +0000605static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100606add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100607{
Damien Millereccb9de2005-06-17 12:59:34 +1000608 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100609
Ben Lindstrom19066a12001-04-12 23:39:26 +0000610 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000611 for (i = 0; i < options->num_ports; i++)
612 add_one_listen_addr(options, addr, options->ports[i]);
613 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000614 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000615}
616
Ben Lindstrombba81212001-06-25 05:01:22 +0000617static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100618add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000619{
620 struct addrinfo hints, *ai, *aitop;
621 char strport[NI_MAXSERV];
622 int gaierr;
623
624 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100625 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000626 hints.ai_socktype = SOCK_STREAM;
627 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100628 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000629 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
630 fatal("bad addr or host: %s (%s)",
631 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100632 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000633 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
634 ;
635 ai->ai_next = options->listen_addrs;
636 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100637}
638
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +0000639/*
640 * Queue a ListenAddress to be processed once we have all of the Ports
641 * and AddressFamily options.
642 */
643static void
644queue_listen_addr(ServerOptions *options, char *addr, int port)
645{
646 options->queued_listen_addrs = xreallocarray(
647 options->queued_listen_addrs, options->num_queued_listens + 1,
648 sizeof(addr));
649 options->queued_listen_ports = xreallocarray(
650 options->queued_listen_ports, options->num_queued_listens + 1,
651 sizeof(port));
652 options->queued_listen_addrs[options->num_queued_listens] =
653 xstrdup(addr);
654 options->queued_listen_ports[options->num_queued_listens] = port;
655 options->num_queued_listens++;
656}
657
658/*
659 * Process queued (text) ListenAddress entries.
660 */
661static void
662process_queued_listen_addrs(ServerOptions *options)
663{
664 u_int i;
665
666 if (options->num_ports == 0)
667 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
668 if (options->address_family == -1)
669 options->address_family = AF_UNSPEC;
670
671 for (i = 0; i < options->num_queued_listens; i++) {
672 add_listen_addr(options, options->queued_listen_addrs[i],
673 options->queued_listen_ports[i]);
674 free(options->queued_listen_addrs[i]);
675 options->queued_listen_addrs[i] = NULL;
676 }
677 free(options->queued_listen_addrs);
678 options->queued_listen_addrs = NULL;
679 free(options->queued_listen_ports);
680 options->queued_listen_ports = NULL;
681 options->num_queued_listens = 0;
682}
683
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000684struct connection_info *
685get_connection_info(int populate, int use_dns)
686{
687 static struct connection_info ci;
688
689 if (!populate)
690 return &ci;
691 ci.host = get_canonical_hostname(use_dns);
692 ci.address = get_remote_ipaddr();
693 ci.laddress = get_local_ipaddr(packet_get_connection_in());
694 ci.lport = get_local_port();
695 return &ci;
696}
697
Darren Tucker45150472006-07-12 22:34:17 +1000698/*
699 * The strategy for the Match blocks is that the config file is parsed twice.
700 *
701 * The first time is at startup. activep is initialized to 1 and the
702 * directives in the global context are processed and acted on. Hitting a
703 * Match directive unsets activep and the directives inside the block are
704 * checked for syntax only.
705 *
706 * The second time is after a connection has been established but before
707 * authentication. activep is initialized to 2 and global config directives
708 * are ignored since they have already been processed. If the criteria in a
709 * Match block is met, activep is set and the subsequent directives
710 * processed and actioned until EOF or another Match block unsets it. Any
711 * options set are copied into the main server config.
712 *
713 * Potential additions/improvements:
714 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
715 *
716 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
717 * Match Address 192.168.0.*
718 * Tag trusted
719 * Match Group wheel
720 * Tag trusted
721 * Match Tag trusted
722 * AllowTcpForwarding yes
723 * GatewayPorts clientspecified
724 * [...]
725 *
726 * - Add a PermittedChannelRequests directive
727 * Match Group shell
728 * PermittedChannelRequests session,forwarded-tcpip
729 */
730
731static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000732match_cfg_line_group(const char *grps, int line, const char *user)
733{
734 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000735 struct passwd *pw;
736
Damien Miller565ca3f2006-08-19 00:23:15 +1000737 if (user == NULL)
738 goto out;
739
740 if ((pw = getpwnam(user)) == NULL) {
741 debug("Can't match group at line %d because user %.100s does "
742 "not exist", line, user);
743 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
744 debug("Can't Match group because user %.100s not in any group "
745 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000746 } else if (ga_match_pattern_list(grps) != 1) {
747 debug("user %.100s does not match group list %.100s at line %d",
748 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000749 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000750 debug("user %.100s matched group list %.100s at line %d", user,
751 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000752 result = 1;
753 }
754out:
755 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000756 return result;
757}
758
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000759/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000760 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100761 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000762 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000763 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000764static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000765match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000766{
Damien Millercf31f382013-10-24 21:02:56 +1100767 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000768 char *arg, *attrib, *cp = *condition;
Darren Tucker45150472006-07-12 22:34:17 +1000769
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000770 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000771 debug3("checking syntax for 'Match %s'", cp);
772 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000773 debug3("checking match for '%s' user %s host %s addr %s "
774 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
775 ci->host ? ci->host : "(null)",
776 ci->address ? ci->address : "(null)",
777 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000778
779 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100780 attributes++;
781 if (strcasecmp(attrib, "all") == 0) {
782 if (attributes != 1 ||
783 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
784 error("'all' cannot be combined with other "
785 "Match attributes");
786 return -1;
787 }
788 *condition = cp;
789 return 1;
790 }
Darren Tucker45150472006-07-12 22:34:17 +1000791 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
792 error("Missing Match criteria for %s", attrib);
793 return -1;
794 }
Darren Tucker45150472006-07-12 22:34:17 +1000795 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000796 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000797 result = 0;
798 continue;
799 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000800 if (match_pattern_list(ci->user, arg, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000801 result = 0;
802 else
803 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000804 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000805 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000806 if (ci == NULL || ci->user == NULL) {
807 result = 0;
808 continue;
809 }
810 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000811 case -1:
812 return -1;
813 case 0:
814 result = 0;
815 }
Darren Tucker45150472006-07-12 22:34:17 +1000816 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000817 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000818 result = 0;
819 continue;
820 }
djm@openbsd.orge661a862015-05-04 06:10:48 +0000821 if (match_hostname(ci->host, arg) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000822 result = 0;
823 else
824 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000825 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000826 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000827 if (ci == NULL || ci->address == NULL) {
828 result = 0;
829 continue;
830 }
831 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000832 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000833 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000834 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000835 break;
836 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000837 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000838 result = 0;
839 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000840 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000841 return -1;
842 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000843 } else if (strcasecmp(attrib, "localaddress") == 0){
844 if (ci == NULL || ci->laddress == NULL) {
845 result = 0;
846 continue;
847 }
848 switch (addr_match_list(ci->laddress, arg)) {
849 case 1:
850 debug("connection from %.100s matched "
851 "'LocalAddress %.100s' at line %d",
852 ci->laddress, arg, line);
853 break;
854 case 0:
855 case -1:
856 result = 0;
857 break;
858 case -2:
859 return -1;
860 }
861 } else if (strcasecmp(attrib, "localport") == 0) {
862 if ((port = a2port(arg)) == -1) {
863 error("Invalid LocalPort '%s' on Match line",
864 arg);
865 return -1;
866 }
867 if (ci == NULL || ci->lport == 0) {
868 result = 0;
869 continue;
870 }
871 /* TODO support port lists */
872 if (port == ci->lport)
873 debug("connection from %.100s matched "
874 "'LocalPort %d' at line %d",
875 ci->laddress, port, line);
876 else
877 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000878 } else {
879 error("Unsupported Match attribute %s", attrib);
880 return -1;
881 }
882 }
Damien Millercf31f382013-10-24 21:02:56 +1100883 if (attributes == 0) {
884 error("One or more attributes required for Match");
885 return -1;
886 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000887 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000888 debug3("match %sfound", result ? "" : "not ");
889 *condition = cp;
890 return result;
891}
892
Damien Millere2754432006-07-24 14:06:47 +1000893#define WHITESPACE " \t\r\n"
894
Damien Miller33322122011-06-20 14:43:11 +1000895/* Multistate option parsing */
896struct multistate {
897 char *key;
898 int value;
899};
900static const struct multistate multistate_addressfamily[] = {
901 { "inet", AF_INET },
902 { "inet6", AF_INET6 },
903 { "any", AF_UNSPEC },
904 { NULL, -1 }
905};
906static const struct multistate multistate_permitrootlogin[] = {
907 { "without-password", PERMIT_NO_PASSWD },
908 { "forced-commands-only", PERMIT_FORCED_ONLY },
909 { "yes", PERMIT_YES },
910 { "no", PERMIT_NO },
911 { NULL, -1 }
912};
913static const struct multistate multistate_compression[] = {
914 { "delayed", COMP_DELAYED },
915 { "yes", COMP_ZLIB },
916 { "no", COMP_NONE },
917 { NULL, -1 }
918};
919static const struct multistate multistate_gatewayports[] = {
920 { "clientspecified", 2 },
921 { "yes", 1 },
922 { "no", 0 },
923 { NULL, -1 }
924};
Damien Miller69ff1df2011-06-23 08:30:03 +1000925static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000926 { "yes", PRIVSEP_NOSANDBOX },
927 { "sandbox", PRIVSEP_ON },
928 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000929 { "no", PRIVSEP_OFF },
930 { NULL, -1 }
931};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100932static const struct multistate multistate_tcpfwd[] = {
933 { "yes", FORWARD_ALLOW },
934 { "all", FORWARD_ALLOW },
935 { "no", FORWARD_DENY },
936 { "remote", FORWARD_REMOTE },
937 { "local", FORWARD_LOCAL },
938 { NULL, -1 }
939};
Damien Miller33322122011-06-20 14:43:11 +1000940
Ben Lindstromade03f62001-12-06 18:22:17 +0000941int
942process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000943 const char *filename, int linenum, int *activep,
944 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000945{
Darren Tucker09c0f032013-05-16 20:48:57 +1000946 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000947 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100948 SyslogFacility *log_facility_ptr;
949 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000950 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000951 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000952 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000953 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000954 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000955
956 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100957 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100958 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000959 /* Ignore leading whitespace */
960 if (*arg == '\0')
961 arg = strdelim(&cp);
962 if (!arg || !*arg || *arg == '#')
963 return 0;
964 intptr = NULL;
965 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000966 opcode = parse_token(arg, filename, linenum, &flags);
967
968 if (activep == NULL) { /* We are processing a command line directive */
969 cmdline = 1;
970 activep = &cmdline;
971 }
972 if (*activep && opcode != sMatch)
973 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
974 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000975 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000976 fatal("%s line %d: Directive '%s' is not allowed "
977 "within a Match block", filename, linenum, arg);
978 } else { /* this is a directive we have already processed */
979 while (arg)
980 arg = strdelim(&cp);
981 return 0;
982 }
983 }
984
Ben Lindstromade03f62001-12-06 18:22:17 +0000985 switch (opcode) {
986 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000987 case sUsePAM:
988 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000989 goto parse_flag;
990
991 /* Standard Options */
992 case sBadOption:
993 return -1;
994 case sPort:
995 /* ignore ports from configfile if cmdline specifies ports */
996 if (options->ports_from_cmdline)
997 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000998 if (options->num_ports >= MAX_PORTS)
999 fatal("%s line %d: too many ports.",
1000 filename, linenum);
1001 arg = strdelim(&cp);
1002 if (!arg || *arg == '\0')
1003 fatal("%s line %d: missing port number.",
1004 filename, linenum);
1005 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001006 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +00001007 fatal("%s line %d: Badly formatted port number.",
1008 filename, linenum);
1009 break;
1010
1011 case sServerKeyBits:
1012 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +10001013 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +00001014 arg = strdelim(&cp);
1015 if (!arg || *arg == '\0')
1016 fatal("%s line %d: missing integer value.",
1017 filename, linenum);
1018 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +10001019 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001020 *intptr = value;
1021 break;
1022
1023 case sLoginGraceTime:
1024 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +10001025 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +00001026 arg = strdelim(&cp);
1027 if (!arg || *arg == '\0')
1028 fatal("%s line %d: missing time value.",
1029 filename, linenum);
1030 if ((value = convtime(arg)) == -1)
1031 fatal("%s line %d: invalid time value.",
1032 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001033 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001034 *intptr = value;
1035 break;
1036
1037 case sKeyRegenerationTime:
1038 intptr = &options->key_regeneration_time;
1039 goto parse_time;
1040
1041 case sListenAddress:
1042 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001043 if (arg == NULL || *arg == '\0')
1044 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +00001045 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +10001046 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1047 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1048 && strchr(p+1, ':') != NULL) {
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001049 queue_listen_addr(options, arg, 0);
Damien Miller203c7052005-08-12 22:11:37 +10001050 break;
1051 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001052 p = hpdelim(&arg);
1053 if (p == NULL)
1054 fatal("%s line %d: bad address:port usage",
1055 filename, linenum);
1056 p = cleanhostname(p);
1057 if (arg == NULL)
1058 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +11001059 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001060 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001061
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00001062 queue_listen_addr(options, p, port);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001063
Ben Lindstromade03f62001-12-06 18:22:17 +00001064 break;
1065
Darren Tucker0f383232005-01-20 10:57:56 +11001066 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +10001067 intptr = &options->address_family;
1068 multistate_ptr = multistate_addressfamily;
Damien Miller33322122011-06-20 14:43:11 +10001069 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +11001070 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +10001071 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +10001072 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +10001073 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +10001074 value = -1;
1075 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1076 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1077 value = multistate_ptr[i].value;
1078 break;
1079 }
1080 }
1081 if (value == -1)
1082 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +11001083 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +10001084 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +11001085 *intptr = value;
1086 break;
1087
Ben Lindstromade03f62001-12-06 18:22:17 +00001088 case sHostKeyFile:
1089 intptr = &options->num_host_key_files;
1090 if (*intptr >= MAX_HOSTKEYS)
1091 fatal("%s line %d: too many host keys specified (max %d).",
1092 filename, linenum, MAX_HOSTKEYS);
1093 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001094 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001095 arg = strdelim(&cp);
1096 if (!arg || *arg == '\0')
1097 fatal("%s line %d: missing file name.",
1098 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001099 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001100 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001101 /* increase optional counter */
1102 if (intptr != NULL)
1103 *intptr = *intptr + 1;
1104 }
1105 break;
1106
Damien Miller85b45e02013-07-20 13:21:52 +10001107 case sHostKeyAgent:
1108 charptr = &options->host_key_agent;
1109 arg = strdelim(&cp);
1110 if (!arg || *arg == '\0')
1111 fatal("%s line %d: missing socket name.",
1112 filename, linenum);
1113 if (*activep && *charptr == NULL)
1114 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1115 xstrdup(arg) : derelativise_path(arg);
1116 break;
1117
Damien Miller0a80ca12010-02-27 07:55:05 +11001118 case sHostCertificate:
1119 intptr = &options->num_host_cert_files;
1120 if (*intptr >= MAX_HOSTKEYS)
1121 fatal("%s line %d: too many host certificates "
1122 "specified (max %d).", filename, linenum,
1123 MAX_HOSTCERTS);
1124 charptr = &options->host_cert_files[*intptr];
1125 goto parse_filename;
1126 break;
1127
Ben Lindstromade03f62001-12-06 18:22:17 +00001128 case sPidFile:
1129 charptr = &options->pid_file;
1130 goto parse_filename;
1131
1132 case sPermitRootLogin:
1133 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001134 multistate_ptr = multistate_permitrootlogin;
1135 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001136
1137 case sIgnoreRhosts:
1138 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001139 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001140 arg = strdelim(&cp);
1141 if (!arg || *arg == '\0')
1142 fatal("%s line %d: missing yes/no argument.",
1143 filename, linenum);
1144 value = 0; /* silence compiler */
1145 if (strcmp(arg, "yes") == 0)
1146 value = 1;
1147 else if (strcmp(arg, "no") == 0)
1148 value = 0;
1149 else
1150 fatal("%s line %d: Bad yes/no argument: %s",
1151 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001152 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001153 *intptr = value;
1154 break;
1155
1156 case sIgnoreUserKnownHosts:
1157 intptr = &options->ignore_user_known_hosts;
1158 goto parse_flag;
1159
Ben Lindstromade03f62001-12-06 18:22:17 +00001160 case sRhostsRSAAuthentication:
1161 intptr = &options->rhosts_rsa_authentication;
1162 goto parse_flag;
1163
1164 case sHostbasedAuthentication:
1165 intptr = &options->hostbased_authentication;
1166 goto parse_flag;
1167
1168 case sHostbasedUsesNameFromPacketOnly:
1169 intptr = &options->hostbased_uses_name_from_packet_only;
1170 goto parse_flag;
1171
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001172 case sHostbasedAcceptedKeyTypes:
1173 charptr = &options->hostbased_key_types;
1174 parse_keytypes:
1175 arg = strdelim(&cp);
1176 if (!arg || *arg == '\0')
1177 fatal("%s line %d: Missing argument.",
1178 filename, linenum);
1179 if (!sshkey_names_valid2(arg, 1))
1180 fatal("%s line %d: Bad key types '%s'.",
1181 filename, linenum, arg ? arg : "<NONE>");
1182 if (*activep && *charptr == NULL)
1183 *charptr = xstrdup(arg);
1184 break;
1185
Ben Lindstromade03f62001-12-06 18:22:17 +00001186 case sRSAAuthentication:
1187 intptr = &options->rsa_authentication;
1188 goto parse_flag;
1189
1190 case sPubkeyAuthentication:
1191 intptr = &options->pubkey_authentication;
1192 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001193
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001194 case sPubkeyAcceptedKeyTypes:
1195 charptr = &options->pubkey_key_types;
1196 goto parse_keytypes;
1197
Ben Lindstromade03f62001-12-06 18:22:17 +00001198 case sKerberosAuthentication:
1199 intptr = &options->kerberos_authentication;
1200 goto parse_flag;
1201
1202 case sKerberosOrLocalPasswd:
1203 intptr = &options->kerberos_or_local_passwd;
1204 goto parse_flag;
1205
1206 case sKerberosTicketCleanup:
1207 intptr = &options->kerberos_ticket_cleanup;
1208 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001209
Darren Tucker22ef5082003-12-31 11:37:34 +11001210 case sKerberosGetAFSToken:
1211 intptr = &options->kerberos_get_afs_token;
1212 goto parse_flag;
1213
Darren Tucker0efd1552003-08-26 11:49:55 +10001214 case sGssAuthentication:
1215 intptr = &options->gss_authentication;
1216 goto parse_flag;
1217
1218 case sGssCleanupCreds:
1219 intptr = &options->gss_cleanup_creds;
1220 goto parse_flag;
1221
djm@openbsd.orgd7c31da2015-05-22 03:50:02 +00001222 case sGssStrictAcceptor:
1223 intptr = &options->gss_strict_acceptor;
1224 goto parse_flag;
1225
Ben Lindstromade03f62001-12-06 18:22:17 +00001226 case sPasswordAuthentication:
1227 intptr = &options->password_authentication;
1228 goto parse_flag;
1229
1230 case sKbdInteractiveAuthentication:
1231 intptr = &options->kbd_interactive_authentication;
1232 goto parse_flag;
1233
1234 case sChallengeResponseAuthentication:
1235 intptr = &options->challenge_response_authentication;
1236 goto parse_flag;
1237
1238 case sPrintMotd:
1239 intptr = &options->print_motd;
1240 goto parse_flag;
1241
1242 case sPrintLastLog:
1243 intptr = &options->print_lastlog;
1244 goto parse_flag;
1245
1246 case sX11Forwarding:
1247 intptr = &options->x11_forwarding;
1248 goto parse_flag;
1249
1250 case sX11DisplayOffset:
1251 intptr = &options->x11_display_offset;
1252 goto parse_int;
1253
Damien Miller95c249f2002-02-05 12:11:34 +11001254 case sX11UseLocalhost:
1255 intptr = &options->x11_use_localhost;
1256 goto parse_flag;
1257
Ben Lindstromade03f62001-12-06 18:22:17 +00001258 case sXAuthLocation:
1259 charptr = &options->xauth_location;
1260 goto parse_filename;
1261
Damien Miller5ff30c62013-10-30 22:21:50 +11001262 case sPermitTTY:
1263 intptr = &options->permit_tty;
1264 goto parse_flag;
1265
Damien Miller72e6b5c2014-07-04 09:00:04 +10001266 case sPermitUserRC:
1267 intptr = &options->permit_user_rc;
1268 goto parse_flag;
1269
Ben Lindstromade03f62001-12-06 18:22:17 +00001270 case sStrictModes:
1271 intptr = &options->strict_modes;
1272 goto parse_flag;
1273
Damien Miller12c150e2003-12-17 16:31:10 +11001274 case sTCPKeepAlive:
1275 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001276 goto parse_flag;
1277
1278 case sEmptyPasswd:
1279 intptr = &options->permit_empty_passwd;
1280 goto parse_flag;
1281
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001282 case sPermitUserEnvironment:
1283 intptr = &options->permit_user_env;
1284 goto parse_flag;
1285
Ben Lindstromade03f62001-12-06 18:22:17 +00001286 case sUseLogin:
1287 intptr = &options->use_login;
1288 goto parse_flag;
1289
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001290 case sCompression:
1291 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001292 multistate_ptr = multistate_compression;
1293 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001294
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001295 case sRekeyLimit:
1296 arg = strdelim(&cp);
1297 if (!arg || *arg == '\0')
1298 fatal("%.200s line %d: Missing argument.", filename,
1299 linenum);
1300 if (strcmp(arg, "default") == 0) {
1301 val64 = 0;
1302 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001303 if (scan_scaled(arg, &val64) == -1)
1304 fatal("%.200s line %d: Bad number '%s': %s",
1305 filename, linenum, arg, strerror(errno));
1306 /* check for too-large or too-small limits */
1307 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001308 fatal("%.200s line %d: RekeyLimit too large",
1309 filename, linenum);
1310 if (val64 != 0 && val64 < 16)
1311 fatal("%.200s line %d: RekeyLimit too small",
1312 filename, linenum);
1313 }
1314 if (*activep && options->rekey_limit == -1)
1315 options->rekey_limit = (u_int32_t)val64;
1316 if (cp != NULL) { /* optional rekey interval present */
1317 if (strcmp(cp, "none") == 0) {
1318 (void)strdelim(&cp); /* discard */
1319 break;
1320 }
1321 intptr = &options->rekey_interval;
1322 goto parse_time;
1323 }
1324 break;
1325
Ben Lindstromade03f62001-12-06 18:22:17 +00001326 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001327 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001328 multistate_ptr = multistate_gatewayports;
1329 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001330
Damien Miller3a961dc2003-06-03 10:25:48 +10001331 case sUseDNS:
1332 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001333 goto parse_flag;
1334
1335 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001336 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001337 arg = strdelim(&cp);
1338 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001339 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001340 fatal("%.200s line %d: unsupported log facility '%s'",
1341 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001342 if (*log_facility_ptr == -1)
1343 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001344 break;
1345
1346 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001347 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001348 arg = strdelim(&cp);
1349 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001350 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001351 fatal("%.200s line %d: unsupported log level '%s'",
1352 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001353 if (*log_level_ptr == -1)
1354 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001355 break;
1356
1357 case sAllowTcpForwarding:
1358 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001359 multistate_ptr = multistate_tcpfwd;
1360 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001361
Damien Miller7acefbb2014-07-18 14:11:24 +10001362 case sAllowStreamLocalForwarding:
1363 intptr = &options->allow_streamlocal_forwarding;
1364 multistate_ptr = multistate_tcpfwd;
1365 goto parse_multistate;
1366
Damien Miller4f755cd2008-05-19 14:57:41 +10001367 case sAllowAgentForwarding:
1368 intptr = &options->allow_agent_forwarding;
1369 goto parse_flag;
1370
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001371 case sUsePrivilegeSeparation:
1372 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001373 multistate_ptr = multistate_privsep;
1374 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001375
Ben Lindstromade03f62001-12-06 18:22:17 +00001376 case sAllowUsers:
1377 while ((arg = strdelim(&cp)) && *arg != '\0') {
1378 if (options->num_allow_users >= MAX_ALLOW_USERS)
1379 fatal("%s line %d: too many allow users.",
1380 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001381 if (!*activep)
1382 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001383 options->allow_users[options->num_allow_users++] =
1384 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001385 }
1386 break;
1387
1388 case sDenyUsers:
1389 while ((arg = strdelim(&cp)) && *arg != '\0') {
1390 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001391 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001392 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001393 if (!*activep)
1394 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001395 options->deny_users[options->num_deny_users++] =
1396 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001397 }
1398 break;
1399
1400 case sAllowGroups:
1401 while ((arg = strdelim(&cp)) && *arg != '\0') {
1402 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1403 fatal("%s line %d: too many allow groups.",
1404 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001405 if (!*activep)
1406 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001407 options->allow_groups[options->num_allow_groups++] =
1408 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001409 }
1410 break;
1411
1412 case sDenyGroups:
1413 while ((arg = strdelim(&cp)) && *arg != '\0') {
1414 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1415 fatal("%s line %d: too many deny groups.",
1416 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001417 if (!*activep)
1418 continue;
1419 options->deny_groups[options->num_deny_groups++] =
1420 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001421 }
1422 break;
1423
1424 case sCiphers:
1425 arg = strdelim(&cp);
1426 if (!arg || *arg == '\0')
1427 fatal("%s line %d: Missing argument.", filename, linenum);
1428 if (!ciphers_valid(arg))
1429 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1430 filename, linenum, arg ? arg : "<NONE>");
1431 if (options->ciphers == NULL)
1432 options->ciphers = xstrdup(arg);
1433 break;
1434
1435 case sMacs:
1436 arg = strdelim(&cp);
1437 if (!arg || *arg == '\0')
1438 fatal("%s line %d: Missing argument.", filename, linenum);
1439 if (!mac_valid(arg))
1440 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1441 filename, linenum, arg ? arg : "<NONE>");
1442 if (options->macs == NULL)
1443 options->macs = xstrdup(arg);
1444 break;
1445
Damien Millerd5f62bf2010-09-24 22:11:14 +10001446 case sKexAlgorithms:
1447 arg = strdelim(&cp);
1448 if (!arg || *arg == '\0')
1449 fatal("%s line %d: Missing argument.",
1450 filename, linenum);
1451 if (!kex_names_valid(arg))
1452 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1453 filename, linenum, arg ? arg : "<NONE>");
1454 if (options->kex_algorithms == NULL)
1455 options->kex_algorithms = xstrdup(arg);
1456 break;
1457
Ben Lindstromade03f62001-12-06 18:22:17 +00001458 case sProtocol:
1459 intptr = &options->protocol;
1460 arg = strdelim(&cp);
1461 if (!arg || *arg == '\0')
1462 fatal("%s line %d: Missing argument.", filename, linenum);
1463 value = proto_spec(arg);
1464 if (value == SSH_PROTO_UNKNOWN)
1465 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001466 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001467 if (*intptr == SSH_PROTO_UNKNOWN)
1468 *intptr = value;
1469 break;
1470
1471 case sSubsystem:
1472 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1473 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001474 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001475 }
1476 arg = strdelim(&cp);
1477 if (!arg || *arg == '\0')
1478 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001479 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001480 if (!*activep) {
1481 arg = strdelim(&cp);
1482 break;
1483 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001484 for (i = 0; i < options->num_subsystems; i++)
1485 if (strcmp(arg, options->subsystem_name[i]) == 0)
1486 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001487 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001488 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1489 arg = strdelim(&cp);
1490 if (!arg || *arg == '\0')
1491 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001492 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001493 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001494
1495 /* Collect arguments (separate to executable) */
1496 p = xstrdup(arg);
1497 len = strlen(p) + 1;
1498 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1499 len += 1 + strlen(arg);
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +00001500 p = xreallocarray(p, 1, len);
Damien Miller917f9b62006-07-10 20:36:47 +10001501 strlcat(p, " ", len);
1502 strlcat(p, arg, len);
1503 }
1504 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001505 options->num_subsystems++;
1506 break;
1507
1508 case sMaxStartups:
1509 arg = strdelim(&cp);
1510 if (!arg || *arg == '\0')
1511 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001512 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001513 if ((n = sscanf(arg, "%d:%d:%d",
1514 &options->max_startups_begin,
1515 &options->max_startups_rate,
1516 &options->max_startups)) == 3) {
1517 if (options->max_startups_begin >
1518 options->max_startups ||
1519 options->max_startups_rate > 100 ||
1520 options->max_startups_rate < 1)
1521 fatal("%s line %d: Illegal MaxStartups spec.",
1522 filename, linenum);
1523 } else if (n != 1)
1524 fatal("%s line %d: Illegal MaxStartups spec.",
1525 filename, linenum);
1526 else
1527 options->max_startups = options->max_startups_begin;
1528 break;
1529
Darren Tucker89413db2004-05-24 10:36:23 +10001530 case sMaxAuthTries:
1531 intptr = &options->max_authtries;
1532 goto parse_int;
1533
Damien Miller7207f642008-05-19 15:34:50 +10001534 case sMaxSessions:
1535 intptr = &options->max_sessions;
1536 goto parse_int;
1537
Ben Lindstromade03f62001-12-06 18:22:17 +00001538 case sBanner:
1539 charptr = &options->banner;
1540 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001541
Ben Lindstromade03f62001-12-06 18:22:17 +00001542 /*
1543 * These options can contain %X options expanded at
1544 * connect time, so that you can specify paths like:
1545 *
1546 * AuthorizedKeysFile /etc/ssh_keys/%u
1547 */
1548 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001549 if (*activep && options->num_authkeys_files == 0) {
1550 while ((arg = strdelim(&cp)) && *arg != '\0') {
1551 if (options->num_authkeys_files >=
1552 MAX_AUTHKEYS_FILES)
1553 fatal("%s line %d: "
1554 "too many authorized keys files.",
1555 filename, linenum);
1556 options->authorized_keys_files[
1557 options->num_authkeys_files++] =
1558 tilde_expand_filename(arg, getuid());
1559 }
1560 }
1561 return 0;
1562
Damien Miller30da3442010-05-10 11:58:03 +10001563 case sAuthorizedPrincipalsFile:
1564 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001565 arg = strdelim(&cp);
1566 if (!arg || *arg == '\0')
1567 fatal("%s line %d: missing file name.",
1568 filename, linenum);
1569 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001570 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001571 /* increase optional counter */
1572 if (intptr != NULL)
1573 *intptr = *intptr + 1;
1574 }
1575 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001576
1577 case sClientAliveInterval:
1578 intptr = &options->client_alive_interval;
1579 goto parse_time;
1580
1581 case sClientAliveCountMax:
1582 intptr = &options->client_alive_count_max;
1583 goto parse_int;
1584
Darren Tucker46bc0752004-05-02 22:11:30 +10001585 case sAcceptEnv:
1586 while ((arg = strdelim(&cp)) && *arg != '\0') {
1587 if (strchr(arg, '=') != NULL)
1588 fatal("%s line %d: Invalid environment name.",
1589 filename, linenum);
1590 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1591 fatal("%s line %d: too many allow env.",
1592 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001593 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001594 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001595 options->accept_env[options->num_accept_env++] =
1596 xstrdup(arg);
1597 }
1598 break;
1599
Damien Millerd27b9472005-12-13 19:29:02 +11001600 case sPermitTunnel:
1601 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001602 arg = strdelim(&cp);
1603 if (!arg || *arg == '\0')
1604 fatal("%s line %d: Missing yes/point-to-point/"
1605 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001606 value = -1;
1607 for (i = 0; tunmode_desc[i].val != -1; i++)
1608 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1609 value = tunmode_desc[i].val;
1610 break;
1611 }
1612 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001613 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1614 "no argument: %s", filename, linenum, arg);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001615 if (*activep && *intptr == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001616 *intptr = value;
1617 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001618
Darren Tucker45150472006-07-12 22:34:17 +10001619 case sMatch:
1620 if (cmdline)
1621 fatal("Match directive not supported as a command-line "
1622 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001623 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001624 if (value < 0)
1625 fatal("%s line %d: Bad Match condition", filename,
1626 linenum);
1627 *activep = value;
1628 break;
1629
Damien Miller9b439df2006-07-24 14:04:00 +10001630 case sPermitOpen:
1631 arg = strdelim(&cp);
1632 if (!arg || *arg == '\0')
1633 fatal("%s line %d: missing PermitOpen specification",
1634 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001635 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001636 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001637 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001638 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001639 options->num_permitted_opens = 0;
1640 }
Damien Miller9b439df2006-07-24 14:04:00 +10001641 break;
1642 }
Damien Millerc6081482012-04-22 11:18:53 +10001643 if (strcmp(arg, "none") == 0) {
1644 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001645 options->num_permitted_opens = 1;
1646 channel_disable_adm_local_opens();
1647 }
1648 break;
1649 }
Damien Millera29b95e2007-01-05 16:28:36 +11001650 if (*activep && n == -1)
1651 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001652 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1653 p = hpdelim(&arg);
1654 if (p == NULL)
1655 fatal("%s line %d: missing host in PermitOpen",
1656 filename, linenum);
1657 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001658 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001659 fatal("%s line %d: bad port number in "
1660 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001661 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001662 options->num_permitted_opens =
1663 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001664 }
Damien Miller9b439df2006-07-24 14:04:00 +10001665 break;
1666
Damien Millere2754432006-07-24 14:06:47 +10001667 case sForceCommand:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001668 if (cp == NULL || *cp == '\0')
Damien Millere2754432006-07-24 14:06:47 +10001669 fatal("%.200s line %d: Missing argument.", filename,
1670 linenum);
1671 len = strspn(cp, WHITESPACE);
1672 if (*activep && options->adm_forced_command == NULL)
1673 options->adm_forced_command = xstrdup(cp + len);
1674 return 0;
1675
Damien Millerd8cb1f12008-02-10 22:40:12 +11001676 case sChrootDirectory:
1677 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001678
1679 arg = strdelim(&cp);
1680 if (!arg || *arg == '\0')
1681 fatal("%s line %d: missing file name.",
1682 filename, linenum);
1683 if (*activep && *charptr == NULL)
1684 *charptr = xstrdup(arg);
1685 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001686
Damien Miller1aed65e2010-03-04 21:53:35 +11001687 case sTrustedUserCAKeys:
1688 charptr = &options->trusted_user_ca_keys;
1689 goto parse_filename;
1690
1691 case sRevokedKeys:
1692 charptr = &options->revoked_keys_file;
1693 goto parse_filename;
1694
Damien Miller0dac6fb2010-11-20 15:19:38 +11001695 case sIPQoS:
1696 arg = strdelim(&cp);
1697 if ((value = parse_ipqos(arg)) == -1)
1698 fatal("%s line %d: Bad IPQoS value: %s",
1699 filename, linenum, arg);
1700 arg = strdelim(&cp);
1701 if (arg == NULL)
1702 value2 = value;
1703 else if ((value2 = parse_ipqos(arg)) == -1)
1704 fatal("%s line %d: Bad IPQoS value: %s",
1705 filename, linenum, arg);
1706 if (*activep) {
1707 options->ip_qos_interactive = value;
1708 options->ip_qos_bulk = value2;
1709 }
1710 break;
1711
Damien Miller23528812012-04-22 11:24:43 +10001712 case sVersionAddendum:
dtucker@openbsd.orgbd902b82015-04-23 04:53:53 +00001713 if (cp == NULL || *cp == '\0')
Damien Miller23528812012-04-22 11:24:43 +10001714 fatal("%.200s line %d: Missing argument.", filename,
1715 linenum);
1716 len = strspn(cp, WHITESPACE);
1717 if (*activep && options->version_addendum == NULL) {
1718 if (strcasecmp(cp + len, "none") == 0)
1719 options->version_addendum = xstrdup("");
1720 else if (strchr(cp + len, '\r') != NULL)
1721 fatal("%.200s line %d: Invalid argument",
1722 filename, linenum);
1723 else
1724 options->version_addendum = xstrdup(cp + len);
1725 }
1726 return 0;
1727
Damien Miller09d3e122012-10-31 08:58:58 +11001728 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001729 if (cp == NULL)
1730 fatal("%.200s line %d: Missing argument.", filename,
1731 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001732 len = strspn(cp, WHITESPACE);
1733 if (*activep && options->authorized_keys_command == NULL) {
1734 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1735 fatal("%.200s line %d: AuthorizedKeysCommand "
1736 "must be an absolute path",
1737 filename, linenum);
1738 options->authorized_keys_command = xstrdup(cp + len);
1739 }
1740 return 0;
1741
1742 case sAuthorizedKeysCommandUser:
1743 charptr = &options->authorized_keys_command_user;
1744
1745 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001746 if (!arg || *arg == '\0')
1747 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1748 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001749 if (*activep && *charptr == NULL)
1750 *charptr = xstrdup(arg);
1751 break;
1752
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00001753 case sAuthorizedPrincipalsCommand:
1754 if (cp == NULL)
1755 fatal("%.200s line %d: Missing argument.", filename,
1756 linenum);
1757 len = strspn(cp, WHITESPACE);
1758 if (*activep &&
1759 options->authorized_principals_command == NULL) {
1760 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1761 fatal("%.200s line %d: "
1762 "AuthorizedPrincipalsCommand must be "
1763 "an absolute path", filename, linenum);
1764 options->authorized_principals_command =
1765 xstrdup(cp + len);
1766 }
1767 return 0;
1768
1769 case sAuthorizedPrincipalsCommandUser:
1770 charptr = &options->authorized_principals_command_user;
1771
1772 arg = strdelim(&cp);
1773 if (!arg || *arg == '\0')
1774 fatal("%s line %d: missing "
1775 "AuthorizedPrincipalsCommandUser argument.",
1776 filename, linenum);
1777 if (*activep && *charptr == NULL)
1778 *charptr = xstrdup(arg);
1779 break;
1780
Damien Millera6e3f012012-11-04 23:21:40 +11001781 case sAuthenticationMethods:
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001782 if (options->num_auth_methods == 0) {
Damien Millera6e3f012012-11-04 23:21:40 +11001783 while ((arg = strdelim(&cp)) && *arg != '\0') {
1784 if (options->num_auth_methods >=
1785 MAX_AUTH_METHODS)
1786 fatal("%s line %d: "
1787 "too many authentication methods.",
1788 filename, linenum);
1789 if (auth2_methods_valid(arg, 0) != 0)
1790 fatal("%s line %d: invalid "
1791 "authentication method list.",
1792 filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001793 if (!*activep)
1794 continue;
Damien Millera6e3f012012-11-04 23:21:40 +11001795 options->auth_methods[
1796 options->num_auth_methods++] = xstrdup(arg);
1797 }
1798 }
1799 return 0;
1800
Damien Miller7acefbb2014-07-18 14:11:24 +10001801 case sStreamLocalBindMask:
1802 arg = strdelim(&cp);
1803 if (!arg || *arg == '\0')
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001804 fatal("%s line %d: missing StreamLocalBindMask "
1805 "argument.", filename, linenum);
Damien Miller7acefbb2014-07-18 14:11:24 +10001806 /* Parse mode in octal format */
1807 value = strtol(arg, &p, 8);
1808 if (arg == p || value < 0 || value > 0777)
1809 fatal("%s line %d: Bad mask.", filename, linenum);
djm@openbsd.org9559d7d2015-05-01 07:08:08 +00001810 if (*activep)
1811 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
Damien Miller7acefbb2014-07-18 14:11:24 +10001812 break;
1813
1814 case sStreamLocalBindUnlink:
1815 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1816 goto parse_flag;
1817
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001818 case sFingerprintHash:
1819 arg = strdelim(&cp);
1820 if (!arg || *arg == '\0')
1821 fatal("%.200s line %d: Missing argument.",
1822 filename, linenum);
1823 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1824 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1825 filename, linenum, arg);
1826 if (*activep)
1827 options->fingerprint_hash = value;
1828 break;
1829
Ben Lindstromade03f62001-12-06 18:22:17 +00001830 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001831 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001832 filename, linenum, arg);
1833 while (arg)
1834 arg = strdelim(&cp);
1835 break;
1836
Damien Millerf9b3feb2003-05-16 11:38:32 +10001837 case sUnsupported:
1838 logit("%s line %d: Unsupported option %s",
1839 filename, linenum, arg);
1840 while (arg)
1841 arg = strdelim(&cp);
1842 break;
1843
Ben Lindstromade03f62001-12-06 18:22:17 +00001844 default:
1845 fatal("%s line %d: Missing handler for opcode %s (%d)",
1846 filename, linenum, arg, opcode);
1847 }
1848 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1849 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1850 filename, linenum, arg);
1851 return 0;
1852}
1853
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001854/* Reads the server configuration file. */
1855
Damien Miller4af51302000-04-16 11:18:38 +10001856void
Darren Tucker645ab752004-06-25 13:33:20 +10001857load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001858{
Damien Miller46cb75a2012-07-31 12:22:37 +10001859 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001860 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001861 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001862
Darren Tucker645ab752004-06-25 13:33:20 +10001863 debug2("%s: filename %s", __func__, filename);
1864 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001865 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001866 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001867 }
Darren Tucker645ab752004-06-25 13:33:20 +10001868 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001869 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001870 lineno++;
1871 if (strlen(line) == sizeof(line) - 1)
1872 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001873 /*
1874 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001875 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001876 * line numbers later for error messages
1877 */
1878 if ((cp = strchr(line, '#')) != NULL)
1879 memcpy(cp, "\n", 2);
1880 cp = line + strspn(line, " \t\r");
1881
1882 buffer_append(conf, cp, strlen(cp));
1883 }
1884 buffer_append(conf, "\0", 1);
1885 fclose(f);
1886 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1887}
1888
1889void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001890parse_server_match_config(ServerOptions *options,
1891 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001892{
Darren Tucker45150472006-07-12 22:34:17 +10001893 ServerOptions mo;
1894
1895 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001896 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001897 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001898}
1899
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001900int parse_server_match_testspec(struct connection_info *ci, char *spec)
1901{
1902 char *p;
1903
1904 while ((p = strsep(&spec, ",")) && *p != '\0') {
1905 if (strncmp(p, "addr=", 5) == 0) {
1906 ci->address = xstrdup(p + 5);
1907 } else if (strncmp(p, "host=", 5) == 0) {
1908 ci->host = xstrdup(p + 5);
1909 } else if (strncmp(p, "user=", 5) == 0) {
1910 ci->user = xstrdup(p + 5);
1911 } else if (strncmp(p, "laddr=", 6) == 0) {
1912 ci->laddress = xstrdup(p + 6);
1913 } else if (strncmp(p, "lport=", 6) == 0) {
1914 ci->lport = a2port(p + 6);
1915 if (ci->lport == -1) {
1916 fprintf(stderr, "Invalid port '%s' in test mode"
1917 " specification %s\n", p+6, p);
1918 return -1;
1919 }
1920 } else {
1921 fprintf(stderr, "Invalid test mode specification %s\n",
1922 p);
1923 return -1;
1924 }
1925 }
1926 return 0;
1927}
1928
1929/*
1930 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1931 * empty spec.
1932 */
1933int server_match_spec_complete(struct connection_info *ci)
1934{
1935 if (ci->user && ci->host && ci->address)
1936 return 1; /* complete */
1937 if (!ci->user && !ci->host && !ci->address)
1938 return -1; /* empty */
1939 return 0; /* partial */
1940}
1941
Darren Tucker1629c072007-02-19 22:25:37 +11001942/*
1943 * Copy any supported values that are set.
1944 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001945 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001946 * array values that are not used pre-authentication, because any that we
1947 * do use must be explictly sent in mm_getpwnamallow().
1948 */
Darren Tucker45150472006-07-12 22:34:17 +10001949void
Darren Tucker1629c072007-02-19 22:25:37 +11001950copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001951{
Damien Miller534b2cc2013-12-05 14:07:27 +11001952#define M_CP_INTOPT(n) do {\
1953 if (src->n != -1) \
1954 dst->n = src->n; \
1955} while (0)
1956
Darren Tucker1629c072007-02-19 22:25:37 +11001957 M_CP_INTOPT(password_authentication);
1958 M_CP_INTOPT(gss_authentication);
1959 M_CP_INTOPT(rsa_authentication);
1960 M_CP_INTOPT(pubkey_authentication);
1961 M_CP_INTOPT(kerberos_authentication);
1962 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001963 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001964 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001965 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001966 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001967
1968 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001969 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001970 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001971 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001972 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001973 M_CP_INTOPT(x11_display_offset);
1974 M_CP_INTOPT(x11_forwarding);
1975 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001976 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001977 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001978 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001979 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001980 M_CP_INTOPT(ip_qos_interactive);
1981 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001982 M_CP_INTOPT(rekey_limit);
1983 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001984
Damien Miller534b2cc2013-12-05 14:07:27 +11001985 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1986#define M_CP_STROPT(n) do {\
1987 if (src->n != NULL && dst->n != src->n) { \
1988 free(dst->n); \
1989 dst->n = src->n; \
1990 } \
1991} while(0)
1992#define M_CP_STRARRAYOPT(n, num_n) do {\
1993 if (src->num_n != 0) { \
1994 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1995 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1996 } \
1997} while(0)
1998
Damien Millerf2e407e2011-05-20 19:04:14 +10001999 /* See comment in servconf.h */
2000 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10002001
Damien Millerc2411902011-05-20 19:03:49 +10002002 /*
2003 * The only things that should be below this point are string options
2004 * which are only used after authentication.
2005 */
Damien Miller5d74e582011-05-20 19:03:31 +10002006 if (preauth)
2007 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002008
Damien Miller5d74e582011-05-20 19:03:31 +10002009 M_CP_STROPT(adm_forced_command);
2010 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10002011}
2012
Darren Tucker1629c072007-02-19 22:25:37 +11002013#undef M_CP_INTOPT
2014#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10002015#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11002016
Darren Tucker45150472006-07-12 22:34:17 +10002017void
2018parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002019 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10002020{
2021 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10002022 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10002023
2024 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2025
Darren Tucker9fbac712004-08-12 22:41:44 +10002026 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002027 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10002028 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11002029 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10002030 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10002031 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11002032 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002033 }
Darren Tuckera627d422013-06-02 07:31:17 +10002034 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00002035 if (bad_options > 0)
2036 fatal("%s: terminating, %d bad configuration options",
2037 filename, bad_options);
dtucker@openbsd.org531a57a2015-04-29 03:48:56 +00002038 process_queued_listen_addrs(options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002039}
Darren Tuckere7140f22008-06-10 23:01:51 +10002040
2041static const char *
Damien Miller82c55872011-06-23 08:20:30 +10002042fmt_multistate_int(int val, const struct multistate *m)
2043{
2044 u_int i;
2045
2046 for (i = 0; m[i].key != NULL; i++) {
2047 if (m[i].value == val)
2048 return m[i].key;
2049 }
2050 return "UNKNOWN";
2051}
2052
2053static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10002054fmt_intarg(ServerOpCodes code, int val)
2055{
Damien Miller82c55872011-06-23 08:20:30 +10002056 if (val == -1)
2057 return "unset";
2058 switch (code) {
2059 case sAddressFamily:
2060 return fmt_multistate_int(val, multistate_addressfamily);
2061 case sPermitRootLogin:
2062 return fmt_multistate_int(val, multistate_permitrootlogin);
2063 case sGatewayPorts:
2064 return fmt_multistate_int(val, multistate_gatewayports);
2065 case sCompression:
2066 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10002067 case sUsePrivilegeSeparation:
2068 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11002069 case sAllowTcpForwarding:
2070 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10002071 case sAllowStreamLocalForwarding:
2072 return fmt_multistate_int(val, multistate_tcpfwd);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002073 case sFingerprintHash:
2074 return ssh_digest_alg_name(val);
Damien Miller82c55872011-06-23 08:20:30 +10002075 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10002076 switch (val) {
2077 case SSH_PROTO_1:
2078 return "1";
2079 case SSH_PROTO_2:
2080 return "2";
2081 case (SSH_PROTO_1|SSH_PROTO_2):
2082 return "2,1";
2083 default:
2084 return "UNKNOWN";
2085 }
Damien Miller82c55872011-06-23 08:20:30 +10002086 default:
2087 switch (val) {
2088 case 0:
2089 return "no";
2090 case 1:
2091 return "yes";
2092 default:
2093 return "UNKNOWN";
2094 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002095 }
Darren Tuckere7140f22008-06-10 23:01:51 +10002096}
2097
2098static const char *
2099lookup_opcode_name(ServerOpCodes code)
2100{
2101 u_int i;
2102
2103 for (i = 0; keywords[i].name != NULL; i++)
2104 if (keywords[i].opcode == code)
2105 return(keywords[i].name);
2106 return "UNKNOWN";
2107}
2108
2109static void
2110dump_cfg_int(ServerOpCodes code, int val)
2111{
2112 printf("%s %d\n", lookup_opcode_name(code), val);
2113}
2114
2115static void
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002116dump_cfg_oct(ServerOpCodes code, int val)
2117{
2118 printf("%s 0%o\n", lookup_opcode_name(code), val);
2119}
2120
2121static void
Darren Tuckere7140f22008-06-10 23:01:51 +10002122dump_cfg_fmtint(ServerOpCodes code, int val)
2123{
2124 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2125}
2126
2127static void
2128dump_cfg_string(ServerOpCodes code, const char *val)
2129{
2130 if (val == NULL)
2131 return;
djm@openbsd.org161cf412014-12-22 07:55:51 +00002132 printf("%s %s\n", lookup_opcode_name(code),
2133 val == NULL ? "none" : val);
Darren Tuckere7140f22008-06-10 23:01:51 +10002134}
2135
2136static void
2137dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2138{
2139 u_int i;
2140
2141 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10002142 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2143}
2144
2145static void
2146dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2147{
2148 u_int i;
2149
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002150 if (count <= 0)
2151 return;
Damien Millerd8478b62011-05-29 21:39:36 +10002152 printf("%s", lookup_opcode_name(code));
2153 for (i = 0; i < count; i++)
2154 printf(" %s", vals[i]);
2155 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10002156}
2157
2158void
2159dump_config(ServerOptions *o)
2160{
2161 u_int i;
2162 int ret;
2163 struct addrinfo *ai;
2164 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002165 char *laddr1 = xstrdup(""), *laddr2 = NULL;
Darren Tuckere7140f22008-06-10 23:01:51 +10002166
2167 /* these are usually at the top of the config */
2168 for (i = 0; i < o->num_ports; i++)
2169 printf("port %d\n", o->ports[i]);
2170 dump_cfg_fmtint(sProtocol, o->protocol);
2171 dump_cfg_fmtint(sAddressFamily, o->address_family);
2172
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002173 /*
2174 * ListenAddress must be after Port. add_one_listen_addr pushes
2175 * addresses onto a stack, so to maintain ordering we need to
2176 * print these in reverse order.
2177 */
Darren Tuckere7140f22008-06-10 23:01:51 +10002178 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2179 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2180 sizeof(addr), port, sizeof(port),
2181 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2182 error("getnameinfo failed: %.100s",
2183 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2184 strerror(errno));
2185 } else {
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002186 laddr2 = laddr1;
Darren Tuckere7140f22008-06-10 23:01:51 +10002187 if (ai->ai_family == AF_INET6)
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002188 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2189 addr, port, laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002190 else
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002191 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2192 addr, port, laddr2);
2193 free(laddr2);
Darren Tuckere7140f22008-06-10 23:01:51 +10002194 }
2195 }
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002196 printf("%s", laddr1);
2197 free(laddr1);
Darren Tuckere7140f22008-06-10 23:01:51 +10002198
2199 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002200#ifdef USE_PAM
Darren Tucker70860b62015-04-17 10:56:13 +10002201 dump_cfg_fmtint(sUsePAM, o->use_pam);
Damien Miller212f0b02008-07-23 17:42:29 +10002202#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002203 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2204 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2205 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2206 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2207 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002208 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002209 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2210 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
dtucker@openbsd.org1108ae22015-04-23 04:59:10 +00002211 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
Darren Tuckere7140f22008-06-10 23:01:51 +10002212
2213 /* formatted integer arguments */
2214 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2215 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2216 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2217 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2218 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2219 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2220 o->hostbased_uses_name_from_packet_only);
2221 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2222 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002223#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002224 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2225 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2226 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002227# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002228 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002229# endif
2230#endif
2231#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002232 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2233 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002234#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002235 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2236 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2237 o->kbd_interactive_authentication);
2238 dump_cfg_fmtint(sChallengeResponseAuthentication,
2239 o->challenge_response_authentication);
2240 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2241 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2242 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2243 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002244 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002245 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002246 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2247 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2248 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2249 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2250 dump_cfg_fmtint(sUseLogin, o->use_login);
2251 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002252 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002253 dump_cfg_fmtint(sUseDNS, o->use_dns);
2254 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002255 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002256 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002257 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002258 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
Darren Tuckere7140f22008-06-10 23:01:51 +10002259
2260 /* string arguments */
2261 dump_cfg_string(sPidFile, o->pid_file);
2262 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002263 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2264 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002265 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002266 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002267 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002268 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2269 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002270 dump_cfg_string(sAuthorizedPrincipalsFile,
2271 o->authorized_principals_file);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002272 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2273 ? "none" : o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002274 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2275 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
djm@openbsd.orgbcc50d82015-05-21 06:43:30 +00002276 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2277 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002278 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002279 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002280 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00002281 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2282 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
2283 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2284 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
Darren Tuckere7140f22008-06-10 23:01:51 +10002285
2286 /* string arguments requiring a lookup */
2287 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2288 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2289
2290 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002291 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2292 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002293 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2294 o->host_key_files);
dtucker@openbsd.org40132ff2015-04-17 04:12:35 +00002295 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
Damien Miller0a80ca12010-02-27 07:55:05 +11002296 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002297 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2298 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2299 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2300 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2301 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002302 dump_cfg_strarray_oneline(sAuthenticationMethods,
2303 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002304
2305 /* other arguments */
2306 for (i = 0; i < o->num_subsystems; i++)
2307 printf("subsystem %s %s\n", o->subsystem_name[i],
2308 o->subsystem_args[i]);
2309
2310 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2311 o->max_startups_rate, o->max_startups);
2312
2313 for (i = 0; tunmode_desc[i].val != -1; i++)
2314 if (tunmode_desc[i].val == o->permit_tun) {
2315 s = tunmode_desc[i].text;
2316 break;
2317 }
2318 dump_cfg_string(sPermitTunnel, s);
2319
Damien Miller91475862011-05-05 14:14:34 +10002320 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2321 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002322
Damien Millera6d6c1f2013-08-21 02:40:01 +10002323 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2324 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002325
Darren Tuckere7140f22008-06-10 23:01:51 +10002326 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002327}