blob: b2a60fd6c6ea03a71ce4dc48c0379296c56e31ee [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Miller1f583df2013-02-12 11:02:08 +11002/* $OpenBSD: servconf.c,v 1.234 2013/02/06 00:20:42 dtucker 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
Damien Millerb8fe89c2006-07-24 14:51:00 +100023#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100024#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100025#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100026#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100027#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100028#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100029#include <unistd.h>
Damien Millerd7834352006-08-05 12:39:39 +100030#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100031#include <errno.h>
Damien Millerbe43ebf2006-07-24 13:51:51 +100032
Damien Millerb84886b2008-05-19 15:05:07 +100033#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100034#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100035#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100037#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100038#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100039#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "misc.h"
42#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100043#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000044#include "kex.h"
45#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100046#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100047#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100048#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100049#include "canohost.h"
50#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110051#include "hostfile.h"
52#include "auth.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000053
Damien Miller3dc71ad2009-01-28 16:31:22 +110054static void add_listen_addr(ServerOptions *, char *, int);
55static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110056
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000057/* Use of privilege separation or not */
58extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100059extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000060
Damien Millerd4a8b7e1999-10-27 13:42:43 +100061/* Initializes the server options to their default values. */
62
Damien Miller4af51302000-04-16 11:18:38 +100063void
Damien Miller95def091999-11-25 00:26:21 +110064initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065{
Damien Miller95def091999-11-25 00:26:21 +110066 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110067
68 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100069 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110070
71 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110072 options->num_ports = 0;
73 options->ports_from_cmdline = 0;
74 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110075 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110076 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110077 options->num_host_cert_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100078 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110079 options->server_key_bits = -1;
80 options->login_grace_time = -1;
81 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000082 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110083 options->ignore_rhosts = -1;
84 options->ignore_user_known_hosts = -1;
85 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000086 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110087 options->x11_forwarding = -1;
88 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110089 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100090 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110091 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110092 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110093 options->log_facility = SYSLOG_FACILITY_NOT_SET;
94 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110095 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000096 options->hostbased_authentication = -1;
97 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110098 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110099 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100100 options->kerberos_authentication = -1;
101 options->kerberos_or_local_passwd = -1;
102 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100103 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000104 options->gss_authentication=-1;
105 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100107 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000108 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100109 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000110 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000112 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100113 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000114 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100115 options->num_allow_users = 0;
116 options->num_deny_users = 0;
117 options->num_allow_groups = 0;
118 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000119 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000120 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000121 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000122 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000123 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000124 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000125 options->max_startups_begin = -1;
126 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000127 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000128 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000129 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000130 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000131 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000132 options->client_alive_interval = -1;
133 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000134 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000135 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100136 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000137 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000138 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100139 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100140 options->authorized_keys_command = NULL;
141 options->authorized_keys_command_user = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100142 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100143 options->revoked_keys_file = NULL;
144 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000145 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100146 options->ip_qos_interactive = -1;
147 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000148 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000149}
150
Damien Miller4af51302000-04-16 11:18:38 +1000151void
Damien Miller95def091999-11-25 00:26:21 +1100152fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000153{
Damien Miller726273e2001-11-12 11:40:11 +1100154 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000155 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000156 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100157
158 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100159 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100160 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100161 if (options->num_host_key_files == 0) {
162 /* fill default hostkeys for protocols */
163 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100164 options->host_key_files[options->num_host_key_files++] =
165 _PATH_HOST_KEY_FILE;
166 if (options->protocol & SSH_PROTO_2) {
167 options->host_key_files[options->num_host_key_files++] =
168 _PATH_HOST_RSA_KEY_FILE;
169 options->host_key_files[options->num_host_key_files++] =
170 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100171#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000172 options->host_key_files[options->num_host_key_files++] =
173 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100174#endif
Damien Miller7fc23732002-01-22 23:19:11 +1100175 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100176 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100177 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100178 if (options->num_ports == 0)
179 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
180 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000181 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000182 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000183 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100184 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000185 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100186 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000187 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100188 if (options->key_regeneration_time == -1)
189 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000190 if (options->permit_root_login == PERMIT_NOT_SET)
191 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100193 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->ignore_user_known_hosts == -1)
195 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100196 if (options->print_motd == -1)
197 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000198 if (options->print_lastlog == -1)
199 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100200 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100201 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100203 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100204 if (options->x11_use_localhost == -1)
205 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000206 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000207 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->strict_modes == -1)
209 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100210 if (options->tcp_keep_alive == -1)
211 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100212 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100213 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100214 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000215 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100216 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100217 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000218 if (options->hostbased_authentication == -1)
219 options->hostbased_authentication = 0;
220 if (options->hostbased_uses_name_from_packet_only == -1)
221 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->rsa_authentication == -1)
223 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100224 if (options->pubkey_authentication == -1)
225 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000227 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->kerberos_or_local_passwd == -1)
229 options->kerberos_or_local_passwd = 1;
230 if (options->kerberos_ticket_cleanup == -1)
231 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100232 if (options->kerberos_get_afs_token == -1)
233 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000234 if (options->gss_authentication == -1)
235 options->gss_authentication = 0;
236 if (options->gss_cleanup_creds == -1)
237 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100238 if (options->password_authentication == -1)
239 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100240 if (options->kbd_interactive_authentication == -1)
241 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000242 if (options->challenge_response_authentication == -1)
243 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100244 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100245 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000246 if (options->permit_user_env == -1)
247 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100248 if (options->use_login == -1)
249 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000250 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000251 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100252 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100253 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000254 if (options->allow_agent_forwarding == -1)
255 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000256 if (options->gateway_ports == -1)
257 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000258 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100259 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000260 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100261 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000262 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100263 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000264 if (options->max_authtries == -1)
265 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000266 if (options->max_sessions == -1)
267 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000268 if (options->use_dns == -1)
269 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000270 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100271 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000272 if (options->client_alive_count_max == -1)
273 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000274 if (options->num_authkeys_files == 0) {
275 options->authorized_keys_files[options->num_authkeys_files++] =
276 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
277 options->authorized_keys_files[options->num_authkeys_files++] =
278 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
279 }
Damien Millerd27b9472005-12-13 19:29:02 +1100280 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100281 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100282 if (options->zero_knowledge_password_authentication == -1)
283 options->zero_knowledge_password_authentication = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100284 if (options->ip_qos_interactive == -1)
285 options->ip_qos_interactive = IPTOS_LOWDELAY;
286 if (options->ip_qos_bulk == -1)
287 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000288 if (options->version_addendum == NULL)
289 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000290 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000291 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000292 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000293
Tim Rice40017b02002-07-14 13:36:49 -0700294#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000295 if (use_privsep && options->compression == 1) {
296 error("This platform does not support both privilege "
297 "separation and compression");
298 error("Compression disabled");
299 options->compression = 0;
300 }
301#endif
302
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000303}
304
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000305/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100306typedef enum {
307 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100308 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000309 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100310 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100311 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
312 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000313 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100314 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100315 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000316 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100317 sPasswordAuthentication, sKbdInteractiveAuthentication,
318 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000319 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100320 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100321 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000322 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100323 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000324 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000325 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000326 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000327 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100328 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000329 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100330 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100331 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100332 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100333 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000334 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000335 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100336 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Millera6e3f012012-11-04 23:21:40 +1100337 sAuthenticationMethods,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000338 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000339} ServerOpCodes;
340
Darren Tucker45150472006-07-12 22:34:17 +1000341#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
342#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
343#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
344
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000345/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100346static struct {
347 const char *name;
348 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000349 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100350} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100351 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000352#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000353 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000354#else
Darren Tucker45150472006-07-12 22:34:17 +1000355 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000356#endif
Darren Tucker45150472006-07-12 22:34:17 +1000357 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100358 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000359 { "port", sPort, SSHCFG_GLOBAL },
360 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
361 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
362 { "pidfile", sPidFile, SSHCFG_GLOBAL },
363 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
364 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
365 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100366 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000367 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
368 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
369 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100370 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
371 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000372 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100373 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
374 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000375 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000376#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100377 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000378 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
379 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100380#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000381 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000382#else
Darren Tucker45150472006-07-12 22:34:17 +1000383 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100384#endif
385#else
Darren Tucker1629c072007-02-19 22:25:37 +1100386 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000387 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
388 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
389 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000390#endif
Darren Tucker45150472006-07-12 22:34:17 +1000391 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
392 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000393#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100394 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000396#else
Darren Tucker1629c072007-02-19 22:25:37 +1100397 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000398 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000399#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100400 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
401 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100402 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000403 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100404#ifdef JPAKE
405 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
406#else
407 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
408#endif
Darren Tucker45150472006-07-12 22:34:17 +1000409 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
410 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
411 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
412 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
413 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
414 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
415 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000416 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
417 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
418 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000419 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
420 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100421 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000422 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
423 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
424 { "compression", sCompression, SSHCFG_GLOBAL },
425 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
426 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
427 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000428 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000429 { "allowusers", sAllowUsers, SSHCFG_ALL },
430 { "denyusers", sDenyUsers, SSHCFG_ALL },
431 { "allowgroups", sAllowGroups, SSHCFG_ALL },
432 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000433 { "ciphers", sCiphers, SSHCFG_GLOBAL },
434 { "macs", sMacs, SSHCFG_GLOBAL },
435 { "protocol", sProtocol, SSHCFG_GLOBAL },
436 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
437 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
438 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000439 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000440 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100441 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "usedns", sUseDNS, SSHCFG_GLOBAL },
443 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
444 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
445 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
446 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000447 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000448 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000449 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000450 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000451 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000452 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000453 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000454 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100455 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100456 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100457 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
458 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000459 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000460 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100461 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100462 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
463 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000464 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100465 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000466 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000467};
468
Darren Tuckere7140f22008-06-10 23:01:51 +1000469static struct {
470 int val;
471 char *text;
472} tunmode_desc[] = {
473 { SSH_TUNMODE_NO, "no" },
474 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
475 { SSH_TUNMODE_ETHERNET, "ethernet" },
476 { SSH_TUNMODE_YES, "yes" },
477 { -1, NULL }
478};
479
Damien Miller5428f641999-11-25 11:54:57 +1100480/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000481 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100482 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000483
Damien Miller4af51302000-04-16 11:18:38 +1000484static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100485parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000486 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000487{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000488 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000489
Damien Miller95def091999-11-25 00:26:21 +1100490 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000491 if (strcasecmp(cp, keywords[i].name) == 0) {
492 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100493 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000494 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000495
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000496 error("%s: line %d: Bad configuration option: %s",
497 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100498 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000499}
500
Darren Tucker88b6fb22010-01-13 22:44:29 +1100501char *
502derelativise_path(const char *path)
503{
Damien Miller44451d02010-03-26 10:40:04 +1100504 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100505
506 expanded = tilde_expand_filename(path, getuid());
507 if (*expanded == '/')
508 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100509 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100510 fatal("%s: getcwd: %s", __func__, strerror(errno));
511 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100512 xfree(expanded);
513 return ret;
514}
515
Ben Lindstrombba81212001-06-25 05:01:22 +0000516static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100517add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100518{
Damien Millereccb9de2005-06-17 12:59:34 +1000519 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100520
521 if (options->num_ports == 0)
522 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100523 if (options->address_family == -1)
524 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000525 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000526 for (i = 0; i < options->num_ports; i++)
527 add_one_listen_addr(options, addr, options->ports[i]);
528 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000529 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000530}
531
Ben Lindstrombba81212001-06-25 05:01:22 +0000532static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100533add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000534{
535 struct addrinfo hints, *ai, *aitop;
536 char strport[NI_MAXSERV];
537 int gaierr;
538
539 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100540 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000541 hints.ai_socktype = SOCK_STREAM;
542 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100543 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000544 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
545 fatal("bad addr or host: %s (%s)",
546 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100547 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000548 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
549 ;
550 ai->ai_next = options->listen_addrs;
551 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100552}
553
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000554struct connection_info *
555get_connection_info(int populate, int use_dns)
556{
557 static struct connection_info ci;
558
559 if (!populate)
560 return &ci;
561 ci.host = get_canonical_hostname(use_dns);
562 ci.address = get_remote_ipaddr();
563 ci.laddress = get_local_ipaddr(packet_get_connection_in());
564 ci.lport = get_local_port();
565 return &ci;
566}
567
Darren Tucker45150472006-07-12 22:34:17 +1000568/*
569 * The strategy for the Match blocks is that the config file is parsed twice.
570 *
571 * The first time is at startup. activep is initialized to 1 and the
572 * directives in the global context are processed and acted on. Hitting a
573 * Match directive unsets activep and the directives inside the block are
574 * checked for syntax only.
575 *
576 * The second time is after a connection has been established but before
577 * authentication. activep is initialized to 2 and global config directives
578 * are ignored since they have already been processed. If the criteria in a
579 * Match block is met, activep is set and the subsequent directives
580 * processed and actioned until EOF or another Match block unsets it. Any
581 * options set are copied into the main server config.
582 *
583 * Potential additions/improvements:
584 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
585 *
586 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
587 * Match Address 192.168.0.*
588 * Tag trusted
589 * Match Group wheel
590 * Tag trusted
591 * Match Tag trusted
592 * AllowTcpForwarding yes
593 * GatewayPorts clientspecified
594 * [...]
595 *
596 * - Add a PermittedChannelRequests directive
597 * Match Group shell
598 * PermittedChannelRequests session,forwarded-tcpip
599 */
600
601static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000602match_cfg_line_group(const char *grps, int line, const char *user)
603{
604 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000605 struct passwd *pw;
606
Damien Miller565ca3f2006-08-19 00:23:15 +1000607 if (user == NULL)
608 goto out;
609
610 if ((pw = getpwnam(user)) == NULL) {
611 debug("Can't match group at line %d because user %.100s does "
612 "not exist", line, user);
613 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
614 debug("Can't Match group because user %.100s not in any group "
615 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000616 } else if (ga_match_pattern_list(grps) != 1) {
617 debug("user %.100s does not match group list %.100s at line %d",
618 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000619 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000620 debug("user %.100s matched group list %.100s at line %d", user,
621 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000622 result = 1;
623 }
624out:
625 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000626 return result;
627}
628
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000629/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000630 * All of the attributes on a single Match line are ANDed together, so we need
631 * to check every * attribute and set the result to zero if any attribute does
632 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000633 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000634static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000635match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000636{
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000637 int result = 1, port;
Darren Tucker45150472006-07-12 22:34:17 +1000638 char *arg, *attrib, *cp = *condition;
639 size_t len;
640
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000641 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000642 debug3("checking syntax for 'Match %s'", cp);
643 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000644 debug3("checking match for '%s' user %s host %s addr %s "
645 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
646 ci->host ? ci->host : "(null)",
647 ci->address ? ci->address : "(null)",
648 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000649
650 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
651 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
652 error("Missing Match criteria for %s", attrib);
653 return -1;
654 }
655 len = strlen(arg);
656 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000657 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000658 result = 0;
659 continue;
660 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000661 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000662 result = 0;
663 else
664 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000665 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000666 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000667 if (ci == NULL || ci->user == NULL) {
668 result = 0;
669 continue;
670 }
671 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000672 case -1:
673 return -1;
674 case 0:
675 result = 0;
676 }
Darren Tucker45150472006-07-12 22:34:17 +1000677 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000678 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000679 result = 0;
680 continue;
681 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000682 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000683 result = 0;
684 else
685 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000686 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000687 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000688 if (ci == NULL || ci->address == NULL) {
689 result = 0;
690 continue;
691 }
692 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000693 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000694 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000696 break;
697 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000698 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000699 result = 0;
700 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000701 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000702 return -1;
703 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000704 } else if (strcasecmp(attrib, "localaddress") == 0){
705 if (ci == NULL || ci->laddress == NULL) {
706 result = 0;
707 continue;
708 }
709 switch (addr_match_list(ci->laddress, arg)) {
710 case 1:
711 debug("connection from %.100s matched "
712 "'LocalAddress %.100s' at line %d",
713 ci->laddress, arg, line);
714 break;
715 case 0:
716 case -1:
717 result = 0;
718 break;
719 case -2:
720 return -1;
721 }
722 } else if (strcasecmp(attrib, "localport") == 0) {
723 if ((port = a2port(arg)) == -1) {
724 error("Invalid LocalPort '%s' on Match line",
725 arg);
726 return -1;
727 }
728 if (ci == NULL || ci->lport == 0) {
729 result = 0;
730 continue;
731 }
732 /* TODO support port lists */
733 if (port == ci->lport)
734 debug("connection from %.100s matched "
735 "'LocalPort %d' at line %d",
736 ci->laddress, port, line);
737 else
738 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000739 } else {
740 error("Unsupported Match attribute %s", attrib);
741 return -1;
742 }
743 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000744 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000745 debug3("match %sfound", result ? "" : "not ");
746 *condition = cp;
747 return result;
748}
749
Damien Millere2754432006-07-24 14:06:47 +1000750#define WHITESPACE " \t\r\n"
751
Damien Miller33322122011-06-20 14:43:11 +1000752/* Multistate option parsing */
753struct multistate {
754 char *key;
755 int value;
756};
757static const struct multistate multistate_addressfamily[] = {
758 { "inet", AF_INET },
759 { "inet6", AF_INET6 },
760 { "any", AF_UNSPEC },
761 { NULL, -1 }
762};
763static const struct multistate multistate_permitrootlogin[] = {
764 { "without-password", PERMIT_NO_PASSWD },
765 { "forced-commands-only", PERMIT_FORCED_ONLY },
766 { "yes", PERMIT_YES },
767 { "no", PERMIT_NO },
768 { NULL, -1 }
769};
770static const struct multistate multistate_compression[] = {
771 { "delayed", COMP_DELAYED },
772 { "yes", COMP_ZLIB },
773 { "no", COMP_NONE },
774 { NULL, -1 }
775};
776static const struct multistate multistate_gatewayports[] = {
777 { "clientspecified", 2 },
778 { "yes", 1 },
779 { "no", 0 },
780 { NULL, -1 }
781};
Damien Miller69ff1df2011-06-23 08:30:03 +1000782static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000783 { "yes", PRIVSEP_NOSANDBOX },
784 { "sandbox", PRIVSEP_ON },
785 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000786 { "no", PRIVSEP_OFF },
787 { NULL, -1 }
788};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100789static const struct multistate multistate_tcpfwd[] = {
790 { "yes", FORWARD_ALLOW },
791 { "all", FORWARD_ALLOW },
792 { "no", FORWARD_DENY },
793 { "remote", FORWARD_REMOTE },
794 { "local", FORWARD_LOCAL },
795 { NULL, -1 }
796};
Damien Miller33322122011-06-20 14:43:11 +1000797
Ben Lindstromade03f62001-12-06 18:22:17 +0000798int
799process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000800 const char *filename, int linenum, int *activep,
801 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000802{
803 char *cp, **charptr, *arg, *p;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100804 int cmdline = 0, *intptr, value, value2, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100805 SyslogFacility *log_facility_ptr;
806 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000807 ServerOpCodes opcode;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100808 int port;
Darren Tucker45150472006-07-12 22:34:17 +1000809 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000810 size_t len;
Damien Miller33322122011-06-20 14:43:11 +1000811 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000812
813 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100814 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100815 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000816 /* Ignore leading whitespace */
817 if (*arg == '\0')
818 arg = strdelim(&cp);
819 if (!arg || !*arg || *arg == '#')
820 return 0;
821 intptr = NULL;
822 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000823 opcode = parse_token(arg, filename, linenum, &flags);
824
825 if (activep == NULL) { /* We are processing a command line directive */
826 cmdline = 1;
827 activep = &cmdline;
828 }
829 if (*activep && opcode != sMatch)
830 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
831 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000832 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000833 fatal("%s line %d: Directive '%s' is not allowed "
834 "within a Match block", filename, linenum, arg);
835 } else { /* this is a directive we have already processed */
836 while (arg)
837 arg = strdelim(&cp);
838 return 0;
839 }
840 }
841
Ben Lindstromade03f62001-12-06 18:22:17 +0000842 switch (opcode) {
843 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000844 case sUsePAM:
845 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000846 goto parse_flag;
847
848 /* Standard Options */
849 case sBadOption:
850 return -1;
851 case sPort:
852 /* ignore ports from configfile if cmdline specifies ports */
853 if (options->ports_from_cmdline)
854 return 0;
855 if (options->listen_addrs != NULL)
856 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100857 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000858 if (options->num_ports >= MAX_PORTS)
859 fatal("%s line %d: too many ports.",
860 filename, linenum);
861 arg = strdelim(&cp);
862 if (!arg || *arg == '\0')
863 fatal("%s line %d: missing port number.",
864 filename, linenum);
865 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100866 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000867 fatal("%s line %d: Badly formatted port number.",
868 filename, linenum);
869 break;
870
871 case sServerKeyBits:
872 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000873 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000874 arg = strdelim(&cp);
875 if (!arg || *arg == '\0')
876 fatal("%s line %d: missing integer value.",
877 filename, linenum);
878 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000879 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000880 *intptr = value;
881 break;
882
883 case sLoginGraceTime:
884 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000885 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000886 arg = strdelim(&cp);
887 if (!arg || *arg == '\0')
888 fatal("%s line %d: missing time value.",
889 filename, linenum);
890 if ((value = convtime(arg)) == -1)
891 fatal("%s line %d: invalid time value.",
892 filename, linenum);
893 if (*intptr == -1)
894 *intptr = value;
895 break;
896
897 case sKeyRegenerationTime:
898 intptr = &options->key_regeneration_time;
899 goto parse_time;
900
901 case sListenAddress:
902 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100903 if (arg == NULL || *arg == '\0')
904 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000905 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000906 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
907 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
908 && strchr(p+1, ':') != NULL) {
909 add_listen_addr(options, arg, 0);
910 break;
911 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100912 p = hpdelim(&arg);
913 if (p == NULL)
914 fatal("%s line %d: bad address:port usage",
915 filename, linenum);
916 p = cleanhostname(p);
917 if (arg == NULL)
918 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100919 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100920 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000921
Damien Millerf91ee4c2005-03-01 21:24:33 +1100922 add_listen_addr(options, p, port);
923
Ben Lindstromade03f62001-12-06 18:22:17 +0000924 break;
925
Darren Tucker0f383232005-01-20 10:57:56 +1100926 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000927 intptr = &options->address_family;
928 multistate_ptr = multistate_addressfamily;
929 if (options->listen_addrs != NULL)
930 fatal("%s line %d: address family must be specified "
931 "before ListenAddress.", filename, linenum);
932 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100933 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000934 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000935 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000936 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000937 value = -1;
938 for (i = 0; multistate_ptr[i].key != NULL; i++) {
939 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
940 value = multistate_ptr[i].value;
941 break;
942 }
943 }
944 if (value == -1)
945 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100946 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000947 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100948 *intptr = value;
949 break;
950
Ben Lindstromade03f62001-12-06 18:22:17 +0000951 case sHostKeyFile:
952 intptr = &options->num_host_key_files;
953 if (*intptr >= MAX_HOSTKEYS)
954 fatal("%s line %d: too many host keys specified (max %d).",
955 filename, linenum, MAX_HOSTKEYS);
956 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000957 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000958 arg = strdelim(&cp);
959 if (!arg || *arg == '\0')
960 fatal("%s line %d: missing file name.",
961 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000962 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100963 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000964 /* increase optional counter */
965 if (intptr != NULL)
966 *intptr = *intptr + 1;
967 }
968 break;
969
Damien Miller0a80ca12010-02-27 07:55:05 +1100970 case sHostCertificate:
971 intptr = &options->num_host_cert_files;
972 if (*intptr >= MAX_HOSTKEYS)
973 fatal("%s line %d: too many host certificates "
974 "specified (max %d).", filename, linenum,
975 MAX_HOSTCERTS);
976 charptr = &options->host_cert_files[*intptr];
977 goto parse_filename;
978 break;
979
Ben Lindstromade03f62001-12-06 18:22:17 +0000980 case sPidFile:
981 charptr = &options->pid_file;
982 goto parse_filename;
983
984 case sPermitRootLogin:
985 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +1000986 multistate_ptr = multistate_permitrootlogin;
987 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +0000988
989 case sIgnoreRhosts:
990 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000991 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000992 arg = strdelim(&cp);
993 if (!arg || *arg == '\0')
994 fatal("%s line %d: missing yes/no argument.",
995 filename, linenum);
996 value = 0; /* silence compiler */
997 if (strcmp(arg, "yes") == 0)
998 value = 1;
999 else if (strcmp(arg, "no") == 0)
1000 value = 0;
1001 else
1002 fatal("%s line %d: Bad yes/no argument: %s",
1003 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001004 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001005 *intptr = value;
1006 break;
1007
1008 case sIgnoreUserKnownHosts:
1009 intptr = &options->ignore_user_known_hosts;
1010 goto parse_flag;
1011
Ben Lindstromade03f62001-12-06 18:22:17 +00001012 case sRhostsRSAAuthentication:
1013 intptr = &options->rhosts_rsa_authentication;
1014 goto parse_flag;
1015
1016 case sHostbasedAuthentication:
1017 intptr = &options->hostbased_authentication;
1018 goto parse_flag;
1019
1020 case sHostbasedUsesNameFromPacketOnly:
1021 intptr = &options->hostbased_uses_name_from_packet_only;
1022 goto parse_flag;
1023
1024 case sRSAAuthentication:
1025 intptr = &options->rsa_authentication;
1026 goto parse_flag;
1027
1028 case sPubkeyAuthentication:
1029 intptr = &options->pubkey_authentication;
1030 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001031
Ben Lindstromade03f62001-12-06 18:22:17 +00001032 case sKerberosAuthentication:
1033 intptr = &options->kerberos_authentication;
1034 goto parse_flag;
1035
1036 case sKerberosOrLocalPasswd:
1037 intptr = &options->kerberos_or_local_passwd;
1038 goto parse_flag;
1039
1040 case sKerberosTicketCleanup:
1041 intptr = &options->kerberos_ticket_cleanup;
1042 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001043
Darren Tucker22ef5082003-12-31 11:37:34 +11001044 case sKerberosGetAFSToken:
1045 intptr = &options->kerberos_get_afs_token;
1046 goto parse_flag;
1047
Darren Tucker0efd1552003-08-26 11:49:55 +10001048 case sGssAuthentication:
1049 intptr = &options->gss_authentication;
1050 goto parse_flag;
1051
1052 case sGssCleanupCreds:
1053 intptr = &options->gss_cleanup_creds;
1054 goto parse_flag;
1055
Ben Lindstromade03f62001-12-06 18:22:17 +00001056 case sPasswordAuthentication:
1057 intptr = &options->password_authentication;
1058 goto parse_flag;
1059
Damien Miller01ed2272008-11-05 16:20:46 +11001060 case sZeroKnowledgePasswordAuthentication:
1061 intptr = &options->zero_knowledge_password_authentication;
1062 goto parse_flag;
1063
Ben Lindstromade03f62001-12-06 18:22:17 +00001064 case sKbdInteractiveAuthentication:
1065 intptr = &options->kbd_interactive_authentication;
1066 goto parse_flag;
1067
1068 case sChallengeResponseAuthentication:
1069 intptr = &options->challenge_response_authentication;
1070 goto parse_flag;
1071
1072 case sPrintMotd:
1073 intptr = &options->print_motd;
1074 goto parse_flag;
1075
1076 case sPrintLastLog:
1077 intptr = &options->print_lastlog;
1078 goto parse_flag;
1079
1080 case sX11Forwarding:
1081 intptr = &options->x11_forwarding;
1082 goto parse_flag;
1083
1084 case sX11DisplayOffset:
1085 intptr = &options->x11_display_offset;
1086 goto parse_int;
1087
Damien Miller95c249f2002-02-05 12:11:34 +11001088 case sX11UseLocalhost:
1089 intptr = &options->x11_use_localhost;
1090 goto parse_flag;
1091
Ben Lindstromade03f62001-12-06 18:22:17 +00001092 case sXAuthLocation:
1093 charptr = &options->xauth_location;
1094 goto parse_filename;
1095
1096 case sStrictModes:
1097 intptr = &options->strict_modes;
1098 goto parse_flag;
1099
Damien Miller12c150e2003-12-17 16:31:10 +11001100 case sTCPKeepAlive:
1101 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001102 goto parse_flag;
1103
1104 case sEmptyPasswd:
1105 intptr = &options->permit_empty_passwd;
1106 goto parse_flag;
1107
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001108 case sPermitUserEnvironment:
1109 intptr = &options->permit_user_env;
1110 goto parse_flag;
1111
Ben Lindstromade03f62001-12-06 18:22:17 +00001112 case sUseLogin:
1113 intptr = &options->use_login;
1114 goto parse_flag;
1115
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001116 case sCompression:
1117 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001118 multistate_ptr = multistate_compression;
1119 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001120
Ben Lindstromade03f62001-12-06 18:22:17 +00001121 case sGatewayPorts:
1122 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001123 multistate_ptr = multistate_gatewayports;
1124 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001125
Damien Miller3a961dc2003-06-03 10:25:48 +10001126 case sUseDNS:
1127 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001128 goto parse_flag;
1129
1130 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001131 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001132 arg = strdelim(&cp);
1133 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001134 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001135 fatal("%.200s line %d: unsupported log facility '%s'",
1136 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001137 if (*log_facility_ptr == -1)
1138 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001139 break;
1140
1141 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001142 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001143 arg = strdelim(&cp);
1144 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001145 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001146 fatal("%.200s line %d: unsupported log level '%s'",
1147 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001148 if (*log_level_ptr == -1)
1149 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001150 break;
1151
1152 case sAllowTcpForwarding:
1153 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001154 multistate_ptr = multistate_tcpfwd;
1155 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001156
Damien Miller4f755cd2008-05-19 14:57:41 +10001157 case sAllowAgentForwarding:
1158 intptr = &options->allow_agent_forwarding;
1159 goto parse_flag;
1160
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001161 case sUsePrivilegeSeparation:
1162 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001163 multistate_ptr = multistate_privsep;
1164 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001165
Ben Lindstromade03f62001-12-06 18:22:17 +00001166 case sAllowUsers:
1167 while ((arg = strdelim(&cp)) && *arg != '\0') {
1168 if (options->num_allow_users >= MAX_ALLOW_USERS)
1169 fatal("%s line %d: too many allow users.",
1170 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001171 if (!*activep)
1172 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001173 options->allow_users[options->num_allow_users++] =
1174 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001175 }
1176 break;
1177
1178 case sDenyUsers:
1179 while ((arg = strdelim(&cp)) && *arg != '\0') {
1180 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001181 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001182 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001183 if (!*activep)
1184 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001185 options->deny_users[options->num_deny_users++] =
1186 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001187 }
1188 break;
1189
1190 case sAllowGroups:
1191 while ((arg = strdelim(&cp)) && *arg != '\0') {
1192 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1193 fatal("%s line %d: too many allow groups.",
1194 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001195 if (!*activep)
1196 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001197 options->allow_groups[options->num_allow_groups++] =
1198 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001199 }
1200 break;
1201
1202 case sDenyGroups:
1203 while ((arg = strdelim(&cp)) && *arg != '\0') {
1204 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1205 fatal("%s line %d: too many deny groups.",
1206 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001207 if (!*activep)
1208 continue;
1209 options->deny_groups[options->num_deny_groups++] =
1210 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001211 }
1212 break;
1213
1214 case sCiphers:
1215 arg = strdelim(&cp);
1216 if (!arg || *arg == '\0')
1217 fatal("%s line %d: Missing argument.", filename, linenum);
1218 if (!ciphers_valid(arg))
1219 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1220 filename, linenum, arg ? arg : "<NONE>");
1221 if (options->ciphers == NULL)
1222 options->ciphers = xstrdup(arg);
1223 break;
1224
1225 case sMacs:
1226 arg = strdelim(&cp);
1227 if (!arg || *arg == '\0')
1228 fatal("%s line %d: Missing argument.", filename, linenum);
1229 if (!mac_valid(arg))
1230 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1231 filename, linenum, arg ? arg : "<NONE>");
1232 if (options->macs == NULL)
1233 options->macs = xstrdup(arg);
1234 break;
1235
Damien Millerd5f62bf2010-09-24 22:11:14 +10001236 case sKexAlgorithms:
1237 arg = strdelim(&cp);
1238 if (!arg || *arg == '\0')
1239 fatal("%s line %d: Missing argument.",
1240 filename, linenum);
1241 if (!kex_names_valid(arg))
1242 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1243 filename, linenum, arg ? arg : "<NONE>");
1244 if (options->kex_algorithms == NULL)
1245 options->kex_algorithms = xstrdup(arg);
1246 break;
1247
Ben Lindstromade03f62001-12-06 18:22:17 +00001248 case sProtocol:
1249 intptr = &options->protocol;
1250 arg = strdelim(&cp);
1251 if (!arg || *arg == '\0')
1252 fatal("%s line %d: Missing argument.", filename, linenum);
1253 value = proto_spec(arg);
1254 if (value == SSH_PROTO_UNKNOWN)
1255 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001256 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001257 if (*intptr == SSH_PROTO_UNKNOWN)
1258 *intptr = value;
1259 break;
1260
1261 case sSubsystem:
1262 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1263 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001264 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001265 }
1266 arg = strdelim(&cp);
1267 if (!arg || *arg == '\0')
1268 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001269 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001270 if (!*activep) {
1271 arg = strdelim(&cp);
1272 break;
1273 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001274 for (i = 0; i < options->num_subsystems; i++)
1275 if (strcmp(arg, options->subsystem_name[i]) == 0)
1276 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001277 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001278 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1279 arg = strdelim(&cp);
1280 if (!arg || *arg == '\0')
1281 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001282 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001283 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001284
1285 /* Collect arguments (separate to executable) */
1286 p = xstrdup(arg);
1287 len = strlen(p) + 1;
1288 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1289 len += 1 + strlen(arg);
1290 p = xrealloc(p, 1, len);
1291 strlcat(p, " ", len);
1292 strlcat(p, arg, len);
1293 }
1294 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001295 options->num_subsystems++;
1296 break;
1297
1298 case sMaxStartups:
1299 arg = strdelim(&cp);
1300 if (!arg || *arg == '\0')
1301 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001302 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001303 if ((n = sscanf(arg, "%d:%d:%d",
1304 &options->max_startups_begin,
1305 &options->max_startups_rate,
1306 &options->max_startups)) == 3) {
1307 if (options->max_startups_begin >
1308 options->max_startups ||
1309 options->max_startups_rate > 100 ||
1310 options->max_startups_rate < 1)
1311 fatal("%s line %d: Illegal MaxStartups spec.",
1312 filename, linenum);
1313 } else if (n != 1)
1314 fatal("%s line %d: Illegal MaxStartups spec.",
1315 filename, linenum);
1316 else
1317 options->max_startups = options->max_startups_begin;
1318 break;
1319
Darren Tucker89413db2004-05-24 10:36:23 +10001320 case sMaxAuthTries:
1321 intptr = &options->max_authtries;
1322 goto parse_int;
1323
Damien Miller7207f642008-05-19 15:34:50 +10001324 case sMaxSessions:
1325 intptr = &options->max_sessions;
1326 goto parse_int;
1327
Ben Lindstromade03f62001-12-06 18:22:17 +00001328 case sBanner:
1329 charptr = &options->banner;
1330 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001331
Ben Lindstromade03f62001-12-06 18:22:17 +00001332 /*
1333 * These options can contain %X options expanded at
1334 * connect time, so that you can specify paths like:
1335 *
1336 * AuthorizedKeysFile /etc/ssh_keys/%u
1337 */
1338 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001339 if (*activep && options->num_authkeys_files == 0) {
1340 while ((arg = strdelim(&cp)) && *arg != '\0') {
1341 if (options->num_authkeys_files >=
1342 MAX_AUTHKEYS_FILES)
1343 fatal("%s line %d: "
1344 "too many authorized keys files.",
1345 filename, linenum);
1346 options->authorized_keys_files[
1347 options->num_authkeys_files++] =
1348 tilde_expand_filename(arg, getuid());
1349 }
1350 }
1351 return 0;
1352
Damien Miller30da3442010-05-10 11:58:03 +10001353 case sAuthorizedPrincipalsFile:
1354 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001355 arg = strdelim(&cp);
1356 if (!arg || *arg == '\0')
1357 fatal("%s line %d: missing file name.",
1358 filename, linenum);
1359 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001360 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001361 /* increase optional counter */
1362 if (intptr != NULL)
1363 *intptr = *intptr + 1;
1364 }
1365 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001366
1367 case sClientAliveInterval:
1368 intptr = &options->client_alive_interval;
1369 goto parse_time;
1370
1371 case sClientAliveCountMax:
1372 intptr = &options->client_alive_count_max;
1373 goto parse_int;
1374
Darren Tucker46bc0752004-05-02 22:11:30 +10001375 case sAcceptEnv:
1376 while ((arg = strdelim(&cp)) && *arg != '\0') {
1377 if (strchr(arg, '=') != NULL)
1378 fatal("%s line %d: Invalid environment name.",
1379 filename, linenum);
1380 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1381 fatal("%s line %d: too many allow env.",
1382 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001383 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001384 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001385 options->accept_env[options->num_accept_env++] =
1386 xstrdup(arg);
1387 }
1388 break;
1389
Damien Millerd27b9472005-12-13 19:29:02 +11001390 case sPermitTunnel:
1391 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001392 arg = strdelim(&cp);
1393 if (!arg || *arg == '\0')
1394 fatal("%s line %d: Missing yes/point-to-point/"
1395 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001396 value = -1;
1397 for (i = 0; tunmode_desc[i].val != -1; i++)
1398 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1399 value = tunmode_desc[i].val;
1400 break;
1401 }
1402 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001403 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1404 "no argument: %s", filename, linenum, arg);
1405 if (*intptr == -1)
1406 *intptr = value;
1407 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001408
Darren Tucker45150472006-07-12 22:34:17 +10001409 case sMatch:
1410 if (cmdline)
1411 fatal("Match directive not supported as a command-line "
1412 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001413 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001414 if (value < 0)
1415 fatal("%s line %d: Bad Match condition", filename,
1416 linenum);
1417 *activep = value;
1418 break;
1419
Damien Miller9b439df2006-07-24 14:04:00 +10001420 case sPermitOpen:
1421 arg = strdelim(&cp);
1422 if (!arg || *arg == '\0')
1423 fatal("%s line %d: missing PermitOpen specification",
1424 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001425 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001426 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001427 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001428 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001429 options->num_permitted_opens = 0;
1430 }
Damien Miller9b439df2006-07-24 14:04:00 +10001431 break;
1432 }
Damien Millerc6081482012-04-22 11:18:53 +10001433 if (strcmp(arg, "none") == 0) {
1434 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001435 options->num_permitted_opens = 1;
1436 channel_disable_adm_local_opens();
1437 }
1438 break;
1439 }
Damien Millera29b95e2007-01-05 16:28:36 +11001440 if (*activep && n == -1)
1441 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001442 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1443 p = hpdelim(&arg);
1444 if (p == NULL)
1445 fatal("%s line %d: missing host in PermitOpen",
1446 filename, linenum);
1447 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001448 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001449 fatal("%s line %d: bad port number in "
1450 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001451 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001452 options->num_permitted_opens =
1453 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001454 }
Damien Miller9b439df2006-07-24 14:04:00 +10001455 break;
1456
Damien Millere2754432006-07-24 14:06:47 +10001457 case sForceCommand:
1458 if (cp == NULL)
1459 fatal("%.200s line %d: Missing argument.", filename,
1460 linenum);
1461 len = strspn(cp, WHITESPACE);
1462 if (*activep && options->adm_forced_command == NULL)
1463 options->adm_forced_command = xstrdup(cp + len);
1464 return 0;
1465
Damien Millerd8cb1f12008-02-10 22:40:12 +11001466 case sChrootDirectory:
1467 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001468
1469 arg = strdelim(&cp);
1470 if (!arg || *arg == '\0')
1471 fatal("%s line %d: missing file name.",
1472 filename, linenum);
1473 if (*activep && *charptr == NULL)
1474 *charptr = xstrdup(arg);
1475 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001476
Damien Miller1aed65e2010-03-04 21:53:35 +11001477 case sTrustedUserCAKeys:
1478 charptr = &options->trusted_user_ca_keys;
1479 goto parse_filename;
1480
1481 case sRevokedKeys:
1482 charptr = &options->revoked_keys_file;
1483 goto parse_filename;
1484
Damien Miller0dac6fb2010-11-20 15:19:38 +11001485 case sIPQoS:
1486 arg = strdelim(&cp);
1487 if ((value = parse_ipqos(arg)) == -1)
1488 fatal("%s line %d: Bad IPQoS value: %s",
1489 filename, linenum, arg);
1490 arg = strdelim(&cp);
1491 if (arg == NULL)
1492 value2 = value;
1493 else if ((value2 = parse_ipqos(arg)) == -1)
1494 fatal("%s line %d: Bad IPQoS value: %s",
1495 filename, linenum, arg);
1496 if (*activep) {
1497 options->ip_qos_interactive = value;
1498 options->ip_qos_bulk = value2;
1499 }
1500 break;
1501
Damien Miller23528812012-04-22 11:24:43 +10001502 case sVersionAddendum:
1503 if (cp == NULL)
1504 fatal("%.200s line %d: Missing argument.", filename,
1505 linenum);
1506 len = strspn(cp, WHITESPACE);
1507 if (*activep && options->version_addendum == NULL) {
1508 if (strcasecmp(cp + len, "none") == 0)
1509 options->version_addendum = xstrdup("");
1510 else if (strchr(cp + len, '\r') != NULL)
1511 fatal("%.200s line %d: Invalid argument",
1512 filename, linenum);
1513 else
1514 options->version_addendum = xstrdup(cp + len);
1515 }
1516 return 0;
1517
Damien Miller09d3e122012-10-31 08:58:58 +11001518 case sAuthorizedKeysCommand:
1519 len = strspn(cp, WHITESPACE);
1520 if (*activep && options->authorized_keys_command == NULL) {
1521 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1522 fatal("%.200s line %d: AuthorizedKeysCommand "
1523 "must be an absolute path",
1524 filename, linenum);
1525 options->authorized_keys_command = xstrdup(cp + len);
1526 }
1527 return 0;
1528
1529 case sAuthorizedKeysCommandUser:
1530 charptr = &options->authorized_keys_command_user;
1531
1532 arg = strdelim(&cp);
1533 if (*activep && *charptr == NULL)
1534 *charptr = xstrdup(arg);
1535 break;
1536
Damien Millera6e3f012012-11-04 23:21:40 +11001537 case sAuthenticationMethods:
1538 if (*activep && options->num_auth_methods == 0) {
1539 while ((arg = strdelim(&cp)) && *arg != '\0') {
1540 if (options->num_auth_methods >=
1541 MAX_AUTH_METHODS)
1542 fatal("%s line %d: "
1543 "too many authentication methods.",
1544 filename, linenum);
1545 if (auth2_methods_valid(arg, 0) != 0)
1546 fatal("%s line %d: invalid "
1547 "authentication method list.",
1548 filename, linenum);
1549 options->auth_methods[
1550 options->num_auth_methods++] = xstrdup(arg);
1551 }
1552 }
1553 return 0;
1554
Ben Lindstromade03f62001-12-06 18:22:17 +00001555 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001556 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001557 filename, linenum, arg);
1558 while (arg)
1559 arg = strdelim(&cp);
1560 break;
1561
Damien Millerf9b3feb2003-05-16 11:38:32 +10001562 case sUnsupported:
1563 logit("%s line %d: Unsupported option %s",
1564 filename, linenum, arg);
1565 while (arg)
1566 arg = strdelim(&cp);
1567 break;
1568
Ben Lindstromade03f62001-12-06 18:22:17 +00001569 default:
1570 fatal("%s line %d: Missing handler for opcode %s (%d)",
1571 filename, linenum, arg, opcode);
1572 }
1573 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1574 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1575 filename, linenum, arg);
1576 return 0;
1577}
1578
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001579/* Reads the server configuration file. */
1580
Damien Miller4af51302000-04-16 11:18:38 +10001581void
Darren Tucker645ab752004-06-25 13:33:20 +10001582load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001583{
Damien Miller46cb75a2012-07-31 12:22:37 +10001584 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001585 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001586 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001587
Darren Tucker645ab752004-06-25 13:33:20 +10001588 debug2("%s: filename %s", __func__, filename);
1589 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001590 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001591 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001592 }
Darren Tucker645ab752004-06-25 13:33:20 +10001593 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001594 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001595 lineno++;
1596 if (strlen(line) == sizeof(line) - 1)
1597 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001598 /*
1599 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001600 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001601 * line numbers later for error messages
1602 */
1603 if ((cp = strchr(line, '#')) != NULL)
1604 memcpy(cp, "\n", 2);
1605 cp = line + strspn(line, " \t\r");
1606
1607 buffer_append(conf, cp, strlen(cp));
1608 }
1609 buffer_append(conf, "\0", 1);
1610 fclose(f);
1611 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1612}
1613
1614void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001615parse_server_match_config(ServerOptions *options,
1616 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001617{
Darren Tucker45150472006-07-12 22:34:17 +10001618 ServerOptions mo;
1619
1620 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001621 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001622 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001623}
1624
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001625int parse_server_match_testspec(struct connection_info *ci, char *spec)
1626{
1627 char *p;
1628
1629 while ((p = strsep(&spec, ",")) && *p != '\0') {
1630 if (strncmp(p, "addr=", 5) == 0) {
1631 ci->address = xstrdup(p + 5);
1632 } else if (strncmp(p, "host=", 5) == 0) {
1633 ci->host = xstrdup(p + 5);
1634 } else if (strncmp(p, "user=", 5) == 0) {
1635 ci->user = xstrdup(p + 5);
1636 } else if (strncmp(p, "laddr=", 6) == 0) {
1637 ci->laddress = xstrdup(p + 6);
1638 } else if (strncmp(p, "lport=", 6) == 0) {
1639 ci->lport = a2port(p + 6);
1640 if (ci->lport == -1) {
1641 fprintf(stderr, "Invalid port '%s' in test mode"
1642 " specification %s\n", p+6, p);
1643 return -1;
1644 }
1645 } else {
1646 fprintf(stderr, "Invalid test mode specification %s\n",
1647 p);
1648 return -1;
1649 }
1650 }
1651 return 0;
1652}
1653
1654/*
1655 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1656 * empty spec.
1657 */
1658int server_match_spec_complete(struct connection_info *ci)
1659{
1660 if (ci->user && ci->host && ci->address)
1661 return 1; /* complete */
1662 if (!ci->user && !ci->host && !ci->address)
1663 return -1; /* empty */
1664 return 0; /* partial */
1665}
1666
Darren Tucker1629c072007-02-19 22:25:37 +11001667/* Helper macros */
1668#define M_CP_INTOPT(n) do {\
1669 if (src->n != -1) \
1670 dst->n = src->n; \
1671} while (0)
1672#define M_CP_STROPT(n) do {\
1673 if (src->n != NULL) { \
1674 if (dst->n != NULL) \
1675 xfree(dst->n); \
1676 dst->n = src->n; \
1677 } \
1678} while(0)
Damien Millerd8478b62011-05-29 21:39:36 +10001679#define M_CP_STRARRAYOPT(n, num_n) do {\
1680 if (src->num_n != 0) { \
1681 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1682 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1683 } \
1684} while(0)
Darren Tucker1629c072007-02-19 22:25:37 +11001685
1686/*
1687 * Copy any supported values that are set.
1688 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001689 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001690 * array values that are not used pre-authentication, because any that we
1691 * do use must be explictly sent in mm_getpwnamallow().
1692 */
Darren Tucker45150472006-07-12 22:34:17 +10001693void
Darren Tucker1629c072007-02-19 22:25:37 +11001694copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001695{
Darren Tucker1629c072007-02-19 22:25:37 +11001696 M_CP_INTOPT(password_authentication);
1697 M_CP_INTOPT(gss_authentication);
1698 M_CP_INTOPT(rsa_authentication);
1699 M_CP_INTOPT(pubkey_authentication);
1700 M_CP_INTOPT(kerberos_authentication);
1701 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001702 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001703 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001704 M_CP_INTOPT(zero_knowledge_password_authentication);
Damien Miller09d3e122012-10-31 08:58:58 +11001705 M_CP_STROPT(authorized_keys_command);
1706 M_CP_STROPT(authorized_keys_command_user);
Darren Tucker15f94272008-01-01 20:36:56 +11001707 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001708 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001709
1710 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001711 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001712 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001713 M_CP_INTOPT(gateway_ports);
1714 M_CP_INTOPT(x11_display_offset);
1715 M_CP_INTOPT(x11_forwarding);
1716 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001717 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001718 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001719 M_CP_INTOPT(ip_qos_interactive);
1720 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker1629c072007-02-19 22:25:37 +11001721
Damien Millerf2e407e2011-05-20 19:04:14 +10001722 /* See comment in servconf.h */
1723 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001724
Damien Millerc2411902011-05-20 19:03:49 +10001725 /*
1726 * The only things that should be below this point are string options
1727 * which are only used after authentication.
1728 */
Damien Miller5d74e582011-05-20 19:03:31 +10001729 if (preauth)
1730 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001731
Damien Miller5d74e582011-05-20 19:03:31 +10001732 M_CP_STROPT(adm_forced_command);
1733 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001734}
1735
Darren Tucker1629c072007-02-19 22:25:37 +11001736#undef M_CP_INTOPT
1737#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001738#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001739
Darren Tucker45150472006-07-12 22:34:17 +10001740void
1741parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001742 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001743{
1744 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001745 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001746
1747 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1748
Darren Tucker9fbac712004-08-12 22:41:44 +10001749 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001750 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001751 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001752 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001753 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001754 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001755 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001756 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001757 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001758 if (bad_options > 0)
1759 fatal("%s: terminating, %d bad configuration options",
1760 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001761}
Darren Tuckere7140f22008-06-10 23:01:51 +10001762
1763static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001764fmt_multistate_int(int val, const struct multistate *m)
1765{
1766 u_int i;
1767
1768 for (i = 0; m[i].key != NULL; i++) {
1769 if (m[i].value == val)
1770 return m[i].key;
1771 }
1772 return "UNKNOWN";
1773}
1774
1775static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001776fmt_intarg(ServerOpCodes code, int val)
1777{
Damien Miller82c55872011-06-23 08:20:30 +10001778 if (val == -1)
1779 return "unset";
1780 switch (code) {
1781 case sAddressFamily:
1782 return fmt_multistate_int(val, multistate_addressfamily);
1783 case sPermitRootLogin:
1784 return fmt_multistate_int(val, multistate_permitrootlogin);
1785 case sGatewayPorts:
1786 return fmt_multistate_int(val, multistate_gatewayports);
1787 case sCompression:
1788 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001789 case sUsePrivilegeSeparation:
1790 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001791 case sAllowTcpForwarding:
1792 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001793 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001794 switch (val) {
1795 case SSH_PROTO_1:
1796 return "1";
1797 case SSH_PROTO_2:
1798 return "2";
1799 case (SSH_PROTO_1|SSH_PROTO_2):
1800 return "2,1";
1801 default:
1802 return "UNKNOWN";
1803 }
Damien Miller82c55872011-06-23 08:20:30 +10001804 default:
1805 switch (val) {
1806 case 0:
1807 return "no";
1808 case 1:
1809 return "yes";
1810 default:
1811 return "UNKNOWN";
1812 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001813 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001814}
1815
1816static const char *
1817lookup_opcode_name(ServerOpCodes code)
1818{
1819 u_int i;
1820
1821 for (i = 0; keywords[i].name != NULL; i++)
1822 if (keywords[i].opcode == code)
1823 return(keywords[i].name);
1824 return "UNKNOWN";
1825}
1826
1827static void
1828dump_cfg_int(ServerOpCodes code, int val)
1829{
1830 printf("%s %d\n", lookup_opcode_name(code), val);
1831}
1832
1833static void
1834dump_cfg_fmtint(ServerOpCodes code, int val)
1835{
1836 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1837}
1838
1839static void
1840dump_cfg_string(ServerOpCodes code, const char *val)
1841{
1842 if (val == NULL)
1843 return;
1844 printf("%s %s\n", lookup_opcode_name(code), val);
1845}
1846
1847static void
1848dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1849{
1850 u_int i;
1851
1852 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001853 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1854}
1855
1856static void
1857dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1858{
1859 u_int i;
1860
1861 printf("%s", lookup_opcode_name(code));
1862 for (i = 0; i < count; i++)
1863 printf(" %s", vals[i]);
1864 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001865}
1866
1867void
1868dump_config(ServerOptions *o)
1869{
1870 u_int i;
1871 int ret;
1872 struct addrinfo *ai;
1873 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1874
1875 /* these are usually at the top of the config */
1876 for (i = 0; i < o->num_ports; i++)
1877 printf("port %d\n", o->ports[i]);
1878 dump_cfg_fmtint(sProtocol, o->protocol);
1879 dump_cfg_fmtint(sAddressFamily, o->address_family);
1880
1881 /* ListenAddress must be after Port */
1882 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1883 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1884 sizeof(addr), port, sizeof(port),
1885 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1886 error("getnameinfo failed: %.100s",
1887 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1888 strerror(errno));
1889 } else {
1890 if (ai->ai_family == AF_INET6)
1891 printf("listenaddress [%s]:%s\n", addr, port);
1892 else
1893 printf("listenaddress %s:%s\n", addr, port);
1894 }
1895 }
1896
1897 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001898#ifdef USE_PAM
1899 dump_cfg_int(sUsePAM, o->use_pam);
1900#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001901 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1902 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1903 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1904 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1905 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001906 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001907 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1908 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1909
1910 /* formatted integer arguments */
1911 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1912 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1913 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1914 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1915 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1916 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1917 o->hostbased_uses_name_from_packet_only);
1918 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1919 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001920#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001921 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1922 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1923 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001924# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001925 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001926# endif
1927#endif
1928#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001929 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1930 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001931#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001932#ifdef JPAKE
1933 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1934 o->zero_knowledge_password_authentication);
1935#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001936 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1937 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1938 o->kbd_interactive_authentication);
1939 dump_cfg_fmtint(sChallengeResponseAuthentication,
1940 o->challenge_response_authentication);
1941 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1942 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1943 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1944 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1945 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1946 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1947 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1948 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1949 dump_cfg_fmtint(sUseLogin, o->use_login);
1950 dump_cfg_fmtint(sCompression, o->compression);
1951 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1952 dump_cfg_fmtint(sUseDNS, o->use_dns);
1953 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1954 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1955
1956 /* string arguments */
1957 dump_cfg_string(sPidFile, o->pid_file);
1958 dump_cfg_string(sXAuthLocation, o->xauth_location);
1959 dump_cfg_string(sCiphers, o->ciphers);
1960 dump_cfg_string(sMacs, o->macs);
1961 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10001962 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11001963 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11001964 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
1965 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10001966 dump_cfg_string(sAuthorizedPrincipalsFile,
1967 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10001968 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11001969 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
1970 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Darren Tuckere7140f22008-06-10 23:01:51 +10001971
1972 /* string arguments requiring a lookup */
1973 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1974 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1975
1976 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10001977 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
1978 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10001979 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1980 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11001981 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
1982 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10001983 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1984 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1985 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1986 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1987 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11001988 dump_cfg_strarray_oneline(sAuthenticationMethods,
1989 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10001990
1991 /* other arguments */
1992 for (i = 0; i < o->num_subsystems; i++)
1993 printf("subsystem %s %s\n", o->subsystem_name[i],
1994 o->subsystem_args[i]);
1995
1996 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1997 o->max_startups_rate, o->max_startups);
1998
1999 for (i = 0; tunmode_desc[i].val != -1; i++)
2000 if (tunmode_desc[i].val == o->permit_tun) {
2001 s = tunmode_desc[i].text;
2002 break;
2003 }
2004 dump_cfg_string(sPermitTunnel, s);
2005
Damien Miller91475862011-05-05 14:14:34 +10002006 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2007 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002008
Darren Tuckere7140f22008-06-10 23:01:51 +10002009 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002010}