blob: 2cdc480e607f41daa86cb8cd60203093c9d6c1c0 [file] [log] [blame]
Darren Tucker535b5e12010-01-08 18:56:48 +11001/* $OpenBSD: servconf.c,v 1.199 2009/12/29 16:38:41 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
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;
Darren Tucker34e314d2010-01-08 17:03:46 +1100131 options->rdomain = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000132}
133
Damien Miller4af51302000-04-16 11:18:38 +1000134void
Damien Miller95def091999-11-25 00:26:21 +1100135fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000136{
Damien Miller726273e2001-11-12 11:40:11 +1100137 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000138 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000139 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100140
141 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100142 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100143 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100144 if (options->num_host_key_files == 0) {
145 /* fill default hostkeys for protocols */
146 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100147 options->host_key_files[options->num_host_key_files++] =
148 _PATH_HOST_KEY_FILE;
149 if (options->protocol & SSH_PROTO_2) {
150 options->host_key_files[options->num_host_key_files++] =
151 _PATH_HOST_RSA_KEY_FILE;
152 options->host_key_files[options->num_host_key_files++] =
153 _PATH_HOST_DSA_KEY_FILE;
154 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100155 }
Damien Miller34132e52000-01-14 15:45:46 +1100156 if (options->num_ports == 0)
157 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
158 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000159 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000160 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000161 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100162 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000163 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100164 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000165 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100166 if (options->key_regeneration_time == -1)
167 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000168 if (options->permit_root_login == PERMIT_NOT_SET)
169 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100170 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100171 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100172 if (options->ignore_user_known_hosts == -1)
173 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100174 if (options->print_motd == -1)
175 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000176 if (options->print_lastlog == -1)
177 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100178 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100179 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100180 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100181 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100182 if (options->x11_use_localhost == -1)
183 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000184 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000185 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100186 if (options->strict_modes == -1)
187 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100188 if (options->tcp_keep_alive == -1)
189 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100190 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100191 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100192 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000193 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100195 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000196 if (options->hostbased_authentication == -1)
197 options->hostbased_authentication = 0;
198 if (options->hostbased_uses_name_from_packet_only == -1)
199 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100200 if (options->rsa_authentication == -1)
201 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100202 if (options->pubkey_authentication == -1)
203 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000205 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100206 if (options->kerberos_or_local_passwd == -1)
207 options->kerberos_or_local_passwd = 1;
208 if (options->kerberos_ticket_cleanup == -1)
209 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100210 if (options->kerberos_get_afs_token == -1)
211 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000212 if (options->gss_authentication == -1)
213 options->gss_authentication = 0;
214 if (options->gss_cleanup_creds == -1)
215 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100216 if (options->password_authentication == -1)
217 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100218 if (options->kbd_interactive_authentication == -1)
219 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000220 if (options->challenge_response_authentication == -1)
221 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100223 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000224 if (options->permit_user_env == -1)
225 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->use_login == -1)
227 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000228 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000229 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100230 if (options->allow_tcp_forwarding == -1)
231 options->allow_tcp_forwarding = 1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000232 if (options->allow_agent_forwarding == -1)
233 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000234 if (options->gateway_ports == -1)
235 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000236 if (options->max_startups == -1)
237 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000238 if (options->max_startups_rate == -1)
239 options->max_startups_rate = 100; /* 100% */
240 if (options->max_startups_begin == -1)
241 options->max_startups_begin = options->max_startups;
Darren Tucker89413db2004-05-24 10:36:23 +1000242 if (options->max_authtries == -1)
243 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000244 if (options->max_sessions == -1)
245 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000246 if (options->use_dns == -1)
247 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000248 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100249 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000250 if (options->client_alive_count_max == -1)
251 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100252 if (options->authorized_keys_file2 == NULL) {
253 /* authorized_keys_file2 falls back to authorized_keys_file */
254 if (options->authorized_keys_file != NULL)
255 options->authorized_keys_file2 = options->authorized_keys_file;
256 else
257 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
258 }
259 if (options->authorized_keys_file == NULL)
260 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Damien Millerd27b9472005-12-13 19:29:02 +1100261 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100262 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100263 if (options->zero_knowledge_password_authentication == -1)
264 options->zero_knowledge_password_authentication = 0;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000265
Ben Lindstromfb62a692002-06-06 19:47:11 +0000266 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000267 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000268 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000269
Tim Rice40017b02002-07-14 13:36:49 -0700270#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000271 if (use_privsep && options->compression == 1) {
272 error("This platform does not support both privilege "
273 "separation and compression");
274 error("Compression disabled");
275 options->compression = 0;
276 }
277#endif
278
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000279}
280
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100282typedef enum {
283 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100284 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000285 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100286 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100287 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
288 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000289 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100290 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100291 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000292 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100293 sPasswordAuthentication, sKbdInteractiveAuthentication,
294 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000295 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100296 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100297 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000298 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100299 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000300 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000301 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000302 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000303 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100304 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000305 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Damien Millerd27b9472005-12-13 19:29:02 +1100306 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100307 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker34e314d2010-01-08 17:03:46 +1100308 sUsePrivilegeSeparation, sAllowAgentForwarding, sRDomain,
Damien Miller01ed2272008-11-05 16:20:46 +1100309 sZeroKnowledgePasswordAuthentication,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000310 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000311} ServerOpCodes;
312
Darren Tucker45150472006-07-12 22:34:17 +1000313#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
314#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
315#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
316
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000317/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100318static struct {
319 const char *name;
320 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000321 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100322} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100323 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000324#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000325 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000326#else
Darren Tucker45150472006-07-12 22:34:17 +1000327 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000328#endif
Darren Tucker45150472006-07-12 22:34:17 +1000329 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100330 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000331 { "port", sPort, SSHCFG_GLOBAL },
332 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
333 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
334 { "pidfile", sPidFile, SSHCFG_GLOBAL },
335 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
336 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
337 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100338 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000339 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
340 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
341 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100342 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
343 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000344 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100345 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
346 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000347 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000348#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100349 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000350 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
351 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100352#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000353 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000354#else
Darren Tucker45150472006-07-12 22:34:17 +1000355 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100356#endif
357#else
Darren Tucker1629c072007-02-19 22:25:37 +1100358 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000359 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
360 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
361 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000362#endif
Darren Tucker45150472006-07-12 22:34:17 +1000363 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
364 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000365#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100366 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000367 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000368#else
Darren Tucker1629c072007-02-19 22:25:37 +1100369 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000370 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000371#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100372 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
373 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100374 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000375 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100376#ifdef JPAKE
377 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
378#else
379 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
380#endif
Darren Tucker45150472006-07-12 22:34:17 +1000381 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
382 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
383 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
384 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
385 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
386 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
387 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000388 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
389 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
390 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000391 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
392 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100393 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000394 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
395 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
396 { "compression", sCompression, SSHCFG_GLOBAL },
397 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
398 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
399 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000400 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000401 { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
402 { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
403 { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
404 { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
405 { "ciphers", sCiphers, SSHCFG_GLOBAL },
406 { "macs", sMacs, SSHCFG_GLOBAL },
407 { "protocol", sProtocol, SSHCFG_GLOBAL },
408 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
409 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
410 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000411 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000412 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100413 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000414 { "usedns", sUseDNS, SSHCFG_GLOBAL },
415 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
416 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
417 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
418 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
419 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
420 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000421 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Darren Tucker45150472006-07-12 22:34:17 +1000422 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
423 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000424 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000425 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000426 { "forcecommand", sForceCommand, SSHCFG_ALL },
Darren Tucker535b5e12010-01-08 18:56:48 +1100427 { "routingdomain", sRDomain, SSHCFG_GLOBAL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100428 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000429 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000430};
431
Darren Tuckere7140f22008-06-10 23:01:51 +1000432static struct {
433 int val;
434 char *text;
435} tunmode_desc[] = {
436 { SSH_TUNMODE_NO, "no" },
437 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
438 { SSH_TUNMODE_ETHERNET, "ethernet" },
439 { SSH_TUNMODE_YES, "yes" },
440 { -1, NULL }
441};
442
Damien Miller5428f641999-11-25 11:54:57 +1100443/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000444 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100445 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000446
Damien Miller4af51302000-04-16 11:18:38 +1000447static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100448parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000449 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000450{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000451 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000452
Damien Miller95def091999-11-25 00:26:21 +1100453 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000454 if (strcasecmp(cp, keywords[i].name) == 0) {
455 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100456 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000457 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000458
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000459 error("%s: line %d: Bad configuration option: %s",
460 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100461 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000462}
463
Ben Lindstrombba81212001-06-25 05:01:22 +0000464static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100465add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100466{
Damien Millereccb9de2005-06-17 12:59:34 +1000467 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100468
469 if (options->num_ports == 0)
470 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100471 if (options->address_family == -1)
472 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000473 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000474 for (i = 0; i < options->num_ports; i++)
475 add_one_listen_addr(options, addr, options->ports[i]);
476 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000477 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000478}
479
Ben Lindstrombba81212001-06-25 05:01:22 +0000480static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100481add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000482{
483 struct addrinfo hints, *ai, *aitop;
484 char strport[NI_MAXSERV];
485 int gaierr;
486
487 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100488 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000489 hints.ai_socktype = SOCK_STREAM;
490 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100491 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000492 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
493 fatal("bad addr or host: %s (%s)",
494 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100495 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000496 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
497 ;
498 ai->ai_next = options->listen_addrs;
499 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100500}
501
Darren Tucker45150472006-07-12 22:34:17 +1000502/*
503 * The strategy for the Match blocks is that the config file is parsed twice.
504 *
505 * The first time is at startup. activep is initialized to 1 and the
506 * directives in the global context are processed and acted on. Hitting a
507 * Match directive unsets activep and the directives inside the block are
508 * checked for syntax only.
509 *
510 * The second time is after a connection has been established but before
511 * authentication. activep is initialized to 2 and global config directives
512 * are ignored since they have already been processed. If the criteria in a
513 * Match block is met, activep is set and the subsequent directives
514 * processed and actioned until EOF or another Match block unsets it. Any
515 * options set are copied into the main server config.
516 *
517 * Potential additions/improvements:
518 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
519 *
520 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
521 * Match Address 192.168.0.*
522 * Tag trusted
523 * Match Group wheel
524 * Tag trusted
525 * Match Tag trusted
526 * AllowTcpForwarding yes
527 * GatewayPorts clientspecified
528 * [...]
529 *
530 * - Add a PermittedChannelRequests directive
531 * Match Group shell
532 * PermittedChannelRequests session,forwarded-tcpip
533 */
534
535static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000536match_cfg_line_group(const char *grps, int line, const char *user)
537{
538 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000539 struct passwd *pw;
540
Damien Miller565ca3f2006-08-19 00:23:15 +1000541 if (user == NULL)
542 goto out;
543
544 if ((pw = getpwnam(user)) == NULL) {
545 debug("Can't match group at line %d because user %.100s does "
546 "not exist", line, user);
547 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
548 debug("Can't Match group because user %.100s not in any group "
549 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000550 } else if (ga_match_pattern_list(grps) != 1) {
551 debug("user %.100s does not match group list %.100s at line %d",
552 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000553 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000554 debug("user %.100s matched group list %.100s at line %d", user,
555 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000556 result = 1;
557 }
558out:
559 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000560 return result;
561}
562
563static int
Darren Tucker45150472006-07-12 22:34:17 +1000564match_cfg_line(char **condition, int line, const char *user, const char *host,
565 const char *address)
566{
567 int result = 1;
568 char *arg, *attrib, *cp = *condition;
569 size_t len;
570
571 if (user == NULL)
572 debug3("checking syntax for 'Match %s'", cp);
573 else
574 debug3("checking match for '%s' user %s host %s addr %s", cp,
575 user ? user : "(null)", host ? host : "(null)",
576 address ? address : "(null)");
577
578 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
579 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
580 error("Missing Match criteria for %s", attrib);
581 return -1;
582 }
583 len = strlen(arg);
584 if (strcasecmp(attrib, "user") == 0) {
585 if (!user) {
586 result = 0;
587 continue;
588 }
589 if (match_pattern_list(user, arg, len, 0) != 1)
590 result = 0;
591 else
592 debug("user %.100s matched 'User %.100s' at "
593 "line %d", user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000594 } else if (strcasecmp(attrib, "group") == 0) {
595 switch (match_cfg_line_group(arg, line, user)) {
596 case -1:
597 return -1;
598 case 0:
599 result = 0;
600 }
Darren Tucker45150472006-07-12 22:34:17 +1000601 } else if (strcasecmp(attrib, "host") == 0) {
602 if (!host) {
603 result = 0;
604 continue;
605 }
606 if (match_hostname(host, arg, len) != 1)
607 result = 0;
608 else
609 debug("connection from %.100s matched 'Host "
610 "%.100s' at line %d", host, arg, line);
611 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000612 switch (addr_match_list(address, arg)) {
613 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000614 debug("connection from %.100s matched 'Address "
615 "%.100s' at line %d", address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000616 break;
617 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000618 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000619 result = 0;
620 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000621 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000622 return -1;
623 }
Darren Tucker45150472006-07-12 22:34:17 +1000624 } else {
625 error("Unsupported Match attribute %s", attrib);
626 return -1;
627 }
628 }
629 if (user != NULL)
630 debug3("match %sfound", result ? "" : "not ");
631 *condition = cp;
632 return result;
633}
634
Damien Millere2754432006-07-24 14:06:47 +1000635#define WHITESPACE " \t\r\n"
636
Ben Lindstromade03f62001-12-06 18:22:17 +0000637int
638process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000639 const char *filename, int linenum, int *activep, const char *user,
640 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000641{
642 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000643 int cmdline = 0, *intptr, value, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100644 SyslogFacility *log_facility_ptr;
645 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000646 ServerOpCodes opcode;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100647 int port;
Darren Tucker45150472006-07-12 22:34:17 +1000648 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000649 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000650
651 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100652 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100653 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000654 /* Ignore leading whitespace */
655 if (*arg == '\0')
656 arg = strdelim(&cp);
657 if (!arg || !*arg || *arg == '#')
658 return 0;
659 intptr = NULL;
660 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000661 opcode = parse_token(arg, filename, linenum, &flags);
662
663 if (activep == NULL) { /* We are processing a command line directive */
664 cmdline = 1;
665 activep = &cmdline;
666 }
667 if (*activep && opcode != sMatch)
668 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
669 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
670 if (user == NULL) {
671 fatal("%s line %d: Directive '%s' is not allowed "
672 "within a Match block", filename, linenum, arg);
673 } else { /* this is a directive we have already processed */
674 while (arg)
675 arg = strdelim(&cp);
676 return 0;
677 }
678 }
679
Ben Lindstromade03f62001-12-06 18:22:17 +0000680 switch (opcode) {
681 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000682 case sUsePAM:
683 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000684 goto parse_flag;
685
686 /* Standard Options */
687 case sBadOption:
688 return -1;
689 case sPort:
690 /* ignore ports from configfile if cmdline specifies ports */
691 if (options->ports_from_cmdline)
692 return 0;
693 if (options->listen_addrs != NULL)
694 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100695 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000696 if (options->num_ports >= MAX_PORTS)
697 fatal("%s line %d: too many ports.",
698 filename, linenum);
699 arg = strdelim(&cp);
700 if (!arg || *arg == '\0')
701 fatal("%s line %d: missing port number.",
702 filename, linenum);
703 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100704 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000705 fatal("%s line %d: Badly formatted port number.",
706 filename, linenum);
707 break;
708
709 case sServerKeyBits:
710 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000711 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000712 arg = strdelim(&cp);
713 if (!arg || *arg == '\0')
714 fatal("%s line %d: missing integer value.",
715 filename, linenum);
716 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000717 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000718 *intptr = value;
719 break;
720
721 case sLoginGraceTime:
722 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000723 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000724 arg = strdelim(&cp);
725 if (!arg || *arg == '\0')
726 fatal("%s line %d: missing time value.",
727 filename, linenum);
728 if ((value = convtime(arg)) == -1)
729 fatal("%s line %d: invalid time value.",
730 filename, linenum);
731 if (*intptr == -1)
732 *intptr = value;
733 break;
734
735 case sKeyRegenerationTime:
736 intptr = &options->key_regeneration_time;
737 goto parse_time;
738
739 case sListenAddress:
740 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100741 if (arg == NULL || *arg == '\0')
742 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000743 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000744 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
745 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
746 && strchr(p+1, ':') != NULL) {
747 add_listen_addr(options, arg, 0);
748 break;
749 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100750 p = hpdelim(&arg);
751 if (p == NULL)
752 fatal("%s line %d: bad address:port usage",
753 filename, linenum);
754 p = cleanhostname(p);
755 if (arg == NULL)
756 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100757 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100758 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000759
Damien Millerf91ee4c2005-03-01 21:24:33 +1100760 add_listen_addr(options, p, port);
761
Ben Lindstromade03f62001-12-06 18:22:17 +0000762 break;
763
Darren Tucker0f383232005-01-20 10:57:56 +1100764 case sAddressFamily:
765 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000766 if (!arg || *arg == '\0')
767 fatal("%s line %d: missing address family.",
768 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100769 intptr = &options->address_family;
770 if (options->listen_addrs != NULL)
771 fatal("%s line %d: address family must be specified before "
772 "ListenAddress.", filename, linenum);
773 if (strcasecmp(arg, "inet") == 0)
774 value = AF_INET;
775 else if (strcasecmp(arg, "inet6") == 0)
776 value = AF_INET6;
777 else if (strcasecmp(arg, "any") == 0)
778 value = AF_UNSPEC;
779 else
780 fatal("%s line %d: unsupported address family \"%s\".",
781 filename, linenum, arg);
782 if (*intptr == -1)
783 *intptr = value;
784 break;
785
Ben Lindstromade03f62001-12-06 18:22:17 +0000786 case sHostKeyFile:
787 intptr = &options->num_host_key_files;
788 if (*intptr >= MAX_HOSTKEYS)
789 fatal("%s line %d: too many host keys specified (max %d).",
790 filename, linenum, MAX_HOSTKEYS);
791 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000792 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000793 arg = strdelim(&cp);
794 if (!arg || *arg == '\0')
795 fatal("%s line %d: missing file name.",
796 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000797 if (*activep && *charptr == NULL) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000798 *charptr = tilde_expand_filename(arg, getuid());
799 /* increase optional counter */
800 if (intptr != NULL)
801 *intptr = *intptr + 1;
802 }
803 break;
804
805 case sPidFile:
806 charptr = &options->pid_file;
807 goto parse_filename;
808
809 case sPermitRootLogin:
810 intptr = &options->permit_root_login;
811 arg = strdelim(&cp);
812 if (!arg || *arg == '\0')
813 fatal("%s line %d: missing yes/"
814 "without-password/forced-commands-only/no "
815 "argument.", filename, linenum);
816 value = 0; /* silence compiler */
817 if (strcmp(arg, "without-password") == 0)
818 value = PERMIT_NO_PASSWD;
819 else if (strcmp(arg, "forced-commands-only") == 0)
820 value = PERMIT_FORCED_ONLY;
821 else if (strcmp(arg, "yes") == 0)
822 value = PERMIT_YES;
823 else if (strcmp(arg, "no") == 0)
824 value = PERMIT_NO;
825 else
826 fatal("%s line %d: Bad yes/"
827 "without-password/forced-commands-only/no "
828 "argument: %s", filename, linenum, arg);
Darren Tucker15f94272008-01-01 20:36:56 +1100829 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000830 *intptr = value;
831 break;
832
833 case sIgnoreRhosts:
834 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000835 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000836 arg = strdelim(&cp);
837 if (!arg || *arg == '\0')
838 fatal("%s line %d: missing yes/no argument.",
839 filename, linenum);
840 value = 0; /* silence compiler */
841 if (strcmp(arg, "yes") == 0)
842 value = 1;
843 else if (strcmp(arg, "no") == 0)
844 value = 0;
845 else
846 fatal("%s line %d: Bad yes/no argument: %s",
847 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000848 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000849 *intptr = value;
850 break;
851
852 case sIgnoreUserKnownHosts:
853 intptr = &options->ignore_user_known_hosts;
854 goto parse_flag;
855
Ben Lindstromade03f62001-12-06 18:22:17 +0000856 case sRhostsRSAAuthentication:
857 intptr = &options->rhosts_rsa_authentication;
858 goto parse_flag;
859
860 case sHostbasedAuthentication:
861 intptr = &options->hostbased_authentication;
862 goto parse_flag;
863
864 case sHostbasedUsesNameFromPacketOnly:
865 intptr = &options->hostbased_uses_name_from_packet_only;
866 goto parse_flag;
867
868 case sRSAAuthentication:
869 intptr = &options->rsa_authentication;
870 goto parse_flag;
871
872 case sPubkeyAuthentication:
873 intptr = &options->pubkey_authentication;
874 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000875
Ben Lindstromade03f62001-12-06 18:22:17 +0000876 case sKerberosAuthentication:
877 intptr = &options->kerberos_authentication;
878 goto parse_flag;
879
880 case sKerberosOrLocalPasswd:
881 intptr = &options->kerberos_or_local_passwd;
882 goto parse_flag;
883
884 case sKerberosTicketCleanup:
885 intptr = &options->kerberos_ticket_cleanup;
886 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000887
Darren Tucker22ef5082003-12-31 11:37:34 +1100888 case sKerberosGetAFSToken:
889 intptr = &options->kerberos_get_afs_token;
890 goto parse_flag;
891
Darren Tucker0efd1552003-08-26 11:49:55 +1000892 case sGssAuthentication:
893 intptr = &options->gss_authentication;
894 goto parse_flag;
895
896 case sGssCleanupCreds:
897 intptr = &options->gss_cleanup_creds;
898 goto parse_flag;
899
Ben Lindstromade03f62001-12-06 18:22:17 +0000900 case sPasswordAuthentication:
901 intptr = &options->password_authentication;
902 goto parse_flag;
903
Damien Miller01ed2272008-11-05 16:20:46 +1100904 case sZeroKnowledgePasswordAuthentication:
905 intptr = &options->zero_knowledge_password_authentication;
906 goto parse_flag;
907
Ben Lindstromade03f62001-12-06 18:22:17 +0000908 case sKbdInteractiveAuthentication:
909 intptr = &options->kbd_interactive_authentication;
910 goto parse_flag;
911
912 case sChallengeResponseAuthentication:
913 intptr = &options->challenge_response_authentication;
914 goto parse_flag;
915
916 case sPrintMotd:
917 intptr = &options->print_motd;
918 goto parse_flag;
919
920 case sPrintLastLog:
921 intptr = &options->print_lastlog;
922 goto parse_flag;
923
924 case sX11Forwarding:
925 intptr = &options->x11_forwarding;
926 goto parse_flag;
927
928 case sX11DisplayOffset:
929 intptr = &options->x11_display_offset;
930 goto parse_int;
931
Damien Miller95c249f2002-02-05 12:11:34 +1100932 case sX11UseLocalhost:
933 intptr = &options->x11_use_localhost;
934 goto parse_flag;
935
Ben Lindstromade03f62001-12-06 18:22:17 +0000936 case sXAuthLocation:
937 charptr = &options->xauth_location;
938 goto parse_filename;
939
940 case sStrictModes:
941 intptr = &options->strict_modes;
942 goto parse_flag;
943
Damien Miller12c150e2003-12-17 16:31:10 +1100944 case sTCPKeepAlive:
945 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000946 goto parse_flag;
947
948 case sEmptyPasswd:
949 intptr = &options->permit_empty_passwd;
950 goto parse_flag;
951
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000952 case sPermitUserEnvironment:
953 intptr = &options->permit_user_env;
954 goto parse_flag;
955
Ben Lindstromade03f62001-12-06 18:22:17 +0000956 case sUseLogin:
957 intptr = &options->use_login;
958 goto parse_flag;
959
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000960 case sCompression:
961 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000962 arg = strdelim(&cp);
963 if (!arg || *arg == '\0')
964 fatal("%s line %d: missing yes/no/delayed "
965 "argument.", filename, linenum);
966 value = 0; /* silence compiler */
967 if (strcmp(arg, "delayed") == 0)
968 value = COMP_DELAYED;
969 else if (strcmp(arg, "yes") == 0)
970 value = COMP_ZLIB;
971 else if (strcmp(arg, "no") == 0)
972 value = COMP_NONE;
973 else
974 fatal("%s line %d: Bad yes/no/delayed "
975 "argument: %s", filename, linenum, arg);
976 if (*intptr == -1)
977 *intptr = value;
978 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000979
Ben Lindstromade03f62001-12-06 18:22:17 +0000980 case sGatewayPorts:
981 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100982 arg = strdelim(&cp);
983 if (!arg || *arg == '\0')
984 fatal("%s line %d: missing yes/no/clientspecified "
985 "argument.", filename, linenum);
986 value = 0; /* silence compiler */
987 if (strcmp(arg, "clientspecified") == 0)
988 value = 2;
989 else if (strcmp(arg, "yes") == 0)
990 value = 1;
991 else if (strcmp(arg, "no") == 0)
992 value = 0;
993 else
994 fatal("%s line %d: Bad yes/no/clientspecified "
995 "argument: %s", filename, linenum, arg);
Darren Tucker82347a82007-02-25 20:37:52 +1100996 if (*activep && *intptr == -1)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100997 *intptr = value;
998 break;
Ben Lindstromade03f62001-12-06 18:22:17 +0000999
Damien Miller3a961dc2003-06-03 10:25:48 +10001000 case sUseDNS:
1001 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001002 goto parse_flag;
1003
1004 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001005 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001006 arg = strdelim(&cp);
1007 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001008 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001009 fatal("%.200s line %d: unsupported log facility '%s'",
1010 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001011 if (*log_facility_ptr == -1)
1012 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001013 break;
1014
1015 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001016 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001017 arg = strdelim(&cp);
1018 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001019 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001020 fatal("%.200s line %d: unsupported log level '%s'",
1021 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001022 if (*log_level_ptr == -1)
1023 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001024 break;
1025
1026 case sAllowTcpForwarding:
1027 intptr = &options->allow_tcp_forwarding;
1028 goto parse_flag;
1029
Damien Miller4f755cd2008-05-19 14:57:41 +10001030 case sAllowAgentForwarding:
1031 intptr = &options->allow_agent_forwarding;
1032 goto parse_flag;
1033
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001034 case sUsePrivilegeSeparation:
1035 intptr = &use_privsep;
1036 goto parse_flag;
1037
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 case sAllowUsers:
1039 while ((arg = strdelim(&cp)) && *arg != '\0') {
1040 if (options->num_allow_users >= MAX_ALLOW_USERS)
1041 fatal("%s line %d: too many allow users.",
1042 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001043 options->allow_users[options->num_allow_users++] =
1044 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001045 }
1046 break;
1047
1048 case sDenyUsers:
1049 while ((arg = strdelim(&cp)) && *arg != '\0') {
1050 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001051 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001052 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001053 options->deny_users[options->num_deny_users++] =
1054 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001055 }
1056 break;
1057
1058 case sAllowGroups:
1059 while ((arg = strdelim(&cp)) && *arg != '\0') {
1060 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1061 fatal("%s line %d: too many allow groups.",
1062 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001063 options->allow_groups[options->num_allow_groups++] =
1064 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001065 }
1066 break;
1067
1068 case sDenyGroups:
1069 while ((arg = strdelim(&cp)) && *arg != '\0') {
1070 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1071 fatal("%s line %d: too many deny groups.",
1072 filename, linenum);
1073 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1074 }
1075 break;
1076
1077 case sCiphers:
1078 arg = strdelim(&cp);
1079 if (!arg || *arg == '\0')
1080 fatal("%s line %d: Missing argument.", filename, linenum);
1081 if (!ciphers_valid(arg))
1082 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1083 filename, linenum, arg ? arg : "<NONE>");
1084 if (options->ciphers == NULL)
1085 options->ciphers = xstrdup(arg);
1086 break;
1087
1088 case sMacs:
1089 arg = strdelim(&cp);
1090 if (!arg || *arg == '\0')
1091 fatal("%s line %d: Missing argument.", filename, linenum);
1092 if (!mac_valid(arg))
1093 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1094 filename, linenum, arg ? arg : "<NONE>");
1095 if (options->macs == NULL)
1096 options->macs = xstrdup(arg);
1097 break;
1098
1099 case sProtocol:
1100 intptr = &options->protocol;
1101 arg = strdelim(&cp);
1102 if (!arg || *arg == '\0')
1103 fatal("%s line %d: Missing argument.", filename, linenum);
1104 value = proto_spec(arg);
1105 if (value == SSH_PROTO_UNKNOWN)
1106 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001107 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001108 if (*intptr == SSH_PROTO_UNKNOWN)
1109 *intptr = value;
1110 break;
1111
1112 case sSubsystem:
1113 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1114 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001115 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001116 }
1117 arg = strdelim(&cp);
1118 if (!arg || *arg == '\0')
1119 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001120 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001121 if (!*activep) {
1122 arg = strdelim(&cp);
1123 break;
1124 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001125 for (i = 0; i < options->num_subsystems; i++)
1126 if (strcmp(arg, options->subsystem_name[i]) == 0)
1127 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001128 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001129 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1130 arg = strdelim(&cp);
1131 if (!arg || *arg == '\0')
1132 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001133 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001134 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001135
1136 /* Collect arguments (separate to executable) */
1137 p = xstrdup(arg);
1138 len = strlen(p) + 1;
1139 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1140 len += 1 + strlen(arg);
1141 p = xrealloc(p, 1, len);
1142 strlcat(p, " ", len);
1143 strlcat(p, arg, len);
1144 }
1145 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001146 options->num_subsystems++;
1147 break;
1148
1149 case sMaxStartups:
1150 arg = strdelim(&cp);
1151 if (!arg || *arg == '\0')
1152 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001153 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001154 if ((n = sscanf(arg, "%d:%d:%d",
1155 &options->max_startups_begin,
1156 &options->max_startups_rate,
1157 &options->max_startups)) == 3) {
1158 if (options->max_startups_begin >
1159 options->max_startups ||
1160 options->max_startups_rate > 100 ||
1161 options->max_startups_rate < 1)
1162 fatal("%s line %d: Illegal MaxStartups spec.",
1163 filename, linenum);
1164 } else if (n != 1)
1165 fatal("%s line %d: Illegal MaxStartups spec.",
1166 filename, linenum);
1167 else
1168 options->max_startups = options->max_startups_begin;
1169 break;
1170
Darren Tucker89413db2004-05-24 10:36:23 +10001171 case sMaxAuthTries:
1172 intptr = &options->max_authtries;
1173 goto parse_int;
1174
Damien Miller7207f642008-05-19 15:34:50 +10001175 case sMaxSessions:
1176 intptr = &options->max_sessions;
1177 goto parse_int;
1178
Ben Lindstromade03f62001-12-06 18:22:17 +00001179 case sBanner:
1180 charptr = &options->banner;
1181 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001182
Ben Lindstromade03f62001-12-06 18:22:17 +00001183 /*
1184 * These options can contain %X options expanded at
1185 * connect time, so that you can specify paths like:
1186 *
1187 * AuthorizedKeysFile /etc/ssh_keys/%u
1188 */
1189 case sAuthorizedKeysFile:
1190 case sAuthorizedKeysFile2:
Damien Miller4dec5d72006-08-05 11:38:40 +10001191 charptr = (opcode == sAuthorizedKeysFile) ?
Ben Lindstromade03f62001-12-06 18:22:17 +00001192 &options->authorized_keys_file :
1193 &options->authorized_keys_file2;
1194 goto parse_filename;
1195
1196 case sClientAliveInterval:
1197 intptr = &options->client_alive_interval;
1198 goto parse_time;
1199
1200 case sClientAliveCountMax:
1201 intptr = &options->client_alive_count_max;
1202 goto parse_int;
1203
Darren Tucker46bc0752004-05-02 22:11:30 +10001204 case sAcceptEnv:
1205 while ((arg = strdelim(&cp)) && *arg != '\0') {
1206 if (strchr(arg, '=') != NULL)
1207 fatal("%s line %d: Invalid environment name.",
1208 filename, linenum);
1209 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1210 fatal("%s line %d: too many allow env.",
1211 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001212 if (!*activep)
1213 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001214 options->accept_env[options->num_accept_env++] =
1215 xstrdup(arg);
1216 }
1217 break;
1218
Damien Millerd27b9472005-12-13 19:29:02 +11001219 case sPermitTunnel:
1220 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001221 arg = strdelim(&cp);
1222 if (!arg || *arg == '\0')
1223 fatal("%s line %d: Missing yes/point-to-point/"
1224 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001225 value = -1;
1226 for (i = 0; tunmode_desc[i].val != -1; i++)
1227 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1228 value = tunmode_desc[i].val;
1229 break;
1230 }
1231 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001232 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1233 "no argument: %s", filename, linenum, arg);
1234 if (*intptr == -1)
1235 *intptr = value;
1236 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001237
Darren Tucker45150472006-07-12 22:34:17 +10001238 case sMatch:
1239 if (cmdline)
1240 fatal("Match directive not supported as a command-line "
1241 "option");
1242 value = match_cfg_line(&cp, linenum, user, host, address);
1243 if (value < 0)
1244 fatal("%s line %d: Bad Match condition", filename,
1245 linenum);
1246 *activep = value;
1247 break;
1248
Damien Miller9b439df2006-07-24 14:04:00 +10001249 case sPermitOpen:
1250 arg = strdelim(&cp);
1251 if (!arg || *arg == '\0')
1252 fatal("%s line %d: missing PermitOpen specification",
1253 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001254 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001255 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001256 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001257 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001258 options->num_permitted_opens = 0;
1259 }
Damien Miller9b439df2006-07-24 14:04:00 +10001260 break;
1261 }
Damien Millera29b95e2007-01-05 16:28:36 +11001262 if (*activep && n == -1)
1263 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001264 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1265 p = hpdelim(&arg);
1266 if (p == NULL)
1267 fatal("%s line %d: missing host in PermitOpen",
1268 filename, linenum);
1269 p = cleanhostname(p);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001270 if (arg == NULL || (port = a2port(arg)) <= 0)
Damien Millera765cf42006-07-24 14:08:13 +10001271 fatal("%s line %d: bad port number in "
1272 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001273 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001274 options->num_permitted_opens =
1275 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001276 }
Damien Miller9b439df2006-07-24 14:04:00 +10001277 break;
1278
Damien Millere2754432006-07-24 14:06:47 +10001279 case sForceCommand:
1280 if (cp == NULL)
1281 fatal("%.200s line %d: Missing argument.", filename,
1282 linenum);
1283 len = strspn(cp, WHITESPACE);
1284 if (*activep && options->adm_forced_command == NULL)
1285 options->adm_forced_command = xstrdup(cp + len);
1286 return 0;
1287
Damien Millerd8cb1f12008-02-10 22:40:12 +11001288 case sChrootDirectory:
1289 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001290
1291 arg = strdelim(&cp);
1292 if (!arg || *arg == '\0')
1293 fatal("%s line %d: missing file name.",
1294 filename, linenum);
1295 if (*activep && *charptr == NULL)
1296 *charptr = xstrdup(arg);
1297 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001298
Darren Tucker34e314d2010-01-08 17:03:46 +11001299 case sRDomain:
1300 intptr = &options->rdomain;
Darren Tucker75456e82010-01-08 18:55:58 +11001301 arg = strdelim(&cp);
1302 if (!arg || *arg == '\0')
1303 fatal("%s line %d: missing rdomain value.",
1304 filename, linenum);
1305 if ((value = a2rdomain(arg)) == -1)
1306 fatal("%s line %d: invalid rdomain value.",
1307 filename, linenum);
1308 if (*intptr == -1)
1309 *intptr = value;
1310 break;
Darren Tucker34e314d2010-01-08 17:03:46 +11001311
Ben Lindstromade03f62001-12-06 18:22:17 +00001312 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001313 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001314 filename, linenum, arg);
1315 while (arg)
1316 arg = strdelim(&cp);
1317 break;
1318
Damien Millerf9b3feb2003-05-16 11:38:32 +10001319 case sUnsupported:
1320 logit("%s line %d: Unsupported option %s",
1321 filename, linenum, arg);
1322 while (arg)
1323 arg = strdelim(&cp);
1324 break;
1325
Ben Lindstromade03f62001-12-06 18:22:17 +00001326 default:
1327 fatal("%s line %d: Missing handler for opcode %s (%d)",
1328 filename, linenum, arg, opcode);
1329 }
1330 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1331 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1332 filename, linenum, arg);
1333 return 0;
1334}
1335
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001336/* Reads the server configuration file. */
1337
Damien Miller4af51302000-04-16 11:18:38 +10001338void
Darren Tucker645ab752004-06-25 13:33:20 +10001339load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001340{
Darren Tucker645ab752004-06-25 13:33:20 +10001341 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001342 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001343
Darren Tucker645ab752004-06-25 13:33:20 +10001344 debug2("%s: filename %s", __func__, filename);
1345 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001346 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001347 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001348 }
Darren Tucker645ab752004-06-25 13:33:20 +10001349 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001350 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001351 /*
1352 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001353 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001354 * line numbers later for error messages
1355 */
1356 if ((cp = strchr(line, '#')) != NULL)
1357 memcpy(cp, "\n", 2);
1358 cp = line + strspn(line, " \t\r");
1359
1360 buffer_append(conf, cp, strlen(cp));
1361 }
1362 buffer_append(conf, "\0", 1);
1363 fclose(f);
1364 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1365}
1366
1367void
Darren Tucker45150472006-07-12 22:34:17 +10001368parse_server_match_config(ServerOptions *options, const char *user,
1369 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001370{
Darren Tucker45150472006-07-12 22:34:17 +10001371 ServerOptions mo;
1372
1373 initialize_server_options(&mo);
1374 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
Darren Tucker1629c072007-02-19 22:25:37 +11001375 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001376}
1377
Darren Tucker1629c072007-02-19 22:25:37 +11001378/* Helper macros */
1379#define M_CP_INTOPT(n) do {\
1380 if (src->n != -1) \
1381 dst->n = src->n; \
1382} while (0)
1383#define M_CP_STROPT(n) do {\
1384 if (src->n != NULL) { \
1385 if (dst->n != NULL) \
1386 xfree(dst->n); \
1387 dst->n = src->n; \
1388 } \
1389} while(0)
1390
1391/*
1392 * Copy any supported values that are set.
1393 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001394 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001395 * array values that are not used pre-authentication, because any that we
1396 * do use must be explictly sent in mm_getpwnamallow().
1397 */
Darren Tucker45150472006-07-12 22:34:17 +10001398void
Darren Tucker1629c072007-02-19 22:25:37 +11001399copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001400{
Darren Tucker1629c072007-02-19 22:25:37 +11001401 M_CP_INTOPT(password_authentication);
1402 M_CP_INTOPT(gss_authentication);
1403 M_CP_INTOPT(rsa_authentication);
1404 M_CP_INTOPT(pubkey_authentication);
1405 M_CP_INTOPT(kerberos_authentication);
1406 M_CP_INTOPT(hostbased_authentication);
1407 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001408 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001409 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001410 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001411
1412 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001413 M_CP_INTOPT(allow_agent_forwarding);
Darren Tucker1629c072007-02-19 22:25:37 +11001414 M_CP_INTOPT(gateway_ports);
1415 M_CP_INTOPT(x11_display_offset);
1416 M_CP_INTOPT(x11_forwarding);
1417 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001418 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001419 M_CP_INTOPT(max_authtries);
Darren Tucker1629c072007-02-19 22:25:37 +11001420
1421 M_CP_STROPT(banner);
1422 if (preauth)
1423 return;
1424 M_CP_STROPT(adm_forced_command);
Damien Millerd8cb1f12008-02-10 22:40:12 +11001425 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001426}
1427
Darren Tucker1629c072007-02-19 22:25:37 +11001428#undef M_CP_INTOPT
1429#undef M_CP_STROPT
1430
Darren Tucker45150472006-07-12 22:34:17 +10001431void
1432parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1433 const char *user, const char *host, const char *address)
1434{
1435 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001436 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001437
1438 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1439
Darren Tucker9fbac712004-08-12 22:41:44 +10001440 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001441 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001442 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001443 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001444 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001445 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001446 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001447 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001448 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001449 if (bad_options > 0)
1450 fatal("%s: terminating, %d bad configuration options",
1451 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001452}
Darren Tuckere7140f22008-06-10 23:01:51 +10001453
1454static const char *
1455fmt_intarg(ServerOpCodes code, int val)
1456{
1457 if (code == sAddressFamily) {
1458 switch (val) {
1459 case AF_INET:
1460 return "inet";
1461 case AF_INET6:
1462 return "inet6";
1463 case AF_UNSPEC:
1464 return "any";
1465 default:
1466 return "UNKNOWN";
1467 }
1468 }
1469 if (code == sPermitRootLogin) {
1470 switch (val) {
1471 case PERMIT_NO_PASSWD:
Darren Tuckerff4350e2008-11-11 16:31:05 +11001472 return "without-password";
Darren Tuckere7140f22008-06-10 23:01:51 +10001473 case PERMIT_FORCED_ONLY:
1474 return "forced-commands-only";
1475 case PERMIT_YES:
1476 return "yes";
1477 }
1478 }
1479 if (code == sProtocol) {
1480 switch (val) {
1481 case SSH_PROTO_1:
1482 return "1";
1483 case SSH_PROTO_2:
1484 return "2";
1485 case (SSH_PROTO_1|SSH_PROTO_2):
1486 return "2,1";
1487 default:
1488 return "UNKNOWN";
1489 }
1490 }
1491 if (code == sGatewayPorts && val == 2)
1492 return "clientspecified";
1493 if (code == sCompression && val == COMP_DELAYED)
1494 return "delayed";
1495 switch (val) {
1496 case -1:
1497 return "unset";
1498 case 0:
1499 return "no";
1500 case 1:
1501 return "yes";
1502 }
1503 return "UNKNOWN";
1504}
1505
1506static const char *
1507lookup_opcode_name(ServerOpCodes code)
1508{
1509 u_int i;
1510
1511 for (i = 0; keywords[i].name != NULL; i++)
1512 if (keywords[i].opcode == code)
1513 return(keywords[i].name);
1514 return "UNKNOWN";
1515}
1516
1517static void
1518dump_cfg_int(ServerOpCodes code, int val)
1519{
1520 printf("%s %d\n", lookup_opcode_name(code), val);
1521}
1522
1523static void
1524dump_cfg_fmtint(ServerOpCodes code, int val)
1525{
1526 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1527}
1528
1529static void
1530dump_cfg_string(ServerOpCodes code, const char *val)
1531{
1532 if (val == NULL)
1533 return;
1534 printf("%s %s\n", lookup_opcode_name(code), val);
1535}
1536
1537static void
1538dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1539{
1540 u_int i;
1541
1542 for (i = 0; i < count; i++)
1543 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1544}
1545
1546void
1547dump_config(ServerOptions *o)
1548{
1549 u_int i;
1550 int ret;
1551 struct addrinfo *ai;
1552 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1553
1554 /* these are usually at the top of the config */
1555 for (i = 0; i < o->num_ports; i++)
1556 printf("port %d\n", o->ports[i]);
1557 dump_cfg_fmtint(sProtocol, o->protocol);
1558 dump_cfg_fmtint(sAddressFamily, o->address_family);
1559
1560 /* ListenAddress must be after Port */
1561 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1562 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1563 sizeof(addr), port, sizeof(port),
1564 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1565 error("getnameinfo failed: %.100s",
1566 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1567 strerror(errno));
1568 } else {
1569 if (ai->ai_family == AF_INET6)
1570 printf("listenaddress [%s]:%s\n", addr, port);
1571 else
1572 printf("listenaddress %s:%s\n", addr, port);
1573 }
1574 }
1575
1576 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001577#ifdef USE_PAM
1578 dump_cfg_int(sUsePAM, o->use_pam);
1579#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001580 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1581 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1582 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1583 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1584 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001585 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001586 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1587 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
Darren Tucker34e314d2010-01-08 17:03:46 +11001588 dump_cfg_int(sRDomain, o->rdomain);
Darren Tuckere7140f22008-06-10 23:01:51 +10001589
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);
1645
1646 /* string arguments requiring a lookup */
1647 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1648 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1649
1650 /* string array arguments */
1651 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1652 o->host_key_files);
1653 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1654 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1655 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1656 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1657 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1658
1659 /* other arguments */
1660 for (i = 0; i < o->num_subsystems; i++)
1661 printf("subsystem %s %s\n", o->subsystem_name[i],
1662 o->subsystem_args[i]);
1663
1664 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1665 o->max_startups_rate, o->max_startups);
1666
1667 for (i = 0; tunmode_desc[i].val != -1; i++)
1668 if (tunmode_desc[i].val == o->permit_tun) {
1669 s = tunmode_desc[i].text;
1670 break;
1671 }
1672 dump_cfg_string(sPermitTunnel, s);
1673
Darren Tuckere7140f22008-06-10 23:01:51 +10001674 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10001675}