blob: 7d027ddb990aeac82779b66cbdf9418b10322a76 [file] [log] [blame]
Damien Miller44451d02010-03-26 10:40:04 +11001/* $OpenBSD: servconf.c,v 1.207 2010/03/25 23:38:28 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{
Damien Miller44451d02010-03-26 10:40:04 +1100473 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100474
475 expanded = tilde_expand_filename(path, getuid());
476 if (*expanded == '/')
477 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100478 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100479 fatal("%s: getcwd: %s", __func__, strerror(errno));
480 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100481 xfree(expanded);
482 return ret;
483}
484
Ben Lindstrombba81212001-06-25 05:01:22 +0000485static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100486add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100487{
Damien Millereccb9de2005-06-17 12:59:34 +1000488 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100489
490 if (options->num_ports == 0)
491 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100492 if (options->address_family == -1)
493 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000494 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000495 for (i = 0; i < options->num_ports; i++)
496 add_one_listen_addr(options, addr, options->ports[i]);
497 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000498 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000499}
500
Ben Lindstrombba81212001-06-25 05:01:22 +0000501static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100502add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000503{
504 struct addrinfo hints, *ai, *aitop;
505 char strport[NI_MAXSERV];
506 int gaierr;
507
508 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100509 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000510 hints.ai_socktype = SOCK_STREAM;
511 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100512 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000513 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
514 fatal("bad addr or host: %s (%s)",
515 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100516 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000517 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
518 ;
519 ai->ai_next = options->listen_addrs;
520 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100521}
522
Darren Tucker45150472006-07-12 22:34:17 +1000523/*
524 * The strategy for the Match blocks is that the config file is parsed twice.
525 *
526 * The first time is at startup. activep is initialized to 1 and the
527 * directives in the global context are processed and acted on. Hitting a
528 * Match directive unsets activep and the directives inside the block are
529 * checked for syntax only.
530 *
531 * The second time is after a connection has been established but before
532 * authentication. activep is initialized to 2 and global config directives
533 * are ignored since they have already been processed. If the criteria in a
534 * Match block is met, activep is set and the subsequent directives
535 * processed and actioned until EOF or another Match block unsets it. Any
536 * options set are copied into the main server config.
537 *
538 * Potential additions/improvements:
539 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
540 *
541 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
542 * Match Address 192.168.0.*
543 * Tag trusted
544 * Match Group wheel
545 * Tag trusted
546 * Match Tag trusted
547 * AllowTcpForwarding yes
548 * GatewayPorts clientspecified
549 * [...]
550 *
551 * - Add a PermittedChannelRequests directive
552 * Match Group shell
553 * PermittedChannelRequests session,forwarded-tcpip
554 */
555
556static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000557match_cfg_line_group(const char *grps, int line, const char *user)
558{
559 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000560 struct passwd *pw;
561
Damien Miller565ca3f2006-08-19 00:23:15 +1000562 if (user == NULL)
563 goto out;
564
565 if ((pw = getpwnam(user)) == NULL) {
566 debug("Can't match group at line %d because user %.100s does "
567 "not exist", line, user);
568 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
569 debug("Can't Match group because user %.100s not in any group "
570 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000571 } else if (ga_match_pattern_list(grps) != 1) {
572 debug("user %.100s does not match group list %.100s at line %d",
573 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000574 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000575 debug("user %.100s matched group list %.100s at line %d", user,
576 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000577 result = 1;
578 }
579out:
580 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000581 return result;
582}
583
584static int
Darren Tucker45150472006-07-12 22:34:17 +1000585match_cfg_line(char **condition, int line, const char *user, const char *host,
586 const char *address)
587{
588 int result = 1;
589 char *arg, *attrib, *cp = *condition;
590 size_t len;
591
592 if (user == NULL)
593 debug3("checking syntax for 'Match %s'", cp);
594 else
595 debug3("checking match for '%s' user %s host %s addr %s", cp,
596 user ? user : "(null)", host ? host : "(null)",
597 address ? address : "(null)");
598
599 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
600 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
601 error("Missing Match criteria for %s", attrib);
602 return -1;
603 }
604 len = strlen(arg);
605 if (strcasecmp(attrib, "user") == 0) {
606 if (!user) {
607 result = 0;
608 continue;
609 }
610 if (match_pattern_list(user, arg, len, 0) != 1)
611 result = 0;
612 else
613 debug("user %.100s matched 'User %.100s' at "
614 "line %d", user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000615 } else if (strcasecmp(attrib, "group") == 0) {
616 switch (match_cfg_line_group(arg, line, user)) {
617 case -1:
618 return -1;
619 case 0:
620 result = 0;
621 }
Darren Tucker45150472006-07-12 22:34:17 +1000622 } else if (strcasecmp(attrib, "host") == 0) {
623 if (!host) {
624 result = 0;
625 continue;
626 }
627 if (match_hostname(host, arg, len) != 1)
628 result = 0;
629 else
630 debug("connection from %.100s matched 'Host "
631 "%.100s' at line %d", host, arg, line);
632 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000633 switch (addr_match_list(address, arg)) {
634 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000635 debug("connection from %.100s matched 'Address "
636 "%.100s' at line %d", address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000637 break;
638 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000639 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000640 result = 0;
641 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000642 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000643 return -1;
644 }
Darren Tucker45150472006-07-12 22:34:17 +1000645 } else {
646 error("Unsupported Match attribute %s", attrib);
647 return -1;
648 }
649 }
650 if (user != NULL)
651 debug3("match %sfound", result ? "" : "not ");
652 *condition = cp;
653 return result;
654}
655
Damien Millere2754432006-07-24 14:06:47 +1000656#define WHITESPACE " \t\r\n"
657
Ben Lindstromade03f62001-12-06 18:22:17 +0000658int
659process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000660 const char *filename, int linenum, int *activep, const char *user,
661 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000662{
663 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000664 int cmdline = 0, *intptr, value, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100665 SyslogFacility *log_facility_ptr;
666 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000667 ServerOpCodes opcode;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100668 int port;
Darren Tucker45150472006-07-12 22:34:17 +1000669 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000670 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000671
672 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100673 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100674 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000675 /* Ignore leading whitespace */
676 if (*arg == '\0')
677 arg = strdelim(&cp);
678 if (!arg || !*arg || *arg == '#')
679 return 0;
680 intptr = NULL;
681 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000682 opcode = parse_token(arg, filename, linenum, &flags);
683
684 if (activep == NULL) { /* We are processing a command line directive */
685 cmdline = 1;
686 activep = &cmdline;
687 }
688 if (*activep && opcode != sMatch)
689 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
690 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
691 if (user == NULL) {
692 fatal("%s line %d: Directive '%s' is not allowed "
693 "within a Match block", filename, linenum, arg);
694 } else { /* this is a directive we have already processed */
695 while (arg)
696 arg = strdelim(&cp);
697 return 0;
698 }
699 }
700
Ben Lindstromade03f62001-12-06 18:22:17 +0000701 switch (opcode) {
702 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000703 case sUsePAM:
704 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000705 goto parse_flag;
706
707 /* Standard Options */
708 case sBadOption:
709 return -1;
710 case sPort:
711 /* ignore ports from configfile if cmdline specifies ports */
712 if (options->ports_from_cmdline)
713 return 0;
714 if (options->listen_addrs != NULL)
715 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100716 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000717 if (options->num_ports >= MAX_PORTS)
718 fatal("%s line %d: too many ports.",
719 filename, linenum);
720 arg = strdelim(&cp);
721 if (!arg || *arg == '\0')
722 fatal("%s line %d: missing port number.",
723 filename, linenum);
724 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100725 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000726 fatal("%s line %d: Badly formatted port number.",
727 filename, linenum);
728 break;
729
730 case sServerKeyBits:
731 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000732 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000733 arg = strdelim(&cp);
734 if (!arg || *arg == '\0')
735 fatal("%s line %d: missing integer value.",
736 filename, linenum);
737 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000738 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000739 *intptr = value;
740 break;
741
742 case sLoginGraceTime:
743 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000744 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000745 arg = strdelim(&cp);
746 if (!arg || *arg == '\0')
747 fatal("%s line %d: missing time value.",
748 filename, linenum);
749 if ((value = convtime(arg)) == -1)
750 fatal("%s line %d: invalid time value.",
751 filename, linenum);
752 if (*intptr == -1)
753 *intptr = value;
754 break;
755
756 case sKeyRegenerationTime:
757 intptr = &options->key_regeneration_time;
758 goto parse_time;
759
760 case sListenAddress:
761 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100762 if (arg == NULL || *arg == '\0')
763 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000764 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000765 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
766 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
767 && strchr(p+1, ':') != NULL) {
768 add_listen_addr(options, arg, 0);
769 break;
770 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100771 p = hpdelim(&arg);
772 if (p == NULL)
773 fatal("%s line %d: bad address:port usage",
774 filename, linenum);
775 p = cleanhostname(p);
776 if (arg == NULL)
777 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100778 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100779 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000780
Damien Millerf91ee4c2005-03-01 21:24:33 +1100781 add_listen_addr(options, p, port);
782
Ben Lindstromade03f62001-12-06 18:22:17 +0000783 break;
784
Darren Tucker0f383232005-01-20 10:57:56 +1100785 case sAddressFamily:
786 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000787 if (!arg || *arg == '\0')
788 fatal("%s line %d: missing address family.",
789 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100790 intptr = &options->address_family;
791 if (options->listen_addrs != NULL)
792 fatal("%s line %d: address family must be specified before "
793 "ListenAddress.", filename, linenum);
794 if (strcasecmp(arg, "inet") == 0)
795 value = AF_INET;
796 else if (strcasecmp(arg, "inet6") == 0)
797 value = AF_INET6;
798 else if (strcasecmp(arg, "any") == 0)
799 value = AF_UNSPEC;
800 else
801 fatal("%s line %d: unsupported address family \"%s\".",
802 filename, linenum, arg);
803 if (*intptr == -1)
804 *intptr = value;
805 break;
806
Ben Lindstromade03f62001-12-06 18:22:17 +0000807 case sHostKeyFile:
808 intptr = &options->num_host_key_files;
809 if (*intptr >= MAX_HOSTKEYS)
810 fatal("%s line %d: too many host keys specified (max %d).",
811 filename, linenum, MAX_HOSTKEYS);
812 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000813 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000814 arg = strdelim(&cp);
815 if (!arg || *arg == '\0')
816 fatal("%s line %d: missing file name.",
817 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000818 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100819 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000820 /* increase optional counter */
821 if (intptr != NULL)
822 *intptr = *intptr + 1;
823 }
824 break;
825
Damien Miller0a80ca12010-02-27 07:55:05 +1100826 case sHostCertificate:
827 intptr = &options->num_host_cert_files;
828 if (*intptr >= MAX_HOSTKEYS)
829 fatal("%s line %d: too many host certificates "
830 "specified (max %d).", filename, linenum,
831 MAX_HOSTCERTS);
832 charptr = &options->host_cert_files[*intptr];
833 goto parse_filename;
834 break;
835
Ben Lindstromade03f62001-12-06 18:22:17 +0000836 case sPidFile:
837 charptr = &options->pid_file;
838 goto parse_filename;
839
840 case sPermitRootLogin:
841 intptr = &options->permit_root_login;
842 arg = strdelim(&cp);
843 if (!arg || *arg == '\0')
844 fatal("%s line %d: missing yes/"
845 "without-password/forced-commands-only/no "
846 "argument.", filename, linenum);
847 value = 0; /* silence compiler */
848 if (strcmp(arg, "without-password") == 0)
849 value = PERMIT_NO_PASSWD;
850 else if (strcmp(arg, "forced-commands-only") == 0)
851 value = PERMIT_FORCED_ONLY;
852 else if (strcmp(arg, "yes") == 0)
853 value = PERMIT_YES;
854 else if (strcmp(arg, "no") == 0)
855 value = PERMIT_NO;
856 else
857 fatal("%s line %d: Bad yes/"
858 "without-password/forced-commands-only/no "
859 "argument: %s", filename, linenum, arg);
Darren Tucker15f94272008-01-01 20:36:56 +1100860 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000861 *intptr = value;
862 break;
863
864 case sIgnoreRhosts:
865 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000866 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000867 arg = strdelim(&cp);
868 if (!arg || *arg == '\0')
869 fatal("%s line %d: missing yes/no argument.",
870 filename, linenum);
871 value = 0; /* silence compiler */
872 if (strcmp(arg, "yes") == 0)
873 value = 1;
874 else if (strcmp(arg, "no") == 0)
875 value = 0;
876 else
877 fatal("%s line %d: Bad yes/no argument: %s",
878 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000879 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000880 *intptr = value;
881 break;
882
883 case sIgnoreUserKnownHosts:
884 intptr = &options->ignore_user_known_hosts;
885 goto parse_flag;
886
Ben Lindstromade03f62001-12-06 18:22:17 +0000887 case sRhostsRSAAuthentication:
888 intptr = &options->rhosts_rsa_authentication;
889 goto parse_flag;
890
891 case sHostbasedAuthentication:
892 intptr = &options->hostbased_authentication;
893 goto parse_flag;
894
895 case sHostbasedUsesNameFromPacketOnly:
896 intptr = &options->hostbased_uses_name_from_packet_only;
897 goto parse_flag;
898
899 case sRSAAuthentication:
900 intptr = &options->rsa_authentication;
901 goto parse_flag;
902
903 case sPubkeyAuthentication:
904 intptr = &options->pubkey_authentication;
905 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000906
Ben Lindstromade03f62001-12-06 18:22:17 +0000907 case sKerberosAuthentication:
908 intptr = &options->kerberos_authentication;
909 goto parse_flag;
910
911 case sKerberosOrLocalPasswd:
912 intptr = &options->kerberos_or_local_passwd;
913 goto parse_flag;
914
915 case sKerberosTicketCleanup:
916 intptr = &options->kerberos_ticket_cleanup;
917 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000918
Darren Tucker22ef5082003-12-31 11:37:34 +1100919 case sKerberosGetAFSToken:
920 intptr = &options->kerberos_get_afs_token;
921 goto parse_flag;
922
Darren Tucker0efd1552003-08-26 11:49:55 +1000923 case sGssAuthentication:
924 intptr = &options->gss_authentication;
925 goto parse_flag;
926
927 case sGssCleanupCreds:
928 intptr = &options->gss_cleanup_creds;
929 goto parse_flag;
930
Ben Lindstromade03f62001-12-06 18:22:17 +0000931 case sPasswordAuthentication:
932 intptr = &options->password_authentication;
933 goto parse_flag;
934
Damien Miller01ed2272008-11-05 16:20:46 +1100935 case sZeroKnowledgePasswordAuthentication:
936 intptr = &options->zero_knowledge_password_authentication;
937 goto parse_flag;
938
Ben Lindstromade03f62001-12-06 18:22:17 +0000939 case sKbdInteractiveAuthentication:
940 intptr = &options->kbd_interactive_authentication;
941 goto parse_flag;
942
943 case sChallengeResponseAuthentication:
944 intptr = &options->challenge_response_authentication;
945 goto parse_flag;
946
947 case sPrintMotd:
948 intptr = &options->print_motd;
949 goto parse_flag;
950
951 case sPrintLastLog:
952 intptr = &options->print_lastlog;
953 goto parse_flag;
954
955 case sX11Forwarding:
956 intptr = &options->x11_forwarding;
957 goto parse_flag;
958
959 case sX11DisplayOffset:
960 intptr = &options->x11_display_offset;
961 goto parse_int;
962
Damien Miller95c249f2002-02-05 12:11:34 +1100963 case sX11UseLocalhost:
964 intptr = &options->x11_use_localhost;
965 goto parse_flag;
966
Ben Lindstromade03f62001-12-06 18:22:17 +0000967 case sXAuthLocation:
968 charptr = &options->xauth_location;
969 goto parse_filename;
970
971 case sStrictModes:
972 intptr = &options->strict_modes;
973 goto parse_flag;
974
Damien Miller12c150e2003-12-17 16:31:10 +1100975 case sTCPKeepAlive:
976 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000977 goto parse_flag;
978
979 case sEmptyPasswd:
980 intptr = &options->permit_empty_passwd;
981 goto parse_flag;
982
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000983 case sPermitUserEnvironment:
984 intptr = &options->permit_user_env;
985 goto parse_flag;
986
Ben Lindstromade03f62001-12-06 18:22:17 +0000987 case sUseLogin:
988 intptr = &options->use_login;
989 goto parse_flag;
990
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000991 case sCompression:
992 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000993 arg = strdelim(&cp);
994 if (!arg || *arg == '\0')
995 fatal("%s line %d: missing yes/no/delayed "
996 "argument.", filename, linenum);
997 value = 0; /* silence compiler */
998 if (strcmp(arg, "delayed") == 0)
999 value = COMP_DELAYED;
1000 else if (strcmp(arg, "yes") == 0)
1001 value = COMP_ZLIB;
1002 else if (strcmp(arg, "no") == 0)
1003 value = COMP_NONE;
1004 else
1005 fatal("%s line %d: Bad yes/no/delayed "
1006 "argument: %s", filename, linenum, arg);
1007 if (*intptr == -1)
1008 *intptr = value;
1009 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001010
Ben Lindstromade03f62001-12-06 18:22:17 +00001011 case sGatewayPorts:
1012 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001013 arg = strdelim(&cp);
1014 if (!arg || *arg == '\0')
1015 fatal("%s line %d: missing yes/no/clientspecified "
1016 "argument.", filename, linenum);
1017 value = 0; /* silence compiler */
1018 if (strcmp(arg, "clientspecified") == 0)
1019 value = 2;
1020 else if (strcmp(arg, "yes") == 0)
1021 value = 1;
1022 else if (strcmp(arg, "no") == 0)
1023 value = 0;
1024 else
1025 fatal("%s line %d: Bad yes/no/clientspecified "
1026 "argument: %s", filename, linenum, arg);
Darren Tucker82347a82007-02-25 20:37:52 +11001027 if (*activep && *intptr == -1)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001028 *intptr = value;
1029 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001030
Damien Miller3a961dc2003-06-03 10:25:48 +10001031 case sUseDNS:
1032 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001033 goto parse_flag;
1034
1035 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001036 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001037 arg = strdelim(&cp);
1038 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001039 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001040 fatal("%.200s line %d: unsupported log facility '%s'",
1041 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001042 if (*log_facility_ptr == -1)
1043 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 break;
1045
1046 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001047 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001048 arg = strdelim(&cp);
1049 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001050 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001051 fatal("%.200s line %d: unsupported log level '%s'",
1052 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001053 if (*log_level_ptr == -1)
1054 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001055 break;
1056
1057 case sAllowTcpForwarding:
1058 intptr = &options->allow_tcp_forwarding;
1059 goto parse_flag;
1060
Damien Miller4f755cd2008-05-19 14:57:41 +10001061 case sAllowAgentForwarding:
1062 intptr = &options->allow_agent_forwarding;
1063 goto parse_flag;
1064
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001065 case sUsePrivilegeSeparation:
1066 intptr = &use_privsep;
1067 goto parse_flag;
1068
Ben Lindstromade03f62001-12-06 18:22:17 +00001069 case sAllowUsers:
1070 while ((arg = strdelim(&cp)) && *arg != '\0') {
1071 if (options->num_allow_users >= MAX_ALLOW_USERS)
1072 fatal("%s line %d: too many allow users.",
1073 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001074 options->allow_users[options->num_allow_users++] =
1075 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001076 }
1077 break;
1078
1079 case sDenyUsers:
1080 while ((arg = strdelim(&cp)) && *arg != '\0') {
1081 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001082 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001083 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001084 options->deny_users[options->num_deny_users++] =
1085 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001086 }
1087 break;
1088
1089 case sAllowGroups:
1090 while ((arg = strdelim(&cp)) && *arg != '\0') {
1091 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1092 fatal("%s line %d: too many allow groups.",
1093 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001094 options->allow_groups[options->num_allow_groups++] =
1095 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001096 }
1097 break;
1098
1099 case sDenyGroups:
1100 while ((arg = strdelim(&cp)) && *arg != '\0') {
1101 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1102 fatal("%s line %d: too many deny groups.",
1103 filename, linenum);
1104 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1105 }
1106 break;
1107
1108 case sCiphers:
1109 arg = strdelim(&cp);
1110 if (!arg || *arg == '\0')
1111 fatal("%s line %d: Missing argument.", filename, linenum);
1112 if (!ciphers_valid(arg))
1113 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1114 filename, linenum, arg ? arg : "<NONE>");
1115 if (options->ciphers == NULL)
1116 options->ciphers = xstrdup(arg);
1117 break;
1118
1119 case sMacs:
1120 arg = strdelim(&cp);
1121 if (!arg || *arg == '\0')
1122 fatal("%s line %d: Missing argument.", filename, linenum);
1123 if (!mac_valid(arg))
1124 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1125 filename, linenum, arg ? arg : "<NONE>");
1126 if (options->macs == NULL)
1127 options->macs = xstrdup(arg);
1128 break;
1129
1130 case sProtocol:
1131 intptr = &options->protocol;
1132 arg = strdelim(&cp);
1133 if (!arg || *arg == '\0')
1134 fatal("%s line %d: Missing argument.", filename, linenum);
1135 value = proto_spec(arg);
1136 if (value == SSH_PROTO_UNKNOWN)
1137 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001138 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001139 if (*intptr == SSH_PROTO_UNKNOWN)
1140 *intptr = value;
1141 break;
1142
1143 case sSubsystem:
1144 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1145 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001146 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001147 }
1148 arg = strdelim(&cp);
1149 if (!arg || *arg == '\0')
1150 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001151 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001152 if (!*activep) {
1153 arg = strdelim(&cp);
1154 break;
1155 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001156 for (i = 0; i < options->num_subsystems; i++)
1157 if (strcmp(arg, options->subsystem_name[i]) == 0)
1158 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001159 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001160 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1161 arg = strdelim(&cp);
1162 if (!arg || *arg == '\0')
1163 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001164 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001165 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001166
1167 /* Collect arguments (separate to executable) */
1168 p = xstrdup(arg);
1169 len = strlen(p) + 1;
1170 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1171 len += 1 + strlen(arg);
1172 p = xrealloc(p, 1, len);
1173 strlcat(p, " ", len);
1174 strlcat(p, arg, len);
1175 }
1176 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001177 options->num_subsystems++;
1178 break;
1179
1180 case sMaxStartups:
1181 arg = strdelim(&cp);
1182 if (!arg || *arg == '\0')
1183 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001184 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001185 if ((n = sscanf(arg, "%d:%d:%d",
1186 &options->max_startups_begin,
1187 &options->max_startups_rate,
1188 &options->max_startups)) == 3) {
1189 if (options->max_startups_begin >
1190 options->max_startups ||
1191 options->max_startups_rate > 100 ||
1192 options->max_startups_rate < 1)
1193 fatal("%s line %d: Illegal MaxStartups spec.",
1194 filename, linenum);
1195 } else if (n != 1)
1196 fatal("%s line %d: Illegal MaxStartups spec.",
1197 filename, linenum);
1198 else
1199 options->max_startups = options->max_startups_begin;
1200 break;
1201
Darren Tucker89413db2004-05-24 10:36:23 +10001202 case sMaxAuthTries:
1203 intptr = &options->max_authtries;
1204 goto parse_int;
1205
Damien Miller7207f642008-05-19 15:34:50 +10001206 case sMaxSessions:
1207 intptr = &options->max_sessions;
1208 goto parse_int;
1209
Ben Lindstromade03f62001-12-06 18:22:17 +00001210 case sBanner:
1211 charptr = &options->banner;
1212 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001213
Ben Lindstromade03f62001-12-06 18:22:17 +00001214 /*
1215 * These options can contain %X options expanded at
1216 * connect time, so that you can specify paths like:
1217 *
1218 * AuthorizedKeysFile /etc/ssh_keys/%u
1219 */
1220 case sAuthorizedKeysFile:
1221 case sAuthorizedKeysFile2:
Damien Miller4dec5d72006-08-05 11:38:40 +10001222 charptr = (opcode == sAuthorizedKeysFile) ?
Ben Lindstromade03f62001-12-06 18:22:17 +00001223 &options->authorized_keys_file :
1224 &options->authorized_keys_file2;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001225 arg = strdelim(&cp);
1226 if (!arg || *arg == '\0')
1227 fatal("%s line %d: missing file name.",
1228 filename, linenum);
1229 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001230 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001231 /* increase optional counter */
1232 if (intptr != NULL)
1233 *intptr = *intptr + 1;
1234 }
1235 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001236
1237 case sClientAliveInterval:
1238 intptr = &options->client_alive_interval;
1239 goto parse_time;
1240
1241 case sClientAliveCountMax:
1242 intptr = &options->client_alive_count_max;
1243 goto parse_int;
1244
Darren Tucker46bc0752004-05-02 22:11:30 +10001245 case sAcceptEnv:
1246 while ((arg = strdelim(&cp)) && *arg != '\0') {
1247 if (strchr(arg, '=') != NULL)
1248 fatal("%s line %d: Invalid environment name.",
1249 filename, linenum);
1250 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1251 fatal("%s line %d: too many allow env.",
1252 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001253 if (!*activep)
1254 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001255 options->accept_env[options->num_accept_env++] =
1256 xstrdup(arg);
1257 }
1258 break;
1259
Damien Millerd27b9472005-12-13 19:29:02 +11001260 case sPermitTunnel:
1261 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001262 arg = strdelim(&cp);
1263 if (!arg || *arg == '\0')
1264 fatal("%s line %d: Missing yes/point-to-point/"
1265 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001266 value = -1;
1267 for (i = 0; tunmode_desc[i].val != -1; i++)
1268 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1269 value = tunmode_desc[i].val;
1270 break;
1271 }
1272 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001273 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1274 "no argument: %s", filename, linenum, arg);
1275 if (*intptr == -1)
1276 *intptr = value;
1277 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001278
Darren Tucker45150472006-07-12 22:34:17 +10001279 case sMatch:
1280 if (cmdline)
1281 fatal("Match directive not supported as a command-line "
1282 "option");
1283 value = match_cfg_line(&cp, linenum, user, host, address);
1284 if (value < 0)
1285 fatal("%s line %d: Bad Match condition", filename,
1286 linenum);
1287 *activep = value;
1288 break;
1289
Damien Miller9b439df2006-07-24 14:04:00 +10001290 case sPermitOpen:
1291 arg = strdelim(&cp);
1292 if (!arg || *arg == '\0')
1293 fatal("%s line %d: missing PermitOpen specification",
1294 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001295 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001296 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001297 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001298 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001299 options->num_permitted_opens = 0;
1300 }
Damien Miller9b439df2006-07-24 14:04:00 +10001301 break;
1302 }
Damien Millera29b95e2007-01-05 16:28:36 +11001303 if (*activep && n == -1)
1304 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001305 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1306 p = hpdelim(&arg);
1307 if (p == NULL)
1308 fatal("%s line %d: missing host in PermitOpen",
1309 filename, linenum);
1310 p = cleanhostname(p);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001311 if (arg == NULL || (port = a2port(arg)) <= 0)
Damien Millera765cf42006-07-24 14:08:13 +10001312 fatal("%s line %d: bad port number in "
1313 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001314 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001315 options->num_permitted_opens =
1316 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001317 }
Damien Miller9b439df2006-07-24 14:04:00 +10001318 break;
1319
Damien Millere2754432006-07-24 14:06:47 +10001320 case sForceCommand:
1321 if (cp == NULL)
1322 fatal("%.200s line %d: Missing argument.", filename,
1323 linenum);
1324 len = strspn(cp, WHITESPACE);
1325 if (*activep && options->adm_forced_command == NULL)
1326 options->adm_forced_command = xstrdup(cp + len);
1327 return 0;
1328
Damien Millerd8cb1f12008-02-10 22:40:12 +11001329 case sChrootDirectory:
1330 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001331
1332 arg = strdelim(&cp);
1333 if (!arg || *arg == '\0')
1334 fatal("%s line %d: missing file name.",
1335 filename, linenum);
1336 if (*activep && *charptr == NULL)
1337 *charptr = xstrdup(arg);
1338 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001339
Damien Miller1aed65e2010-03-04 21:53:35 +11001340 case sTrustedUserCAKeys:
1341 charptr = &options->trusted_user_ca_keys;
1342 goto parse_filename;
1343
1344 case sRevokedKeys:
1345 charptr = &options->revoked_keys_file;
1346 goto parse_filename;
1347
Ben Lindstromade03f62001-12-06 18:22:17 +00001348 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001349 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001350 filename, linenum, arg);
1351 while (arg)
1352 arg = strdelim(&cp);
1353 break;
1354
Damien Millerf9b3feb2003-05-16 11:38:32 +10001355 case sUnsupported:
1356 logit("%s line %d: Unsupported option %s",
1357 filename, linenum, arg);
1358 while (arg)
1359 arg = strdelim(&cp);
1360 break;
1361
Ben Lindstromade03f62001-12-06 18:22:17 +00001362 default:
1363 fatal("%s line %d: Missing handler for opcode %s (%d)",
1364 filename, linenum, arg, opcode);
1365 }
1366 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1367 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1368 filename, linenum, arg);
1369 return 0;
1370}
1371
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001372/* Reads the server configuration file. */
1373
Damien Miller4af51302000-04-16 11:18:38 +10001374void
Darren Tucker645ab752004-06-25 13:33:20 +10001375load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001376{
Darren Tucker645ab752004-06-25 13:33:20 +10001377 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001378 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001379
Darren Tucker645ab752004-06-25 13:33:20 +10001380 debug2("%s: filename %s", __func__, filename);
1381 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001382 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001383 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001384 }
Darren Tucker645ab752004-06-25 13:33:20 +10001385 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001386 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001387 /*
1388 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001389 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001390 * line numbers later for error messages
1391 */
1392 if ((cp = strchr(line, '#')) != NULL)
1393 memcpy(cp, "\n", 2);
1394 cp = line + strspn(line, " \t\r");
1395
1396 buffer_append(conf, cp, strlen(cp));
1397 }
1398 buffer_append(conf, "\0", 1);
1399 fclose(f);
1400 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1401}
1402
1403void
Darren Tucker45150472006-07-12 22:34:17 +10001404parse_server_match_config(ServerOptions *options, const char *user,
1405 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001406{
Darren Tucker45150472006-07-12 22:34:17 +10001407 ServerOptions mo;
1408
1409 initialize_server_options(&mo);
1410 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
Darren Tucker1629c072007-02-19 22:25:37 +11001411 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001412}
1413
Darren Tucker1629c072007-02-19 22:25:37 +11001414/* Helper macros */
1415#define M_CP_INTOPT(n) do {\
1416 if (src->n != -1) \
1417 dst->n = src->n; \
1418} while (0)
1419#define M_CP_STROPT(n) do {\
1420 if (src->n != NULL) { \
1421 if (dst->n != NULL) \
1422 xfree(dst->n); \
1423 dst->n = src->n; \
1424 } \
1425} while(0)
1426
1427/*
1428 * Copy any supported values that are set.
1429 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001430 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001431 * array values that are not used pre-authentication, because any that we
1432 * do use must be explictly sent in mm_getpwnamallow().
1433 */
Darren Tucker45150472006-07-12 22:34:17 +10001434void
Darren Tucker1629c072007-02-19 22:25:37 +11001435copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001436{
Darren Tucker1629c072007-02-19 22:25:37 +11001437 M_CP_INTOPT(password_authentication);
1438 M_CP_INTOPT(gss_authentication);
1439 M_CP_INTOPT(rsa_authentication);
1440 M_CP_INTOPT(pubkey_authentication);
1441 M_CP_INTOPT(kerberos_authentication);
1442 M_CP_INTOPT(hostbased_authentication);
1443 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001444 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001445 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001446 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001447
1448 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001449 M_CP_INTOPT(allow_agent_forwarding);
Darren Tucker1629c072007-02-19 22:25:37 +11001450 M_CP_INTOPT(gateway_ports);
1451 M_CP_INTOPT(x11_display_offset);
1452 M_CP_INTOPT(x11_forwarding);
1453 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001454 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001455 M_CP_INTOPT(max_authtries);
Darren Tucker1629c072007-02-19 22:25:37 +11001456
1457 M_CP_STROPT(banner);
1458 if (preauth)
1459 return;
1460 M_CP_STROPT(adm_forced_command);
Damien Millerd8cb1f12008-02-10 22:40:12 +11001461 M_CP_STROPT(chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11001462 M_CP_STROPT(trusted_user_ca_keys);
1463 M_CP_STROPT(revoked_keys_file);
Darren Tucker45150472006-07-12 22:34:17 +10001464}
1465
Darren Tucker1629c072007-02-19 22:25:37 +11001466#undef M_CP_INTOPT
1467#undef M_CP_STROPT
1468
Darren Tucker45150472006-07-12 22:34:17 +10001469void
1470parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1471 const char *user, const char *host, const char *address)
1472{
1473 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001474 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001475
1476 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1477
Darren Tucker9fbac712004-08-12 22:41:44 +10001478 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001479 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001480 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001481 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001482 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001483 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001484 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001485 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001486 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001487 if (bad_options > 0)
1488 fatal("%s: terminating, %d bad configuration options",
1489 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001490}
Darren Tuckere7140f22008-06-10 23:01:51 +10001491
1492static const char *
1493fmt_intarg(ServerOpCodes code, int val)
1494{
1495 if (code == sAddressFamily) {
1496 switch (val) {
1497 case AF_INET:
1498 return "inet";
1499 case AF_INET6:
1500 return "inet6";
1501 case AF_UNSPEC:
1502 return "any";
1503 default:
1504 return "UNKNOWN";
1505 }
1506 }
1507 if (code == sPermitRootLogin) {
1508 switch (val) {
1509 case PERMIT_NO_PASSWD:
Darren Tuckerff4350e2008-11-11 16:31:05 +11001510 return "without-password";
Darren Tuckere7140f22008-06-10 23:01:51 +10001511 case PERMIT_FORCED_ONLY:
1512 return "forced-commands-only";
1513 case PERMIT_YES:
1514 return "yes";
1515 }
1516 }
1517 if (code == sProtocol) {
1518 switch (val) {
1519 case SSH_PROTO_1:
1520 return "1";
1521 case SSH_PROTO_2:
1522 return "2";
1523 case (SSH_PROTO_1|SSH_PROTO_2):
1524 return "2,1";
1525 default:
1526 return "UNKNOWN";
1527 }
1528 }
1529 if (code == sGatewayPorts && val == 2)
1530 return "clientspecified";
1531 if (code == sCompression && val == COMP_DELAYED)
1532 return "delayed";
1533 switch (val) {
1534 case -1:
1535 return "unset";
1536 case 0:
1537 return "no";
1538 case 1:
1539 return "yes";
1540 }
1541 return "UNKNOWN";
1542}
1543
1544static const char *
1545lookup_opcode_name(ServerOpCodes code)
1546{
1547 u_int i;
1548
1549 for (i = 0; keywords[i].name != NULL; i++)
1550 if (keywords[i].opcode == code)
1551 return(keywords[i].name);
1552 return "UNKNOWN";
1553}
1554
1555static void
1556dump_cfg_int(ServerOpCodes code, int val)
1557{
1558 printf("%s %d\n", lookup_opcode_name(code), val);
1559}
1560
1561static void
1562dump_cfg_fmtint(ServerOpCodes code, int val)
1563{
1564 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1565}
1566
1567static void
1568dump_cfg_string(ServerOpCodes code, const char *val)
1569{
1570 if (val == NULL)
1571 return;
1572 printf("%s %s\n", lookup_opcode_name(code), val);
1573}
1574
1575static void
1576dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1577{
1578 u_int i;
1579
1580 for (i = 0; i < count; i++)
1581 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1582}
1583
1584void
1585dump_config(ServerOptions *o)
1586{
1587 u_int i;
1588 int ret;
1589 struct addrinfo *ai;
1590 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1591
1592 /* these are usually at the top of the config */
1593 for (i = 0; i < o->num_ports; i++)
1594 printf("port %d\n", o->ports[i]);
1595 dump_cfg_fmtint(sProtocol, o->protocol);
1596 dump_cfg_fmtint(sAddressFamily, o->address_family);
1597
1598 /* ListenAddress must be after Port */
1599 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1600 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1601 sizeof(addr), port, sizeof(port),
1602 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1603 error("getnameinfo failed: %.100s",
1604 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1605 strerror(errno));
1606 } else {
1607 if (ai->ai_family == AF_INET6)
1608 printf("listenaddress [%s]:%s\n", addr, port);
1609 else
1610 printf("listenaddress %s:%s\n", addr, port);
1611 }
1612 }
1613
1614 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001615#ifdef USE_PAM
1616 dump_cfg_int(sUsePAM, o->use_pam);
1617#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001618 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1619 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1620 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1621 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1622 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001623 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001624 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1625 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1626
1627 /* formatted integer arguments */
1628 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1629 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1630 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1631 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1632 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1633 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1634 o->hostbased_uses_name_from_packet_only);
1635 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1636 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001637#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001638 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1639 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1640 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001641# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001642 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001643# endif
1644#endif
1645#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001646 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1647 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001648#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001649#ifdef JPAKE
1650 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1651 o->zero_knowledge_password_authentication);
1652#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001653 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1654 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1655 o->kbd_interactive_authentication);
1656 dump_cfg_fmtint(sChallengeResponseAuthentication,
1657 o->challenge_response_authentication);
1658 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1659 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1660 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1661 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1662 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1663 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1664 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1665 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1666 dump_cfg_fmtint(sUseLogin, o->use_login);
1667 dump_cfg_fmtint(sCompression, o->compression);
1668 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1669 dump_cfg_fmtint(sUseDNS, o->use_dns);
1670 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1671 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1672
1673 /* string arguments */
1674 dump_cfg_string(sPidFile, o->pid_file);
1675 dump_cfg_string(sXAuthLocation, o->xauth_location);
1676 dump_cfg_string(sCiphers, o->ciphers);
1677 dump_cfg_string(sMacs, o->macs);
1678 dump_cfg_string(sBanner, o->banner);
1679 dump_cfg_string(sAuthorizedKeysFile, o->authorized_keys_file);
1680 dump_cfg_string(sAuthorizedKeysFile2, o->authorized_keys_file2);
1681 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11001682 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11001683 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
1684 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Darren Tuckere7140f22008-06-10 23:01:51 +10001685
1686 /* string arguments requiring a lookup */
1687 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1688 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1689
1690 /* string array arguments */
1691 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1692 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11001693 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
1694 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10001695 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1696 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1697 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1698 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1699 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1700
1701 /* other arguments */
1702 for (i = 0; i < o->num_subsystems; i++)
1703 printf("subsystem %s %s\n", o->subsystem_name[i],
1704 o->subsystem_args[i]);
1705
1706 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1707 o->max_startups_rate, o->max_startups);
1708
1709 for (i = 0; tunmode_desc[i].val != -1; i++)
1710 if (tunmode_desc[i].val == o->permit_tun) {
1711 s = tunmode_desc[i].text;
1712 break;
1713 }
1714 dump_cfg_string(sPermitTunnel, s);
1715
Darren Tuckere7140f22008-06-10 23:01:51 +10001716 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10001717}