blob: c556986e38c9d43ae634f71a6d11ae4ef61a7699 [file] [log] [blame]
Damien Miller30da3442010-05-10 11:58:03 +10001/* $OpenBSD: servconf.c,v 1.208 2010/05/07 11:30:29 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 Miller30da3442010-05-10 11:58:03 +1000134 options->authorized_principals_file = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000135}
136
Damien Miller4af51302000-04-16 11:18:38 +1000137void
Damien Miller95def091999-11-25 00:26:21 +1100138fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000139{
Damien Miller726273e2001-11-12 11:40:11 +1100140 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000141 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000142 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100143
144 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100145 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100146 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100147 if (options->num_host_key_files == 0) {
148 /* fill default hostkeys for protocols */
149 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100150 options->host_key_files[options->num_host_key_files++] =
151 _PATH_HOST_KEY_FILE;
152 if (options->protocol & SSH_PROTO_2) {
153 options->host_key_files[options->num_host_key_files++] =
154 _PATH_HOST_RSA_KEY_FILE;
155 options->host_key_files[options->num_host_key_files++] =
156 _PATH_HOST_DSA_KEY_FILE;
157 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100158 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100159 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100160 if (options->num_ports == 0)
161 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
162 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000163 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000164 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000165 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100166 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000167 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100168 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000169 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100170 if (options->key_regeneration_time == -1)
171 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000172 if (options->permit_root_login == PERMIT_NOT_SET)
173 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100174 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100175 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100176 if (options->ignore_user_known_hosts == -1)
177 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100178 if (options->print_motd == -1)
179 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000180 if (options->print_lastlog == -1)
181 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100182 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100183 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100184 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100185 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100186 if (options->x11_use_localhost == -1)
187 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000188 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000189 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100190 if (options->strict_modes == -1)
191 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100192 if (options->tcp_keep_alive == -1)
193 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100194 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100195 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100196 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000197 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100199 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000200 if (options->hostbased_authentication == -1)
201 options->hostbased_authentication = 0;
202 if (options->hostbased_uses_name_from_packet_only == -1)
203 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->rsa_authentication == -1)
205 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100206 if (options->pubkey_authentication == -1)
207 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000209 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->kerberos_or_local_passwd == -1)
211 options->kerberos_or_local_passwd = 1;
212 if (options->kerberos_ticket_cleanup == -1)
213 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100214 if (options->kerberos_get_afs_token == -1)
215 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000216 if (options->gss_authentication == -1)
217 options->gss_authentication = 0;
218 if (options->gss_cleanup_creds == -1)
219 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->password_authentication == -1)
221 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100222 if (options->kbd_interactive_authentication == -1)
223 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000224 if (options->challenge_response_authentication == -1)
225 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100227 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000228 if (options->permit_user_env == -1)
229 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->use_login == -1)
231 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000232 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000233 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100234 if (options->allow_tcp_forwarding == -1)
235 options->allow_tcp_forwarding = 1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000236 if (options->allow_agent_forwarding == -1)
237 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000238 if (options->gateway_ports == -1)
239 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000240 if (options->max_startups == -1)
241 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000242 if (options->max_startups_rate == -1)
243 options->max_startups_rate = 100; /* 100% */
244 if (options->max_startups_begin == -1)
245 options->max_startups_begin = options->max_startups;
Darren Tucker89413db2004-05-24 10:36:23 +1000246 if (options->max_authtries == -1)
247 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000248 if (options->max_sessions == -1)
249 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000250 if (options->use_dns == -1)
251 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000252 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100253 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000254 if (options->client_alive_count_max == -1)
255 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100256 if (options->authorized_keys_file2 == NULL) {
257 /* authorized_keys_file2 falls back to authorized_keys_file */
258 if (options->authorized_keys_file != NULL)
259 options->authorized_keys_file2 = options->authorized_keys_file;
260 else
261 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
262 }
263 if (options->authorized_keys_file == NULL)
264 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Damien Millerd27b9472005-12-13 19:29:02 +1100265 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100266 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100267 if (options->zero_knowledge_password_authentication == -1)
268 options->zero_knowledge_password_authentication = 0;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000269
Ben Lindstromfb62a692002-06-06 19:47:11 +0000270 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000271 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000272 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000273
Tim Rice40017b02002-07-14 13:36:49 -0700274#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000275 if (use_privsep && options->compression == 1) {
276 error("This platform does not support both privilege "
277 "separation and compression");
278 error("Compression disabled");
279 options->compression = 0;
280 }
281#endif
282
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000283}
284
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000285/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100286typedef enum {
287 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100288 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000289 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100290 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100291 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
292 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000293 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100294 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100295 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000296 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100297 sPasswordAuthentication, sKbdInteractiveAuthentication,
298 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000299 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100300 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100301 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000302 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100303 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000304 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000305 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000306 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000307 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100308 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000309 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Damien Millerd27b9472005-12-13 19:29:02 +1100310 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100311 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100312 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100313 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000314 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000315 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000316} ServerOpCodes;
317
Darren Tucker45150472006-07-12 22:34:17 +1000318#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
319#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
320#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
321
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000322/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100323static struct {
324 const char *name;
325 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000326 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100327} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100328 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000329#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000330 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000331#else
Darren Tucker45150472006-07-12 22:34:17 +1000332 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000333#endif
Darren Tucker45150472006-07-12 22:34:17 +1000334 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100335 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000336 { "port", sPort, SSHCFG_GLOBAL },
337 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
338 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
339 { "pidfile", sPidFile, SSHCFG_GLOBAL },
340 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
341 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
342 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100343 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000344 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
345 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
346 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100347 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
348 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000349 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100350 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
351 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000352 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000353#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100354 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000355 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
356 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100357#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000358 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000359#else
Darren Tucker45150472006-07-12 22:34:17 +1000360 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100361#endif
362#else
Darren Tucker1629c072007-02-19 22:25:37 +1100363 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000364 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
365 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
366 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000367#endif
Darren Tucker45150472006-07-12 22:34:17 +1000368 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
369 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000370#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100371 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000372 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000373#else
Darren Tucker1629c072007-02-19 22:25:37 +1100374 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000375 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000376#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100377 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
378 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100379 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000380 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100381#ifdef JPAKE
382 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
383#else
384 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
385#endif
Darren Tucker45150472006-07-12 22:34:17 +1000386 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
387 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
388 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
389 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
390 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
391 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
392 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000393 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
394 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
395 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000396 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
397 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100398 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000399 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
400 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
401 { "compression", sCompression, SSHCFG_GLOBAL },
402 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
403 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
404 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000405 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000406 { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
407 { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
408 { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
409 { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
410 { "ciphers", sCiphers, SSHCFG_GLOBAL },
411 { "macs", sMacs, SSHCFG_GLOBAL },
412 { "protocol", sProtocol, SSHCFG_GLOBAL },
413 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
414 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
415 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000416 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000417 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100418 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000419 { "usedns", sUseDNS, SSHCFG_GLOBAL },
420 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
421 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
422 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
423 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
424 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
425 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000426 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Darren Tucker45150472006-07-12 22:34:17 +1000427 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
428 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Darren Tucker64cee362009-06-21 20:26:17 +1000429 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000430 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000431 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100432 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100433 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100434 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
435 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Miller30da3442010-05-10 11:58:03 +1000436 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000437 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000438};
439
Darren Tuckere7140f22008-06-10 23:01:51 +1000440static struct {
441 int val;
442 char *text;
443} tunmode_desc[] = {
444 { SSH_TUNMODE_NO, "no" },
445 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
446 { SSH_TUNMODE_ETHERNET, "ethernet" },
447 { SSH_TUNMODE_YES, "yes" },
448 { -1, NULL }
449};
450
Damien Miller5428f641999-11-25 11:54:57 +1100451/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000452 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100453 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000454
Damien Miller4af51302000-04-16 11:18:38 +1000455static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100456parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000457 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000458{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000459 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000460
Damien Miller95def091999-11-25 00:26:21 +1100461 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000462 if (strcasecmp(cp, keywords[i].name) == 0) {
463 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100464 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000465 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000466
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000467 error("%s: line %d: Bad configuration option: %s",
468 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100469 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000470}
471
Darren Tucker88b6fb22010-01-13 22:44:29 +1100472char *
473derelativise_path(const char *path)
474{
Damien Miller44451d02010-03-26 10:40:04 +1100475 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100476
477 expanded = tilde_expand_filename(path, getuid());
478 if (*expanded == '/')
479 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100480 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100481 fatal("%s: getcwd: %s", __func__, strerror(errno));
482 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100483 xfree(expanded);
484 return ret;
485}
486
Ben Lindstrombba81212001-06-25 05:01:22 +0000487static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100488add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100489{
Damien Millereccb9de2005-06-17 12:59:34 +1000490 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100491
492 if (options->num_ports == 0)
493 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100494 if (options->address_family == -1)
495 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000496 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000497 for (i = 0; i < options->num_ports; i++)
498 add_one_listen_addr(options, addr, options->ports[i]);
499 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000500 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000501}
502
Ben Lindstrombba81212001-06-25 05:01:22 +0000503static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100504add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000505{
506 struct addrinfo hints, *ai, *aitop;
507 char strport[NI_MAXSERV];
508 int gaierr;
509
510 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100511 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000512 hints.ai_socktype = SOCK_STREAM;
513 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100514 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000515 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
516 fatal("bad addr or host: %s (%s)",
517 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100518 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000519 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
520 ;
521 ai->ai_next = options->listen_addrs;
522 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100523}
524
Darren Tucker45150472006-07-12 22:34:17 +1000525/*
526 * The strategy for the Match blocks is that the config file is parsed twice.
527 *
528 * The first time is at startup. activep is initialized to 1 and the
529 * directives in the global context are processed and acted on. Hitting a
530 * Match directive unsets activep and the directives inside the block are
531 * checked for syntax only.
532 *
533 * The second time is after a connection has been established but before
534 * authentication. activep is initialized to 2 and global config directives
535 * are ignored since they have already been processed. If the criteria in a
536 * Match block is met, activep is set and the subsequent directives
537 * processed and actioned until EOF or another Match block unsets it. Any
538 * options set are copied into the main server config.
539 *
540 * Potential additions/improvements:
541 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
542 *
543 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
544 * Match Address 192.168.0.*
545 * Tag trusted
546 * Match Group wheel
547 * Tag trusted
548 * Match Tag trusted
549 * AllowTcpForwarding yes
550 * GatewayPorts clientspecified
551 * [...]
552 *
553 * - Add a PermittedChannelRequests directive
554 * Match Group shell
555 * PermittedChannelRequests session,forwarded-tcpip
556 */
557
558static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000559match_cfg_line_group(const char *grps, int line, const char *user)
560{
561 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000562 struct passwd *pw;
563
Damien Miller565ca3f2006-08-19 00:23:15 +1000564 if (user == NULL)
565 goto out;
566
567 if ((pw = getpwnam(user)) == NULL) {
568 debug("Can't match group at line %d because user %.100s does "
569 "not exist", line, user);
570 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
571 debug("Can't Match group because user %.100s not in any group "
572 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000573 } else if (ga_match_pattern_list(grps) != 1) {
574 debug("user %.100s does not match group list %.100s at line %d",
575 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000576 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000577 debug("user %.100s matched group list %.100s at line %d", user,
578 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000579 result = 1;
580 }
581out:
582 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000583 return result;
584}
585
586static int
Darren Tucker45150472006-07-12 22:34:17 +1000587match_cfg_line(char **condition, int line, const char *user, const char *host,
588 const char *address)
589{
590 int result = 1;
591 char *arg, *attrib, *cp = *condition;
592 size_t len;
593
594 if (user == NULL)
595 debug3("checking syntax for 'Match %s'", cp);
596 else
597 debug3("checking match for '%s' user %s host %s addr %s", cp,
598 user ? user : "(null)", host ? host : "(null)",
599 address ? address : "(null)");
600
601 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
602 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
603 error("Missing Match criteria for %s", attrib);
604 return -1;
605 }
606 len = strlen(arg);
607 if (strcasecmp(attrib, "user") == 0) {
608 if (!user) {
609 result = 0;
610 continue;
611 }
612 if (match_pattern_list(user, arg, len, 0) != 1)
613 result = 0;
614 else
615 debug("user %.100s matched 'User %.100s' at "
616 "line %d", user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000617 } else if (strcasecmp(attrib, "group") == 0) {
618 switch (match_cfg_line_group(arg, line, user)) {
619 case -1:
620 return -1;
621 case 0:
622 result = 0;
623 }
Darren Tucker45150472006-07-12 22:34:17 +1000624 } else if (strcasecmp(attrib, "host") == 0) {
625 if (!host) {
626 result = 0;
627 continue;
628 }
629 if (match_hostname(host, arg, len) != 1)
630 result = 0;
631 else
632 debug("connection from %.100s matched 'Host "
633 "%.100s' at line %d", host, arg, line);
634 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000635 switch (addr_match_list(address, arg)) {
636 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000637 debug("connection from %.100s matched 'Address "
638 "%.100s' at line %d", address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000639 break;
640 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000641 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000642 result = 0;
643 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000644 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000645 return -1;
646 }
Darren Tucker45150472006-07-12 22:34:17 +1000647 } else {
648 error("Unsupported Match attribute %s", attrib);
649 return -1;
650 }
651 }
652 if (user != NULL)
653 debug3("match %sfound", result ? "" : "not ");
654 *condition = cp;
655 return result;
656}
657
Damien Millere2754432006-07-24 14:06:47 +1000658#define WHITESPACE " \t\r\n"
659
Ben Lindstromade03f62001-12-06 18:22:17 +0000660int
661process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000662 const char *filename, int linenum, int *activep, const char *user,
663 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000664{
665 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000666 int cmdline = 0, *intptr, value, n;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100667 SyslogFacility *log_facility_ptr;
668 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000669 ServerOpCodes opcode;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100670 int port;
Darren Tucker45150472006-07-12 22:34:17 +1000671 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000672 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000673
674 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100675 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100676 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000677 /* Ignore leading whitespace */
678 if (*arg == '\0')
679 arg = strdelim(&cp);
680 if (!arg || !*arg || *arg == '#')
681 return 0;
682 intptr = NULL;
683 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000684 opcode = parse_token(arg, filename, linenum, &flags);
685
686 if (activep == NULL) { /* We are processing a command line directive */
687 cmdline = 1;
688 activep = &cmdline;
689 }
690 if (*activep && opcode != sMatch)
691 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
692 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
693 if (user == NULL) {
694 fatal("%s line %d: Directive '%s' is not allowed "
695 "within a Match block", filename, linenum, arg);
696 } else { /* this is a directive we have already processed */
697 while (arg)
698 arg = strdelim(&cp);
699 return 0;
700 }
701 }
702
Ben Lindstromade03f62001-12-06 18:22:17 +0000703 switch (opcode) {
704 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000705 case sUsePAM:
706 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000707 goto parse_flag;
708
709 /* Standard Options */
710 case sBadOption:
711 return -1;
712 case sPort:
713 /* ignore ports from configfile if cmdline specifies ports */
714 if (options->ports_from_cmdline)
715 return 0;
716 if (options->listen_addrs != NULL)
717 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100718 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000719 if (options->num_ports >= MAX_PORTS)
720 fatal("%s line %d: too many ports.",
721 filename, linenum);
722 arg = strdelim(&cp);
723 if (!arg || *arg == '\0')
724 fatal("%s line %d: missing port number.",
725 filename, linenum);
726 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100727 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000728 fatal("%s line %d: Badly formatted port number.",
729 filename, linenum);
730 break;
731
732 case sServerKeyBits:
733 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000734 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000735 arg = strdelim(&cp);
736 if (!arg || *arg == '\0')
737 fatal("%s line %d: missing integer value.",
738 filename, linenum);
739 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000740 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000741 *intptr = value;
742 break;
743
744 case sLoginGraceTime:
745 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000746 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000747 arg = strdelim(&cp);
748 if (!arg || *arg == '\0')
749 fatal("%s line %d: missing time value.",
750 filename, linenum);
751 if ((value = convtime(arg)) == -1)
752 fatal("%s line %d: invalid time value.",
753 filename, linenum);
754 if (*intptr == -1)
755 *intptr = value;
756 break;
757
758 case sKeyRegenerationTime:
759 intptr = &options->key_regeneration_time;
760 goto parse_time;
761
762 case sListenAddress:
763 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100764 if (arg == NULL || *arg == '\0')
765 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000766 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000767 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
768 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
769 && strchr(p+1, ':') != NULL) {
770 add_listen_addr(options, arg, 0);
771 break;
772 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100773 p = hpdelim(&arg);
774 if (p == NULL)
775 fatal("%s line %d: bad address:port usage",
776 filename, linenum);
777 p = cleanhostname(p);
778 if (arg == NULL)
779 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100780 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100781 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000782
Damien Millerf91ee4c2005-03-01 21:24:33 +1100783 add_listen_addr(options, p, port);
784
Ben Lindstromade03f62001-12-06 18:22:17 +0000785 break;
786
Darren Tucker0f383232005-01-20 10:57:56 +1100787 case sAddressFamily:
788 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000789 if (!arg || *arg == '\0')
790 fatal("%s line %d: missing address family.",
791 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100792 intptr = &options->address_family;
793 if (options->listen_addrs != NULL)
794 fatal("%s line %d: address family must be specified before "
795 "ListenAddress.", filename, linenum);
796 if (strcasecmp(arg, "inet") == 0)
797 value = AF_INET;
798 else if (strcasecmp(arg, "inet6") == 0)
799 value = AF_INET6;
800 else if (strcasecmp(arg, "any") == 0)
801 value = AF_UNSPEC;
802 else
803 fatal("%s line %d: unsupported address family \"%s\".",
804 filename, linenum, arg);
805 if (*intptr == -1)
806 *intptr = value;
807 break;
808
Ben Lindstromade03f62001-12-06 18:22:17 +0000809 case sHostKeyFile:
810 intptr = &options->num_host_key_files;
811 if (*intptr >= MAX_HOSTKEYS)
812 fatal("%s line %d: too many host keys specified (max %d).",
813 filename, linenum, MAX_HOSTKEYS);
814 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000815 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000816 arg = strdelim(&cp);
817 if (!arg || *arg == '\0')
818 fatal("%s line %d: missing file name.",
819 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000820 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100821 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000822 /* increase optional counter */
823 if (intptr != NULL)
824 *intptr = *intptr + 1;
825 }
826 break;
827
Damien Miller0a80ca12010-02-27 07:55:05 +1100828 case sHostCertificate:
829 intptr = &options->num_host_cert_files;
830 if (*intptr >= MAX_HOSTKEYS)
831 fatal("%s line %d: too many host certificates "
832 "specified (max %d).", filename, linenum,
833 MAX_HOSTCERTS);
834 charptr = &options->host_cert_files[*intptr];
835 goto parse_filename;
836 break;
837
Ben Lindstromade03f62001-12-06 18:22:17 +0000838 case sPidFile:
839 charptr = &options->pid_file;
840 goto parse_filename;
841
842 case sPermitRootLogin:
843 intptr = &options->permit_root_login;
844 arg = strdelim(&cp);
845 if (!arg || *arg == '\0')
846 fatal("%s line %d: missing yes/"
847 "without-password/forced-commands-only/no "
848 "argument.", filename, linenum);
849 value = 0; /* silence compiler */
850 if (strcmp(arg, "without-password") == 0)
851 value = PERMIT_NO_PASSWD;
852 else if (strcmp(arg, "forced-commands-only") == 0)
853 value = PERMIT_FORCED_ONLY;
854 else if (strcmp(arg, "yes") == 0)
855 value = PERMIT_YES;
856 else if (strcmp(arg, "no") == 0)
857 value = PERMIT_NO;
858 else
859 fatal("%s line %d: Bad yes/"
860 "without-password/forced-commands-only/no "
861 "argument: %s", filename, linenum, arg);
Darren Tucker15f94272008-01-01 20:36:56 +1100862 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000863 *intptr = value;
864 break;
865
866 case sIgnoreRhosts:
867 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000868 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +0000869 arg = strdelim(&cp);
870 if (!arg || *arg == '\0')
871 fatal("%s line %d: missing yes/no argument.",
872 filename, linenum);
873 value = 0; /* silence compiler */
874 if (strcmp(arg, "yes") == 0)
875 value = 1;
876 else if (strcmp(arg, "no") == 0)
877 value = 0;
878 else
879 fatal("%s line %d: Bad yes/no argument: %s",
880 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000881 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000882 *intptr = value;
883 break;
884
885 case sIgnoreUserKnownHosts:
886 intptr = &options->ignore_user_known_hosts;
887 goto parse_flag;
888
Ben Lindstromade03f62001-12-06 18:22:17 +0000889 case sRhostsRSAAuthentication:
890 intptr = &options->rhosts_rsa_authentication;
891 goto parse_flag;
892
893 case sHostbasedAuthentication:
894 intptr = &options->hostbased_authentication;
895 goto parse_flag;
896
897 case sHostbasedUsesNameFromPacketOnly:
898 intptr = &options->hostbased_uses_name_from_packet_only;
899 goto parse_flag;
900
901 case sRSAAuthentication:
902 intptr = &options->rsa_authentication;
903 goto parse_flag;
904
905 case sPubkeyAuthentication:
906 intptr = &options->pubkey_authentication;
907 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000908
Ben Lindstromade03f62001-12-06 18:22:17 +0000909 case sKerberosAuthentication:
910 intptr = &options->kerberos_authentication;
911 goto parse_flag;
912
913 case sKerberosOrLocalPasswd:
914 intptr = &options->kerberos_or_local_passwd;
915 goto parse_flag;
916
917 case sKerberosTicketCleanup:
918 intptr = &options->kerberos_ticket_cleanup;
919 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000920
Darren Tucker22ef5082003-12-31 11:37:34 +1100921 case sKerberosGetAFSToken:
922 intptr = &options->kerberos_get_afs_token;
923 goto parse_flag;
924
Darren Tucker0efd1552003-08-26 11:49:55 +1000925 case sGssAuthentication:
926 intptr = &options->gss_authentication;
927 goto parse_flag;
928
929 case sGssCleanupCreds:
930 intptr = &options->gss_cleanup_creds;
931 goto parse_flag;
932
Ben Lindstromade03f62001-12-06 18:22:17 +0000933 case sPasswordAuthentication:
934 intptr = &options->password_authentication;
935 goto parse_flag;
936
Damien Miller01ed2272008-11-05 16:20:46 +1100937 case sZeroKnowledgePasswordAuthentication:
938 intptr = &options->zero_knowledge_password_authentication;
939 goto parse_flag;
940
Ben Lindstromade03f62001-12-06 18:22:17 +0000941 case sKbdInteractiveAuthentication:
942 intptr = &options->kbd_interactive_authentication;
943 goto parse_flag;
944
945 case sChallengeResponseAuthentication:
946 intptr = &options->challenge_response_authentication;
947 goto parse_flag;
948
949 case sPrintMotd:
950 intptr = &options->print_motd;
951 goto parse_flag;
952
953 case sPrintLastLog:
954 intptr = &options->print_lastlog;
955 goto parse_flag;
956
957 case sX11Forwarding:
958 intptr = &options->x11_forwarding;
959 goto parse_flag;
960
961 case sX11DisplayOffset:
962 intptr = &options->x11_display_offset;
963 goto parse_int;
964
Damien Miller95c249f2002-02-05 12:11:34 +1100965 case sX11UseLocalhost:
966 intptr = &options->x11_use_localhost;
967 goto parse_flag;
968
Ben Lindstromade03f62001-12-06 18:22:17 +0000969 case sXAuthLocation:
970 charptr = &options->xauth_location;
971 goto parse_filename;
972
973 case sStrictModes:
974 intptr = &options->strict_modes;
975 goto parse_flag;
976
Damien Miller12c150e2003-12-17 16:31:10 +1100977 case sTCPKeepAlive:
978 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000979 goto parse_flag;
980
981 case sEmptyPasswd:
982 intptr = &options->permit_empty_passwd;
983 goto parse_flag;
984
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000985 case sPermitUserEnvironment:
986 intptr = &options->permit_user_env;
987 goto parse_flag;
988
Ben Lindstromade03f62001-12-06 18:22:17 +0000989 case sUseLogin:
990 intptr = &options->use_login;
991 goto parse_flag;
992
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000993 case sCompression:
994 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000995 arg = strdelim(&cp);
996 if (!arg || *arg == '\0')
997 fatal("%s line %d: missing yes/no/delayed "
998 "argument.", filename, linenum);
999 value = 0; /* silence compiler */
1000 if (strcmp(arg, "delayed") == 0)
1001 value = COMP_DELAYED;
1002 else if (strcmp(arg, "yes") == 0)
1003 value = COMP_ZLIB;
1004 else if (strcmp(arg, "no") == 0)
1005 value = COMP_NONE;
1006 else
1007 fatal("%s line %d: Bad yes/no/delayed "
1008 "argument: %s", filename, linenum, arg);
1009 if (*intptr == -1)
1010 *intptr = value;
1011 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001012
Ben Lindstromade03f62001-12-06 18:22:17 +00001013 case sGatewayPorts:
1014 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001015 arg = strdelim(&cp);
1016 if (!arg || *arg == '\0')
1017 fatal("%s line %d: missing yes/no/clientspecified "
1018 "argument.", filename, linenum);
1019 value = 0; /* silence compiler */
1020 if (strcmp(arg, "clientspecified") == 0)
1021 value = 2;
1022 else if (strcmp(arg, "yes") == 0)
1023 value = 1;
1024 else if (strcmp(arg, "no") == 0)
1025 value = 0;
1026 else
1027 fatal("%s line %d: Bad yes/no/clientspecified "
1028 "argument: %s", filename, linenum, arg);
Darren Tucker82347a82007-02-25 20:37:52 +11001029 if (*activep && *intptr == -1)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001030 *intptr = value;
1031 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001032
Damien Miller3a961dc2003-06-03 10:25:48 +10001033 case sUseDNS:
1034 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001035 goto parse_flag;
1036
1037 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001038 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001039 arg = strdelim(&cp);
1040 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001041 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001042 fatal("%.200s line %d: unsupported log facility '%s'",
1043 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001044 if (*log_facility_ptr == -1)
1045 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001046 break;
1047
1048 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001049 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001050 arg = strdelim(&cp);
1051 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001052 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001053 fatal("%.200s line %d: unsupported log level '%s'",
1054 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001055 if (*log_level_ptr == -1)
1056 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001057 break;
1058
1059 case sAllowTcpForwarding:
1060 intptr = &options->allow_tcp_forwarding;
1061 goto parse_flag;
1062
Damien Miller4f755cd2008-05-19 14:57:41 +10001063 case sAllowAgentForwarding:
1064 intptr = &options->allow_agent_forwarding;
1065 goto parse_flag;
1066
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001067 case sUsePrivilegeSeparation:
1068 intptr = &use_privsep;
1069 goto parse_flag;
1070
Ben Lindstromade03f62001-12-06 18:22:17 +00001071 case sAllowUsers:
1072 while ((arg = strdelim(&cp)) && *arg != '\0') {
1073 if (options->num_allow_users >= MAX_ALLOW_USERS)
1074 fatal("%s line %d: too many allow users.",
1075 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001076 options->allow_users[options->num_allow_users++] =
1077 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001078 }
1079 break;
1080
1081 case sDenyUsers:
1082 while ((arg = strdelim(&cp)) && *arg != '\0') {
1083 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001084 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001085 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001086 options->deny_users[options->num_deny_users++] =
1087 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001088 }
1089 break;
1090
1091 case sAllowGroups:
1092 while ((arg = strdelim(&cp)) && *arg != '\0') {
1093 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1094 fatal("%s line %d: too many allow groups.",
1095 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +00001096 options->allow_groups[options->num_allow_groups++] =
1097 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001098 }
1099 break;
1100
1101 case sDenyGroups:
1102 while ((arg = strdelim(&cp)) && *arg != '\0') {
1103 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1104 fatal("%s line %d: too many deny groups.",
1105 filename, linenum);
1106 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1107 }
1108 break;
1109
1110 case sCiphers:
1111 arg = strdelim(&cp);
1112 if (!arg || *arg == '\0')
1113 fatal("%s line %d: Missing argument.", filename, linenum);
1114 if (!ciphers_valid(arg))
1115 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1116 filename, linenum, arg ? arg : "<NONE>");
1117 if (options->ciphers == NULL)
1118 options->ciphers = xstrdup(arg);
1119 break;
1120
1121 case sMacs:
1122 arg = strdelim(&cp);
1123 if (!arg || *arg == '\0')
1124 fatal("%s line %d: Missing argument.", filename, linenum);
1125 if (!mac_valid(arg))
1126 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1127 filename, linenum, arg ? arg : "<NONE>");
1128 if (options->macs == NULL)
1129 options->macs = xstrdup(arg);
1130 break;
1131
1132 case sProtocol:
1133 intptr = &options->protocol;
1134 arg = strdelim(&cp);
1135 if (!arg || *arg == '\0')
1136 fatal("%s line %d: Missing argument.", filename, linenum);
1137 value = proto_spec(arg);
1138 if (value == SSH_PROTO_UNKNOWN)
1139 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001140 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001141 if (*intptr == SSH_PROTO_UNKNOWN)
1142 *intptr = value;
1143 break;
1144
1145 case sSubsystem:
1146 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1147 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001148 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001149 }
1150 arg = strdelim(&cp);
1151 if (!arg || *arg == '\0')
1152 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001153 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001154 if (!*activep) {
1155 arg = strdelim(&cp);
1156 break;
1157 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001158 for (i = 0; i < options->num_subsystems; i++)
1159 if (strcmp(arg, options->subsystem_name[i]) == 0)
1160 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001161 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001162 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1163 arg = strdelim(&cp);
1164 if (!arg || *arg == '\0')
1165 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001166 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001167 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001168
1169 /* Collect arguments (separate to executable) */
1170 p = xstrdup(arg);
1171 len = strlen(p) + 1;
1172 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1173 len += 1 + strlen(arg);
1174 p = xrealloc(p, 1, len);
1175 strlcat(p, " ", len);
1176 strlcat(p, arg, len);
1177 }
1178 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001179 options->num_subsystems++;
1180 break;
1181
1182 case sMaxStartups:
1183 arg = strdelim(&cp);
1184 if (!arg || *arg == '\0')
1185 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001186 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001187 if ((n = sscanf(arg, "%d:%d:%d",
1188 &options->max_startups_begin,
1189 &options->max_startups_rate,
1190 &options->max_startups)) == 3) {
1191 if (options->max_startups_begin >
1192 options->max_startups ||
1193 options->max_startups_rate > 100 ||
1194 options->max_startups_rate < 1)
1195 fatal("%s line %d: Illegal MaxStartups spec.",
1196 filename, linenum);
1197 } else if (n != 1)
1198 fatal("%s line %d: Illegal MaxStartups spec.",
1199 filename, linenum);
1200 else
1201 options->max_startups = options->max_startups_begin;
1202 break;
1203
Darren Tucker89413db2004-05-24 10:36:23 +10001204 case sMaxAuthTries:
1205 intptr = &options->max_authtries;
1206 goto parse_int;
1207
Damien Miller7207f642008-05-19 15:34:50 +10001208 case sMaxSessions:
1209 intptr = &options->max_sessions;
1210 goto parse_int;
1211
Ben Lindstromade03f62001-12-06 18:22:17 +00001212 case sBanner:
1213 charptr = &options->banner;
1214 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001215
Ben Lindstromade03f62001-12-06 18:22:17 +00001216 /*
1217 * These options can contain %X options expanded at
1218 * connect time, so that you can specify paths like:
1219 *
1220 * AuthorizedKeysFile /etc/ssh_keys/%u
1221 */
1222 case sAuthorizedKeysFile:
Damien Miller30da3442010-05-10 11:58:03 +10001223 charptr = &options->authorized_keys_file;
1224 goto parse_tilde_filename;
Ben Lindstromade03f62001-12-06 18:22:17 +00001225 case sAuthorizedKeysFile2:
Damien Miller30da3442010-05-10 11:58:03 +10001226 charptr = &options->authorized_keys_file2;
1227 goto parse_tilde_filename;
1228 case sAuthorizedPrincipalsFile:
1229 charptr = &options->authorized_principals_file;
1230 parse_tilde_filename:
Damien Millerc4cb47b2010-03-22 05:52:26 +11001231 arg = strdelim(&cp);
1232 if (!arg || *arg == '\0')
1233 fatal("%s line %d: missing file name.",
1234 filename, linenum);
1235 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001236 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001237 /* increase optional counter */
1238 if (intptr != NULL)
1239 *intptr = *intptr + 1;
1240 }
1241 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001242
1243 case sClientAliveInterval:
1244 intptr = &options->client_alive_interval;
1245 goto parse_time;
1246
1247 case sClientAliveCountMax:
1248 intptr = &options->client_alive_count_max;
1249 goto parse_int;
1250
Darren Tucker46bc0752004-05-02 22:11:30 +10001251 case sAcceptEnv:
1252 while ((arg = strdelim(&cp)) && *arg != '\0') {
1253 if (strchr(arg, '=') != NULL)
1254 fatal("%s line %d: Invalid environment name.",
1255 filename, linenum);
1256 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1257 fatal("%s line %d: too many allow env.",
1258 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001259 if (!*activep)
1260 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001261 options->accept_env[options->num_accept_env++] =
1262 xstrdup(arg);
1263 }
1264 break;
1265
Damien Millerd27b9472005-12-13 19:29:02 +11001266 case sPermitTunnel:
1267 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001268 arg = strdelim(&cp);
1269 if (!arg || *arg == '\0')
1270 fatal("%s line %d: Missing yes/point-to-point/"
1271 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001272 value = -1;
1273 for (i = 0; tunmode_desc[i].val != -1; i++)
1274 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1275 value = tunmode_desc[i].val;
1276 break;
1277 }
1278 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001279 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1280 "no argument: %s", filename, linenum, arg);
1281 if (*intptr == -1)
1282 *intptr = value;
1283 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001284
Darren Tucker45150472006-07-12 22:34:17 +10001285 case sMatch:
1286 if (cmdline)
1287 fatal("Match directive not supported as a command-line "
1288 "option");
1289 value = match_cfg_line(&cp, linenum, user, host, address);
1290 if (value < 0)
1291 fatal("%s line %d: Bad Match condition", filename,
1292 linenum);
1293 *activep = value;
1294 break;
1295
Damien Miller9b439df2006-07-24 14:04:00 +10001296 case sPermitOpen:
1297 arg = strdelim(&cp);
1298 if (!arg || *arg == '\0')
1299 fatal("%s line %d: missing PermitOpen specification",
1300 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001301 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001302 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001303 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001304 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001305 options->num_permitted_opens = 0;
1306 }
Damien Miller9b439df2006-07-24 14:04:00 +10001307 break;
1308 }
Damien Millera29b95e2007-01-05 16:28:36 +11001309 if (*activep && n == -1)
1310 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001311 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1312 p = hpdelim(&arg);
1313 if (p == NULL)
1314 fatal("%s line %d: missing host in PermitOpen",
1315 filename, linenum);
1316 p = cleanhostname(p);
Damien Miller3dc71ad2009-01-28 16:31:22 +11001317 if (arg == NULL || (port = a2port(arg)) <= 0)
Damien Millera765cf42006-07-24 14:08:13 +10001318 fatal("%s line %d: bad port number in "
1319 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001320 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001321 options->num_permitted_opens =
1322 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001323 }
Damien Miller9b439df2006-07-24 14:04:00 +10001324 break;
1325
Damien Millere2754432006-07-24 14:06:47 +10001326 case sForceCommand:
1327 if (cp == NULL)
1328 fatal("%.200s line %d: Missing argument.", filename,
1329 linenum);
1330 len = strspn(cp, WHITESPACE);
1331 if (*activep && options->adm_forced_command == NULL)
1332 options->adm_forced_command = xstrdup(cp + len);
1333 return 0;
1334
Damien Millerd8cb1f12008-02-10 22:40:12 +11001335 case sChrootDirectory:
1336 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001337
1338 arg = strdelim(&cp);
1339 if (!arg || *arg == '\0')
1340 fatal("%s line %d: missing file name.",
1341 filename, linenum);
1342 if (*activep && *charptr == NULL)
1343 *charptr = xstrdup(arg);
1344 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001345
Damien Miller1aed65e2010-03-04 21:53:35 +11001346 case sTrustedUserCAKeys:
1347 charptr = &options->trusted_user_ca_keys;
1348 goto parse_filename;
1349
1350 case sRevokedKeys:
1351 charptr = &options->revoked_keys_file;
1352 goto parse_filename;
1353
Ben Lindstromade03f62001-12-06 18:22:17 +00001354 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001355 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001356 filename, linenum, arg);
1357 while (arg)
1358 arg = strdelim(&cp);
1359 break;
1360
Damien Millerf9b3feb2003-05-16 11:38:32 +10001361 case sUnsupported:
1362 logit("%s line %d: Unsupported option %s",
1363 filename, linenum, arg);
1364 while (arg)
1365 arg = strdelim(&cp);
1366 break;
1367
Ben Lindstromade03f62001-12-06 18:22:17 +00001368 default:
1369 fatal("%s line %d: Missing handler for opcode %s (%d)",
1370 filename, linenum, arg, opcode);
1371 }
1372 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1373 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1374 filename, linenum, arg);
1375 return 0;
1376}
1377
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001378/* Reads the server configuration file. */
1379
Damien Miller4af51302000-04-16 11:18:38 +10001380void
Darren Tucker645ab752004-06-25 13:33:20 +10001381load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001382{
Darren Tucker645ab752004-06-25 13:33:20 +10001383 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001384 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001385
Darren Tucker645ab752004-06-25 13:33:20 +10001386 debug2("%s: filename %s", __func__, filename);
1387 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001388 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001389 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001390 }
Darren Tucker645ab752004-06-25 13:33:20 +10001391 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001392 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001393 /*
1394 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001395 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001396 * line numbers later for error messages
1397 */
1398 if ((cp = strchr(line, '#')) != NULL)
1399 memcpy(cp, "\n", 2);
1400 cp = line + strspn(line, " \t\r");
1401
1402 buffer_append(conf, cp, strlen(cp));
1403 }
1404 buffer_append(conf, "\0", 1);
1405 fclose(f);
1406 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1407}
1408
1409void
Darren Tucker45150472006-07-12 22:34:17 +10001410parse_server_match_config(ServerOptions *options, const char *user,
1411 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001412{
Darren Tucker45150472006-07-12 22:34:17 +10001413 ServerOptions mo;
1414
1415 initialize_server_options(&mo);
1416 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
Darren Tucker1629c072007-02-19 22:25:37 +11001417 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001418}
1419
Darren Tucker1629c072007-02-19 22:25:37 +11001420/* Helper macros */
1421#define M_CP_INTOPT(n) do {\
1422 if (src->n != -1) \
1423 dst->n = src->n; \
1424} while (0)
1425#define M_CP_STROPT(n) do {\
1426 if (src->n != NULL) { \
1427 if (dst->n != NULL) \
1428 xfree(dst->n); \
1429 dst->n = src->n; \
1430 } \
1431} while(0)
1432
1433/*
1434 * Copy any supported values that are set.
1435 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001436 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001437 * array values that are not used pre-authentication, because any that we
1438 * do use must be explictly sent in mm_getpwnamallow().
1439 */
Darren Tucker45150472006-07-12 22:34:17 +10001440void
Darren Tucker1629c072007-02-19 22:25:37 +11001441copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001442{
Darren Tucker1629c072007-02-19 22:25:37 +11001443 M_CP_INTOPT(password_authentication);
1444 M_CP_INTOPT(gss_authentication);
1445 M_CP_INTOPT(rsa_authentication);
1446 M_CP_INTOPT(pubkey_authentication);
1447 M_CP_INTOPT(kerberos_authentication);
1448 M_CP_INTOPT(hostbased_authentication);
1449 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001450 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001451 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001452 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001453
1454 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001455 M_CP_INTOPT(allow_agent_forwarding);
Darren Tucker1629c072007-02-19 22:25:37 +11001456 M_CP_INTOPT(gateway_ports);
1457 M_CP_INTOPT(x11_display_offset);
1458 M_CP_INTOPT(x11_forwarding);
1459 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001460 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001461 M_CP_INTOPT(max_authtries);
Darren Tucker1629c072007-02-19 22:25:37 +11001462
1463 M_CP_STROPT(banner);
1464 if (preauth)
1465 return;
1466 M_CP_STROPT(adm_forced_command);
Damien Millerd8cb1f12008-02-10 22:40:12 +11001467 M_CP_STROPT(chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11001468 M_CP_STROPT(trusted_user_ca_keys);
1469 M_CP_STROPT(revoked_keys_file);
Darren Tucker45150472006-07-12 22:34:17 +10001470}
1471
Darren Tucker1629c072007-02-19 22:25:37 +11001472#undef M_CP_INTOPT
1473#undef M_CP_STROPT
1474
Darren Tucker45150472006-07-12 22:34:17 +10001475void
1476parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1477 const char *user, const char *host, const char *address)
1478{
1479 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001480 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001481
1482 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1483
Darren Tucker9fbac712004-08-12 22:41:44 +10001484 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001485 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001486 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001487 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001488 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001489 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001490 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001491 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001492 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001493 if (bad_options > 0)
1494 fatal("%s: terminating, %d bad configuration options",
1495 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001496}
Darren Tuckere7140f22008-06-10 23:01:51 +10001497
1498static const char *
1499fmt_intarg(ServerOpCodes code, int val)
1500{
1501 if (code == sAddressFamily) {
1502 switch (val) {
1503 case AF_INET:
1504 return "inet";
1505 case AF_INET6:
1506 return "inet6";
1507 case AF_UNSPEC:
1508 return "any";
1509 default:
1510 return "UNKNOWN";
1511 }
1512 }
1513 if (code == sPermitRootLogin) {
1514 switch (val) {
1515 case PERMIT_NO_PASSWD:
Darren Tuckerff4350e2008-11-11 16:31:05 +11001516 return "without-password";
Darren Tuckere7140f22008-06-10 23:01:51 +10001517 case PERMIT_FORCED_ONLY:
1518 return "forced-commands-only";
1519 case PERMIT_YES:
1520 return "yes";
1521 }
1522 }
1523 if (code == sProtocol) {
1524 switch (val) {
1525 case SSH_PROTO_1:
1526 return "1";
1527 case SSH_PROTO_2:
1528 return "2";
1529 case (SSH_PROTO_1|SSH_PROTO_2):
1530 return "2,1";
1531 default:
1532 return "UNKNOWN";
1533 }
1534 }
1535 if (code == sGatewayPorts && val == 2)
1536 return "clientspecified";
1537 if (code == sCompression && val == COMP_DELAYED)
1538 return "delayed";
1539 switch (val) {
1540 case -1:
1541 return "unset";
1542 case 0:
1543 return "no";
1544 case 1:
1545 return "yes";
1546 }
1547 return "UNKNOWN";
1548}
1549
1550static const char *
1551lookup_opcode_name(ServerOpCodes code)
1552{
1553 u_int i;
1554
1555 for (i = 0; keywords[i].name != NULL; i++)
1556 if (keywords[i].opcode == code)
1557 return(keywords[i].name);
1558 return "UNKNOWN";
1559}
1560
1561static void
1562dump_cfg_int(ServerOpCodes code, int val)
1563{
1564 printf("%s %d\n", lookup_opcode_name(code), val);
1565}
1566
1567static void
1568dump_cfg_fmtint(ServerOpCodes code, int val)
1569{
1570 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1571}
1572
1573static void
1574dump_cfg_string(ServerOpCodes code, const char *val)
1575{
1576 if (val == NULL)
1577 return;
1578 printf("%s %s\n", lookup_opcode_name(code), val);
1579}
1580
1581static void
1582dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1583{
1584 u_int i;
1585
1586 for (i = 0; i < count; i++)
1587 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1588}
1589
1590void
1591dump_config(ServerOptions *o)
1592{
1593 u_int i;
1594 int ret;
1595 struct addrinfo *ai;
1596 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1597
1598 /* these are usually at the top of the config */
1599 for (i = 0; i < o->num_ports; i++)
1600 printf("port %d\n", o->ports[i]);
1601 dump_cfg_fmtint(sProtocol, o->protocol);
1602 dump_cfg_fmtint(sAddressFamily, o->address_family);
1603
1604 /* ListenAddress must be after Port */
1605 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1606 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1607 sizeof(addr), port, sizeof(port),
1608 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1609 error("getnameinfo failed: %.100s",
1610 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1611 strerror(errno));
1612 } else {
1613 if (ai->ai_family == AF_INET6)
1614 printf("listenaddress [%s]:%s\n", addr, port);
1615 else
1616 printf("listenaddress %s:%s\n", addr, port);
1617 }
1618 }
1619
1620 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001621#ifdef USE_PAM
1622 dump_cfg_int(sUsePAM, o->use_pam);
1623#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001624 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1625 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1626 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1627 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1628 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001629 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001630 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1631 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1632
1633 /* formatted integer arguments */
1634 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1635 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1636 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1637 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1638 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1639 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1640 o->hostbased_uses_name_from_packet_only);
1641 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1642 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001643#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001644 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1645 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1646 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001647# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001648 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001649# endif
1650#endif
1651#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001652 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1653 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001654#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001655#ifdef JPAKE
1656 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1657 o->zero_knowledge_password_authentication);
1658#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001659 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1660 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1661 o->kbd_interactive_authentication);
1662 dump_cfg_fmtint(sChallengeResponseAuthentication,
1663 o->challenge_response_authentication);
1664 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1665 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1666 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1667 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1668 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1669 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1670 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1671 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1672 dump_cfg_fmtint(sUseLogin, o->use_login);
1673 dump_cfg_fmtint(sCompression, o->compression);
1674 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1675 dump_cfg_fmtint(sUseDNS, o->use_dns);
1676 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1677 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1678
1679 /* string arguments */
1680 dump_cfg_string(sPidFile, o->pid_file);
1681 dump_cfg_string(sXAuthLocation, o->xauth_location);
1682 dump_cfg_string(sCiphers, o->ciphers);
1683 dump_cfg_string(sMacs, o->macs);
1684 dump_cfg_string(sBanner, o->banner);
1685 dump_cfg_string(sAuthorizedKeysFile, o->authorized_keys_file);
1686 dump_cfg_string(sAuthorizedKeysFile2, o->authorized_keys_file2);
1687 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11001688 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11001689 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
1690 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10001691 dump_cfg_string(sAuthorizedPrincipalsFile,
1692 o->authorized_principals_file);
Darren Tuckere7140f22008-06-10 23:01:51 +10001693
1694 /* string arguments requiring a lookup */
1695 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
1696 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
1697
1698 /* string array arguments */
1699 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
1700 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11001701 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
1702 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10001703 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
1704 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
1705 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
1706 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
1707 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1708
1709 /* other arguments */
1710 for (i = 0; i < o->num_subsystems; i++)
1711 printf("subsystem %s %s\n", o->subsystem_name[i],
1712 o->subsystem_args[i]);
1713
1714 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
1715 o->max_startups_rate, o->max_startups);
1716
1717 for (i = 0; tunmode_desc[i].val != -1; i++)
1718 if (tunmode_desc[i].val == o->permit_tun) {
1719 s = tunmode_desc[i].text;
1720 break;
1721 }
1722 dump_cfg_string(sPermitTunnel, s);
1723
Darren Tuckere7140f22008-06-10 23:01:51 +10001724 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10001725}