blob: 09296c9cfa3a0a4456833374ceeb33b0d58f2aaf [file] [log] [blame]
Darren Tucker88b6fb22010-01-13 22:44:29 +11001/* $OpenBSD: servconf.c,v 1.202 2010/01/13 03:48:12 djm 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
Damien Miller3dc71ad2009-01-28 16:31:22 +110045static void add_listen_addr(ServerOptions *, char *, int);
46static void add_one_listen_addr(ServerOptions *, char *, int);
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)
Darren Tuckerbad50762009-10-11 21:51:08 +1100142 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100143 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,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100307 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 Tucker64cee362009-06-21 20:26: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 },
Darren Tucker64cee362009-06-21 20:26:17 +1000420 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Darren Tucker45150472006-07-12 22:34:17 +1000421 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
422 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000423 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000424 { "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
Darren Tucker88b6fb22010-01-13 22:44:29 +1100462char *
463derelativise_path(const char *path)
464{
465 char *expanded, *ret, *cwd;
466
467 expanded = tilde_expand_filename(path, getuid());
468 if (*expanded == '/')
469 return expanded;
470 if ((cwd = getcwd(NULL, 0)) == NULL)
471 fatal("%s: getcwd: %s", __func__, strerror(errno));
472 xasprintf(&ret, "%s/%s", cwd, expanded);
473 xfree(cwd);
474 xfree(expanded);
475 return ret;
476}
477
Ben Lindstrombba81212001-06-25 05:01:22 +0000478static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100479add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100480{
Damien Millereccb9de2005-06-17 12:59:34 +1000481 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100482
483 if (options->num_ports == 0)
484 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100485 if (options->address_family == -1)
486 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000487 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000488 for (i = 0; i < options->num_ports; i++)
489 add_one_listen_addr(options, addr, options->ports[i]);
490 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000491 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000492}
493
Ben Lindstrombba81212001-06-25 05:01:22 +0000494static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100495add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000496{
497 struct addrinfo hints, *ai, *aitop;
498 char strport[NI_MAXSERV];
499 int gaierr;
500
501 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100502 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000503 hints.ai_socktype = SOCK_STREAM;
504 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100505 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000506 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
507 fatal("bad addr or host: %s (%s)",
508 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100509 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000510 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
511 ;
512 ai->ai_next = options->listen_addrs;
513 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100514}
515
Darren Tucker45150472006-07-12 22:34:17 +1000516/*
517 * The strategy for the Match blocks is that the config file is parsed twice.
518 *
519 * The first time is at startup. activep is initialized to 1 and the
520 * directives in the global context are processed and acted on. Hitting a
521 * Match directive unsets activep and the directives inside the block are
522 * checked for syntax only.
523 *
524 * The second time is after a connection has been established but before
525 * authentication. activep is initialized to 2 and global config directives
526 * are ignored since they have already been processed. If the criteria in a
527 * Match block is met, activep is set and the subsequent directives
528 * processed and actioned until EOF or another Match block unsets it. Any
529 * options set are copied into the main server config.
530 *
531 * Potential additions/improvements:
532 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
533 *
534 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
535 * Match Address 192.168.0.*
536 * Tag trusted
537 * Match Group wheel
538 * Tag trusted
539 * Match Tag trusted
540 * AllowTcpForwarding yes
541 * GatewayPorts clientspecified
542 * [...]
543 *
544 * - Add a PermittedChannelRequests directive
545 * Match Group shell
546 * PermittedChannelRequests session,forwarded-tcpip
547 */
548
549static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000550match_cfg_line_group(const char *grps, int line, const char *user)
551{
552 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000553 struct passwd *pw;
554
Damien Miller565ca3f2006-08-19 00:23:15 +1000555 if (user == NULL)
556 goto out;
557
558 if ((pw = getpwnam(user)) == NULL) {
559 debug("Can't match group at line %d because user %.100s does "
560 "not exist", line, user);
561 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
562 debug("Can't Match group because user %.100s not in any group "
563 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000564 } else if (ga_match_pattern_list(grps) != 1) {
565 debug("user %.100s does not match group list %.100s at line %d",
566 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000567 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000568 debug("user %.100s matched group list %.100s at line %d", user,
569 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000570 result = 1;
571 }
572out:
573 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000574 return result;
575}
576
577static int
Darren Tucker45150472006-07-12 22:34:17 +1000578match_cfg_line(char **condition, int line, const char *user, const char *host,
579 const char *address)
580{
581 int result = 1;
582 char *arg, *attrib, *cp = *condition;
583 size_t len;
584
585 if (user == NULL)
586 debug3("checking syntax for 'Match %s'", cp);
587 else
588 debug3("checking match for '%s' user %s host %s addr %s", cp,
589 user ? user : "(null)", host ? host : "(null)",
590 address ? address : "(null)");
591
592 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
593 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
594 error("Missing Match criteria for %s", attrib);
595 return -1;
596 }
597 len = strlen(arg);
598 if (strcasecmp(attrib, "user") == 0) {
599 if (!user) {
600 result = 0;
601 continue;
602 }
603 if (match_pattern_list(user, arg, len, 0) != 1)
604 result = 0;
605 else
606 debug("user %.100s matched 'User %.100s' at "
607 "line %d", user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000608 } else if (strcasecmp(attrib, "group") == 0) {
609 switch (match_cfg_line_group(arg, line, user)) {
610 case -1:
611 return -1;
612 case 0:
613 result = 0;
614 }
Darren Tucker45150472006-07-12 22:34:17 +1000615 } else if (strcasecmp(attrib, "host") == 0) {
616 if (!host) {
617 result = 0;
618 continue;
619 }
620 if (match_hostname(host, arg, len) != 1)
621 result = 0;
622 else
623 debug("connection from %.100s matched 'Host "
624 "%.100s' at line %d", host, arg, line);
625 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000626 switch (addr_match_list(address, arg)) {
627 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000628 debug("connection from %.100s matched 'Address "
629 "%.100s' at line %d", address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000630 break;
631 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000632 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000633 result = 0;
634 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000635 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000636 return -1;
637 }
Darren Tucker45150472006-07-12 22:34:17 +1000638 } else {
639 error("Unsupported Match attribute %s", attrib);
640 return -1;
641 }
642 }
643 if (user != NULL)
644 debug3("match %sfound", result ? "" : "not ");
645 *condition = cp;
646 return result;
647}
648
Damien Millere2754432006-07-24 14:06:47 +1000649#define WHITESPACE " \t\r\n"
650
Ben Lindstromade03f62001-12-06 18:22:17 +0000651int
652process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000653 const char *filename, int linenum, int *activep, const char *user,
654 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000655{
656 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000657 int cmdline = 0, *intptr, value, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100658 SyslogFacility *log_facility_ptr;
659 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000660 ServerOpCodes opcode;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100661 int port;
Darren Tucker45150472006-07-12 22:34:17 +1000662 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000663 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000664
665 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100666 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100667 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000668 /* Ignore leading whitespace */
669 if (*arg == '\0')
670 arg = strdelim(&cp);
671 if (!arg || !*arg || *arg == '#')
672 return 0;
673 intptr = NULL;
674 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000675 opcode = parse_token(arg, filename, linenum, &flags);
676
677 if (activep == NULL) { /* We are processing a command line directive */
678 cmdline = 1;
679 activep = &cmdline;
680 }
681 if (*activep && opcode != sMatch)
682 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
683 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
684 if (user == NULL) {
685 fatal("%s line %d: Directive '%s' is not allowed "
686 "within a Match block", filename, linenum, arg);
687 } else { /* this is a directive we have already processed */
688 while (arg)
689 arg = strdelim(&cp);
690 return 0;
691 }
692 }
693
Ben Lindstromade03f62001-12-06 18:22:17 +0000694 switch (opcode) {
695 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000696 case sUsePAM:
697 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000698 goto parse_flag;
699
700 /* Standard Options */
701 case sBadOption:
702 return -1;
703 case sPort:
704 /* ignore ports from configfile if cmdline specifies ports */
705 if (options->ports_from_cmdline)
706 return 0;
707 if (options->listen_addrs != NULL)
708 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100709 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000710 if (options->num_ports >= MAX_PORTS)
711 fatal("%s line %d: too many ports.",
712 filename, linenum);
713 arg = strdelim(&cp);
714 if (!arg || *arg == '\0')
715 fatal("%s line %d: missing port number.",
716 filename, linenum);
717 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100718 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000719 fatal("%s line %d: Badly formatted port number.",
720 filename, linenum);
721 break;
722
723 case sServerKeyBits:
724 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000725 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000726 arg = strdelim(&cp);
727 if (!arg || *arg == '\0')
728 fatal("%s line %d: missing integer value.",
729 filename, linenum);
730 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000731 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000732 *intptr = value;
733 break;
734
735 case sLoginGraceTime:
736 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000737 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000738 arg = strdelim(&cp);
739 if (!arg || *arg == '\0')
740 fatal("%s line %d: missing time value.",
741 filename, linenum);
742 if ((value = convtime(arg)) == -1)
743 fatal("%s line %d: invalid time value.",
744 filename, linenum);
745 if (*intptr == -1)
746 *intptr = value;
747 break;
748
749 case sKeyRegenerationTime:
750 intptr = &options->key_regeneration_time;
751 goto parse_time;
752
753 case sListenAddress:
754 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100755 if (arg == NULL || *arg == '\0')
756 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000757 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000758 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
759 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
760 && strchr(p+1, ':') != NULL) {
761 add_listen_addr(options, arg, 0);
762 break;
763 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100764 p = hpdelim(&arg);
765 if (p == NULL)
766 fatal("%s line %d: bad address:port usage",
767 filename, linenum);
768 p = cleanhostname(p);
769 if (arg == NULL)
770 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100771 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100772 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000773
Damien Millerf91ee4c2005-03-01 21:24:33 +1100774 add_listen_addr(options, p, port);
775
Ben Lindstromade03f62001-12-06 18:22:17 +0000776 break;
777
Darren Tucker0f383232005-01-20 10:57:56 +1100778 case sAddressFamily:
779 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000780 if (!arg || *arg == '\0')
781 fatal("%s line %d: missing address family.",
782 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100783 intptr = &options->address_family;
784 if (options->listen_addrs != NULL)
785 fatal("%s line %d: address family must be specified before "
786 "ListenAddress.", filename, linenum);
787 if (strcasecmp(arg, "inet") == 0)
788 value = AF_INET;
789 else if (strcasecmp(arg, "inet6") == 0)
790 value = AF_INET6;
791 else if (strcasecmp(arg, "any") == 0)
792 value = AF_UNSPEC;
793 else
794 fatal("%s line %d: unsupported address family \"%s\".",
795 filename, linenum, arg);
796 if (*intptr == -1)
797 *intptr = value;
798 break;
799
Ben Lindstromade03f62001-12-06 18:22:17 +0000800 case sHostKeyFile:
801 intptr = &options->num_host_key_files;
802 if (*intptr >= MAX_HOSTKEYS)
803 fatal("%s line %d: too many host keys specified (max %d).",
804 filename, linenum, MAX_HOSTKEYS);
805 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000806 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000807 arg = strdelim(&cp);
808 if (!arg || *arg == '\0')
809 fatal("%s line %d: missing file name.",
810 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000811 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100812 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000813 /* increase optional counter */
814 if (intptr != NULL)
815 *intptr = *intptr + 1;
816 }
817 break;
818
819 case sPidFile:
820 charptr = &options->pid_file;
821 goto parse_filename;
822
823 case sPermitRootLogin:
824 intptr = &options->permit_root_login;
825 arg = strdelim(&cp);
826 if (!arg || *arg == '\0')
827 fatal("%s line %d: missing yes/"
828 "without-password/forced-commands-only/no "
829 "argument.", filename, linenum);
830 value = 0; /* silence compiler */
831 if (strcmp(arg, "without-password") == 0)
832 value = PERMIT_NO_PASSWD;
833 else if (strcmp(arg, "forced-commands-only") == 0)
834 value = PERMIT_FORCED_ONLY;
835 else if (strcmp(arg, "yes") == 0)
836 value = PERMIT_YES;
837 else if (strcmp(arg, "no") == 0)
838 value = PERMIT_NO;
839 else
840 fatal("%s line %d: Bad yes/"
841 "without-password/forced-commands-only/no "
842 "argument: %s", filename, linenum, arg);
Darren Tucker15f94272008-01-01 20:36:56 +1100843 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000844 *intptr = value;
845 break;
846
847 case sIgnoreRhosts:
848 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000849 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000850 arg = strdelim(&cp);
851 if (!arg || *arg == '\0')
852 fatal("%s line %d: missing yes/no argument.",
853 filename, linenum);
854 value = 0; /* silence compiler */
855 if (strcmp(arg, "yes") == 0)
856 value = 1;
857 else if (strcmp(arg, "no") == 0)
858 value = 0;
859 else
860 fatal("%s line %d: Bad yes/no argument: %s",
861 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000862 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000863 *intptr = value;
864 break;
865
866 case sIgnoreUserKnownHosts:
867 intptr = &options->ignore_user_known_hosts;
868 goto parse_flag;
869
Ben Lindstromade03f62001-12-06 18:22:17 +0000870 case sRhostsRSAAuthentication:
871 intptr = &options->rhosts_rsa_authentication;
872 goto parse_flag;
873
874 case sHostbasedAuthentication:
875 intptr = &options->hostbased_authentication;
876 goto parse_flag;
877
878 case sHostbasedUsesNameFromPacketOnly:
879 intptr = &options->hostbased_uses_name_from_packet_only;
880 goto parse_flag;
881
882 case sRSAAuthentication:
883 intptr = &options->rsa_authentication;
884 goto parse_flag;
885
886 case sPubkeyAuthentication:
887 intptr = &options->pubkey_authentication;
888 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000889
Ben Lindstromade03f62001-12-06 18:22:17 +0000890 case sKerberosAuthentication:
891 intptr = &options->kerberos_authentication;
892 goto parse_flag;
893
894 case sKerberosOrLocalPasswd:
895 intptr = &options->kerberos_or_local_passwd;
896 goto parse_flag;
897
898 case sKerberosTicketCleanup:
899 intptr = &options->kerberos_ticket_cleanup;
900 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000901
Darren Tucker22ef5082003-12-31 11:37:34 +1100902 case sKerberosGetAFSToken:
903 intptr = &options->kerberos_get_afs_token;
904 goto parse_flag;
905
Darren Tucker0efd1552003-08-26 11:49:55 +1000906 case sGssAuthentication:
907 intptr = &options->gss_authentication;
908 goto parse_flag;
909
910 case sGssCleanupCreds:
911 intptr = &options->gss_cleanup_creds;
912 goto parse_flag;
913
Ben Lindstromade03f62001-12-06 18:22:17 +0000914 case sPasswordAuthentication:
915 intptr = &options->password_authentication;
916 goto parse_flag;
917
Damien Miller01ed2272008-11-05 16:20:46 +1100918 case sZeroKnowledgePasswordAuthentication:
919 intptr = &options->zero_knowledge_password_authentication;
920 goto parse_flag;
921
Ben Lindstromade03f62001-12-06 18:22:17 +0000922 case sKbdInteractiveAuthentication:
923 intptr = &options->kbd_interactive_authentication;
924 goto parse_flag;
925
926 case sChallengeResponseAuthentication:
927 intptr = &options->challenge_response_authentication;
928 goto parse_flag;
929
930 case sPrintMotd:
931 intptr = &options->print_motd;
932 goto parse_flag;
933
934 case sPrintLastLog:
935 intptr = &options->print_lastlog;
936 goto parse_flag;
937
938 case sX11Forwarding:
939 intptr = &options->x11_forwarding;
940 goto parse_flag;
941
942 case sX11DisplayOffset:
943 intptr = &options->x11_display_offset;
944 goto parse_int;
945
Damien Miller95c249f2002-02-05 12:11:34 +1100946 case sX11UseLocalhost:
947 intptr = &options->x11_use_localhost;
948 goto parse_flag;
949
Ben Lindstromade03f62001-12-06 18:22:17 +0000950 case sXAuthLocation:
951 charptr = &options->xauth_location;
952 goto parse_filename;
953
954 case sStrictModes:
955 intptr = &options->strict_modes;
956 goto parse_flag;
957
Damien Miller12c150e2003-12-17 16:31:10 +1100958 case sTCPKeepAlive:
959 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000960 goto parse_flag;
961
962 case sEmptyPasswd:
963 intptr = &options->permit_empty_passwd;
964 goto parse_flag;
965
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000966 case sPermitUserEnvironment:
967 intptr = &options->permit_user_env;
968 goto parse_flag;
969
Ben Lindstromade03f62001-12-06 18:22:17 +0000970 case sUseLogin:
971 intptr = &options->use_login;
972 goto parse_flag;
973
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000974 case sCompression:
975 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000976 arg = strdelim(&cp);
977 if (!arg || *arg == '\0')
978 fatal("%s line %d: missing yes/no/delayed "
979 "argument.", filename, linenum);
980 value = 0; /* silence compiler */
981 if (strcmp(arg, "delayed") == 0)
982 value = COMP_DELAYED;
983 else if (strcmp(arg, "yes") == 0)
984 value = COMP_ZLIB;
985 else if (strcmp(arg, "no") == 0)
986 value = COMP_NONE;
987 else
988 fatal("%s line %d: Bad yes/no/delayed "
989 "argument: %s", filename, linenum, arg);
990 if (*intptr == -1)
991 *intptr = value;
992 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000993
Ben Lindstromade03f62001-12-06 18:22:17 +0000994 case sGatewayPorts:
995 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100996 arg = strdelim(&cp);
997 if (!arg || *arg == '\0')
998 fatal("%s line %d: missing yes/no/clientspecified "
999 "argument.", filename, linenum);
1000 value = 0; /* silence compiler */
1001 if (strcmp(arg, "clientspecified") == 0)
1002 value = 2;
1003 else if (strcmp(arg, "yes") == 0)
1004 value = 1;
1005 else if (strcmp(arg, "no") == 0)
1006 value = 0;
1007 else
1008 fatal("%s line %d: Bad yes/no/clientspecified "
1009 "argument: %s", filename, linenum, arg);
Darren Tucker82347a82007-02-25 20:37:52 +11001010 if (*activep && *intptr == -1)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001011 *intptr = value;
1012 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001013
Damien Miller3a961dc2003-06-03 10:25:48 +10001014 case sUseDNS:
1015 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001016 goto parse_flag;
1017
1018 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001019 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001020 arg = strdelim(&cp);
1021 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001022 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001023 fatal("%.200s line %d: unsupported log facility '%s'",
1024 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001025 if (*log_facility_ptr == -1)
1026 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001027 break;
1028
1029 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001030 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001031 arg = strdelim(&cp);
1032 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001033 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001034 fatal("%.200s line %d: unsupported log level '%s'",
1035 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001036 if (*log_level_ptr == -1)
1037 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 break;
1039
1040 case sAllowTcpForwarding:
1041 intptr = &options->allow_tcp_forwarding;
1042 goto parse_flag;
1043
Damien Miller4f755cd2008-05-19 14:57:41 +10001044 case sAllowAgentForwarding:
1045 intptr = &options->allow_agent_forwarding;
1046 goto parse_flag;
1047
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001048 case sUsePrivilegeSeparation:
1049 intptr = &use_privsep;
1050 goto parse_flag;
1051
Ben Lindstromade03f62001-12-06 18:22:17 +00001052 case sAllowUsers:
1053 while ((arg = strdelim(&cp)) && *arg != '\0') {
1054 if (options->num_allow_users >= MAX_ALLOW_USERS)
1055 fatal("%s line %d: too many allow users.",
1056 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001057 options->allow_users[options->num_allow_users++] =
1058 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001059 }
1060 break;
1061
1062 case sDenyUsers:
1063 while ((arg = strdelim(&cp)) && *arg != '\0') {
1064 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001065 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001066 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001067 options->deny_users[options->num_deny_users++] =
1068 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001069 }
1070 break;
1071
1072 case sAllowGroups:
1073 while ((arg = strdelim(&cp)) && *arg != '\0') {
1074 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1075 fatal("%s line %d: too many allow groups.",
1076 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001077 options->allow_groups[options->num_allow_groups++] =
1078 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001079 }
1080 break;
1081
1082 case sDenyGroups:
1083 while ((arg = strdelim(&cp)) && *arg != '\0') {
1084 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1085 fatal("%s line %d: too many deny groups.",
1086 filename, linenum);
1087 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1088 }
1089 break;
1090
1091 case sCiphers:
1092 arg = strdelim(&cp);
1093 if (!arg || *arg == '\0')
1094 fatal("%s line %d: Missing argument.", filename, linenum);
1095 if (!ciphers_valid(arg))
1096 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1097 filename, linenum, arg ? arg : "<NONE>");
1098 if (options->ciphers == NULL)
1099 options->ciphers = xstrdup(arg);
1100 break;
1101
1102 case sMacs:
1103 arg = strdelim(&cp);
1104 if (!arg || *arg == '\0')
1105 fatal("%s line %d: Missing argument.", filename, linenum);
1106 if (!mac_valid(arg))
1107 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1108 filename, linenum, arg ? arg : "<NONE>");
1109 if (options->macs == NULL)
1110 options->macs = xstrdup(arg);
1111 break;
1112
1113 case sProtocol:
1114 intptr = &options->protocol;
1115 arg = strdelim(&cp);
1116 if (!arg || *arg == '\0')
1117 fatal("%s line %d: Missing argument.", filename, linenum);
1118 value = proto_spec(arg);
1119 if (value == SSH_PROTO_UNKNOWN)
1120 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001121 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001122 if (*intptr == SSH_PROTO_UNKNOWN)
1123 *intptr = value;
1124 break;
1125
1126 case sSubsystem:
1127 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1128 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001129 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001130 }
1131 arg = strdelim(&cp);
1132 if (!arg || *arg == '\0')
1133 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001134 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001135 if (!*activep) {
1136 arg = strdelim(&cp);
1137 break;
1138 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001139 for (i = 0; i < options->num_subsystems; i++)
1140 if (strcmp(arg, options->subsystem_name[i]) == 0)
1141 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001142 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001143 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1144 arg = strdelim(&cp);
1145 if (!arg || *arg == '\0')
1146 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001147 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001148 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001149
1150 /* Collect arguments (separate to executable) */
1151 p = xstrdup(arg);
1152 len = strlen(p) + 1;
1153 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1154 len += 1 + strlen(arg);
1155 p = xrealloc(p, 1, len);
1156 strlcat(p, " ", len);
1157 strlcat(p, arg, len);
1158 }
1159 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001160 options->num_subsystems++;
1161 break;
1162
1163 case sMaxStartups:
1164 arg = strdelim(&cp);
1165 if (!arg || *arg == '\0')
1166 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001167 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001168 if ((n = sscanf(arg, "%d:%d:%d",
1169 &options->max_startups_begin,
1170 &options->max_startups_rate,
1171 &options->max_startups)) == 3) {
1172 if (options->max_startups_begin >
1173 options->max_startups ||
1174 options->max_startups_rate > 100 ||
1175 options->max_startups_rate < 1)
1176 fatal("%s line %d: Illegal MaxStartups spec.",
1177 filename, linenum);
1178 } else if (n != 1)
1179 fatal("%s line %d: Illegal MaxStartups spec.",
1180 filename, linenum);
1181 else
1182 options->max_startups = options->max_startups_begin;
1183 break;
1184
Darren Tucker89413db2004-05-24 10:36:23 +10001185 case sMaxAuthTries:
1186 intptr = &options->max_authtries;
1187 goto parse_int;
1188
Damien Miller7207f642008-05-19 15:34:50 +10001189 case sMaxSessions:
1190 intptr = &options->max_sessions;
1191 goto parse_int;
1192
Ben Lindstromade03f62001-12-06 18:22:17 +00001193 case sBanner:
1194 charptr = &options->banner;
1195 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001196
Ben Lindstromade03f62001-12-06 18:22:17 +00001197 /*
1198 * These options can contain %X options expanded at
1199 * connect time, so that you can specify paths like:
1200 *
1201 * AuthorizedKeysFile /etc/ssh_keys/%u
1202 */
1203 case sAuthorizedKeysFile:
1204 case sAuthorizedKeysFile2:
Damien Miller4dec5d72006-08-05 11:38:40 +10001205 charptr = (opcode == sAuthorizedKeysFile) ?
Ben Lindstromade03f62001-12-06 18:22:17 +00001206 &options->authorized_keys_file :
1207 &options->authorized_keys_file2;
1208 goto parse_filename;
1209
1210 case sClientAliveInterval:
1211 intptr = &options->client_alive_interval;
1212 goto parse_time;
1213
1214 case sClientAliveCountMax:
1215 intptr = &options->client_alive_count_max;
1216 goto parse_int;
1217
Darren Tucker46bc0752004-05-02 22:11:30 +10001218 case sAcceptEnv:
1219 while ((arg = strdelim(&cp)) && *arg != '\0') {
1220 if (strchr(arg, '=') != NULL)
1221 fatal("%s line %d: Invalid environment name.",
1222 filename, linenum);
1223 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1224 fatal("%s line %d: too many allow env.",
1225 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001226 if (!*activep)
1227 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001228 options->accept_env[options->num_accept_env++] =
1229 xstrdup(arg);
1230 }
1231 break;
1232
Damien Millerd27b9472005-12-13 19:29:02 +11001233 case sPermitTunnel:
1234 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001235 arg = strdelim(&cp);
1236 if (!arg || *arg == '\0')
1237 fatal("%s line %d: Missing yes/point-to-point/"
1238 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001239 value = -1;
1240 for (i = 0; tunmode_desc[i].val != -1; i++)
1241 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1242 value = tunmode_desc[i].val;
1243 break;
1244 }
1245 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001246 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1247 "no argument: %s", filename, linenum, arg);
1248 if (*intptr == -1)
1249 *intptr = value;
1250 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001251
Darren Tucker45150472006-07-12 22:34:17 +10001252 case sMatch:
1253 if (cmdline)
1254 fatal("Match directive not supported as a command-line "
1255 "option");
1256 value = match_cfg_line(&cp, linenum, user, host, address);
1257 if (value < 0)
1258 fatal("%s line %d: Bad Match condition", filename,
1259 linenum);
1260 *activep = value;
1261 break;
1262
Damien Miller9b439df2006-07-24 14:04:00 +10001263 case sPermitOpen:
1264 arg = strdelim(&cp);
1265 if (!arg || *arg == '\0')
1266 fatal("%s line %d: missing PermitOpen specification",
1267 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001268 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001269 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001270 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001271 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001272 options->num_permitted_opens = 0;
1273 }
Damien Miller9b439df2006-07-24 14:04:00 +10001274 break;
1275 }
Damien Millera29b95e2007-01-05 16:28:36 +11001276 if (*activep && n == -1)
1277 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001278 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1279 p = hpdelim(&arg);
1280 if (p == NULL)
1281 fatal("%s line %d: missing host in PermitOpen",
1282 filename, linenum);
1283 p = cleanhostname(p);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001284 if (arg == NULL || (port = a2port(arg)) <= 0)
Damien Millera765cf42006-07-24 14:08:13 +10001285 fatal("%s line %d: bad port number in "
1286 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001287 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001288 options->num_permitted_opens =
1289 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001290 }
Damien Miller9b439df2006-07-24 14:04:00 +10001291 break;
1292
Damien Millere2754432006-07-24 14:06:47 +10001293 case sForceCommand:
1294 if (cp == NULL)
1295 fatal("%.200s line %d: Missing argument.", filename,
1296 linenum);
1297 len = strspn(cp, WHITESPACE);
1298 if (*activep && options->adm_forced_command == NULL)
1299 options->adm_forced_command = xstrdup(cp + len);
1300 return 0;
1301
Damien Millerd8cb1f12008-02-10 22:40:12 +11001302 case sChrootDirectory:
1303 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001304
1305 arg = strdelim(&cp);
1306 if (!arg || *arg == '\0')
1307 fatal("%s line %d: missing file name.",
1308 filename, linenum);
1309 if (*activep && *charptr == NULL)
1310 *charptr = xstrdup(arg);
1311 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001312
Ben Lindstromade03f62001-12-06 18:22:17 +00001313 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001314 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001315 filename, linenum, arg);
1316 while (arg)
1317 arg = strdelim(&cp);
1318 break;
1319
Damien Millerf9b3feb2003-05-16 11:38:32 +10001320 case sUnsupported:
1321 logit("%s line %d: Unsupported option %s",
1322 filename, linenum, arg);
1323 while (arg)
1324 arg = strdelim(&cp);
1325 break;
1326
Ben Lindstromade03f62001-12-06 18:22:17 +00001327 default:
1328 fatal("%s line %d: Missing handler for opcode %s (%d)",
1329 filename, linenum, arg, opcode);
1330 }
1331 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1332 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1333 filename, linenum, arg);
1334 return 0;
1335}
1336
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001337/* Reads the server configuration file. */
1338
Damien Miller4af51302000-04-16 11:18:38 +10001339void
Darren Tucker645ab752004-06-25 13:33:20 +10001340load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001341{
Darren Tucker645ab752004-06-25 13:33:20 +10001342 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001343 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001344
Darren Tucker645ab752004-06-25 13:33:20 +10001345 debug2("%s: filename %s", __func__, filename);
1346 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001347 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001348 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001349 }
Darren Tucker645ab752004-06-25 13:33:20 +10001350 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001351 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001352 /*
1353 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001354 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001355 * line numbers later for error messages
1356 */
1357 if ((cp = strchr(line, '#')) != NULL)
1358 memcpy(cp, "\n", 2);
1359 cp = line + strspn(line, " \t\r");
1360
1361 buffer_append(conf, cp, strlen(cp));
1362 }
1363 buffer_append(conf, "\0", 1);
1364 fclose(f);
1365 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1366}
1367
1368void
Darren Tucker45150472006-07-12 22:34:17 +10001369parse_server_match_config(ServerOptions *options, const char *user,
1370 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001371{
Darren Tucker45150472006-07-12 22:34:17 +10001372 ServerOptions mo;
1373
1374 initialize_server_options(&mo);
1375 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
Darren Tucker1629c072007-02-19 22:25:37 +11001376 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001377}
1378
Darren Tucker1629c072007-02-19 22:25:37 +11001379/* Helper macros */
1380#define M_CP_INTOPT(n) do {\
1381 if (src->n != -1) \
1382 dst->n = src->n; \
1383} while (0)
1384#define M_CP_STROPT(n) do {\
1385 if (src->n != NULL) { \
1386 if (dst->n != NULL) \
1387 xfree(dst->n); \
1388 dst->n = src->n; \
1389 } \
1390} while(0)
1391
1392/*
1393 * Copy any supported values that are set.
1394 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001395 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001396 * array values that are not used pre-authentication, because any that we
1397 * do use must be explictly sent in mm_getpwnamallow().
1398 */
Darren Tucker45150472006-07-12 22:34:17 +10001399void
Darren Tucker1629c072007-02-19 22:25:37 +11001400copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001401{
Darren Tucker1629c072007-02-19 22:25:37 +11001402 M_CP_INTOPT(password_authentication);
1403 M_CP_INTOPT(gss_authentication);
1404 M_CP_INTOPT(rsa_authentication);
1405 M_CP_INTOPT(pubkey_authentication);
1406 M_CP_INTOPT(kerberos_authentication);
1407 M_CP_INTOPT(hostbased_authentication);
1408 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001409 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001410 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001411 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001412
1413 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001414 M_CP_INTOPT(allow_agent_forwarding);
Darren Tucker1629c072007-02-19 22:25:37 +11001415 M_CP_INTOPT(gateway_ports);
1416 M_CP_INTOPT(x11_display_offset);
1417 M_CP_INTOPT(x11_forwarding);
1418 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001419 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001420 M_CP_INTOPT(max_authtries);
Darren Tucker1629c072007-02-19 22:25:37 +11001421
1422 M_CP_STROPT(banner);
1423 if (preauth)
1424 return;
1425 M_CP_STROPT(adm_forced_command);
Damien Millerd8cb1f12008-02-10 22:40:12 +11001426 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001427}
1428
Darren Tucker1629c072007-02-19 22:25:37 +11001429#undef M_CP_INTOPT
1430#undef M_CP_STROPT
1431
Darren Tucker45150472006-07-12 22:34:17 +10001432void
1433parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1434 const char *user, const char *host, const char *address)
1435{
1436 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001437 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001438
1439 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1440
Darren Tucker9fbac712004-08-12 22:41:44 +10001441 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001442 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001443 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001444 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001445 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001446 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001447 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001448 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001449 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001450 if (bad_options > 0)
1451 fatal("%s: terminating, %d bad configuration options",
1452 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001453}
Darren Tuckere7140f22008-06-10 23:01:51 +10001454
1455static const char *
1456fmt_intarg(ServerOpCodes code, int val)
1457{
1458 if (code == sAddressFamily) {
1459 switch (val) {
1460 case AF_INET:
1461 return "inet";
1462 case AF_INET6:
1463 return "inet6";
1464 case AF_UNSPEC:
1465 return "any";
1466 default:
1467 return "UNKNOWN";
1468 }
1469 }
1470 if (code == sPermitRootLogin) {
1471 switch (val) {
1472 case PERMIT_NO_PASSWD:
Darren Tuckerff4350e2008-11-11 16:31:05 +11001473 return "without-password";
Darren Tuckere7140f22008-06-10 23:01:51 +10001474 case PERMIT_FORCED_ONLY:
1475 return "forced-commands-only";
1476 case PERMIT_YES:
1477 return "yes";
1478 }
1479 }
1480 if (code == sProtocol) {
1481 switch (val) {
1482 case SSH_PROTO_1:
1483 return "1";
1484 case SSH_PROTO_2:
1485 return "2";
1486 case (SSH_PROTO_1|SSH_PROTO_2):
1487 return "2,1";
1488 default:
1489 return "UNKNOWN";
1490 }
1491 }
1492 if (code == sGatewayPorts && val == 2)
1493 return "clientspecified";
1494 if (code == sCompression && val == COMP_DELAYED)
1495 return "delayed";
1496 switch (val) {
1497 case -1:
1498 return "unset";
1499 case 0:
1500 return "no";
1501 case 1:
1502 return "yes";
1503 }
1504 return "UNKNOWN";
1505}
1506
1507static const char *
1508lookup_opcode_name(ServerOpCodes code)
1509{
1510 u_int i;
1511
1512 for (i = 0; keywords[i].name != NULL; i++)
1513 if (keywords[i].opcode == code)
1514 return(keywords[i].name);
1515 return "UNKNOWN";
1516}
1517
1518static void
1519dump_cfg_int(ServerOpCodes code, int val)
1520{
1521 printf("%s %d\n", lookup_opcode_name(code), val);
1522}
1523
1524static void
1525dump_cfg_fmtint(ServerOpCodes code, int val)
1526{
1527 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1528}
1529
1530static void
1531dump_cfg_string(ServerOpCodes code, const char *val)
1532{
1533 if (val == NULL)
1534 return;
1535 printf("%s %s\n", lookup_opcode_name(code), val);
1536}
1537
1538static void
1539dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1540{
1541 u_int i;
1542
1543 for (i = 0; i < count; i++)
1544 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1545}
1546
1547void
1548dump_config(ServerOptions *o)
1549{
1550 u_int i;
1551 int ret;
1552 struct addrinfo *ai;
1553 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1554
1555 /* these are usually at the top of the config */
1556 for (i = 0; i < o->num_ports; i++)
1557 printf("port %d\n", o->ports[i]);
1558 dump_cfg_fmtint(sProtocol, o->protocol);
1559 dump_cfg_fmtint(sAddressFamily, o->address_family);
1560
1561 /* ListenAddress must be after Port */
1562 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1563 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1564 sizeof(addr), port, sizeof(port),
1565 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1566 error("getnameinfo failed: %.100s",
1567 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1568 strerror(errno));
1569 } else {
1570 if (ai->ai_family == AF_INET6)
1571 printf("listenaddress [%s]:%s\n", addr, port);
1572 else
1573 printf("listenaddress %s:%s\n", addr, port);
1574 }
1575 }
1576
1577 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001578#ifdef USE_PAM
1579 dump_cfg_int(sUsePAM, o->use_pam);
1580#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001581 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1582 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1583 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1584 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1585 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001586 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001587 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1588 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1589
1590 /* formatted integer arguments */
1591 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1592 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1593 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1594 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1595 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1596 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1597 o->hostbased_uses_name_from_packet_only);
1598 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1599 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001600#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001601 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1602 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1603 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001604# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001605 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001606# endif
1607#endif
1608#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001609 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1610 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001611#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001612#ifdef JPAKE
1613 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1614 o->zero_knowledge_password_authentication);
1615#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001616 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1617 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1618 o->kbd_interactive_authentication);
1619 dump_cfg_fmtint(sChallengeResponseAuthentication,
1620 o->challenge_response_authentication);
1621 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1622 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1623 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1624 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1625 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1626 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1627 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1628 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1629 dump_cfg_fmtint(sUseLogin, o->use_login);
1630 dump_cfg_fmtint(sCompression, o->compression);
1631 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1632 dump_cfg_fmtint(sUseDNS, o->use_dns);
1633 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1634 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1635
1636 /* string arguments */
1637 dump_cfg_string(sPidFile, o->pid_file);
1638 dump_cfg_string(sXAuthLocation, o->xauth_location);
1639 dump_cfg_string(sCiphers, o->ciphers);
1640 dump_cfg_string(sMacs, o->macs);
1641 dump_cfg_string(sBanner, o->banner);
1642 dump_cfg_string(sAuthorizedKeysFile, o->authorized_keys_file);
1643 dump_cfg_string(sAuthorizedKeysFile2, o->authorized_keys_file2);
1644 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11001645 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Darren Tuckere7140f22008-06-10 23:01:51 +10001646
1647 /* string arguments requiring a lookup */
1648 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1649 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1650
1651 /* string array arguments */
1652 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1653 o->host_key_files);
1654 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1655 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1656 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1657 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1658 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1659
1660 /* other arguments */
1661 for (i = 0; i < o->num_subsystems; i++)
1662 printf("subsystem %s %s\n", o->subsystem_name[i],
1663 o->subsystem_args[i]);
1664
1665 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1666 o->max_startups_rate, o->max_startups);
1667
1668 for (i = 0; tunmode_desc[i].val != -1; i++)
1669 if (tunmode_desc[i].val == o->permit_tun) {
1670 s = tunmode_desc[i].text;
1671 break;
1672 }
1673 dump_cfg_string(sPermitTunnel, s);
1674
Darren Tuckere7140f22008-06-10 23:01:51 +10001675 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10001676}