blob: 659a1eb21b319853ca2bda615c7de65cccd0f56e [file] [log] [blame]
Darren Tucker49c31c42008-11-11 16:39:44 +11001/* $OpenBSD: servconf.c,v 1.192 2008/11/11 02:58:09 stevesk Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002/*
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10005 *
Damien Millere4340be2000-09-16 13:29:08 +11006 * As far as I am concerned, the code I have written for this software
7 * can be used freely for any purpose. Any derived versions of this
8 * software must be clearly marked as such, and if the derived work is
9 * incompatible with the protocol description in the RFC file, it must be
10 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110011 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100012
13#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
Damien Millere3b60b52006-07-10 21:08:03 +100015#include <sys/types.h>
16#include <sys/socket.h>
17
Damien Millerb8fe89c2006-07-24 14:51:00 +100018#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100019#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100020#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100021#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100022#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100023#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100024#include <unistd.h>
Damien Millerd7834352006-08-05 12:39:39 +100025#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100026#include <errno.h>
Damien Millerbe43ebf2006-07-24 13:51:51 +100027
Damien Millerb84886b2008-05-19 15:05:07 +100028#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100029#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100030#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000031#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100032#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100033#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100034#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000035#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036#include "misc.h"
37#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000039#include "kex.h"
40#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100041#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100042#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100043#include "groupaccess.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000044
Ben Lindstrombba81212001-06-25 05:01:22 +000045static void add_listen_addr(ServerOptions *, char *, u_short);
46static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110047
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000048/* Use of privilege separation or not */
49extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100050extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000051
Damien Millerd4a8b7e1999-10-27 13:42:43 +100052/* Initializes the server options to their default values. */
53
Damien Miller4af51302000-04-16 11:18:38 +100054void
Damien Miller95def091999-11-25 00:26:21 +110055initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100056{
Damien Miller95def091999-11-25 00:26:21 +110057 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110058
59 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100060 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110061
62 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110063 options->num_ports = 0;
64 options->ports_from_cmdline = 0;
65 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110066 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110067 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100068 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110069 options->server_key_bits = -1;
70 options->login_grace_time = -1;
71 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000072 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110073 options->ignore_rhosts = -1;
74 options->ignore_user_known_hosts = -1;
75 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000076 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110077 options->x11_forwarding = -1;
78 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110079 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100080 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110081 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110082 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110083 options->log_facility = SYSLOG_FACILITY_NOT_SET;
84 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110085 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000086 options->hostbased_authentication = -1;
87 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110088 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110089 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110090 options->kerberos_authentication = -1;
91 options->kerberos_or_local_passwd = -1;
92 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +110093 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +100094 options->gss_authentication=-1;
95 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +110096 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110097 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000098 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110099 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000100 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000102 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100103 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000104 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100105 options->num_allow_users = 0;
106 options->num_deny_users = 0;
107 options->num_allow_groups = 0;
108 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000109 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000110 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000111 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000112 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000113 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000114 options->max_startups_begin = -1;
115 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000116 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000117 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000118 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000119 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000120 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000121 options->client_alive_interval = -1;
122 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000123 options->authorized_keys_file = NULL;
124 options->authorized_keys_file2 = NULL;
Darren Tucker46bc0752004-05-02 22:11:30 +1000125 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100126 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000127 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000128 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100129 options->chroot_directory = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100130 options->zero_knowledge_password_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000131}
132
Damien Miller4af51302000-04-16 11:18:38 +1000133void
Damien Miller95def091999-11-25 00:26:21 +1100134fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000135{
Damien Miller726273e2001-11-12 11:40:11 +1100136 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000137 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000138 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100139
140 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100141 if (options->protocol == SSH_PROTO_UNKNOWN)
142 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
143 if (options->num_host_key_files == 0) {
144 /* fill default hostkeys for protocols */
145 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100146 options->host_key_files[options->num_host_key_files++] =
147 _PATH_HOST_KEY_FILE;
148 if (options->protocol & SSH_PROTO_2) {
149 options->host_key_files[options->num_host_key_files++] =
150 _PATH_HOST_RSA_KEY_FILE;
151 options->host_key_files[options->num_host_key_files++] =
152 _PATH_HOST_DSA_KEY_FILE;
153 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100154 }
Damien Miller34132e52000-01-14 15:45:46 +1100155 if (options->num_ports == 0)
156 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
157 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000158 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000159 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000160 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100161 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000162 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100163 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000164 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->key_regeneration_time == -1)
166 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000167 if (options->permit_root_login == PERMIT_NOT_SET)
168 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100169 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100170 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->ignore_user_known_hosts == -1)
172 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->print_motd == -1)
174 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000175 if (options->print_lastlog == -1)
176 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100177 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100178 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100180 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100181 if (options->x11_use_localhost == -1)
182 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000183 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000184 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->strict_modes == -1)
186 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100187 if (options->tcp_keep_alive == -1)
188 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100189 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100190 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100191 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000192 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100193 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100194 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000195 if (options->hostbased_authentication == -1)
196 options->hostbased_authentication = 0;
197 if (options->hostbased_uses_name_from_packet_only == -1)
198 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->rsa_authentication == -1)
200 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100201 if (options->pubkey_authentication == -1)
202 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000204 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->kerberos_or_local_passwd == -1)
206 options->kerberos_or_local_passwd = 1;
207 if (options->kerberos_ticket_cleanup == -1)
208 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100209 if (options->kerberos_get_afs_token == -1)
210 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000211 if (options->gss_authentication == -1)
212 options->gss_authentication = 0;
213 if (options->gss_cleanup_creds == -1)
214 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100215 if (options->password_authentication == -1)
216 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100217 if (options->kbd_interactive_authentication == -1)
218 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000219 if (options->challenge_response_authentication == -1)
220 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100221 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100222 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000223 if (options->permit_user_env == -1)
224 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100225 if (options->use_login == -1)
226 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000227 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000228 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100229 if (options->allow_tcp_forwarding == -1)
230 options->allow_tcp_forwarding = 1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000231 if (options->allow_agent_forwarding == -1)
232 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000233 if (options->gateway_ports == -1)
234 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000235 if (options->max_startups == -1)
236 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000237 if (options->max_startups_rate == -1)
238 options->max_startups_rate = 100; /* 100% */
239 if (options->max_startups_begin == -1)
240 options->max_startups_begin = options->max_startups;
Darren Tucker89413db2004-05-24 10:36:23 +1000241 if (options->max_authtries == -1)
242 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000243 if (options->max_sessions == -1)
244 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000245 if (options->use_dns == -1)
246 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000247 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100248 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000249 if (options->client_alive_count_max == -1)
250 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100251 if (options->authorized_keys_file2 == NULL) {
252 /* authorized_keys_file2 falls back to authorized_keys_file */
253 if (options->authorized_keys_file != NULL)
254 options->authorized_keys_file2 = options->authorized_keys_file;
255 else
256 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
257 }
258 if (options->authorized_keys_file == NULL)
259 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Damien Millerd27b9472005-12-13 19:29:02 +1100260 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100261 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100262 if (options->zero_knowledge_password_authentication == -1)
263 options->zero_knowledge_password_authentication = 0;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000264
Ben Lindstromfb62a692002-06-06 19:47:11 +0000265 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000266 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000267 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000268
Tim Rice40017b02002-07-14 13:36:49 -0700269#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000270 if (use_privsep && options->compression == 1) {
271 error("This platform does not support both privilege "
272 "separation and compression");
273 error("Compression disabled");
274 options->compression = 0;
275 }
276#endif
277
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278}
279
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000280/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100281typedef enum {
282 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100283 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000284 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100285 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100286 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
287 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000288 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100289 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100290 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000291 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100292 sPasswordAuthentication, sKbdInteractiveAuthentication,
293 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000294 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100295 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100296 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000297 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100298 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000299 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000300 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000301 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000302 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100303 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000304 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Damien Millerd27b9472005-12-13 19:29:02 +1100305 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100306 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Damien Miller4f755cd2008-05-19 14:57:41 +1000307 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller01ed2272008-11-05 16:20:46 +1100308 sZeroKnowledgePasswordAuthentication,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000309 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000310} ServerOpCodes;
311
Darren Tucker45150472006-07-12 22:34:17 +1000312#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
313#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
314#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
315
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000316/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100317static struct {
318 const char *name;
319 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000320 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100321} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100322 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000323#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000324 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000325#else
Darren Tucker45150472006-07-12 22:34:17 +1000326 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000327#endif
Darren Tucker45150472006-07-12 22:34:17 +1000328 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100329 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000330 { "port", sPort, SSHCFG_GLOBAL },
331 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
332 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
333 { "pidfile", sPidFile, SSHCFG_GLOBAL },
334 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
335 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
336 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100337 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000338 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
339 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
340 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100341 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
342 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000343 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100344 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
345 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000346 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000347#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100348 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000349 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
350 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100351#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000352 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000353#else
Darren Tucker45150472006-07-12 22:34:17 +1000354 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100355#endif
356#else
Darren Tucker1629c072007-02-19 22:25:37 +1100357 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000358 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
359 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
360 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000361#endif
Darren Tucker45150472006-07-12 22:34:17 +1000362 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
363 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000364#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100365 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000366 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000367#else
Darren Tucker1629c072007-02-19 22:25:37 +1100368 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000369 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000370#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100371 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
372 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100373 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000374 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100375#ifdef JPAKE
376 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
377#else
378 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
379#endif
Darren Tucker45150472006-07-12 22:34:17 +1000380 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
381 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
382 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
383 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
384 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
385 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
386 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000387 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
388 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
389 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000390 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
391 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100392 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000393 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
394 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
395 { "compression", sCompression, SSHCFG_GLOBAL },
396 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
397 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
398 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000399 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000400 { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
401 { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
402 { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
403 { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
404 { "ciphers", sCiphers, SSHCFG_GLOBAL },
405 { "macs", sMacs, SSHCFG_GLOBAL },
406 { "protocol", sProtocol, SSHCFG_GLOBAL },
407 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
408 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
409 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000410 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000411 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100412 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000413 { "usedns", sUseDNS, SSHCFG_GLOBAL },
414 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
415 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
416 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
417 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
418 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
419 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
420 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL },
421 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
422 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Damien Miller9b439df2006-07-24 14:04:00 +1000423 { "match", sMatch, SSHCFG_ALL },
424 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000425 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100426 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000427 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000428};
429
Darren Tuckere7140f22008-06-10 23:01:51 +1000430static struct {
431 int val;
432 char *text;
433} tunmode_desc[] = {
434 { SSH_TUNMODE_NO, "no" },
435 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
436 { SSH_TUNMODE_ETHERNET, "ethernet" },
437 { SSH_TUNMODE_YES, "yes" },
438 { -1, NULL }
439};
440
Damien Miller5428f641999-11-25 11:54:57 +1100441/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000442 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100443 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000444
Damien Miller4af51302000-04-16 11:18:38 +1000445static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100446parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000447 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000448{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000449 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000450
Damien Miller95def091999-11-25 00:26:21 +1100451 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000452 if (strcasecmp(cp, keywords[i].name) == 0) {
453 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100454 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000455 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000456
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000457 error("%s: line %d: Bad configuration option: %s",
458 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100459 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000460}
461
Ben Lindstrombba81212001-06-25 05:01:22 +0000462static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000463add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100464{
Damien Millereccb9de2005-06-17 12:59:34 +1000465 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100466
467 if (options->num_ports == 0)
468 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100469 if (options->address_family == -1)
470 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000471 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000472 for (i = 0; i < options->num_ports; i++)
473 add_one_listen_addr(options, addr, options->ports[i]);
474 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000475 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000476}
477
Ben Lindstrombba81212001-06-25 05:01:22 +0000478static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000479add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
480{
481 struct addrinfo hints, *ai, *aitop;
482 char strport[NI_MAXSERV];
483 int gaierr;
484
485 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100486 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000487 hints.ai_socktype = SOCK_STREAM;
488 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000489 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000490 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
491 fatal("bad addr or host: %s (%s)",
492 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100493 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000494 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
495 ;
496 ai->ai_next = options->listen_addrs;
497 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100498}
499
Darren Tucker45150472006-07-12 22:34:17 +1000500/*
501 * The strategy for the Match blocks is that the config file is parsed twice.
502 *
503 * The first time is at startup. activep is initialized to 1 and the
504 * directives in the global context are processed and acted on. Hitting a
505 * Match directive unsets activep and the directives inside the block are
506 * checked for syntax only.
507 *
508 * The second time is after a connection has been established but before
509 * authentication. activep is initialized to 2 and global config directives
510 * are ignored since they have already been processed. If the criteria in a
511 * Match block is met, activep is set and the subsequent directives
512 * processed and actioned until EOF or another Match block unsets it. Any
513 * options set are copied into the main server config.
514 *
515 * Potential additions/improvements:
516 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
517 *
518 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
519 * Match Address 192.168.0.*
520 * Tag trusted
521 * Match Group wheel
522 * Tag trusted
523 * Match Tag trusted
524 * AllowTcpForwarding yes
525 * GatewayPorts clientspecified
526 * [...]
527 *
528 * - Add a PermittedChannelRequests directive
529 * Match Group shell
530 * PermittedChannelRequests session,forwarded-tcpip
531 */
532
533static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000534match_cfg_line_group(const char *grps, int line, const char *user)
535{
536 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000537 struct passwd *pw;
538
Damien Miller565ca3f2006-08-19 00:23:15 +1000539 if (user == NULL)
540 goto out;
541
542 if ((pw = getpwnam(user)) == NULL) {
543 debug("Can't match group at line %d because user %.100s does "
544 "not exist", line, user);
545 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
546 debug("Can't Match group because user %.100s not in any group "
547 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000548 } else if (ga_match_pattern_list(grps) != 1) {
549 debug("user %.100s does not match group list %.100s at line %d",
550 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000551 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000552 debug("user %.100s matched group list %.100s at line %d", user,
553 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000554 result = 1;
555 }
556out:
557 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000558 return result;
559}
560
561static int
Darren Tucker45150472006-07-12 22:34:17 +1000562match_cfg_line(char **condition, int line, const char *user, const char *host,
563 const char *address)
564{
565 int result = 1;
566 char *arg, *attrib, *cp = *condition;
567 size_t len;
568
569 if (user == NULL)
570 debug3("checking syntax for 'Match %s'", cp);
571 else
572 debug3("checking match for '%s' user %s host %s addr %s", cp,
573 user ? user : "(null)", host ? host : "(null)",
574 address ? address : "(null)");
575
576 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
577 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
578 error("Missing Match criteria for %s", attrib);
579 return -1;
580 }
581 len = strlen(arg);
582 if (strcasecmp(attrib, "user") == 0) {
583 if (!user) {
584 result = 0;
585 continue;
586 }
587 if (match_pattern_list(user, arg, len, 0) != 1)
588 result = 0;
589 else
590 debug("user %.100s matched 'User %.100s' at "
591 "line %d", user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000592 } else if (strcasecmp(attrib, "group") == 0) {
593 switch (match_cfg_line_group(arg, line, user)) {
594 case -1:
595 return -1;
596 case 0:
597 result = 0;
598 }
Darren Tucker45150472006-07-12 22:34:17 +1000599 } else if (strcasecmp(attrib, "host") == 0) {
600 if (!host) {
601 result = 0;
602 continue;
603 }
604 if (match_hostname(host, arg, len) != 1)
605 result = 0;
606 else
607 debug("connection from %.100s matched 'Host "
608 "%.100s' at line %d", host, arg, line);
609 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000610 switch (addr_match_list(address, arg)) {
611 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000612 debug("connection from %.100s matched 'Address "
613 "%.100s' at line %d", address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000614 break;
615 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000616 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000617 result = 0;
618 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000619 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000620 return -1;
621 }
Darren Tucker45150472006-07-12 22:34:17 +1000622 } else {
623 error("Unsupported Match attribute %s", attrib);
624 return -1;
625 }
626 }
627 if (user != NULL)
628 debug3("match %sfound", result ? "" : "not ");
629 *condition = cp;
630 return result;
631}
632
Damien Millere2754432006-07-24 14:06:47 +1000633#define WHITESPACE " \t\r\n"
634
Ben Lindstromade03f62001-12-06 18:22:17 +0000635int
636process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000637 const char *filename, int linenum, int *activep, const char *user,
638 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000639{
640 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000641 int cmdline = 0, *intptr, value, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100642 SyslogFacility *log_facility_ptr;
643 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000644 ServerOpCodes opcode;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100645 u_short port;
Darren Tucker45150472006-07-12 22:34:17 +1000646 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000647 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000648
649 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100650 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100651 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000652 /* Ignore leading whitespace */
653 if (*arg == '\0')
654 arg = strdelim(&cp);
655 if (!arg || !*arg || *arg == '#')
656 return 0;
657 intptr = NULL;
658 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000659 opcode = parse_token(arg, filename, linenum, &flags);
660
661 if (activep == NULL) { /* We are processing a command line directive */
662 cmdline = 1;
663 activep = &cmdline;
664 }
665 if (*activep && opcode != sMatch)
666 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
667 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
668 if (user == NULL) {
669 fatal("%s line %d: Directive '%s' is not allowed "
670 "within a Match block", filename, linenum, arg);
671 } else { /* this is a directive we have already processed */
672 while (arg)
673 arg = strdelim(&cp);
674 return 0;
675 }
676 }
677
Ben Lindstromade03f62001-12-06 18:22:17 +0000678 switch (opcode) {
679 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000680 case sUsePAM:
681 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000682 goto parse_flag;
683
684 /* Standard Options */
685 case sBadOption:
686 return -1;
687 case sPort:
688 /* ignore ports from configfile if cmdline specifies ports */
689 if (options->ports_from_cmdline)
690 return 0;
691 if (options->listen_addrs != NULL)
692 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100693 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000694 if (options->num_ports >= MAX_PORTS)
695 fatal("%s line %d: too many ports.",
696 filename, linenum);
697 arg = strdelim(&cp);
698 if (!arg || *arg == '\0')
699 fatal("%s line %d: missing port number.",
700 filename, linenum);
701 options->ports[options->num_ports++] = a2port(arg);
702 if (options->ports[options->num_ports-1] == 0)
703 fatal("%s line %d: Badly formatted port number.",
704 filename, linenum);
705 break;
706
707 case sServerKeyBits:
708 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000709 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000710 arg = strdelim(&cp);
711 if (!arg || *arg == '\0')
712 fatal("%s line %d: missing integer value.",
713 filename, linenum);
714 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000715 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000716 *intptr = value;
717 break;
718
719 case sLoginGraceTime:
720 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000721 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000722 arg = strdelim(&cp);
723 if (!arg || *arg == '\0')
724 fatal("%s line %d: missing time value.",
725 filename, linenum);
726 if ((value = convtime(arg)) == -1)
727 fatal("%s line %d: invalid time value.",
728 filename, linenum);
729 if (*intptr == -1)
730 *intptr = value;
731 break;
732
733 case sKeyRegenerationTime:
734 intptr = &options->key_regeneration_time;
735 goto parse_time;
736
737 case sListenAddress:
738 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100739 if (arg == NULL || *arg == '\0')
740 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000741 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000742 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
743 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
744 && strchr(p+1, ':') != NULL) {
745 add_listen_addr(options, arg, 0);
746 break;
747 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100748 p = hpdelim(&arg);
749 if (p == NULL)
750 fatal("%s line %d: bad address:port usage",
751 filename, linenum);
752 p = cleanhostname(p);
753 if (arg == NULL)
754 port = 0;
755 else if ((port = a2port(arg)) == 0)
756 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000757
Damien Millerf91ee4c2005-03-01 21:24:33 +1100758 add_listen_addr(options, p, port);
759
Ben Lindstromade03f62001-12-06 18:22:17 +0000760 break;
761
Darren Tucker0f383232005-01-20 10:57:56 +1100762 case sAddressFamily:
763 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000764 if (!arg || *arg == '\0')
765 fatal("%s line %d: missing address family.",
766 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100767 intptr = &options->address_family;
768 if (options->listen_addrs != NULL)
769 fatal("%s line %d: address family must be specified before "
770 "ListenAddress.", filename, linenum);
771 if (strcasecmp(arg, "inet") == 0)
772 value = AF_INET;
773 else if (strcasecmp(arg, "inet6") == 0)
774 value = AF_INET6;
775 else if (strcasecmp(arg, "any") == 0)
776 value = AF_UNSPEC;
777 else
778 fatal("%s line %d: unsupported address family \"%s\".",
779 filename, linenum, arg);
780 if (*intptr == -1)
781 *intptr = value;
782 break;
783
Ben Lindstromade03f62001-12-06 18:22:17 +0000784 case sHostKeyFile:
785 intptr = &options->num_host_key_files;
786 if (*intptr >= MAX_HOSTKEYS)
787 fatal("%s line %d: too many host keys specified (max %d).",
788 filename, linenum, MAX_HOSTKEYS);
789 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000790 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000791 arg = strdelim(&cp);
792 if (!arg || *arg == '\0')
793 fatal("%s line %d: missing file name.",
794 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000795 if (*activep && *charptr == NULL) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000796 *charptr = tilde_expand_filename(arg, getuid());
797 /* increase optional counter */
798 if (intptr != NULL)
799 *intptr = *intptr + 1;
800 }
801 break;
802
803 case sPidFile:
804 charptr = &options->pid_file;
805 goto parse_filename;
806
807 case sPermitRootLogin:
808 intptr = &options->permit_root_login;
809 arg = strdelim(&cp);
810 if (!arg || *arg == '\0')
811 fatal("%s line %d: missing yes/"
812 "without-password/forced-commands-only/no "
813 "argument.", filename, linenum);
814 value = 0; /* silence compiler */
815 if (strcmp(arg, "without-password") == 0)
816 value = PERMIT_NO_PASSWD;
817 else if (strcmp(arg, "forced-commands-only") == 0)
818 value = PERMIT_FORCED_ONLY;
819 else if (strcmp(arg, "yes") == 0)
820 value = PERMIT_YES;
821 else if (strcmp(arg, "no") == 0)
822 value = PERMIT_NO;
823 else
824 fatal("%s line %d: Bad yes/"
825 "without-password/forced-commands-only/no "
826 "argument: %s", filename, linenum, arg);
Darren Tucker15f94272008-01-01 20:36:56 +1100827 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000828 *intptr = value;
829 break;
830
831 case sIgnoreRhosts:
832 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000833 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000834 arg = strdelim(&cp);
835 if (!arg || *arg == '\0')
836 fatal("%s line %d: missing yes/no argument.",
837 filename, linenum);
838 value = 0; /* silence compiler */
839 if (strcmp(arg, "yes") == 0)
840 value = 1;
841 else if (strcmp(arg, "no") == 0)
842 value = 0;
843 else
844 fatal("%s line %d: Bad yes/no argument: %s",
845 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000846 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000847 *intptr = value;
848 break;
849
850 case sIgnoreUserKnownHosts:
851 intptr = &options->ignore_user_known_hosts;
852 goto parse_flag;
853
Ben Lindstromade03f62001-12-06 18:22:17 +0000854 case sRhostsRSAAuthentication:
855 intptr = &options->rhosts_rsa_authentication;
856 goto parse_flag;
857
858 case sHostbasedAuthentication:
859 intptr = &options->hostbased_authentication;
860 goto parse_flag;
861
862 case sHostbasedUsesNameFromPacketOnly:
863 intptr = &options->hostbased_uses_name_from_packet_only;
864 goto parse_flag;
865
866 case sRSAAuthentication:
867 intptr = &options->rsa_authentication;
868 goto parse_flag;
869
870 case sPubkeyAuthentication:
871 intptr = &options->pubkey_authentication;
872 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000873
Ben Lindstromade03f62001-12-06 18:22:17 +0000874 case sKerberosAuthentication:
875 intptr = &options->kerberos_authentication;
876 goto parse_flag;
877
878 case sKerberosOrLocalPasswd:
879 intptr = &options->kerberos_or_local_passwd;
880 goto parse_flag;
881
882 case sKerberosTicketCleanup:
883 intptr = &options->kerberos_ticket_cleanup;
884 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000885
Darren Tucker22ef5082003-12-31 11:37:34 +1100886 case sKerberosGetAFSToken:
887 intptr = &options->kerberos_get_afs_token;
888 goto parse_flag;
889
Darren Tucker0efd1552003-08-26 11:49:55 +1000890 case sGssAuthentication:
891 intptr = &options->gss_authentication;
892 goto parse_flag;
893
894 case sGssCleanupCreds:
895 intptr = &options->gss_cleanup_creds;
896 goto parse_flag;
897
Ben Lindstromade03f62001-12-06 18:22:17 +0000898 case sPasswordAuthentication:
899 intptr = &options->password_authentication;
900 goto parse_flag;
901
Damien Miller01ed2272008-11-05 16:20:46 +1100902 case sZeroKnowledgePasswordAuthentication:
903 intptr = &options->zero_knowledge_password_authentication;
904 goto parse_flag;
905
Ben Lindstromade03f62001-12-06 18:22:17 +0000906 case sKbdInteractiveAuthentication:
907 intptr = &options->kbd_interactive_authentication;
908 goto parse_flag;
909
910 case sChallengeResponseAuthentication:
911 intptr = &options->challenge_response_authentication;
912 goto parse_flag;
913
914 case sPrintMotd:
915 intptr = &options->print_motd;
916 goto parse_flag;
917
918 case sPrintLastLog:
919 intptr = &options->print_lastlog;
920 goto parse_flag;
921
922 case sX11Forwarding:
923 intptr = &options->x11_forwarding;
924 goto parse_flag;
925
926 case sX11DisplayOffset:
927 intptr = &options->x11_display_offset;
928 goto parse_int;
929
Damien Miller95c249f2002-02-05 12:11:34 +1100930 case sX11UseLocalhost:
931 intptr = &options->x11_use_localhost;
932 goto parse_flag;
933
Ben Lindstromade03f62001-12-06 18:22:17 +0000934 case sXAuthLocation:
935 charptr = &options->xauth_location;
936 goto parse_filename;
937
938 case sStrictModes:
939 intptr = &options->strict_modes;
940 goto parse_flag;
941
Damien Miller12c150e2003-12-17 16:31:10 +1100942 case sTCPKeepAlive:
943 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000944 goto parse_flag;
945
946 case sEmptyPasswd:
947 intptr = &options->permit_empty_passwd;
948 goto parse_flag;
949
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000950 case sPermitUserEnvironment:
951 intptr = &options->permit_user_env;
952 goto parse_flag;
953
Ben Lindstromade03f62001-12-06 18:22:17 +0000954 case sUseLogin:
955 intptr = &options->use_login;
956 goto parse_flag;
957
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000958 case sCompression:
959 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000960 arg = strdelim(&cp);
961 if (!arg || *arg == '\0')
962 fatal("%s line %d: missing yes/no/delayed "
963 "argument.", filename, linenum);
964 value = 0; /* silence compiler */
965 if (strcmp(arg, "delayed") == 0)
966 value = COMP_DELAYED;
967 else if (strcmp(arg, "yes") == 0)
968 value = COMP_ZLIB;
969 else if (strcmp(arg, "no") == 0)
970 value = COMP_NONE;
971 else
972 fatal("%s line %d: Bad yes/no/delayed "
973 "argument: %s", filename, linenum, arg);
974 if (*intptr == -1)
975 *intptr = value;
976 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000977
Ben Lindstromade03f62001-12-06 18:22:17 +0000978 case sGatewayPorts:
979 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100980 arg = strdelim(&cp);
981 if (!arg || *arg == '\0')
982 fatal("%s line %d: missing yes/no/clientspecified "
983 "argument.", filename, linenum);
984 value = 0; /* silence compiler */
985 if (strcmp(arg, "clientspecified") == 0)
986 value = 2;
987 else if (strcmp(arg, "yes") == 0)
988 value = 1;
989 else if (strcmp(arg, "no") == 0)
990 value = 0;
991 else
992 fatal("%s line %d: Bad yes/no/clientspecified "
993 "argument: %s", filename, linenum, arg);
Darren Tucker82347a82007-02-25 20:37:52 +1100994 if (*activep && *intptr == -1)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100995 *intptr = value;
996 break;
Ben Lindstromade03f62001-12-06 18:22:17 +0000997
Damien Miller3a961dc2003-06-03 10:25:48 +1000998 case sUseDNS:
999 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001000 goto parse_flag;
1001
1002 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001003 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001004 arg = strdelim(&cp);
1005 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001006 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001007 fatal("%.200s line %d: unsupported log facility '%s'",
1008 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001009 if (*log_facility_ptr == -1)
1010 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001011 break;
1012
1013 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001014 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001015 arg = strdelim(&cp);
1016 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001017 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001018 fatal("%.200s line %d: unsupported log level '%s'",
1019 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001020 if (*log_level_ptr == -1)
1021 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001022 break;
1023
1024 case sAllowTcpForwarding:
1025 intptr = &options->allow_tcp_forwarding;
1026 goto parse_flag;
1027
Damien Miller4f755cd2008-05-19 14:57:41 +10001028 case sAllowAgentForwarding:
1029 intptr = &options->allow_agent_forwarding;
1030 goto parse_flag;
1031
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001032 case sUsePrivilegeSeparation:
1033 intptr = &use_privsep;
1034 goto parse_flag;
1035
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 case sAllowUsers:
1037 while ((arg = strdelim(&cp)) && *arg != '\0') {
1038 if (options->num_allow_users >= MAX_ALLOW_USERS)
1039 fatal("%s line %d: too many allow users.",
1040 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001041 options->allow_users[options->num_allow_users++] =
1042 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001043 }
1044 break;
1045
1046 case sDenyUsers:
1047 while ((arg = strdelim(&cp)) && *arg != '\0') {
1048 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001049 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001050 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001051 options->deny_users[options->num_deny_users++] =
1052 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001053 }
1054 break;
1055
1056 case sAllowGroups:
1057 while ((arg = strdelim(&cp)) && *arg != '\0') {
1058 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1059 fatal("%s line %d: too many allow groups.",
1060 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001061 options->allow_groups[options->num_allow_groups++] =
1062 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001063 }
1064 break;
1065
1066 case sDenyGroups:
1067 while ((arg = strdelim(&cp)) && *arg != '\0') {
1068 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1069 fatal("%s line %d: too many deny groups.",
1070 filename, linenum);
1071 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1072 }
1073 break;
1074
1075 case sCiphers:
1076 arg = strdelim(&cp);
1077 if (!arg || *arg == '\0')
1078 fatal("%s line %d: Missing argument.", filename, linenum);
1079 if (!ciphers_valid(arg))
1080 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1081 filename, linenum, arg ? arg : "<NONE>");
1082 if (options->ciphers == NULL)
1083 options->ciphers = xstrdup(arg);
1084 break;
1085
1086 case sMacs:
1087 arg = strdelim(&cp);
1088 if (!arg || *arg == '\0')
1089 fatal("%s line %d: Missing argument.", filename, linenum);
1090 if (!mac_valid(arg))
1091 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1092 filename, linenum, arg ? arg : "<NONE>");
1093 if (options->macs == NULL)
1094 options->macs = xstrdup(arg);
1095 break;
1096
1097 case sProtocol:
1098 intptr = &options->protocol;
1099 arg = strdelim(&cp);
1100 if (!arg || *arg == '\0')
1101 fatal("%s line %d: Missing argument.", filename, linenum);
1102 value = proto_spec(arg);
1103 if (value == SSH_PROTO_UNKNOWN)
1104 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001105 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001106 if (*intptr == SSH_PROTO_UNKNOWN)
1107 *intptr = value;
1108 break;
1109
1110 case sSubsystem:
1111 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1112 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001113 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001114 }
1115 arg = strdelim(&cp);
1116 if (!arg || *arg == '\0')
1117 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001118 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001119 if (!*activep) {
1120 arg = strdelim(&cp);
1121 break;
1122 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001123 for (i = 0; i < options->num_subsystems; i++)
1124 if (strcmp(arg, options->subsystem_name[i]) == 0)
1125 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001126 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001127 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1128 arg = strdelim(&cp);
1129 if (!arg || *arg == '\0')
1130 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001131 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001132 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001133
1134 /* Collect arguments (separate to executable) */
1135 p = xstrdup(arg);
1136 len = strlen(p) + 1;
1137 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1138 len += 1 + strlen(arg);
1139 p = xrealloc(p, 1, len);
1140 strlcat(p, " ", len);
1141 strlcat(p, arg, len);
1142 }
1143 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001144 options->num_subsystems++;
1145 break;
1146
1147 case sMaxStartups:
1148 arg = strdelim(&cp);
1149 if (!arg || *arg == '\0')
1150 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001151 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001152 if ((n = sscanf(arg, "%d:%d:%d",
1153 &options->max_startups_begin,
1154 &options->max_startups_rate,
1155 &options->max_startups)) == 3) {
1156 if (options->max_startups_begin >
1157 options->max_startups ||
1158 options->max_startups_rate > 100 ||
1159 options->max_startups_rate < 1)
1160 fatal("%s line %d: Illegal MaxStartups spec.",
1161 filename, linenum);
1162 } else if (n != 1)
1163 fatal("%s line %d: Illegal MaxStartups spec.",
1164 filename, linenum);
1165 else
1166 options->max_startups = options->max_startups_begin;
1167 break;
1168
Darren Tucker89413db2004-05-24 10:36:23 +10001169 case sMaxAuthTries:
1170 intptr = &options->max_authtries;
1171 goto parse_int;
1172
Damien Miller7207f642008-05-19 15:34:50 +10001173 case sMaxSessions:
1174 intptr = &options->max_sessions;
1175 goto parse_int;
1176
Ben Lindstromade03f62001-12-06 18:22:17 +00001177 case sBanner:
1178 charptr = &options->banner;
1179 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001180
Ben Lindstromade03f62001-12-06 18:22:17 +00001181 /*
1182 * These options can contain %X options expanded at
1183 * connect time, so that you can specify paths like:
1184 *
1185 * AuthorizedKeysFile /etc/ssh_keys/%u
1186 */
1187 case sAuthorizedKeysFile:
1188 case sAuthorizedKeysFile2:
Damien Miller4dec5d72006-08-05 11:38:40 +10001189 charptr = (opcode == sAuthorizedKeysFile) ?
Ben Lindstromade03f62001-12-06 18:22:17 +00001190 &options->authorized_keys_file :
1191 &options->authorized_keys_file2;
1192 goto parse_filename;
1193
1194 case sClientAliveInterval:
1195 intptr = &options->client_alive_interval;
1196 goto parse_time;
1197
1198 case sClientAliveCountMax:
1199 intptr = &options->client_alive_count_max;
1200 goto parse_int;
1201
Darren Tucker46bc0752004-05-02 22:11:30 +10001202 case sAcceptEnv:
1203 while ((arg = strdelim(&cp)) && *arg != '\0') {
1204 if (strchr(arg, '=') != NULL)
1205 fatal("%s line %d: Invalid environment name.",
1206 filename, linenum);
1207 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1208 fatal("%s line %d: too many allow env.",
1209 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001210 if (!*activep)
1211 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001212 options->accept_env[options->num_accept_env++] =
1213 xstrdup(arg);
1214 }
1215 break;
1216
Damien Millerd27b9472005-12-13 19:29:02 +11001217 case sPermitTunnel:
1218 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001219 arg = strdelim(&cp);
1220 if (!arg || *arg == '\0')
1221 fatal("%s line %d: Missing yes/point-to-point/"
1222 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001223 value = -1;
1224 for (i = 0; tunmode_desc[i].val != -1; i++)
1225 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1226 value = tunmode_desc[i].val;
1227 break;
1228 }
1229 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001230 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1231 "no argument: %s", filename, linenum, arg);
1232 if (*intptr == -1)
1233 *intptr = value;
1234 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001235
Darren Tucker45150472006-07-12 22:34:17 +10001236 case sMatch:
1237 if (cmdline)
1238 fatal("Match directive not supported as a command-line "
1239 "option");
1240 value = match_cfg_line(&cp, linenum, user, host, address);
1241 if (value < 0)
1242 fatal("%s line %d: Bad Match condition", filename,
1243 linenum);
1244 *activep = value;
1245 break;
1246
Damien Miller9b439df2006-07-24 14:04:00 +10001247 case sPermitOpen:
1248 arg = strdelim(&cp);
1249 if (!arg || *arg == '\0')
1250 fatal("%s line %d: missing PermitOpen specification",
1251 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001252 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001253 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001254 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001255 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001256 options->num_permitted_opens = 0;
1257 }
Damien Miller9b439df2006-07-24 14:04:00 +10001258 break;
1259 }
Damien Millera29b95e2007-01-05 16:28:36 +11001260 if (*activep && n == -1)
1261 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001262 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1263 p = hpdelim(&arg);
1264 if (p == NULL)
1265 fatal("%s line %d: missing host in PermitOpen",
1266 filename, linenum);
1267 p = cleanhostname(p);
1268 if (arg == NULL || (port = a2port(arg)) == 0)
1269 fatal("%s line %d: bad port number in "
1270 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001271 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001272 options->num_permitted_opens =
1273 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001274 }
Damien Miller9b439df2006-07-24 14:04:00 +10001275 break;
1276
Damien Millere2754432006-07-24 14:06:47 +10001277 case sForceCommand:
1278 if (cp == NULL)
1279 fatal("%.200s line %d: Missing argument.", filename,
1280 linenum);
1281 len = strspn(cp, WHITESPACE);
1282 if (*activep && options->adm_forced_command == NULL)
1283 options->adm_forced_command = xstrdup(cp + len);
1284 return 0;
1285
Damien Millerd8cb1f12008-02-10 22:40:12 +11001286 case sChrootDirectory:
1287 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001288
1289 arg = strdelim(&cp);
1290 if (!arg || *arg == '\0')
1291 fatal("%s line %d: missing file name.",
1292 filename, linenum);
1293 if (*activep && *charptr == NULL)
1294 *charptr = xstrdup(arg);
1295 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001296
Ben Lindstromade03f62001-12-06 18:22:17 +00001297 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001298 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001299 filename, linenum, arg);
1300 while (arg)
1301 arg = strdelim(&cp);
1302 break;
1303
Damien Millerf9b3feb2003-05-16 11:38:32 +10001304 case sUnsupported:
1305 logit("%s line %d: Unsupported option %s",
1306 filename, linenum, arg);
1307 while (arg)
1308 arg = strdelim(&cp);
1309 break;
1310
Ben Lindstromade03f62001-12-06 18:22:17 +00001311 default:
1312 fatal("%s line %d: Missing handler for opcode %s (%d)",
1313 filename, linenum, arg, opcode);
1314 }
1315 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1316 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1317 filename, linenum, arg);
1318 return 0;
1319}
1320
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001321/* Reads the server configuration file. */
1322
Damien Miller4af51302000-04-16 11:18:38 +10001323void
Darren Tucker645ab752004-06-25 13:33:20 +10001324load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001325{
Darren Tucker645ab752004-06-25 13:33:20 +10001326 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001327 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001328
Darren Tucker645ab752004-06-25 13:33:20 +10001329 debug2("%s: filename %s", __func__, filename);
1330 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001331 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001332 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001333 }
Darren Tucker645ab752004-06-25 13:33:20 +10001334 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001335 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001336 /*
1337 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001338 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001339 * line numbers later for error messages
1340 */
1341 if ((cp = strchr(line, '#')) != NULL)
1342 memcpy(cp, "\n", 2);
1343 cp = line + strspn(line, " \t\r");
1344
1345 buffer_append(conf, cp, strlen(cp));
1346 }
1347 buffer_append(conf, "\0", 1);
1348 fclose(f);
1349 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1350}
1351
1352void
Darren Tucker45150472006-07-12 22:34:17 +10001353parse_server_match_config(ServerOptions *options, const char *user,
1354 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001355{
Darren Tucker45150472006-07-12 22:34:17 +10001356 ServerOptions mo;
1357
1358 initialize_server_options(&mo);
1359 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
Darren Tucker1629c072007-02-19 22:25:37 +11001360 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001361}
1362
Darren Tucker1629c072007-02-19 22:25:37 +11001363/* Helper macros */
1364#define M_CP_INTOPT(n) do {\
1365 if (src->n != -1) \
1366 dst->n = src->n; \
1367} while (0)
1368#define M_CP_STROPT(n) do {\
1369 if (src->n != NULL) { \
1370 if (dst->n != NULL) \
1371 xfree(dst->n); \
1372 dst->n = src->n; \
1373 } \
1374} while(0)
1375
1376/*
1377 * Copy any supported values that are set.
1378 *
1379 * If the preauth flag is set, we do not bother copying the the string or
1380 * array values that are not used pre-authentication, because any that we
1381 * do use must be explictly sent in mm_getpwnamallow().
1382 */
Darren Tucker45150472006-07-12 22:34:17 +10001383void
Darren Tucker1629c072007-02-19 22:25:37 +11001384copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001385{
Darren Tucker1629c072007-02-19 22:25:37 +11001386 M_CP_INTOPT(password_authentication);
1387 M_CP_INTOPT(gss_authentication);
1388 M_CP_INTOPT(rsa_authentication);
1389 M_CP_INTOPT(pubkey_authentication);
1390 M_CP_INTOPT(kerberos_authentication);
1391 M_CP_INTOPT(hostbased_authentication);
1392 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001393 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001394 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001395 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001396
1397 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001398 M_CP_INTOPT(allow_agent_forwarding);
Darren Tucker1629c072007-02-19 22:25:37 +11001399 M_CP_INTOPT(gateway_ports);
1400 M_CP_INTOPT(x11_display_offset);
1401 M_CP_INTOPT(x11_forwarding);
1402 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001403 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001404 M_CP_INTOPT(max_authtries);
Darren Tucker1629c072007-02-19 22:25:37 +11001405
1406 M_CP_STROPT(banner);
1407 if (preauth)
1408 return;
1409 M_CP_STROPT(adm_forced_command);
Damien Millerd8cb1f12008-02-10 22:40:12 +11001410 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001411}
1412
Darren Tucker1629c072007-02-19 22:25:37 +11001413#undef M_CP_INTOPT
1414#undef M_CP_STROPT
1415
Darren Tucker45150472006-07-12 22:34:17 +10001416void
1417parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1418 const char *user, const char *host, const char *address)
1419{
1420 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001421 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001422
1423 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1424
Darren Tucker9fbac712004-08-12 22:41:44 +10001425 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001426 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001427 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001428 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001429 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001430 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001431 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001432 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001433 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001434 if (bad_options > 0)
1435 fatal("%s: terminating, %d bad configuration options",
1436 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001437}
Darren Tuckere7140f22008-06-10 23:01:51 +10001438
1439static const char *
1440fmt_intarg(ServerOpCodes code, int val)
1441{
1442 if (code == sAddressFamily) {
1443 switch (val) {
1444 case AF_INET:
1445 return "inet";
1446 case AF_INET6:
1447 return "inet6";
1448 case AF_UNSPEC:
1449 return "any";
1450 default:
1451 return "UNKNOWN";
1452 }
1453 }
1454 if (code == sPermitRootLogin) {
1455 switch (val) {
1456 case PERMIT_NO_PASSWD:
Darren Tuckerff4350e2008-11-11 16:31:05 +11001457 return "without-password";
Darren Tuckere7140f22008-06-10 23:01:51 +10001458 case PERMIT_FORCED_ONLY:
1459 return "forced-commands-only";
1460 case PERMIT_YES:
1461 return "yes";
1462 }
1463 }
1464 if (code == sProtocol) {
1465 switch (val) {
1466 case SSH_PROTO_1:
1467 return "1";
1468 case SSH_PROTO_2:
1469 return "2";
1470 case (SSH_PROTO_1|SSH_PROTO_2):
1471 return "2,1";
1472 default:
1473 return "UNKNOWN";
1474 }
1475 }
1476 if (code == sGatewayPorts && val == 2)
1477 return "clientspecified";
1478 if (code == sCompression && val == COMP_DELAYED)
1479 return "delayed";
1480 switch (val) {
1481 case -1:
1482 return "unset";
1483 case 0:
1484 return "no";
1485 case 1:
1486 return "yes";
1487 }
1488 return "UNKNOWN";
1489}
1490
1491static const char *
1492lookup_opcode_name(ServerOpCodes code)
1493{
1494 u_int i;
1495
1496 for (i = 0; keywords[i].name != NULL; i++)
1497 if (keywords[i].opcode == code)
1498 return(keywords[i].name);
1499 return "UNKNOWN";
1500}
1501
1502static void
1503dump_cfg_int(ServerOpCodes code, int val)
1504{
1505 printf("%s %d\n", lookup_opcode_name(code), val);
1506}
1507
1508static void
1509dump_cfg_fmtint(ServerOpCodes code, int val)
1510{
1511 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1512}
1513
1514static void
1515dump_cfg_string(ServerOpCodes code, const char *val)
1516{
1517 if (val == NULL)
1518 return;
1519 printf("%s %s\n", lookup_opcode_name(code), val);
1520}
1521
1522static void
1523dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1524{
1525 u_int i;
1526
1527 for (i = 0; i < count; i++)
1528 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1529}
1530
1531void
1532dump_config(ServerOptions *o)
1533{
1534 u_int i;
1535 int ret;
1536 struct addrinfo *ai;
1537 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1538
1539 /* these are usually at the top of the config */
1540 for (i = 0; i < o->num_ports; i++)
1541 printf("port %d\n", o->ports[i]);
1542 dump_cfg_fmtint(sProtocol, o->protocol);
1543 dump_cfg_fmtint(sAddressFamily, o->address_family);
1544
1545 /* ListenAddress must be after Port */
1546 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1547 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1548 sizeof(addr), port, sizeof(port),
1549 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1550 error("getnameinfo failed: %.100s",
1551 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1552 strerror(errno));
1553 } else {
1554 if (ai->ai_family == AF_INET6)
1555 printf("listenaddress [%s]:%s\n", addr, port);
1556 else
1557 printf("listenaddress %s:%s\n", addr, port);
1558 }
1559 }
1560
1561 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001562#ifdef USE_PAM
1563 dump_cfg_int(sUsePAM, o->use_pam);
1564#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001565 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1566 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1567 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1568 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1569 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001570 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001571 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1572 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1573
1574 /* formatted integer arguments */
1575 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1576 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1577 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1578 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1579 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1580 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1581 o->hostbased_uses_name_from_packet_only);
1582 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1583 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001584#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001585 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1586 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1587 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001588# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001589 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001590# endif
1591#endif
1592#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001593 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1594 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001595#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001596#ifdef JPAKE
1597 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1598 o->zero_knowledge_password_authentication);
1599#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001600 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1601 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1602 o->kbd_interactive_authentication);
1603 dump_cfg_fmtint(sChallengeResponseAuthentication,
1604 o->challenge_response_authentication);
1605 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1606 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1607 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1608 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1609 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1610 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1611 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1612 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1613 dump_cfg_fmtint(sUseLogin, o->use_login);
1614 dump_cfg_fmtint(sCompression, o->compression);
1615 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1616 dump_cfg_fmtint(sUseDNS, o->use_dns);
1617 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1618 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1619
1620 /* string arguments */
1621 dump_cfg_string(sPidFile, o->pid_file);
1622 dump_cfg_string(sXAuthLocation, o->xauth_location);
1623 dump_cfg_string(sCiphers, o->ciphers);
1624 dump_cfg_string(sMacs, o->macs);
1625 dump_cfg_string(sBanner, o->banner);
1626 dump_cfg_string(sAuthorizedKeysFile, o->authorized_keys_file);
1627 dump_cfg_string(sAuthorizedKeysFile2, o->authorized_keys_file2);
1628 dump_cfg_string(sForceCommand, o->adm_forced_command);
1629
1630 /* string arguments requiring a lookup */
1631 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1632 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1633
1634 /* string array arguments */
1635 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1636 o->host_key_files);
1637 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1638 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1639 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1640 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1641 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1642
1643 /* other arguments */
1644 for (i = 0; i < o->num_subsystems; i++)
1645 printf("subsystem %s %s\n", o->subsystem_name[i],
1646 o->subsystem_args[i]);
1647
1648 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1649 o->max_startups_rate, o->max_startups);
1650
1651 for (i = 0; tunmode_desc[i].val != -1; i++)
1652 if (tunmode_desc[i].val == o->permit_tun) {
1653 s = tunmode_desc[i].text;
1654 break;
1655 }
1656 dump_cfg_string(sPermitTunnel, s);
1657
1658 printf("permitopen");
1659 channel_print_adm_permitted_opens();
1660 printf("\n");
1661}