blob: e09e0f1c8c82c041ffa42bebb43a077bc1ea912a [file] [log] [blame]
Damien Millerc4cb47b2010-03-22 05:52:26 +11001/* $OpenBSD: servconf.c,v 1.205 2010/03/12 01:06:25 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 Miller0a80ca12010-02-27 07:55:05 +110068 options->num_host_cert_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100069 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110070 options->server_key_bits = -1;
71 options->login_grace_time = -1;
72 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000073 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110074 options->ignore_rhosts = -1;
75 options->ignore_user_known_hosts = -1;
76 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000077 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110078 options->x11_forwarding = -1;
79 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110080 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100081 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110082 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110083 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110084 options->log_facility = SYSLOG_FACILITY_NOT_SET;
85 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110086 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000087 options->hostbased_authentication = -1;
88 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110089 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110090 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110091 options->kerberos_authentication = -1;
92 options->kerberos_or_local_passwd = -1;
93 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +110094 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +100095 options->gss_authentication=-1;
96 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +110097 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110098 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000099 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100100 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000101 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000103 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100104 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000105 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->num_allow_users = 0;
107 options->num_deny_users = 0;
108 options->num_allow_groups = 0;
109 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000110 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000111 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000112 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000113 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000114 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000115 options->max_startups_begin = -1;
116 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000117 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000118 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000119 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000120 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000121 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000122 options->client_alive_interval = -1;
123 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000124 options->authorized_keys_file = NULL;
125 options->authorized_keys_file2 = NULL;
Darren Tucker46bc0752004-05-02 22:11:30 +1000126 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100127 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000128 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000129 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100130 options->chroot_directory = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100131 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100132 options->revoked_keys_file = NULL;
133 options->trusted_user_ca_keys = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000134}
135
Damien Miller4af51302000-04-16 11:18:38 +1000136void
Damien Miller95def091999-11-25 00:26:21 +1100137fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000138{
Damien Miller726273e2001-11-12 11:40:11 +1100139 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000140 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000141 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100142
143 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100144 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100145 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100146 if (options->num_host_key_files == 0) {
147 /* fill default hostkeys for protocols */
148 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100149 options->host_key_files[options->num_host_key_files++] =
150 _PATH_HOST_KEY_FILE;
151 if (options->protocol & SSH_PROTO_2) {
152 options->host_key_files[options->num_host_key_files++] =
153 _PATH_HOST_RSA_KEY_FILE;
154 options->host_key_files[options->num_host_key_files++] =
155 _PATH_HOST_DSA_KEY_FILE;
156 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100157 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100158 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100159 if (options->num_ports == 0)
160 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
161 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000162 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000163 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000164 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000166 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000168 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100169 if (options->key_regeneration_time == -1)
170 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000171 if (options->permit_root_login == PERMIT_NOT_SET)
172 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100174 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100175 if (options->ignore_user_known_hosts == -1)
176 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100177 if (options->print_motd == -1)
178 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000179 if (options->print_lastlog == -1)
180 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100181 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100182 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100183 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100184 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100185 if (options->x11_use_localhost == -1)
186 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000187 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000188 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100189 if (options->strict_modes == -1)
190 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100191 if (options->tcp_keep_alive == -1)
192 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100193 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100194 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100195 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000196 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100198 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000199 if (options->hostbased_authentication == -1)
200 options->hostbased_authentication = 0;
201 if (options->hostbased_uses_name_from_packet_only == -1)
202 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->rsa_authentication == -1)
204 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100205 if (options->pubkey_authentication == -1)
206 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000208 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->kerberos_or_local_passwd == -1)
210 options->kerberos_or_local_passwd = 1;
211 if (options->kerberos_ticket_cleanup == -1)
212 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100213 if (options->kerberos_get_afs_token == -1)
214 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000215 if (options->gss_authentication == -1)
216 options->gss_authentication = 0;
217 if (options->gss_cleanup_creds == -1)
218 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100219 if (options->password_authentication == -1)
220 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100221 if (options->kbd_interactive_authentication == -1)
222 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000223 if (options->challenge_response_authentication == -1)
224 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100225 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100226 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000227 if (options->permit_user_env == -1)
228 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->use_login == -1)
230 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000231 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000232 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100233 if (options->allow_tcp_forwarding == -1)
234 options->allow_tcp_forwarding = 1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000235 if (options->allow_agent_forwarding == -1)
236 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000237 if (options->gateway_ports == -1)
238 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000239 if (options->max_startups == -1)
240 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000241 if (options->max_startups_rate == -1)
242 options->max_startups_rate = 100; /* 100% */
243 if (options->max_startups_begin == -1)
244 options->max_startups_begin = options->max_startups;
Darren Tucker89413db2004-05-24 10:36:23 +1000245 if (options->max_authtries == -1)
246 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000247 if (options->max_sessions == -1)
248 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000249 if (options->use_dns == -1)
250 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000251 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100252 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000253 if (options->client_alive_count_max == -1)
254 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100255 if (options->authorized_keys_file2 == NULL) {
256 /* authorized_keys_file2 falls back to authorized_keys_file */
257 if (options->authorized_keys_file != NULL)
258 options->authorized_keys_file2 = options->authorized_keys_file;
259 else
260 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
261 }
262 if (options->authorized_keys_file == NULL)
263 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Damien Millerd27b9472005-12-13 19:29:02 +1100264 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100265 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100266 if (options->zero_knowledge_password_authentication == -1)
267 options->zero_knowledge_password_authentication = 0;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000268
Ben Lindstromfb62a692002-06-06 19:47:11 +0000269 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000270 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000271 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000272
Tim Rice40017b02002-07-14 13:36:49 -0700273#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000274 if (use_privsep && options->compression == 1) {
275 error("This platform does not support both privilege "
276 "separation and compression");
277 error("Compression disabled");
278 options->compression = 0;
279 }
280#endif
281
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000282}
283
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000284/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100285typedef enum {
286 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100287 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000288 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100289 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100290 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
291 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000292 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100293 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100294 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000295 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100296 sPasswordAuthentication, sKbdInteractiveAuthentication,
297 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000298 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100299 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100300 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000301 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100302 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000303 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000304 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000305 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000306 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100307 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000308 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Damien Millerd27b9472005-12-13 19:29:02 +1100309 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100310 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100311 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100312 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller1aed65e2010-03-04 21:53:35 +1100313 sRevokedKeys, sTrustedUserCAKeys,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000314 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000315} ServerOpCodes;
316
Darren Tucker45150472006-07-12 22:34:17 +1000317#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
318#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
319#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
320
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000321/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100322static struct {
323 const char *name;
324 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000325 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100326} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100327 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000328#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000329 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000330#else
Darren Tucker45150472006-07-12 22:34:17 +1000331 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000332#endif
Darren Tucker45150472006-07-12 22:34:17 +1000333 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100334 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000335 { "port", sPort, SSHCFG_GLOBAL },
336 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
337 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
338 { "pidfile", sPidFile, SSHCFG_GLOBAL },
339 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
340 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
341 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100342 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000343 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
344 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
345 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100346 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
347 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000348 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100349 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
350 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000351 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000352#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100353 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000354 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
355 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100356#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000357 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000358#else
Darren Tucker45150472006-07-12 22:34:17 +1000359 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100360#endif
361#else
Darren Tucker1629c072007-02-19 22:25:37 +1100362 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000363 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
364 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
365 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000366#endif
Darren Tucker45150472006-07-12 22:34:17 +1000367 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
368 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000369#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100370 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000371 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000372#else
Darren Tucker1629c072007-02-19 22:25:37 +1100373 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000374 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000375#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100376 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
377 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100378 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000379 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100380#ifdef JPAKE
381 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
382#else
383 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
384#endif
Darren Tucker45150472006-07-12 22:34:17 +1000385 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
386 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
387 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
388 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
389 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
390 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
391 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000392 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
393 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
394 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
396 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100397 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000398 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
399 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
400 { "compression", sCompression, SSHCFG_GLOBAL },
401 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
402 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
403 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000404 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000405 { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
406 { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
407 { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
408 { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
409 { "ciphers", sCiphers, SSHCFG_GLOBAL },
410 { "macs", sMacs, SSHCFG_GLOBAL },
411 { "protocol", sProtocol, SSHCFG_GLOBAL },
412 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
413 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
414 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000415 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000416 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100417 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000418 { "usedns", sUseDNS, SSHCFG_GLOBAL },
419 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
420 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
421 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
422 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
423 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
424 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000425 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Darren Tucker45150472006-07-12 22:34:17 +1000426 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
427 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000428 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000429 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000430 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100431 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100432 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100433 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
434 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000435 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000436};
437
Darren Tuckere7140f22008-06-10 23:01:51 +1000438static struct {
439 int val;
440 char *text;
441} tunmode_desc[] = {
442 { SSH_TUNMODE_NO, "no" },
443 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
444 { SSH_TUNMODE_ETHERNET, "ethernet" },
445 { SSH_TUNMODE_YES, "yes" },
446 { -1, NULL }
447};
448
Damien Miller5428f641999-11-25 11:54:57 +1100449/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000450 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100451 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000452
Damien Miller4af51302000-04-16 11:18:38 +1000453static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100454parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000455 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000456{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000457 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000458
Damien Miller95def091999-11-25 00:26:21 +1100459 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000460 if (strcasecmp(cp, keywords[i].name) == 0) {
461 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100462 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000463 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000464
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000465 error("%s: line %d: Bad configuration option: %s",
466 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100467 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000468}
469
Darren Tucker88b6fb22010-01-13 22:44:29 +1100470char *
471derelativise_path(const char *path)
472{
473 char *expanded, *ret, *cwd;
474
475 expanded = tilde_expand_filename(path, getuid());
476 if (*expanded == '/')
477 return expanded;
478 if ((cwd = getcwd(NULL, 0)) == NULL)
479 fatal("%s: getcwd: %s", __func__, strerror(errno));
480 xasprintf(&ret, "%s/%s", cwd, expanded);
481 xfree(cwd);
482 xfree(expanded);
483 return ret;
484}
485
Ben Lindstrombba81212001-06-25 05:01:22 +0000486static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100487add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100488{
Damien Millereccb9de2005-06-17 12:59:34 +1000489 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100490
491 if (options->num_ports == 0)
492 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100493 if (options->address_family == -1)
494 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000495 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000496 for (i = 0; i < options->num_ports; i++)
497 add_one_listen_addr(options, addr, options->ports[i]);
498 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000499 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000500}
501
Ben Lindstrombba81212001-06-25 05:01:22 +0000502static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100503add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000504{
505 struct addrinfo hints, *ai, *aitop;
506 char strport[NI_MAXSERV];
507 int gaierr;
508
509 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100510 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000511 hints.ai_socktype = SOCK_STREAM;
512 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100513 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000514 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
515 fatal("bad addr or host: %s (%s)",
516 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100517 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000518 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
519 ;
520 ai->ai_next = options->listen_addrs;
521 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100522}
523
Darren Tucker45150472006-07-12 22:34:17 +1000524/*
525 * The strategy for the Match blocks is that the config file is parsed twice.
526 *
527 * The first time is at startup. activep is initialized to 1 and the
528 * directives in the global context are processed and acted on. Hitting a
529 * Match directive unsets activep and the directives inside the block are
530 * checked for syntax only.
531 *
532 * The second time is after a connection has been established but before
533 * authentication. activep is initialized to 2 and global config directives
534 * are ignored since they have already been processed. If the criteria in a
535 * Match block is met, activep is set and the subsequent directives
536 * processed and actioned until EOF or another Match block unsets it. Any
537 * options set are copied into the main server config.
538 *
539 * Potential additions/improvements:
540 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
541 *
542 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
543 * Match Address 192.168.0.*
544 * Tag trusted
545 * Match Group wheel
546 * Tag trusted
547 * Match Tag trusted
548 * AllowTcpForwarding yes
549 * GatewayPorts clientspecified
550 * [...]
551 *
552 * - Add a PermittedChannelRequests directive
553 * Match Group shell
554 * PermittedChannelRequests session,forwarded-tcpip
555 */
556
557static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000558match_cfg_line_group(const char *grps, int line, const char *user)
559{
560 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000561 struct passwd *pw;
562
Damien Miller565ca3f2006-08-19 00:23:15 +1000563 if (user == NULL)
564 goto out;
565
566 if ((pw = getpwnam(user)) == NULL) {
567 debug("Can't match group at line %d because user %.100s does "
568 "not exist", line, user);
569 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
570 debug("Can't Match group because user %.100s not in any group "
571 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000572 } else if (ga_match_pattern_list(grps) != 1) {
573 debug("user %.100s does not match group list %.100s at line %d",
574 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000575 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000576 debug("user %.100s matched group list %.100s at line %d", user,
577 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000578 result = 1;
579 }
580out:
581 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000582 return result;
583}
584
585static int
Darren Tucker45150472006-07-12 22:34:17 +1000586match_cfg_line(char **condition, int line, const char *user, const char *host,
587 const char *address)
588{
589 int result = 1;
590 char *arg, *attrib, *cp = *condition;
591 size_t len;
592
593 if (user == NULL)
594 debug3("checking syntax for 'Match %s'", cp);
595 else
596 debug3("checking match for '%s' user %s host %s addr %s", cp,
597 user ? user : "(null)", host ? host : "(null)",
598 address ? address : "(null)");
599
600 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
601 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
602 error("Missing Match criteria for %s", attrib);
603 return -1;
604 }
605 len = strlen(arg);
606 if (strcasecmp(attrib, "user") == 0) {
607 if (!user) {
608 result = 0;
609 continue;
610 }
611 if (match_pattern_list(user, arg, len, 0) != 1)
612 result = 0;
613 else
614 debug("user %.100s matched 'User %.100s' at "
615 "line %d", user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000616 } else if (strcasecmp(attrib, "group") == 0) {
617 switch (match_cfg_line_group(arg, line, user)) {
618 case -1:
619 return -1;
620 case 0:
621 result = 0;
622 }
Darren Tucker45150472006-07-12 22:34:17 +1000623 } else if (strcasecmp(attrib, "host") == 0) {
624 if (!host) {
625 result = 0;
626 continue;
627 }
628 if (match_hostname(host, arg, len) != 1)
629 result = 0;
630 else
631 debug("connection from %.100s matched 'Host "
632 "%.100s' at line %d", host, arg, line);
633 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000634 switch (addr_match_list(address, arg)) {
635 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000636 debug("connection from %.100s matched 'Address "
637 "%.100s' at line %d", address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000638 break;
639 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000640 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000641 result = 0;
642 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000643 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000644 return -1;
645 }
Darren Tucker45150472006-07-12 22:34:17 +1000646 } else {
647 error("Unsupported Match attribute %s", attrib);
648 return -1;
649 }
650 }
651 if (user != NULL)
652 debug3("match %sfound", result ? "" : "not ");
653 *condition = cp;
654 return result;
655}
656
Damien Millere2754432006-07-24 14:06:47 +1000657#define WHITESPACE " \t\r\n"
658
Ben Lindstromade03f62001-12-06 18:22:17 +0000659int
660process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000661 const char *filename, int linenum, int *activep, const char *user,
662 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000663{
664 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000665 int cmdline = 0, *intptr, value, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100666 SyslogFacility *log_facility_ptr;
667 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000668 ServerOpCodes opcode;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100669 int port;
Darren Tucker45150472006-07-12 22:34:17 +1000670 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000671 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000672
673 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100674 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100675 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000676 /* Ignore leading whitespace */
677 if (*arg == '\0')
678 arg = strdelim(&cp);
679 if (!arg || !*arg || *arg == '#')
680 return 0;
681 intptr = NULL;
682 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000683 opcode = parse_token(arg, filename, linenum, &flags);
684
685 if (activep == NULL) { /* We are processing a command line directive */
686 cmdline = 1;
687 activep = &cmdline;
688 }
689 if (*activep && opcode != sMatch)
690 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
691 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
692 if (user == NULL) {
693 fatal("%s line %d: Directive '%s' is not allowed "
694 "within a Match block", filename, linenum, arg);
695 } else { /* this is a directive we have already processed */
696 while (arg)
697 arg = strdelim(&cp);
698 return 0;
699 }
700 }
701
Ben Lindstromade03f62001-12-06 18:22:17 +0000702 switch (opcode) {
703 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000704 case sUsePAM:
705 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000706 goto parse_flag;
707
708 /* Standard Options */
709 case sBadOption:
710 return -1;
711 case sPort:
712 /* ignore ports from configfile if cmdline specifies ports */
713 if (options->ports_from_cmdline)
714 return 0;
715 if (options->listen_addrs != NULL)
716 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100717 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000718 if (options->num_ports >= MAX_PORTS)
719 fatal("%s line %d: too many ports.",
720 filename, linenum);
721 arg = strdelim(&cp);
722 if (!arg || *arg == '\0')
723 fatal("%s line %d: missing port number.",
724 filename, linenum);
725 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100726 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000727 fatal("%s line %d: Badly formatted port number.",
728 filename, linenum);
729 break;
730
731 case sServerKeyBits:
732 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000733 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000734 arg = strdelim(&cp);
735 if (!arg || *arg == '\0')
736 fatal("%s line %d: missing integer value.",
737 filename, linenum);
738 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000739 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000740 *intptr = value;
741 break;
742
743 case sLoginGraceTime:
744 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000745 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000746 arg = strdelim(&cp);
747 if (!arg || *arg == '\0')
748 fatal("%s line %d: missing time value.",
749 filename, linenum);
750 if ((value = convtime(arg)) == -1)
751 fatal("%s line %d: invalid time value.",
752 filename, linenum);
753 if (*intptr == -1)
754 *intptr = value;
755 break;
756
757 case sKeyRegenerationTime:
758 intptr = &options->key_regeneration_time;
759 goto parse_time;
760
761 case sListenAddress:
762 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100763 if (arg == NULL || *arg == '\0')
764 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000765 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000766 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
767 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
768 && strchr(p+1, ':') != NULL) {
769 add_listen_addr(options, arg, 0);
770 break;
771 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100772 p = hpdelim(&arg);
773 if (p == NULL)
774 fatal("%s line %d: bad address:port usage",
775 filename, linenum);
776 p = cleanhostname(p);
777 if (arg == NULL)
778 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100779 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100780 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000781
Damien Millerf91ee4c2005-03-01 21:24:33 +1100782 add_listen_addr(options, p, port);
783
Ben Lindstromade03f62001-12-06 18:22:17 +0000784 break;
785
Darren Tucker0f383232005-01-20 10:57:56 +1100786 case sAddressFamily:
787 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000788 if (!arg || *arg == '\0')
789 fatal("%s line %d: missing address family.",
790 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100791 intptr = &options->address_family;
792 if (options->listen_addrs != NULL)
793 fatal("%s line %d: address family must be specified before "
794 "ListenAddress.", filename, linenum);
795 if (strcasecmp(arg, "inet") == 0)
796 value = AF_INET;
797 else if (strcasecmp(arg, "inet6") == 0)
798 value = AF_INET6;
799 else if (strcasecmp(arg, "any") == 0)
800 value = AF_UNSPEC;
801 else
802 fatal("%s line %d: unsupported address family \"%s\".",
803 filename, linenum, arg);
804 if (*intptr == -1)
805 *intptr = value;
806 break;
807
Ben Lindstromade03f62001-12-06 18:22:17 +0000808 case sHostKeyFile:
809 intptr = &options->num_host_key_files;
810 if (*intptr >= MAX_HOSTKEYS)
811 fatal("%s line %d: too many host keys specified (max %d).",
812 filename, linenum, MAX_HOSTKEYS);
813 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000814 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000815 arg = strdelim(&cp);
816 if (!arg || *arg == '\0')
817 fatal("%s line %d: missing file name.",
818 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000819 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100820 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000821 /* increase optional counter */
822 if (intptr != NULL)
823 *intptr = *intptr + 1;
824 }
825 break;
826
Damien Miller0a80ca12010-02-27 07:55:05 +1100827 case sHostCertificate:
828 intptr = &options->num_host_cert_files;
829 if (*intptr >= MAX_HOSTKEYS)
830 fatal("%s line %d: too many host certificates "
831 "specified (max %d).", filename, linenum,
832 MAX_HOSTCERTS);
833 charptr = &options->host_cert_files[*intptr];
834 goto parse_filename;
835 break;
836
Ben Lindstromade03f62001-12-06 18:22:17 +0000837 case sPidFile:
838 charptr = &options->pid_file;
839 goto parse_filename;
840
841 case sPermitRootLogin:
842 intptr = &options->permit_root_login;
843 arg = strdelim(&cp);
844 if (!arg || *arg == '\0')
845 fatal("%s line %d: missing yes/"
846 "without-password/forced-commands-only/no "
847 "argument.", filename, linenum);
848 value = 0; /* silence compiler */
849 if (strcmp(arg, "without-password") == 0)
850 value = PERMIT_NO_PASSWD;
851 else if (strcmp(arg, "forced-commands-only") == 0)
852 value = PERMIT_FORCED_ONLY;
853 else if (strcmp(arg, "yes") == 0)
854 value = PERMIT_YES;
855 else if (strcmp(arg, "no") == 0)
856 value = PERMIT_NO;
857 else
858 fatal("%s line %d: Bad yes/"
859 "without-password/forced-commands-only/no "
860 "argument: %s", filename, linenum, arg);
Darren Tucker15f94272008-01-01 20:36:56 +1100861 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000862 *intptr = value;
863 break;
864
865 case sIgnoreRhosts:
866 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000867 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000868 arg = strdelim(&cp);
869 if (!arg || *arg == '\0')
870 fatal("%s line %d: missing yes/no argument.",
871 filename, linenum);
872 value = 0; /* silence compiler */
873 if (strcmp(arg, "yes") == 0)
874 value = 1;
875 else if (strcmp(arg, "no") == 0)
876 value = 0;
877 else
878 fatal("%s line %d: Bad yes/no argument: %s",
879 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000880 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000881 *intptr = value;
882 break;
883
884 case sIgnoreUserKnownHosts:
885 intptr = &options->ignore_user_known_hosts;
886 goto parse_flag;
887
Ben Lindstromade03f62001-12-06 18:22:17 +0000888 case sRhostsRSAAuthentication:
889 intptr = &options->rhosts_rsa_authentication;
890 goto parse_flag;
891
892 case sHostbasedAuthentication:
893 intptr = &options->hostbased_authentication;
894 goto parse_flag;
895
896 case sHostbasedUsesNameFromPacketOnly:
897 intptr = &options->hostbased_uses_name_from_packet_only;
898 goto parse_flag;
899
900 case sRSAAuthentication:
901 intptr = &options->rsa_authentication;
902 goto parse_flag;
903
904 case sPubkeyAuthentication:
905 intptr = &options->pubkey_authentication;
906 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000907
Ben Lindstromade03f62001-12-06 18:22:17 +0000908 case sKerberosAuthentication:
909 intptr = &options->kerberos_authentication;
910 goto parse_flag;
911
912 case sKerberosOrLocalPasswd:
913 intptr = &options->kerberos_or_local_passwd;
914 goto parse_flag;
915
916 case sKerberosTicketCleanup:
917 intptr = &options->kerberos_ticket_cleanup;
918 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000919
Darren Tucker22ef5082003-12-31 11:37:34 +1100920 case sKerberosGetAFSToken:
921 intptr = &options->kerberos_get_afs_token;
922 goto parse_flag;
923
Darren Tucker0efd1552003-08-26 11:49:55 +1000924 case sGssAuthentication:
925 intptr = &options->gss_authentication;
926 goto parse_flag;
927
928 case sGssCleanupCreds:
929 intptr = &options->gss_cleanup_creds;
930 goto parse_flag;
931
Ben Lindstromade03f62001-12-06 18:22:17 +0000932 case sPasswordAuthentication:
933 intptr = &options->password_authentication;
934 goto parse_flag;
935
Damien Miller01ed2272008-11-05 16:20:46 +1100936 case sZeroKnowledgePasswordAuthentication:
937 intptr = &options->zero_knowledge_password_authentication;
938 goto parse_flag;
939
Ben Lindstromade03f62001-12-06 18:22:17 +0000940 case sKbdInteractiveAuthentication:
941 intptr = &options->kbd_interactive_authentication;
942 goto parse_flag;
943
944 case sChallengeResponseAuthentication:
945 intptr = &options->challenge_response_authentication;
946 goto parse_flag;
947
948 case sPrintMotd:
949 intptr = &options->print_motd;
950 goto parse_flag;
951
952 case sPrintLastLog:
953 intptr = &options->print_lastlog;
954 goto parse_flag;
955
956 case sX11Forwarding:
957 intptr = &options->x11_forwarding;
958 goto parse_flag;
959
960 case sX11DisplayOffset:
961 intptr = &options->x11_display_offset;
962 goto parse_int;
963
Damien Miller95c249f2002-02-05 12:11:34 +1100964 case sX11UseLocalhost:
965 intptr = &options->x11_use_localhost;
966 goto parse_flag;
967
Ben Lindstromade03f62001-12-06 18:22:17 +0000968 case sXAuthLocation:
969 charptr = &options->xauth_location;
970 goto parse_filename;
971
972 case sStrictModes:
973 intptr = &options->strict_modes;
974 goto parse_flag;
975
Damien Miller12c150e2003-12-17 16:31:10 +1100976 case sTCPKeepAlive:
977 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000978 goto parse_flag;
979
980 case sEmptyPasswd:
981 intptr = &options->permit_empty_passwd;
982 goto parse_flag;
983
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000984 case sPermitUserEnvironment:
985 intptr = &options->permit_user_env;
986 goto parse_flag;
987
Ben Lindstromade03f62001-12-06 18:22:17 +0000988 case sUseLogin:
989 intptr = &options->use_login;
990 goto parse_flag;
991
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000992 case sCompression:
993 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000994 arg = strdelim(&cp);
995 if (!arg || *arg == '\0')
996 fatal("%s line %d: missing yes/no/delayed "
997 "argument.", filename, linenum);
998 value = 0; /* silence compiler */
999 if (strcmp(arg, "delayed") == 0)
1000 value = COMP_DELAYED;
1001 else if (strcmp(arg, "yes") == 0)
1002 value = COMP_ZLIB;
1003 else if (strcmp(arg, "no") == 0)
1004 value = COMP_NONE;
1005 else
1006 fatal("%s line %d: Bad yes/no/delayed "
1007 "argument: %s", filename, linenum, arg);
1008 if (*intptr == -1)
1009 *intptr = value;
1010 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001011
Ben Lindstromade03f62001-12-06 18:22:17 +00001012 case sGatewayPorts:
1013 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001014 arg = strdelim(&cp);
1015 if (!arg || *arg == '\0')
1016 fatal("%s line %d: missing yes/no/clientspecified "
1017 "argument.", filename, linenum);
1018 value = 0; /* silence compiler */
1019 if (strcmp(arg, "clientspecified") == 0)
1020 value = 2;
1021 else if (strcmp(arg, "yes") == 0)
1022 value = 1;
1023 else if (strcmp(arg, "no") == 0)
1024 value = 0;
1025 else
1026 fatal("%s line %d: Bad yes/no/clientspecified "
1027 "argument: %s", filename, linenum, arg);
Darren Tucker82347a82007-02-25 20:37:52 +11001028 if (*activep && *intptr == -1)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001029 *intptr = value;
1030 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001031
Damien Miller3a961dc2003-06-03 10:25:48 +10001032 case sUseDNS:
1033 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001034 goto parse_flag;
1035
1036 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001037 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 arg = strdelim(&cp);
1039 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001040 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001041 fatal("%.200s line %d: unsupported log facility '%s'",
1042 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001043 if (*log_facility_ptr == -1)
1044 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001045 break;
1046
1047 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001048 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001049 arg = strdelim(&cp);
1050 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001051 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001052 fatal("%.200s line %d: unsupported log level '%s'",
1053 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001054 if (*log_level_ptr == -1)
1055 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001056 break;
1057
1058 case sAllowTcpForwarding:
1059 intptr = &options->allow_tcp_forwarding;
1060 goto parse_flag;
1061
Damien Miller4f755cd2008-05-19 14:57:41 +10001062 case sAllowAgentForwarding:
1063 intptr = &options->allow_agent_forwarding;
1064 goto parse_flag;
1065
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001066 case sUsePrivilegeSeparation:
1067 intptr = &use_privsep;
1068 goto parse_flag;
1069
Ben Lindstromade03f62001-12-06 18:22:17 +00001070 case sAllowUsers:
1071 while ((arg = strdelim(&cp)) && *arg != '\0') {
1072 if (options->num_allow_users >= MAX_ALLOW_USERS)
1073 fatal("%s line %d: too many allow users.",
1074 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001075 options->allow_users[options->num_allow_users++] =
1076 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001077 }
1078 break;
1079
1080 case sDenyUsers:
1081 while ((arg = strdelim(&cp)) && *arg != '\0') {
1082 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001083 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001084 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001085 options->deny_users[options->num_deny_users++] =
1086 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001087 }
1088 break;
1089
1090 case sAllowGroups:
1091 while ((arg = strdelim(&cp)) && *arg != '\0') {
1092 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1093 fatal("%s line %d: too many allow groups.",
1094 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001095 options->allow_groups[options->num_allow_groups++] =
1096 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001097 }
1098 break;
1099
1100 case sDenyGroups:
1101 while ((arg = strdelim(&cp)) && *arg != '\0') {
1102 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1103 fatal("%s line %d: too many deny groups.",
1104 filename, linenum);
1105 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1106 }
1107 break;
1108
1109 case sCiphers:
1110 arg = strdelim(&cp);
1111 if (!arg || *arg == '\0')
1112 fatal("%s line %d: Missing argument.", filename, linenum);
1113 if (!ciphers_valid(arg))
1114 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1115 filename, linenum, arg ? arg : "<NONE>");
1116 if (options->ciphers == NULL)
1117 options->ciphers = xstrdup(arg);
1118 break;
1119
1120 case sMacs:
1121 arg = strdelim(&cp);
1122 if (!arg || *arg == '\0')
1123 fatal("%s line %d: Missing argument.", filename, linenum);
1124 if (!mac_valid(arg))
1125 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1126 filename, linenum, arg ? arg : "<NONE>");
1127 if (options->macs == NULL)
1128 options->macs = xstrdup(arg);
1129 break;
1130
1131 case sProtocol:
1132 intptr = &options->protocol;
1133 arg = strdelim(&cp);
1134 if (!arg || *arg == '\0')
1135 fatal("%s line %d: Missing argument.", filename, linenum);
1136 value = proto_spec(arg);
1137 if (value == SSH_PROTO_UNKNOWN)
1138 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001139 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001140 if (*intptr == SSH_PROTO_UNKNOWN)
1141 *intptr = value;
1142 break;
1143
1144 case sSubsystem:
1145 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1146 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001147 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001148 }
1149 arg = strdelim(&cp);
1150 if (!arg || *arg == '\0')
1151 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001152 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001153 if (!*activep) {
1154 arg = strdelim(&cp);
1155 break;
1156 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001157 for (i = 0; i < options->num_subsystems; i++)
1158 if (strcmp(arg, options->subsystem_name[i]) == 0)
1159 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001160 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001161 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1162 arg = strdelim(&cp);
1163 if (!arg || *arg == '\0')
1164 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001165 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001166 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001167
1168 /* Collect arguments (separate to executable) */
1169 p = xstrdup(arg);
1170 len = strlen(p) + 1;
1171 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1172 len += 1 + strlen(arg);
1173 p = xrealloc(p, 1, len);
1174 strlcat(p, " ", len);
1175 strlcat(p, arg, len);
1176 }
1177 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001178 options->num_subsystems++;
1179 break;
1180
1181 case sMaxStartups:
1182 arg = strdelim(&cp);
1183 if (!arg || *arg == '\0')
1184 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001185 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001186 if ((n = sscanf(arg, "%d:%d:%d",
1187 &options->max_startups_begin,
1188 &options->max_startups_rate,
1189 &options->max_startups)) == 3) {
1190 if (options->max_startups_begin >
1191 options->max_startups ||
1192 options->max_startups_rate > 100 ||
1193 options->max_startups_rate < 1)
1194 fatal("%s line %d: Illegal MaxStartups spec.",
1195 filename, linenum);
1196 } else if (n != 1)
1197 fatal("%s line %d: Illegal MaxStartups spec.",
1198 filename, linenum);
1199 else
1200 options->max_startups = options->max_startups_begin;
1201 break;
1202
Darren Tucker89413db2004-05-24 10:36:23 +10001203 case sMaxAuthTries:
1204 intptr = &options->max_authtries;
1205 goto parse_int;
1206
Damien Miller7207f642008-05-19 15:34:50 +10001207 case sMaxSessions:
1208 intptr = &options->max_sessions;
1209 goto parse_int;
1210
Ben Lindstromade03f62001-12-06 18:22:17 +00001211 case sBanner:
1212 charptr = &options->banner;
1213 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001214
Ben Lindstromade03f62001-12-06 18:22:17 +00001215 /*
1216 * These options can contain %X options expanded at
1217 * connect time, so that you can specify paths like:
1218 *
1219 * AuthorizedKeysFile /etc/ssh_keys/%u
1220 */
1221 case sAuthorizedKeysFile:
1222 case sAuthorizedKeysFile2:
Damien Miller4dec5d72006-08-05 11:38:40 +10001223 charptr = (opcode == sAuthorizedKeysFile) ?
Ben Lindstromade03f62001-12-06 18:22:17 +00001224 &options->authorized_keys_file :
1225 &options->authorized_keys_file2;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001226 arg = strdelim(&cp);
1227 if (!arg || *arg == '\0')
1228 fatal("%s line %d: missing file name.",
1229 filename, linenum);
1230 if (*activep && *charptr == NULL) {
1231 *charptr = derelativise_path(arg);
1232 /* increase optional counter */
1233 if (intptr != NULL)
1234 *intptr = *intptr + 1;
1235 }
1236 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001237
1238 case sClientAliveInterval:
1239 intptr = &options->client_alive_interval;
1240 goto parse_time;
1241
1242 case sClientAliveCountMax:
1243 intptr = &options->client_alive_count_max;
1244 goto parse_int;
1245
Darren Tucker46bc0752004-05-02 22:11:30 +10001246 case sAcceptEnv:
1247 while ((arg = strdelim(&cp)) && *arg != '\0') {
1248 if (strchr(arg, '=') != NULL)
1249 fatal("%s line %d: Invalid environment name.",
1250 filename, linenum);
1251 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1252 fatal("%s line %d: too many allow env.",
1253 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001254 if (!*activep)
1255 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001256 options->accept_env[options->num_accept_env++] =
1257 xstrdup(arg);
1258 }
1259 break;
1260
Damien Millerd27b9472005-12-13 19:29:02 +11001261 case sPermitTunnel:
1262 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001263 arg = strdelim(&cp);
1264 if (!arg || *arg == '\0')
1265 fatal("%s line %d: Missing yes/point-to-point/"
1266 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001267 value = -1;
1268 for (i = 0; tunmode_desc[i].val != -1; i++)
1269 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1270 value = tunmode_desc[i].val;
1271 break;
1272 }
1273 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001274 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1275 "no argument: %s", filename, linenum, arg);
1276 if (*intptr == -1)
1277 *intptr = value;
1278 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001279
Darren Tucker45150472006-07-12 22:34:17 +10001280 case sMatch:
1281 if (cmdline)
1282 fatal("Match directive not supported as a command-line "
1283 "option");
1284 value = match_cfg_line(&cp, linenum, user, host, address);
1285 if (value < 0)
1286 fatal("%s line %d: Bad Match condition", filename,
1287 linenum);
1288 *activep = value;
1289 break;
1290
Damien Miller9b439df2006-07-24 14:04:00 +10001291 case sPermitOpen:
1292 arg = strdelim(&cp);
1293 if (!arg || *arg == '\0')
1294 fatal("%s line %d: missing PermitOpen specification",
1295 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001296 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001297 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001298 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001299 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001300 options->num_permitted_opens = 0;
1301 }
Damien Miller9b439df2006-07-24 14:04:00 +10001302 break;
1303 }
Damien Millera29b95e2007-01-05 16:28:36 +11001304 if (*activep && n == -1)
1305 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001306 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1307 p = hpdelim(&arg);
1308 if (p == NULL)
1309 fatal("%s line %d: missing host in PermitOpen",
1310 filename, linenum);
1311 p = cleanhostname(p);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001312 if (arg == NULL || (port = a2port(arg)) <= 0)
Damien Millera765cf42006-07-24 14:08:13 +10001313 fatal("%s line %d: bad port number in "
1314 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001315 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001316 options->num_permitted_opens =
1317 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001318 }
Damien Miller9b439df2006-07-24 14:04:00 +10001319 break;
1320
Damien Millere2754432006-07-24 14:06:47 +10001321 case sForceCommand:
1322 if (cp == NULL)
1323 fatal("%.200s line %d: Missing argument.", filename,
1324 linenum);
1325 len = strspn(cp, WHITESPACE);
1326 if (*activep && options->adm_forced_command == NULL)
1327 options->adm_forced_command = xstrdup(cp + len);
1328 return 0;
1329
Damien Millerd8cb1f12008-02-10 22:40:12 +11001330 case sChrootDirectory:
1331 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001332
1333 arg = strdelim(&cp);
1334 if (!arg || *arg == '\0')
1335 fatal("%s line %d: missing file name.",
1336 filename, linenum);
1337 if (*activep && *charptr == NULL)
1338 *charptr = xstrdup(arg);
1339 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001340
Damien Miller1aed65e2010-03-04 21:53:35 +11001341 case sTrustedUserCAKeys:
1342 charptr = &options->trusted_user_ca_keys;
1343 goto parse_filename;
1344
1345 case sRevokedKeys:
1346 charptr = &options->revoked_keys_file;
1347 goto parse_filename;
1348
Ben Lindstromade03f62001-12-06 18:22:17 +00001349 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001350 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001351 filename, linenum, arg);
1352 while (arg)
1353 arg = strdelim(&cp);
1354 break;
1355
Damien Millerf9b3feb2003-05-16 11:38:32 +10001356 case sUnsupported:
1357 logit("%s line %d: Unsupported option %s",
1358 filename, linenum, arg);
1359 while (arg)
1360 arg = strdelim(&cp);
1361 break;
1362
Ben Lindstromade03f62001-12-06 18:22:17 +00001363 default:
1364 fatal("%s line %d: Missing handler for opcode %s (%d)",
1365 filename, linenum, arg, opcode);
1366 }
1367 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1368 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1369 filename, linenum, arg);
1370 return 0;
1371}
1372
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001373/* Reads the server configuration file. */
1374
Damien Miller4af51302000-04-16 11:18:38 +10001375void
Darren Tucker645ab752004-06-25 13:33:20 +10001376load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001377{
Darren Tucker645ab752004-06-25 13:33:20 +10001378 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001379 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001380
Darren Tucker645ab752004-06-25 13:33:20 +10001381 debug2("%s: filename %s", __func__, filename);
1382 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001383 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001384 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001385 }
Darren Tucker645ab752004-06-25 13:33:20 +10001386 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001387 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001388 /*
1389 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001390 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001391 * line numbers later for error messages
1392 */
1393 if ((cp = strchr(line, '#')) != NULL)
1394 memcpy(cp, "\n", 2);
1395 cp = line + strspn(line, " \t\r");
1396
1397 buffer_append(conf, cp, strlen(cp));
1398 }
1399 buffer_append(conf, "\0", 1);
1400 fclose(f);
1401 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1402}
1403
1404void
Darren Tucker45150472006-07-12 22:34:17 +10001405parse_server_match_config(ServerOptions *options, const char *user,
1406 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001407{
Darren Tucker45150472006-07-12 22:34:17 +10001408 ServerOptions mo;
1409
1410 initialize_server_options(&mo);
1411 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
Darren Tucker1629c072007-02-19 22:25:37 +11001412 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001413}
1414
Darren Tucker1629c072007-02-19 22:25:37 +11001415/* Helper macros */
1416#define M_CP_INTOPT(n) do {\
1417 if (src->n != -1) \
1418 dst->n = src->n; \
1419} while (0)
1420#define M_CP_STROPT(n) do {\
1421 if (src->n != NULL) { \
1422 if (dst->n != NULL) \
1423 xfree(dst->n); \
1424 dst->n = src->n; \
1425 } \
1426} while(0)
1427
1428/*
1429 * Copy any supported values that are set.
1430 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001431 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001432 * array values that are not used pre-authentication, because any that we
1433 * do use must be explictly sent in mm_getpwnamallow().
1434 */
Darren Tucker45150472006-07-12 22:34:17 +10001435void
Darren Tucker1629c072007-02-19 22:25:37 +11001436copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001437{
Darren Tucker1629c072007-02-19 22:25:37 +11001438 M_CP_INTOPT(password_authentication);
1439 M_CP_INTOPT(gss_authentication);
1440 M_CP_INTOPT(rsa_authentication);
1441 M_CP_INTOPT(pubkey_authentication);
1442 M_CP_INTOPT(kerberos_authentication);
1443 M_CP_INTOPT(hostbased_authentication);
1444 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001445 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001446 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001447 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001448
1449 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001450 M_CP_INTOPT(allow_agent_forwarding);
Darren Tucker1629c072007-02-19 22:25:37 +11001451 M_CP_INTOPT(gateway_ports);
1452 M_CP_INTOPT(x11_display_offset);
1453 M_CP_INTOPT(x11_forwarding);
1454 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001455 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001456 M_CP_INTOPT(max_authtries);
Darren Tucker1629c072007-02-19 22:25:37 +11001457
1458 M_CP_STROPT(banner);
1459 if (preauth)
1460 return;
1461 M_CP_STROPT(adm_forced_command);
Damien Millerd8cb1f12008-02-10 22:40:12 +11001462 M_CP_STROPT(chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11001463 M_CP_STROPT(trusted_user_ca_keys);
1464 M_CP_STROPT(revoked_keys_file);
Darren Tucker45150472006-07-12 22:34:17 +10001465}
1466
Darren Tucker1629c072007-02-19 22:25:37 +11001467#undef M_CP_INTOPT
1468#undef M_CP_STROPT
1469
Darren Tucker45150472006-07-12 22:34:17 +10001470void
1471parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1472 const char *user, const char *host, const char *address)
1473{
1474 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001475 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001476
1477 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1478
Darren Tucker9fbac712004-08-12 22:41:44 +10001479 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001480 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001481 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001482 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001483 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001484 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001485 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001486 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001487 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001488 if (bad_options > 0)
1489 fatal("%s: terminating, %d bad configuration options",
1490 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001491}
Darren Tuckere7140f22008-06-10 23:01:51 +10001492
1493static const char *
1494fmt_intarg(ServerOpCodes code, int val)
1495{
1496 if (code == sAddressFamily) {
1497 switch (val) {
1498 case AF_INET:
1499 return "inet";
1500 case AF_INET6:
1501 return "inet6";
1502 case AF_UNSPEC:
1503 return "any";
1504 default:
1505 return "UNKNOWN";
1506 }
1507 }
1508 if (code == sPermitRootLogin) {
1509 switch (val) {
1510 case PERMIT_NO_PASSWD:
Darren Tuckerff4350e2008-11-11 16:31:05 +11001511 return "without-password";
Darren Tuckere7140f22008-06-10 23:01:51 +10001512 case PERMIT_FORCED_ONLY:
1513 return "forced-commands-only";
1514 case PERMIT_YES:
1515 return "yes";
1516 }
1517 }
1518 if (code == sProtocol) {
1519 switch (val) {
1520 case SSH_PROTO_1:
1521 return "1";
1522 case SSH_PROTO_2:
1523 return "2";
1524 case (SSH_PROTO_1|SSH_PROTO_2):
1525 return "2,1";
1526 default:
1527 return "UNKNOWN";
1528 }
1529 }
1530 if (code == sGatewayPorts && val == 2)
1531 return "clientspecified";
1532 if (code == sCompression && val == COMP_DELAYED)
1533 return "delayed";
1534 switch (val) {
1535 case -1:
1536 return "unset";
1537 case 0:
1538 return "no";
1539 case 1:
1540 return "yes";
1541 }
1542 return "UNKNOWN";
1543}
1544
1545static const char *
1546lookup_opcode_name(ServerOpCodes code)
1547{
1548 u_int i;
1549
1550 for (i = 0; keywords[i].name != NULL; i++)
1551 if (keywords[i].opcode == code)
1552 return(keywords[i].name);
1553 return "UNKNOWN";
1554}
1555
1556static void
1557dump_cfg_int(ServerOpCodes code, int val)
1558{
1559 printf("%s %d\n", lookup_opcode_name(code), val);
1560}
1561
1562static void
1563dump_cfg_fmtint(ServerOpCodes code, int val)
1564{
1565 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1566}
1567
1568static void
1569dump_cfg_string(ServerOpCodes code, const char *val)
1570{
1571 if (val == NULL)
1572 return;
1573 printf("%s %s\n", lookup_opcode_name(code), val);
1574}
1575
1576static void
1577dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1578{
1579 u_int i;
1580
1581 for (i = 0; i < count; i++)
1582 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1583}
1584
1585void
1586dump_config(ServerOptions *o)
1587{
1588 u_int i;
1589 int ret;
1590 struct addrinfo *ai;
1591 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1592
1593 /* these are usually at the top of the config */
1594 for (i = 0; i < o->num_ports; i++)
1595 printf("port %d\n", o->ports[i]);
1596 dump_cfg_fmtint(sProtocol, o->protocol);
1597 dump_cfg_fmtint(sAddressFamily, o->address_family);
1598
1599 /* ListenAddress must be after Port */
1600 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1601 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1602 sizeof(addr), port, sizeof(port),
1603 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1604 error("getnameinfo failed: %.100s",
1605 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1606 strerror(errno));
1607 } else {
1608 if (ai->ai_family == AF_INET6)
1609 printf("listenaddress [%s]:%s\n", addr, port);
1610 else
1611 printf("listenaddress %s:%s\n", addr, port);
1612 }
1613 }
1614
1615 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001616#ifdef USE_PAM
1617 dump_cfg_int(sUsePAM, o->use_pam);
1618#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001619 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1620 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1621 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1622 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1623 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001624 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001625 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1626 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1627
1628 /* formatted integer arguments */
1629 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1630 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1631 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1632 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1633 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1634 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1635 o->hostbased_uses_name_from_packet_only);
1636 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1637 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001638#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001639 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1640 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1641 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001642# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001643 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001644# endif
1645#endif
1646#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001647 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1648 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001649#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001650#ifdef JPAKE
1651 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1652 o->zero_knowledge_password_authentication);
1653#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001654 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1655 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1656 o->kbd_interactive_authentication);
1657 dump_cfg_fmtint(sChallengeResponseAuthentication,
1658 o->challenge_response_authentication);
1659 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1660 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1661 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1662 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1663 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1664 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1665 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1666 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1667 dump_cfg_fmtint(sUseLogin, o->use_login);
1668 dump_cfg_fmtint(sCompression, o->compression);
1669 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1670 dump_cfg_fmtint(sUseDNS, o->use_dns);
1671 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1672 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1673
1674 /* string arguments */
1675 dump_cfg_string(sPidFile, o->pid_file);
1676 dump_cfg_string(sXAuthLocation, o->xauth_location);
1677 dump_cfg_string(sCiphers, o->ciphers);
1678 dump_cfg_string(sMacs, o->macs);
1679 dump_cfg_string(sBanner, o->banner);
1680 dump_cfg_string(sAuthorizedKeysFile, o->authorized_keys_file);
1681 dump_cfg_string(sAuthorizedKeysFile2, o->authorized_keys_file2);
1682 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11001683 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11001684 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
1685 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Darren Tuckere7140f22008-06-10 23:01:51 +10001686
1687 /* string arguments requiring a lookup */
1688 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1689 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1690
1691 /* string array arguments */
1692 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1693 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11001694 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
1695 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10001696 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1697 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1698 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1699 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1700 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1701
1702 /* other arguments */
1703 for (i = 0; i < o->num_subsystems; i++)
1704 printf("subsystem %s %s\n", o->subsystem_name[i],
1705 o->subsystem_args[i]);
1706
1707 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1708 o->max_startups_rate, o->max_startups);
1709
1710 for (i = 0; tunmode_desc[i].val != -1; i++)
1711 if (tunmode_desc[i].val == o->permit_tun) {
1712 s = tunmode_desc[i].text;
1713 break;
1714 }
1715 dump_cfg_string(sPermitTunnel, s);
1716
Darren Tuckere7140f22008-06-10 23:01:51 +10001717 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10001718}