blob: 0a6cdb655ceec9e1762fbef682a625144c6d0194 [file] [log] [blame]
Damien Miller0a80ca12010-02-27 07:55:05 +11001/* $OpenBSD: servconf.c,v 1.203 2010/02/26 20:29:54 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 Millerd4a8b7e1999-10-27 13:42:43 +1000132}
133
Damien Miller4af51302000-04-16 11:18:38 +1000134void
Damien Miller95def091999-11-25 00:26:21 +1100135fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000136{
Damien Miller726273e2001-11-12 11:40:11 +1100137 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000138 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000139 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100140
141 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100142 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100143 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100144 if (options->num_host_key_files == 0) {
145 /* fill default hostkeys for protocols */
146 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100147 options->host_key_files[options->num_host_key_files++] =
148 _PATH_HOST_KEY_FILE;
149 if (options->protocol & SSH_PROTO_2) {
150 options->host_key_files[options->num_host_key_files++] =
151 _PATH_HOST_RSA_KEY_FILE;
152 options->host_key_files[options->num_host_key_files++] =
153 _PATH_HOST_DSA_KEY_FILE;
154 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100155 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100156 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100157 if (options->num_ports == 0)
158 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
159 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000160 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000161 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000162 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100163 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000164 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000166 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->key_regeneration_time == -1)
168 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000169 if (options->permit_root_login == PERMIT_NOT_SET)
170 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100172 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->ignore_user_known_hosts == -1)
174 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100175 if (options->print_motd == -1)
176 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000177 if (options->print_lastlog == -1)
178 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100180 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100181 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100182 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100183 if (options->x11_use_localhost == -1)
184 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000185 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000186 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100187 if (options->strict_modes == -1)
188 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100189 if (options->tcp_keep_alive == -1)
190 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100191 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100192 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100193 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000194 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100195 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100196 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000197 if (options->hostbased_authentication == -1)
198 options->hostbased_authentication = 0;
199 if (options->hostbased_uses_name_from_packet_only == -1)
200 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->rsa_authentication == -1)
202 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100203 if (options->pubkey_authentication == -1)
204 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000206 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->kerberos_or_local_passwd == -1)
208 options->kerberos_or_local_passwd = 1;
209 if (options->kerberos_ticket_cleanup == -1)
210 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100211 if (options->kerberos_get_afs_token == -1)
212 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000213 if (options->gss_authentication == -1)
214 options->gss_authentication = 0;
215 if (options->gss_cleanup_creds == -1)
216 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100217 if (options->password_authentication == -1)
218 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100219 if (options->kbd_interactive_authentication == -1)
220 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000221 if (options->challenge_response_authentication == -1)
222 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100223 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100224 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000225 if (options->permit_user_env == -1)
226 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100227 if (options->use_login == -1)
228 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000229 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000230 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100231 if (options->allow_tcp_forwarding == -1)
232 options->allow_tcp_forwarding = 1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000233 if (options->allow_agent_forwarding == -1)
234 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000235 if (options->gateway_ports == -1)
236 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000237 if (options->max_startups == -1)
238 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000239 if (options->max_startups_rate == -1)
240 options->max_startups_rate = 100; /* 100% */
241 if (options->max_startups_begin == -1)
242 options->max_startups_begin = options->max_startups;
Darren Tucker89413db2004-05-24 10:36:23 +1000243 if (options->max_authtries == -1)
244 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000245 if (options->max_sessions == -1)
246 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000247 if (options->use_dns == -1)
248 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000249 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100250 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000251 if (options->client_alive_count_max == -1)
252 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100253 if (options->authorized_keys_file2 == NULL) {
254 /* authorized_keys_file2 falls back to authorized_keys_file */
255 if (options->authorized_keys_file != NULL)
256 options->authorized_keys_file2 = options->authorized_keys_file;
257 else
258 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
259 }
260 if (options->authorized_keys_file == NULL)
261 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Damien Millerd27b9472005-12-13 19:29:02 +1100262 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100263 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100264 if (options->zero_knowledge_password_authentication == -1)
265 options->zero_knowledge_password_authentication = 0;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000266
Ben Lindstromfb62a692002-06-06 19:47:11 +0000267 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000268 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000269 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000270
Tim Rice40017b02002-07-14 13:36:49 -0700271#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000272 if (use_privsep && options->compression == 1) {
273 error("This platform does not support both privilege "
274 "separation and compression");
275 error("Compression disabled");
276 options->compression = 0;
277 }
278#endif
279
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000280}
281
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000282/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100283typedef enum {
284 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100285 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000286 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100287 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100288 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
289 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000290 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100291 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100292 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000293 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100294 sPasswordAuthentication, sKbdInteractiveAuthentication,
295 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000296 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100297 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100298 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000299 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100300 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000301 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000302 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000303 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000304 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100305 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000306 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Damien Millerd27b9472005-12-13 19:29:02 +1100307 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100308 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100309 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100310 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000311 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000312} ServerOpCodes;
313
Darren Tucker45150472006-07-12 22:34:17 +1000314#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
315#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
316#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
317
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000318/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100319static struct {
320 const char *name;
321 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000322 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100323} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100324 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000325#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000326 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000327#else
Darren Tucker45150472006-07-12 22:34:17 +1000328 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000329#endif
Darren Tucker45150472006-07-12 22:34:17 +1000330 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100331 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000332 { "port", sPort, SSHCFG_GLOBAL },
333 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
334 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
335 { "pidfile", sPidFile, SSHCFG_GLOBAL },
336 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
337 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
338 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100339 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000340 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
341 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
342 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100343 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
344 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000345 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100346 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
347 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000348 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000349#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100350 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000351 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
352 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100353#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000354 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000355#else
Darren Tucker45150472006-07-12 22:34:17 +1000356 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100357#endif
358#else
Darren Tucker1629c072007-02-19 22:25:37 +1100359 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000360 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
361 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
362 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000363#endif
Darren Tucker45150472006-07-12 22:34:17 +1000364 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
365 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000366#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100367 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000368 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000369#else
Darren Tucker1629c072007-02-19 22:25:37 +1100370 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000371 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000372#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100373 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
374 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100375 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000376 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100377#ifdef JPAKE
378 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
379#else
380 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
381#endif
Darren Tucker45150472006-07-12 22:34:17 +1000382 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
383 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
384 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
385 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
386 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
387 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
388 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000389 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
390 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
391 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000392 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
393 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100394 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
396 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
397 { "compression", sCompression, SSHCFG_GLOBAL },
398 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
399 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
400 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000401 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000402 { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
403 { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
404 { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
405 { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
406 { "ciphers", sCiphers, SSHCFG_GLOBAL },
407 { "macs", sMacs, SSHCFG_GLOBAL },
408 { "protocol", sProtocol, SSHCFG_GLOBAL },
409 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
410 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
411 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000412 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000413 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100414 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000415 { "usedns", sUseDNS, SSHCFG_GLOBAL },
416 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
417 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
418 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
419 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
420 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
421 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000422 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Darren Tucker45150472006-07-12 22:34:17 +1000423 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
424 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000425 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000426 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000427 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100428 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100429 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000430 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000431};
432
Darren Tuckere7140f22008-06-10 23:01:51 +1000433static struct {
434 int val;
435 char *text;
436} tunmode_desc[] = {
437 { SSH_TUNMODE_NO, "no" },
438 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
439 { SSH_TUNMODE_ETHERNET, "ethernet" },
440 { SSH_TUNMODE_YES, "yes" },
441 { -1, NULL }
442};
443
Damien Miller5428f641999-11-25 11:54:57 +1100444/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000445 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100446 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000447
Damien Miller4af51302000-04-16 11:18:38 +1000448static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100449parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000450 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000451{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000452 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000453
Damien Miller95def091999-11-25 00:26:21 +1100454 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000455 if (strcasecmp(cp, keywords[i].name) == 0) {
456 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100457 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000458 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000459
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000460 error("%s: line %d: Bad configuration option: %s",
461 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100462 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000463}
464
Darren Tucker88b6fb22010-01-13 22:44:29 +1100465char *
466derelativise_path(const char *path)
467{
468 char *expanded, *ret, *cwd;
469
470 expanded = tilde_expand_filename(path, getuid());
471 if (*expanded == '/')
472 return expanded;
473 if ((cwd = getcwd(NULL, 0)) == NULL)
474 fatal("%s: getcwd: %s", __func__, strerror(errno));
475 xasprintf(&ret, "%s/%s", cwd, expanded);
476 xfree(cwd);
477 xfree(expanded);
478 return ret;
479}
480
Ben Lindstrombba81212001-06-25 05:01:22 +0000481static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100482add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100483{
Damien Millereccb9de2005-06-17 12:59:34 +1000484 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100485
486 if (options->num_ports == 0)
487 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100488 if (options->address_family == -1)
489 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000490 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000491 for (i = 0; i < options->num_ports; i++)
492 add_one_listen_addr(options, addr, options->ports[i]);
493 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000494 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000495}
496
Ben Lindstrombba81212001-06-25 05:01:22 +0000497static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100498add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000499{
500 struct addrinfo hints, *ai, *aitop;
501 char strport[NI_MAXSERV];
502 int gaierr;
503
504 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100505 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000506 hints.ai_socktype = SOCK_STREAM;
507 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100508 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000509 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
510 fatal("bad addr or host: %s (%s)",
511 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100512 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000513 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
514 ;
515 ai->ai_next = options->listen_addrs;
516 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100517}
518
Darren Tucker45150472006-07-12 22:34:17 +1000519/*
520 * The strategy for the Match blocks is that the config file is parsed twice.
521 *
522 * The first time is at startup. activep is initialized to 1 and the
523 * directives in the global context are processed and acted on. Hitting a
524 * Match directive unsets activep and the directives inside the block are
525 * checked for syntax only.
526 *
527 * The second time is after a connection has been established but before
528 * authentication. activep is initialized to 2 and global config directives
529 * are ignored since they have already been processed. If the criteria in a
530 * Match block is met, activep is set and the subsequent directives
531 * processed and actioned until EOF or another Match block unsets it. Any
532 * options set are copied into the main server config.
533 *
534 * Potential additions/improvements:
535 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
536 *
537 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
538 * Match Address 192.168.0.*
539 * Tag trusted
540 * Match Group wheel
541 * Tag trusted
542 * Match Tag trusted
543 * AllowTcpForwarding yes
544 * GatewayPorts clientspecified
545 * [...]
546 *
547 * - Add a PermittedChannelRequests directive
548 * Match Group shell
549 * PermittedChannelRequests session,forwarded-tcpip
550 */
551
552static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000553match_cfg_line_group(const char *grps, int line, const char *user)
554{
555 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000556 struct passwd *pw;
557
Damien Miller565ca3f2006-08-19 00:23:15 +1000558 if (user == NULL)
559 goto out;
560
561 if ((pw = getpwnam(user)) == NULL) {
562 debug("Can't match group at line %d because user %.100s does "
563 "not exist", line, user);
564 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
565 debug("Can't Match group because user %.100s not in any group "
566 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000567 } else if (ga_match_pattern_list(grps) != 1) {
568 debug("user %.100s does not match group list %.100s at line %d",
569 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000570 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000571 debug("user %.100s matched group list %.100s at line %d", user,
572 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000573 result = 1;
574 }
575out:
576 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000577 return result;
578}
579
580static int
Darren Tucker45150472006-07-12 22:34:17 +1000581match_cfg_line(char **condition, int line, const char *user, const char *host,
582 const char *address)
583{
584 int result = 1;
585 char *arg, *attrib, *cp = *condition;
586 size_t len;
587
588 if (user == NULL)
589 debug3("checking syntax for 'Match %s'", cp);
590 else
591 debug3("checking match for '%s' user %s host %s addr %s", cp,
592 user ? user : "(null)", host ? host : "(null)",
593 address ? address : "(null)");
594
595 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
596 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
597 error("Missing Match criteria for %s", attrib);
598 return -1;
599 }
600 len = strlen(arg);
601 if (strcasecmp(attrib, "user") == 0) {
602 if (!user) {
603 result = 0;
604 continue;
605 }
606 if (match_pattern_list(user, arg, len, 0) != 1)
607 result = 0;
608 else
609 debug("user %.100s matched 'User %.100s' at "
610 "line %d", user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000611 } else if (strcasecmp(attrib, "group") == 0) {
612 switch (match_cfg_line_group(arg, line, user)) {
613 case -1:
614 return -1;
615 case 0:
616 result = 0;
617 }
Darren Tucker45150472006-07-12 22:34:17 +1000618 } else if (strcasecmp(attrib, "host") == 0) {
619 if (!host) {
620 result = 0;
621 continue;
622 }
623 if (match_hostname(host, arg, len) != 1)
624 result = 0;
625 else
626 debug("connection from %.100s matched 'Host "
627 "%.100s' at line %d", host, arg, line);
628 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000629 switch (addr_match_list(address, arg)) {
630 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000631 debug("connection from %.100s matched 'Address "
632 "%.100s' at line %d", address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000633 break;
634 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000635 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000636 result = 0;
637 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000638 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000639 return -1;
640 }
Darren Tucker45150472006-07-12 22:34:17 +1000641 } else {
642 error("Unsupported Match attribute %s", attrib);
643 return -1;
644 }
645 }
646 if (user != NULL)
647 debug3("match %sfound", result ? "" : "not ");
648 *condition = cp;
649 return result;
650}
651
Damien Millere2754432006-07-24 14:06:47 +1000652#define WHITESPACE " \t\r\n"
653
Ben Lindstromade03f62001-12-06 18:22:17 +0000654int
655process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000656 const char *filename, int linenum, int *activep, const char *user,
657 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000658{
659 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000660 int cmdline = 0, *intptr, value, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100661 SyslogFacility *log_facility_ptr;
662 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000663 ServerOpCodes opcode;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100664 int port;
Darren Tucker45150472006-07-12 22:34:17 +1000665 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000666 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000667
668 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100669 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100670 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000671 /* Ignore leading whitespace */
672 if (*arg == '\0')
673 arg = strdelim(&cp);
674 if (!arg || !*arg || *arg == '#')
675 return 0;
676 intptr = NULL;
677 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000678 opcode = parse_token(arg, filename, linenum, &flags);
679
680 if (activep == NULL) { /* We are processing a command line directive */
681 cmdline = 1;
682 activep = &cmdline;
683 }
684 if (*activep && opcode != sMatch)
685 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
686 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
687 if (user == NULL) {
688 fatal("%s line %d: Directive '%s' is not allowed "
689 "within a Match block", filename, linenum, arg);
690 } else { /* this is a directive we have already processed */
691 while (arg)
692 arg = strdelim(&cp);
693 return 0;
694 }
695 }
696
Ben Lindstromade03f62001-12-06 18:22:17 +0000697 switch (opcode) {
698 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000699 case sUsePAM:
700 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000701 goto parse_flag;
702
703 /* Standard Options */
704 case sBadOption:
705 return -1;
706 case sPort:
707 /* ignore ports from configfile if cmdline specifies ports */
708 if (options->ports_from_cmdline)
709 return 0;
710 if (options->listen_addrs != NULL)
711 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100712 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000713 if (options->num_ports >= MAX_PORTS)
714 fatal("%s line %d: too many ports.",
715 filename, linenum);
716 arg = strdelim(&cp);
717 if (!arg || *arg == '\0')
718 fatal("%s line %d: missing port number.",
719 filename, linenum);
720 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100721 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000722 fatal("%s line %d: Badly formatted port number.",
723 filename, linenum);
724 break;
725
726 case sServerKeyBits:
727 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000728 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000729 arg = strdelim(&cp);
730 if (!arg || *arg == '\0')
731 fatal("%s line %d: missing integer value.",
732 filename, linenum);
733 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000734 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000735 *intptr = value;
736 break;
737
738 case sLoginGraceTime:
739 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000740 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000741 arg = strdelim(&cp);
742 if (!arg || *arg == '\0')
743 fatal("%s line %d: missing time value.",
744 filename, linenum);
745 if ((value = convtime(arg)) == -1)
746 fatal("%s line %d: invalid time value.",
747 filename, linenum);
748 if (*intptr == -1)
749 *intptr = value;
750 break;
751
752 case sKeyRegenerationTime:
753 intptr = &options->key_regeneration_time;
754 goto parse_time;
755
756 case sListenAddress:
757 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100758 if (arg == NULL || *arg == '\0')
759 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000760 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000761 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
762 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
763 && strchr(p+1, ':') != NULL) {
764 add_listen_addr(options, arg, 0);
765 break;
766 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100767 p = hpdelim(&arg);
768 if (p == NULL)
769 fatal("%s line %d: bad address:port usage",
770 filename, linenum);
771 p = cleanhostname(p);
772 if (arg == NULL)
773 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100774 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100775 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000776
Damien Millerf91ee4c2005-03-01 21:24:33 +1100777 add_listen_addr(options, p, port);
778
Ben Lindstromade03f62001-12-06 18:22:17 +0000779 break;
780
Darren Tucker0f383232005-01-20 10:57:56 +1100781 case sAddressFamily:
782 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000783 if (!arg || *arg == '\0')
784 fatal("%s line %d: missing address family.",
785 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100786 intptr = &options->address_family;
787 if (options->listen_addrs != NULL)
788 fatal("%s line %d: address family must be specified before "
789 "ListenAddress.", filename, linenum);
790 if (strcasecmp(arg, "inet") == 0)
791 value = AF_INET;
792 else if (strcasecmp(arg, "inet6") == 0)
793 value = AF_INET6;
794 else if (strcasecmp(arg, "any") == 0)
795 value = AF_UNSPEC;
796 else
797 fatal("%s line %d: unsupported address family \"%s\".",
798 filename, linenum, arg);
799 if (*intptr == -1)
800 *intptr = value;
801 break;
802
Ben Lindstromade03f62001-12-06 18:22:17 +0000803 case sHostKeyFile:
804 intptr = &options->num_host_key_files;
805 if (*intptr >= MAX_HOSTKEYS)
806 fatal("%s line %d: too many host keys specified (max %d).",
807 filename, linenum, MAX_HOSTKEYS);
808 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000809 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000810 arg = strdelim(&cp);
811 if (!arg || *arg == '\0')
812 fatal("%s line %d: missing file name.",
813 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000814 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100815 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000816 /* increase optional counter */
817 if (intptr != NULL)
818 *intptr = *intptr + 1;
819 }
820 break;
821
Damien Miller0a80ca12010-02-27 07:55:05 +1100822 case sHostCertificate:
823 intptr = &options->num_host_cert_files;
824 if (*intptr >= MAX_HOSTKEYS)
825 fatal("%s line %d: too many host certificates "
826 "specified (max %d).", filename, linenum,
827 MAX_HOSTCERTS);
828 charptr = &options->host_cert_files[*intptr];
829 goto parse_filename;
830 break;
831
Ben Lindstromade03f62001-12-06 18:22:17 +0000832 case sPidFile:
833 charptr = &options->pid_file;
834 goto parse_filename;
835
836 case sPermitRootLogin:
837 intptr = &options->permit_root_login;
838 arg = strdelim(&cp);
839 if (!arg || *arg == '\0')
840 fatal("%s line %d: missing yes/"
841 "without-password/forced-commands-only/no "
842 "argument.", filename, linenum);
843 value = 0; /* silence compiler */
844 if (strcmp(arg, "without-password") == 0)
845 value = PERMIT_NO_PASSWD;
846 else if (strcmp(arg, "forced-commands-only") == 0)
847 value = PERMIT_FORCED_ONLY;
848 else if (strcmp(arg, "yes") == 0)
849 value = PERMIT_YES;
850 else if (strcmp(arg, "no") == 0)
851 value = PERMIT_NO;
852 else
853 fatal("%s line %d: Bad yes/"
854 "without-password/forced-commands-only/no "
855 "argument: %s", filename, linenum, arg);
Darren Tucker15f94272008-01-01 20:36:56 +1100856 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000857 *intptr = value;
858 break;
859
860 case sIgnoreRhosts:
861 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000862 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000863 arg = strdelim(&cp);
864 if (!arg || *arg == '\0')
865 fatal("%s line %d: missing yes/no argument.",
866 filename, linenum);
867 value = 0; /* silence compiler */
868 if (strcmp(arg, "yes") == 0)
869 value = 1;
870 else if (strcmp(arg, "no") == 0)
871 value = 0;
872 else
873 fatal("%s line %d: Bad yes/no argument: %s",
874 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000875 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000876 *intptr = value;
877 break;
878
879 case sIgnoreUserKnownHosts:
880 intptr = &options->ignore_user_known_hosts;
881 goto parse_flag;
882
Ben Lindstromade03f62001-12-06 18:22:17 +0000883 case sRhostsRSAAuthentication:
884 intptr = &options->rhosts_rsa_authentication;
885 goto parse_flag;
886
887 case sHostbasedAuthentication:
888 intptr = &options->hostbased_authentication;
889 goto parse_flag;
890
891 case sHostbasedUsesNameFromPacketOnly:
892 intptr = &options->hostbased_uses_name_from_packet_only;
893 goto parse_flag;
894
895 case sRSAAuthentication:
896 intptr = &options->rsa_authentication;
897 goto parse_flag;
898
899 case sPubkeyAuthentication:
900 intptr = &options->pubkey_authentication;
901 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000902
Ben Lindstromade03f62001-12-06 18:22:17 +0000903 case sKerberosAuthentication:
904 intptr = &options->kerberos_authentication;
905 goto parse_flag;
906
907 case sKerberosOrLocalPasswd:
908 intptr = &options->kerberos_or_local_passwd;
909 goto parse_flag;
910
911 case sKerberosTicketCleanup:
912 intptr = &options->kerberos_ticket_cleanup;
913 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000914
Darren Tucker22ef5082003-12-31 11:37:34 +1100915 case sKerberosGetAFSToken:
916 intptr = &options->kerberos_get_afs_token;
917 goto parse_flag;
918
Darren Tucker0efd1552003-08-26 11:49:55 +1000919 case sGssAuthentication:
920 intptr = &options->gss_authentication;
921 goto parse_flag;
922
923 case sGssCleanupCreds:
924 intptr = &options->gss_cleanup_creds;
925 goto parse_flag;
926
Ben Lindstromade03f62001-12-06 18:22:17 +0000927 case sPasswordAuthentication:
928 intptr = &options->password_authentication;
929 goto parse_flag;
930
Damien Miller01ed2272008-11-05 16:20:46 +1100931 case sZeroKnowledgePasswordAuthentication:
932 intptr = &options->zero_knowledge_password_authentication;
933 goto parse_flag;
934
Ben Lindstromade03f62001-12-06 18:22:17 +0000935 case sKbdInteractiveAuthentication:
936 intptr = &options->kbd_interactive_authentication;
937 goto parse_flag;
938
939 case sChallengeResponseAuthentication:
940 intptr = &options->challenge_response_authentication;
941 goto parse_flag;
942
943 case sPrintMotd:
944 intptr = &options->print_motd;
945 goto parse_flag;
946
947 case sPrintLastLog:
948 intptr = &options->print_lastlog;
949 goto parse_flag;
950
951 case sX11Forwarding:
952 intptr = &options->x11_forwarding;
953 goto parse_flag;
954
955 case sX11DisplayOffset:
956 intptr = &options->x11_display_offset;
957 goto parse_int;
958
Damien Miller95c249f2002-02-05 12:11:34 +1100959 case sX11UseLocalhost:
960 intptr = &options->x11_use_localhost;
961 goto parse_flag;
962
Ben Lindstromade03f62001-12-06 18:22:17 +0000963 case sXAuthLocation:
964 charptr = &options->xauth_location;
965 goto parse_filename;
966
967 case sStrictModes:
968 intptr = &options->strict_modes;
969 goto parse_flag;
970
Damien Miller12c150e2003-12-17 16:31:10 +1100971 case sTCPKeepAlive:
972 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000973 goto parse_flag;
974
975 case sEmptyPasswd:
976 intptr = &options->permit_empty_passwd;
977 goto parse_flag;
978
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000979 case sPermitUserEnvironment:
980 intptr = &options->permit_user_env;
981 goto parse_flag;
982
Ben Lindstromade03f62001-12-06 18:22:17 +0000983 case sUseLogin:
984 intptr = &options->use_login;
985 goto parse_flag;
986
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000987 case sCompression:
988 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000989 arg = strdelim(&cp);
990 if (!arg || *arg == '\0')
991 fatal("%s line %d: missing yes/no/delayed "
992 "argument.", filename, linenum);
993 value = 0; /* silence compiler */
994 if (strcmp(arg, "delayed") == 0)
995 value = COMP_DELAYED;
996 else if (strcmp(arg, "yes") == 0)
997 value = COMP_ZLIB;
998 else if (strcmp(arg, "no") == 0)
999 value = COMP_NONE;
1000 else
1001 fatal("%s line %d: Bad yes/no/delayed "
1002 "argument: %s", filename, linenum, arg);
1003 if (*intptr == -1)
1004 *intptr = value;
1005 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001006
Ben Lindstromade03f62001-12-06 18:22:17 +00001007 case sGatewayPorts:
1008 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001009 arg = strdelim(&cp);
1010 if (!arg || *arg == '\0')
1011 fatal("%s line %d: missing yes/no/clientspecified "
1012 "argument.", filename, linenum);
1013 value = 0; /* silence compiler */
1014 if (strcmp(arg, "clientspecified") == 0)
1015 value = 2;
1016 else if (strcmp(arg, "yes") == 0)
1017 value = 1;
1018 else if (strcmp(arg, "no") == 0)
1019 value = 0;
1020 else
1021 fatal("%s line %d: Bad yes/no/clientspecified "
1022 "argument: %s", filename, linenum, arg);
Darren Tucker82347a82007-02-25 20:37:52 +11001023 if (*activep && *intptr == -1)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001024 *intptr = value;
1025 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001026
Damien Miller3a961dc2003-06-03 10:25:48 +10001027 case sUseDNS:
1028 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001029 goto parse_flag;
1030
1031 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001032 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001033 arg = strdelim(&cp);
1034 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001035 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 fatal("%.200s line %d: unsupported log facility '%s'",
1037 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001038 if (*log_facility_ptr == -1)
1039 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001040 break;
1041
1042 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001043 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 arg = strdelim(&cp);
1045 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001046 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001047 fatal("%.200s line %d: unsupported log level '%s'",
1048 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001049 if (*log_level_ptr == -1)
1050 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001051 break;
1052
1053 case sAllowTcpForwarding:
1054 intptr = &options->allow_tcp_forwarding;
1055 goto parse_flag;
1056
Damien Miller4f755cd2008-05-19 14:57:41 +10001057 case sAllowAgentForwarding:
1058 intptr = &options->allow_agent_forwarding;
1059 goto parse_flag;
1060
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001061 case sUsePrivilegeSeparation:
1062 intptr = &use_privsep;
1063 goto parse_flag;
1064
Ben Lindstromade03f62001-12-06 18:22:17 +00001065 case sAllowUsers:
1066 while ((arg = strdelim(&cp)) && *arg != '\0') {
1067 if (options->num_allow_users >= MAX_ALLOW_USERS)
1068 fatal("%s line %d: too many allow users.",
1069 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001070 options->allow_users[options->num_allow_users++] =
1071 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001072 }
1073 break;
1074
1075 case sDenyUsers:
1076 while ((arg = strdelim(&cp)) && *arg != '\0') {
1077 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001078 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001079 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001080 options->deny_users[options->num_deny_users++] =
1081 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001082 }
1083 break;
1084
1085 case sAllowGroups:
1086 while ((arg = strdelim(&cp)) && *arg != '\0') {
1087 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1088 fatal("%s line %d: too many allow groups.",
1089 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001090 options->allow_groups[options->num_allow_groups++] =
1091 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001092 }
1093 break;
1094
1095 case sDenyGroups:
1096 while ((arg = strdelim(&cp)) && *arg != '\0') {
1097 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1098 fatal("%s line %d: too many deny groups.",
1099 filename, linenum);
1100 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1101 }
1102 break;
1103
1104 case sCiphers:
1105 arg = strdelim(&cp);
1106 if (!arg || *arg == '\0')
1107 fatal("%s line %d: Missing argument.", filename, linenum);
1108 if (!ciphers_valid(arg))
1109 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1110 filename, linenum, arg ? arg : "<NONE>");
1111 if (options->ciphers == NULL)
1112 options->ciphers = xstrdup(arg);
1113 break;
1114
1115 case sMacs:
1116 arg = strdelim(&cp);
1117 if (!arg || *arg == '\0')
1118 fatal("%s line %d: Missing argument.", filename, linenum);
1119 if (!mac_valid(arg))
1120 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1121 filename, linenum, arg ? arg : "<NONE>");
1122 if (options->macs == NULL)
1123 options->macs = xstrdup(arg);
1124 break;
1125
1126 case sProtocol:
1127 intptr = &options->protocol;
1128 arg = strdelim(&cp);
1129 if (!arg || *arg == '\0')
1130 fatal("%s line %d: Missing argument.", filename, linenum);
1131 value = proto_spec(arg);
1132 if (value == SSH_PROTO_UNKNOWN)
1133 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001134 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001135 if (*intptr == SSH_PROTO_UNKNOWN)
1136 *intptr = value;
1137 break;
1138
1139 case sSubsystem:
1140 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1141 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001142 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001143 }
1144 arg = strdelim(&cp);
1145 if (!arg || *arg == '\0')
1146 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001147 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001148 if (!*activep) {
1149 arg = strdelim(&cp);
1150 break;
1151 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001152 for (i = 0; i < options->num_subsystems; i++)
1153 if (strcmp(arg, options->subsystem_name[i]) == 0)
1154 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001155 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001156 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1157 arg = strdelim(&cp);
1158 if (!arg || *arg == '\0')
1159 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001160 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001161 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001162
1163 /* Collect arguments (separate to executable) */
1164 p = xstrdup(arg);
1165 len = strlen(p) + 1;
1166 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1167 len += 1 + strlen(arg);
1168 p = xrealloc(p, 1, len);
1169 strlcat(p, " ", len);
1170 strlcat(p, arg, len);
1171 }
1172 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001173 options->num_subsystems++;
1174 break;
1175
1176 case sMaxStartups:
1177 arg = strdelim(&cp);
1178 if (!arg || *arg == '\0')
1179 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001180 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001181 if ((n = sscanf(arg, "%d:%d:%d",
1182 &options->max_startups_begin,
1183 &options->max_startups_rate,
1184 &options->max_startups)) == 3) {
1185 if (options->max_startups_begin >
1186 options->max_startups ||
1187 options->max_startups_rate > 100 ||
1188 options->max_startups_rate < 1)
1189 fatal("%s line %d: Illegal MaxStartups spec.",
1190 filename, linenum);
1191 } else if (n != 1)
1192 fatal("%s line %d: Illegal MaxStartups spec.",
1193 filename, linenum);
1194 else
1195 options->max_startups = options->max_startups_begin;
1196 break;
1197
Darren Tucker89413db2004-05-24 10:36:23 +10001198 case sMaxAuthTries:
1199 intptr = &options->max_authtries;
1200 goto parse_int;
1201
Damien Miller7207f642008-05-19 15:34:50 +10001202 case sMaxSessions:
1203 intptr = &options->max_sessions;
1204 goto parse_int;
1205
Ben Lindstromade03f62001-12-06 18:22:17 +00001206 case sBanner:
1207 charptr = &options->banner;
1208 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001209
Ben Lindstromade03f62001-12-06 18:22:17 +00001210 /*
1211 * These options can contain %X options expanded at
1212 * connect time, so that you can specify paths like:
1213 *
1214 * AuthorizedKeysFile /etc/ssh_keys/%u
1215 */
1216 case sAuthorizedKeysFile:
1217 case sAuthorizedKeysFile2:
Damien Miller4dec5d72006-08-05 11:38:40 +10001218 charptr = (opcode == sAuthorizedKeysFile) ?
Ben Lindstromade03f62001-12-06 18:22:17 +00001219 &options->authorized_keys_file :
1220 &options->authorized_keys_file2;
1221 goto parse_filename;
1222
1223 case sClientAliveInterval:
1224 intptr = &options->client_alive_interval;
1225 goto parse_time;
1226
1227 case sClientAliveCountMax:
1228 intptr = &options->client_alive_count_max;
1229 goto parse_int;
1230
Darren Tucker46bc0752004-05-02 22:11:30 +10001231 case sAcceptEnv:
1232 while ((arg = strdelim(&cp)) && *arg != '\0') {
1233 if (strchr(arg, '=') != NULL)
1234 fatal("%s line %d: Invalid environment name.",
1235 filename, linenum);
1236 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1237 fatal("%s line %d: too many allow env.",
1238 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001239 if (!*activep)
1240 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001241 options->accept_env[options->num_accept_env++] =
1242 xstrdup(arg);
1243 }
1244 break;
1245
Damien Millerd27b9472005-12-13 19:29:02 +11001246 case sPermitTunnel:
1247 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001248 arg = strdelim(&cp);
1249 if (!arg || *arg == '\0')
1250 fatal("%s line %d: Missing yes/point-to-point/"
1251 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001252 value = -1;
1253 for (i = 0; tunmode_desc[i].val != -1; i++)
1254 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1255 value = tunmode_desc[i].val;
1256 break;
1257 }
1258 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001259 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1260 "no argument: %s", filename, linenum, arg);
1261 if (*intptr == -1)
1262 *intptr = value;
1263 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001264
Darren Tucker45150472006-07-12 22:34:17 +10001265 case sMatch:
1266 if (cmdline)
1267 fatal("Match directive not supported as a command-line "
1268 "option");
1269 value = match_cfg_line(&cp, linenum, user, host, address);
1270 if (value < 0)
1271 fatal("%s line %d: Bad Match condition", filename,
1272 linenum);
1273 *activep = value;
1274 break;
1275
Damien Miller9b439df2006-07-24 14:04:00 +10001276 case sPermitOpen:
1277 arg = strdelim(&cp);
1278 if (!arg || *arg == '\0')
1279 fatal("%s line %d: missing PermitOpen specification",
1280 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001281 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001282 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001283 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001284 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001285 options->num_permitted_opens = 0;
1286 }
Damien Miller9b439df2006-07-24 14:04:00 +10001287 break;
1288 }
Damien Millera29b95e2007-01-05 16:28:36 +11001289 if (*activep && n == -1)
1290 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001291 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1292 p = hpdelim(&arg);
1293 if (p == NULL)
1294 fatal("%s line %d: missing host in PermitOpen",
1295 filename, linenum);
1296 p = cleanhostname(p);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001297 if (arg == NULL || (port = a2port(arg)) <= 0)
Damien Millera765cf42006-07-24 14:08:13 +10001298 fatal("%s line %d: bad port number in "
1299 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001300 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001301 options->num_permitted_opens =
1302 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001303 }
Damien Miller9b439df2006-07-24 14:04:00 +10001304 break;
1305
Damien Millere2754432006-07-24 14:06:47 +10001306 case sForceCommand:
1307 if (cp == NULL)
1308 fatal("%.200s line %d: Missing argument.", filename,
1309 linenum);
1310 len = strspn(cp, WHITESPACE);
1311 if (*activep && options->adm_forced_command == NULL)
1312 options->adm_forced_command = xstrdup(cp + len);
1313 return 0;
1314
Damien Millerd8cb1f12008-02-10 22:40:12 +11001315 case sChrootDirectory:
1316 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001317
1318 arg = strdelim(&cp);
1319 if (!arg || *arg == '\0')
1320 fatal("%s line %d: missing file name.",
1321 filename, linenum);
1322 if (*activep && *charptr == NULL)
1323 *charptr = xstrdup(arg);
1324 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001325
Ben Lindstromade03f62001-12-06 18:22:17 +00001326 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001327 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001328 filename, linenum, arg);
1329 while (arg)
1330 arg = strdelim(&cp);
1331 break;
1332
Damien Millerf9b3feb2003-05-16 11:38:32 +10001333 case sUnsupported:
1334 logit("%s line %d: Unsupported option %s",
1335 filename, linenum, arg);
1336 while (arg)
1337 arg = strdelim(&cp);
1338 break;
1339
Ben Lindstromade03f62001-12-06 18:22:17 +00001340 default:
1341 fatal("%s line %d: Missing handler for opcode %s (%d)",
1342 filename, linenum, arg, opcode);
1343 }
1344 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1345 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1346 filename, linenum, arg);
1347 return 0;
1348}
1349
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001350/* Reads the server configuration file. */
1351
Damien Miller4af51302000-04-16 11:18:38 +10001352void
Darren Tucker645ab752004-06-25 13:33:20 +10001353load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001354{
Darren Tucker645ab752004-06-25 13:33:20 +10001355 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001356 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001357
Darren Tucker645ab752004-06-25 13:33:20 +10001358 debug2("%s: filename %s", __func__, filename);
1359 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001360 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001361 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001362 }
Darren Tucker645ab752004-06-25 13:33:20 +10001363 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001364 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001365 /*
1366 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001367 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001368 * line numbers later for error messages
1369 */
1370 if ((cp = strchr(line, '#')) != NULL)
1371 memcpy(cp, "\n", 2);
1372 cp = line + strspn(line, " \t\r");
1373
1374 buffer_append(conf, cp, strlen(cp));
1375 }
1376 buffer_append(conf, "\0", 1);
1377 fclose(f);
1378 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1379}
1380
1381void
Darren Tucker45150472006-07-12 22:34:17 +10001382parse_server_match_config(ServerOptions *options, const char *user,
1383 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001384{
Darren Tucker45150472006-07-12 22:34:17 +10001385 ServerOptions mo;
1386
1387 initialize_server_options(&mo);
1388 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
Darren Tucker1629c072007-02-19 22:25:37 +11001389 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001390}
1391
Darren Tucker1629c072007-02-19 22:25:37 +11001392/* Helper macros */
1393#define M_CP_INTOPT(n) do {\
1394 if (src->n != -1) \
1395 dst->n = src->n; \
1396} while (0)
1397#define M_CP_STROPT(n) do {\
1398 if (src->n != NULL) { \
1399 if (dst->n != NULL) \
1400 xfree(dst->n); \
1401 dst->n = src->n; \
1402 } \
1403} while(0)
1404
1405/*
1406 * Copy any supported values that are set.
1407 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001408 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001409 * array values that are not used pre-authentication, because any that we
1410 * do use must be explictly sent in mm_getpwnamallow().
1411 */
Darren Tucker45150472006-07-12 22:34:17 +10001412void
Darren Tucker1629c072007-02-19 22:25:37 +11001413copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001414{
Darren Tucker1629c072007-02-19 22:25:37 +11001415 M_CP_INTOPT(password_authentication);
1416 M_CP_INTOPT(gss_authentication);
1417 M_CP_INTOPT(rsa_authentication);
1418 M_CP_INTOPT(pubkey_authentication);
1419 M_CP_INTOPT(kerberos_authentication);
1420 M_CP_INTOPT(hostbased_authentication);
1421 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001422 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001423 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001424 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001425
1426 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001427 M_CP_INTOPT(allow_agent_forwarding);
Darren Tucker1629c072007-02-19 22:25:37 +11001428 M_CP_INTOPT(gateway_ports);
1429 M_CP_INTOPT(x11_display_offset);
1430 M_CP_INTOPT(x11_forwarding);
1431 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001432 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001433 M_CP_INTOPT(max_authtries);
Darren Tucker1629c072007-02-19 22:25:37 +11001434
1435 M_CP_STROPT(banner);
1436 if (preauth)
1437 return;
1438 M_CP_STROPT(adm_forced_command);
Damien Millerd8cb1f12008-02-10 22:40:12 +11001439 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001440}
1441
Darren Tucker1629c072007-02-19 22:25:37 +11001442#undef M_CP_INTOPT
1443#undef M_CP_STROPT
1444
Darren Tucker45150472006-07-12 22:34:17 +10001445void
1446parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1447 const char *user, const char *host, const char *address)
1448{
1449 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001450 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001451
1452 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1453
Darren Tucker9fbac712004-08-12 22:41:44 +10001454 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001455 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001456 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001457 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001458 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001459 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001460 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001461 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001462 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001463 if (bad_options > 0)
1464 fatal("%s: terminating, %d bad configuration options",
1465 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001466}
Darren Tuckere7140f22008-06-10 23:01:51 +10001467
1468static const char *
1469fmt_intarg(ServerOpCodes code, int val)
1470{
1471 if (code == sAddressFamily) {
1472 switch (val) {
1473 case AF_INET:
1474 return "inet";
1475 case AF_INET6:
1476 return "inet6";
1477 case AF_UNSPEC:
1478 return "any";
1479 default:
1480 return "UNKNOWN";
1481 }
1482 }
1483 if (code == sPermitRootLogin) {
1484 switch (val) {
1485 case PERMIT_NO_PASSWD:
Darren Tuckerff4350e2008-11-11 16:31:05 +11001486 return "without-password";
Darren Tuckere7140f22008-06-10 23:01:51 +10001487 case PERMIT_FORCED_ONLY:
1488 return "forced-commands-only";
1489 case PERMIT_YES:
1490 return "yes";
1491 }
1492 }
1493 if (code == sProtocol) {
1494 switch (val) {
1495 case SSH_PROTO_1:
1496 return "1";
1497 case SSH_PROTO_2:
1498 return "2";
1499 case (SSH_PROTO_1|SSH_PROTO_2):
1500 return "2,1";
1501 default:
1502 return "UNKNOWN";
1503 }
1504 }
1505 if (code == sGatewayPorts && val == 2)
1506 return "clientspecified";
1507 if (code == sCompression && val == COMP_DELAYED)
1508 return "delayed";
1509 switch (val) {
1510 case -1:
1511 return "unset";
1512 case 0:
1513 return "no";
1514 case 1:
1515 return "yes";
1516 }
1517 return "UNKNOWN";
1518}
1519
1520static const char *
1521lookup_opcode_name(ServerOpCodes code)
1522{
1523 u_int i;
1524
1525 for (i = 0; keywords[i].name != NULL; i++)
1526 if (keywords[i].opcode == code)
1527 return(keywords[i].name);
1528 return "UNKNOWN";
1529}
1530
1531static void
1532dump_cfg_int(ServerOpCodes code, int val)
1533{
1534 printf("%s %d\n", lookup_opcode_name(code), val);
1535}
1536
1537static void
1538dump_cfg_fmtint(ServerOpCodes code, int val)
1539{
1540 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1541}
1542
1543static void
1544dump_cfg_string(ServerOpCodes code, const char *val)
1545{
1546 if (val == NULL)
1547 return;
1548 printf("%s %s\n", lookup_opcode_name(code), val);
1549}
1550
1551static void
1552dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1553{
1554 u_int i;
1555
1556 for (i = 0; i < count; i++)
1557 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1558}
1559
1560void
1561dump_config(ServerOptions *o)
1562{
1563 u_int i;
1564 int ret;
1565 struct addrinfo *ai;
1566 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1567
1568 /* these are usually at the top of the config */
1569 for (i = 0; i < o->num_ports; i++)
1570 printf("port %d\n", o->ports[i]);
1571 dump_cfg_fmtint(sProtocol, o->protocol);
1572 dump_cfg_fmtint(sAddressFamily, o->address_family);
1573
1574 /* ListenAddress must be after Port */
1575 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1576 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1577 sizeof(addr), port, sizeof(port),
1578 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1579 error("getnameinfo failed: %.100s",
1580 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1581 strerror(errno));
1582 } else {
1583 if (ai->ai_family == AF_INET6)
1584 printf("listenaddress [%s]:%s\n", addr, port);
1585 else
1586 printf("listenaddress %s:%s\n", addr, port);
1587 }
1588 }
1589
1590 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001591#ifdef USE_PAM
1592 dump_cfg_int(sUsePAM, o->use_pam);
1593#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001594 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1595 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1596 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1597 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1598 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001599 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001600 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1601 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1602
1603 /* formatted integer arguments */
1604 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1605 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1606 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1607 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1608 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1609 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1610 o->hostbased_uses_name_from_packet_only);
1611 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1612 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001613#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001614 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1615 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1616 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001617# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001618 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001619# endif
1620#endif
1621#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001622 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1623 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001624#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001625#ifdef JPAKE
1626 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1627 o->zero_knowledge_password_authentication);
1628#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001629 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1630 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1631 o->kbd_interactive_authentication);
1632 dump_cfg_fmtint(sChallengeResponseAuthentication,
1633 o->challenge_response_authentication);
1634 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1635 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1636 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1637 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1638 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1639 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1640 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1641 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1642 dump_cfg_fmtint(sUseLogin, o->use_login);
1643 dump_cfg_fmtint(sCompression, o->compression);
1644 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1645 dump_cfg_fmtint(sUseDNS, o->use_dns);
1646 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1647 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1648
1649 /* string arguments */
1650 dump_cfg_string(sPidFile, o->pid_file);
1651 dump_cfg_string(sXAuthLocation, o->xauth_location);
1652 dump_cfg_string(sCiphers, o->ciphers);
1653 dump_cfg_string(sMacs, o->macs);
1654 dump_cfg_string(sBanner, o->banner);
1655 dump_cfg_string(sAuthorizedKeysFile, o->authorized_keys_file);
1656 dump_cfg_string(sAuthorizedKeysFile2, o->authorized_keys_file2);
1657 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11001658 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Darren Tuckere7140f22008-06-10 23:01:51 +10001659
1660 /* string arguments requiring a lookup */
1661 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1662 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1663
1664 /* string array arguments */
1665 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1666 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11001667 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
1668 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10001669 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1670 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1671 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1672 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1673 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1674
1675 /* other arguments */
1676 for (i = 0; i < o->num_subsystems; i++)
1677 printf("subsystem %s %s\n", o->subsystem_name[i],
1678 o->subsystem_args[i]);
1679
1680 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1681 o->max_startups_rate, o->max_startups);
1682
1683 for (i = 0; tunmode_desc[i].val != -1; i++)
1684 if (tunmode_desc[i].val == o->permit_tun) {
1685 s = tunmode_desc[i].text;
1686 break;
1687 }
1688 dump_cfg_string(sPermitTunnel, s);
1689
Darren Tuckere7140f22008-06-10 23:01:51 +10001690 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10001691}