blob: 4e3026b83a3c1870530d7968683e4154f94eaa21 [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002/* $OpenBSD: servconf.c,v 1.235 2013/05/16 04:09:14 dtucker Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
Damien Millerd7834352006-08-05 12:39:39 +100031#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100032#include <errno.h>
Damien Millerbe43ebf2006-07-24 13:51:51 +100033
Damien Millerb84886b2008-05-19 15:05:07 +100034#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100035#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100036#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000037#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100040#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000042#include "misc.h"
43#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100044#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000045#include "kex.h"
46#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100047#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100048#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100049#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100050#include "canohost.h"
51#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110052#include "hostfile.h"
53#include "auth.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000054
Damien Miller3dc71ad2009-01-28 16:31:22 +110055static void add_listen_addr(ServerOptions *, char *, int);
56static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110057
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000058/* Use of privilege separation or not */
59extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100060extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000061
Damien Millerd4a8b7e1999-10-27 13:42:43 +100062/* Initializes the server options to their default values. */
63
Damien Miller4af51302000-04-16 11:18:38 +100064void
Damien Miller95def091999-11-25 00:26:21 +110065initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100066{
Damien Miller95def091999-11-25 00:26:21 +110067 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110068
69 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100070 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110071
72 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110073 options->num_ports = 0;
74 options->ports_from_cmdline = 0;
75 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110076 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110077 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110078 options->num_host_cert_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100079 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110080 options->server_key_bits = -1;
81 options->login_grace_time = -1;
82 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000083 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110084 options->ignore_rhosts = -1;
85 options->ignore_user_known_hosts = -1;
86 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000087 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110088 options->x11_forwarding = -1;
89 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110090 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100091 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110092 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110093 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110094 options->log_facility = SYSLOG_FACILITY_NOT_SET;
95 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110096 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000097 options->hostbased_authentication = -1;
98 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110099 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100100 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->kerberos_authentication = -1;
102 options->kerberos_or_local_passwd = -1;
103 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100104 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000105 options->gss_authentication=-1;
106 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100108 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000109 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100110 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000111 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000113 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000114 options->rekey_limit = -1;
115 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100116 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000117 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100118 options->num_allow_users = 0;
119 options->num_deny_users = 0;
120 options->num_allow_groups = 0;
121 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000122 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000123 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000124 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000125 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000126 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000127 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000128 options->max_startups_begin = -1;
129 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000130 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000131 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000132 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000133 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000134 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000135 options->client_alive_interval = -1;
136 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000137 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000138 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100139 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000140 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000141 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100142 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100143 options->authorized_keys_command = NULL;
144 options->authorized_keys_command_user = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100145 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100146 options->revoked_keys_file = NULL;
147 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000148 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100149 options->ip_qos_interactive = -1;
150 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000151 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000152}
153
Damien Miller4af51302000-04-16 11:18:38 +1000154void
Damien Miller95def091999-11-25 00:26:21 +1100155fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000156{
Damien Miller726273e2001-11-12 11:40:11 +1100157 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000158 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000159 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100160
161 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100162 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100163 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100164 if (options->num_host_key_files == 0) {
165 /* fill default hostkeys for protocols */
166 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100167 options->host_key_files[options->num_host_key_files++] =
168 _PATH_HOST_KEY_FILE;
169 if (options->protocol & SSH_PROTO_2) {
170 options->host_key_files[options->num_host_key_files++] =
171 _PATH_HOST_RSA_KEY_FILE;
172 options->host_key_files[options->num_host_key_files++] =
173 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100174#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000175 options->host_key_files[options->num_host_key_files++] =
176 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100177#endif
Damien Miller7fc23732002-01-22 23:19:11 +1100178 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100179 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100180 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100181 if (options->num_ports == 0)
182 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
183 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000184 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000185 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000186 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100187 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000188 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100189 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000190 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->key_regeneration_time == -1)
192 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000193 if (options->permit_root_login == PERMIT_NOT_SET)
194 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100195 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100196 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->ignore_user_known_hosts == -1)
198 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->print_motd == -1)
200 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000201 if (options->print_lastlog == -1)
202 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100204 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100206 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100207 if (options->x11_use_localhost == -1)
208 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000209 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000210 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100211 if (options->strict_modes == -1)
212 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100213 if (options->tcp_keep_alive == -1)
214 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100215 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100216 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100217 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000218 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100219 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100220 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000221 if (options->hostbased_authentication == -1)
222 options->hostbased_authentication = 0;
223 if (options->hostbased_uses_name_from_packet_only == -1)
224 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100225 if (options->rsa_authentication == -1)
226 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100227 if (options->pubkey_authentication == -1)
228 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000230 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100231 if (options->kerberos_or_local_passwd == -1)
232 options->kerberos_or_local_passwd = 1;
233 if (options->kerberos_ticket_cleanup == -1)
234 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100235 if (options->kerberos_get_afs_token == -1)
236 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000237 if (options->gss_authentication == -1)
238 options->gss_authentication = 0;
239 if (options->gss_cleanup_creds == -1)
240 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100241 if (options->password_authentication == -1)
242 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100243 if (options->kbd_interactive_authentication == -1)
244 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000245 if (options->challenge_response_authentication == -1)
246 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100247 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100248 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000249 if (options->permit_user_env == -1)
250 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100251 if (options->use_login == -1)
252 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000253 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000254 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000255 if (options->rekey_limit == -1)
256 options->rekey_limit = 0;
257 if (options->rekey_interval == -1)
258 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100259 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100260 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000261 if (options->allow_agent_forwarding == -1)
262 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000263 if (options->gateway_ports == -1)
264 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000265 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100266 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000267 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100268 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000269 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100270 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000271 if (options->max_authtries == -1)
272 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000273 if (options->max_sessions == -1)
274 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000275 if (options->use_dns == -1)
276 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000277 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100278 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000279 if (options->client_alive_count_max == -1)
280 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000281 if (options->num_authkeys_files == 0) {
282 options->authorized_keys_files[options->num_authkeys_files++] =
283 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
284 options->authorized_keys_files[options->num_authkeys_files++] =
285 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
286 }
Damien Millerd27b9472005-12-13 19:29:02 +1100287 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100288 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100289 if (options->zero_knowledge_password_authentication == -1)
290 options->zero_knowledge_password_authentication = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100291 if (options->ip_qos_interactive == -1)
292 options->ip_qos_interactive = IPTOS_LOWDELAY;
293 if (options->ip_qos_bulk == -1)
294 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000295 if (options->version_addendum == NULL)
296 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000297 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000298 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000299 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000300
Tim Rice40017b02002-07-14 13:36:49 -0700301#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000302 if (use_privsep && options->compression == 1) {
303 error("This platform does not support both privilege "
304 "separation and compression");
305 error("Compression disabled");
306 options->compression = 0;
307 }
308#endif
309
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000310}
311
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000312/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100313typedef enum {
314 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100315 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000316 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100317 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100318 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
319 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000320 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100321 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100322 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000323 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100324 sPasswordAuthentication, sKbdInteractiveAuthentication,
325 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000326 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100327 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100328 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000329 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000330 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000331 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000332 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000333 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000334 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100335 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000336 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100337 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100338 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100339 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100340 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000341 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000342 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100343 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Millera6e3f012012-11-04 23:21:40 +1100344 sAuthenticationMethods,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000345 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000346} ServerOpCodes;
347
Darren Tucker45150472006-07-12 22:34:17 +1000348#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
349#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
350#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
351
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000352/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100353static struct {
354 const char *name;
355 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000356 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100357} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100358 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000359#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000360 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000361#else
Darren Tucker45150472006-07-12 22:34:17 +1000362 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000363#endif
Darren Tucker45150472006-07-12 22:34:17 +1000364 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100365 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000366 { "port", sPort, SSHCFG_GLOBAL },
367 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
368 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
369 { "pidfile", sPidFile, SSHCFG_GLOBAL },
370 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
371 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
372 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100373 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000374 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
375 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
376 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100377 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
378 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000379 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100380 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
381 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000382 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000383#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100384 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000385 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
386 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100387#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000388 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000389#else
Darren Tucker45150472006-07-12 22:34:17 +1000390 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100391#endif
392#else
Darren Tucker1629c072007-02-19 22:25:37 +1100393 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000394 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
395 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
396 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000397#endif
Darren Tucker45150472006-07-12 22:34:17 +1000398 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
399 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000400#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100401 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000402 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000403#else
Darren Tucker1629c072007-02-19 22:25:37 +1100404 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000405 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000406#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100407 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
408 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100409 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000410 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100411#ifdef JPAKE
412 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
413#else
414 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
415#endif
Darren Tucker45150472006-07-12 22:34:17 +1000416 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
417 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
418 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
419 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
420 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
421 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
422 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000423 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
424 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
425 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000426 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
427 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100428 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000429 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
430 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
431 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000432 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000433 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
434 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
435 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000436 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000437 { "allowusers", sAllowUsers, SSHCFG_ALL },
438 { "denyusers", sDenyUsers, SSHCFG_ALL },
439 { "allowgroups", sAllowGroups, SSHCFG_ALL },
440 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000441 { "ciphers", sCiphers, SSHCFG_GLOBAL },
442 { "macs", sMacs, SSHCFG_GLOBAL },
443 { "protocol", sProtocol, SSHCFG_GLOBAL },
444 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
445 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
446 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000447 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000448 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100449 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000450 { "usedns", sUseDNS, SSHCFG_GLOBAL },
451 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
452 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
453 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
454 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000455 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000456 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000457 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000458 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000459 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000460 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000461 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000462 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100463 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100464 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100465 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
466 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000467 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000468 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100469 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100470 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
471 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000472 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100473 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000474 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000475};
476
Darren Tuckere7140f22008-06-10 23:01:51 +1000477static struct {
478 int val;
479 char *text;
480} tunmode_desc[] = {
481 { SSH_TUNMODE_NO, "no" },
482 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
483 { SSH_TUNMODE_ETHERNET, "ethernet" },
484 { SSH_TUNMODE_YES, "yes" },
485 { -1, NULL }
486};
487
Damien Miller5428f641999-11-25 11:54:57 +1100488/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000489 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100490 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000491
Damien Miller4af51302000-04-16 11:18:38 +1000492static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100493parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000494 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000495{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000496 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000497
Damien Miller95def091999-11-25 00:26:21 +1100498 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000499 if (strcasecmp(cp, keywords[i].name) == 0) {
500 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100501 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000502 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000503
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000504 error("%s: line %d: Bad configuration option: %s",
505 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100506 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000507}
508
Darren Tucker88b6fb22010-01-13 22:44:29 +1100509char *
510derelativise_path(const char *path)
511{
Damien Miller44451d02010-03-26 10:40:04 +1100512 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100513
514 expanded = tilde_expand_filename(path, getuid());
515 if (*expanded == '/')
516 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100517 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100518 fatal("%s: getcwd: %s", __func__, strerror(errno));
519 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100520 xfree(expanded);
521 return ret;
522}
523
Ben Lindstrombba81212001-06-25 05:01:22 +0000524static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100525add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100526{
Damien Millereccb9de2005-06-17 12:59:34 +1000527 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100528
529 if (options->num_ports == 0)
530 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100531 if (options->address_family == -1)
532 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000533 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000534 for (i = 0; i < options->num_ports; i++)
535 add_one_listen_addr(options, addr, options->ports[i]);
536 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000537 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000538}
539
Ben Lindstrombba81212001-06-25 05:01:22 +0000540static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100541add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000542{
543 struct addrinfo hints, *ai, *aitop;
544 char strport[NI_MAXSERV];
545 int gaierr;
546
547 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100548 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000549 hints.ai_socktype = SOCK_STREAM;
550 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100551 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000552 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
553 fatal("bad addr or host: %s (%s)",
554 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100555 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000556 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
557 ;
558 ai->ai_next = options->listen_addrs;
559 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100560}
561
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000562struct connection_info *
563get_connection_info(int populate, int use_dns)
564{
565 static struct connection_info ci;
566
567 if (!populate)
568 return &ci;
569 ci.host = get_canonical_hostname(use_dns);
570 ci.address = get_remote_ipaddr();
571 ci.laddress = get_local_ipaddr(packet_get_connection_in());
572 ci.lport = get_local_port();
573 return &ci;
574}
575
Darren Tucker45150472006-07-12 22:34:17 +1000576/*
577 * The strategy for the Match blocks is that the config file is parsed twice.
578 *
579 * The first time is at startup. activep is initialized to 1 and the
580 * directives in the global context are processed and acted on. Hitting a
581 * Match directive unsets activep and the directives inside the block are
582 * checked for syntax only.
583 *
584 * The second time is after a connection has been established but before
585 * authentication. activep is initialized to 2 and global config directives
586 * are ignored since they have already been processed. If the criteria in a
587 * Match block is met, activep is set and the subsequent directives
588 * processed and actioned until EOF or another Match block unsets it. Any
589 * options set are copied into the main server config.
590 *
591 * Potential additions/improvements:
592 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
593 *
594 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
595 * Match Address 192.168.0.*
596 * Tag trusted
597 * Match Group wheel
598 * Tag trusted
599 * Match Tag trusted
600 * AllowTcpForwarding yes
601 * GatewayPorts clientspecified
602 * [...]
603 *
604 * - Add a PermittedChannelRequests directive
605 * Match Group shell
606 * PermittedChannelRequests session,forwarded-tcpip
607 */
608
609static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000610match_cfg_line_group(const char *grps, int line, const char *user)
611{
612 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000613 struct passwd *pw;
614
Damien Miller565ca3f2006-08-19 00:23:15 +1000615 if (user == NULL)
616 goto out;
617
618 if ((pw = getpwnam(user)) == NULL) {
619 debug("Can't match group at line %d because user %.100s does "
620 "not exist", line, user);
621 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
622 debug("Can't Match group because user %.100s not in any group "
623 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000624 } else if (ga_match_pattern_list(grps) != 1) {
625 debug("user %.100s does not match group list %.100s at line %d",
626 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000627 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000628 debug("user %.100s matched group list %.100s at line %d", user,
629 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000630 result = 1;
631 }
632out:
633 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000634 return result;
635}
636
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000637/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000638 * All of the attributes on a single Match line are ANDed together, so we need
639 * to check every * attribute and set the result to zero if any attribute does
640 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000641 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000642static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000643match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000644{
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000645 int result = 1, port;
Darren Tucker45150472006-07-12 22:34:17 +1000646 char *arg, *attrib, *cp = *condition;
647 size_t len;
648
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000649 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000650 debug3("checking syntax for 'Match %s'", cp);
651 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000652 debug3("checking match for '%s' user %s host %s addr %s "
653 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
654 ci->host ? ci->host : "(null)",
655 ci->address ? ci->address : "(null)",
656 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000657
658 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
659 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
660 error("Missing Match criteria for %s", attrib);
661 return -1;
662 }
663 len = strlen(arg);
664 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000665 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000666 result = 0;
667 continue;
668 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000669 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000670 result = 0;
671 else
672 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000673 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000674 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000675 if (ci == NULL || ci->user == NULL) {
676 result = 0;
677 continue;
678 }
679 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000680 case -1:
681 return -1;
682 case 0:
683 result = 0;
684 }
Darren Tucker45150472006-07-12 22:34:17 +1000685 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000686 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000687 result = 0;
688 continue;
689 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000690 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000691 result = 0;
692 else
693 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000694 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000695 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000696 if (ci == NULL || ci->address == NULL) {
697 result = 0;
698 continue;
699 }
700 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000701 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000702 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000703 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000704 break;
705 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000706 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000707 result = 0;
708 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000709 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000710 return -1;
711 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000712 } else if (strcasecmp(attrib, "localaddress") == 0){
713 if (ci == NULL || ci->laddress == NULL) {
714 result = 0;
715 continue;
716 }
717 switch (addr_match_list(ci->laddress, arg)) {
718 case 1:
719 debug("connection from %.100s matched "
720 "'LocalAddress %.100s' at line %d",
721 ci->laddress, arg, line);
722 break;
723 case 0:
724 case -1:
725 result = 0;
726 break;
727 case -2:
728 return -1;
729 }
730 } else if (strcasecmp(attrib, "localport") == 0) {
731 if ((port = a2port(arg)) == -1) {
732 error("Invalid LocalPort '%s' on Match line",
733 arg);
734 return -1;
735 }
736 if (ci == NULL || ci->lport == 0) {
737 result = 0;
738 continue;
739 }
740 /* TODO support port lists */
741 if (port == ci->lport)
742 debug("connection from %.100s matched "
743 "'LocalPort %d' at line %d",
744 ci->laddress, port, line);
745 else
746 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000747 } else {
748 error("Unsupported Match attribute %s", attrib);
749 return -1;
750 }
751 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000752 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000753 debug3("match %sfound", result ? "" : "not ");
754 *condition = cp;
755 return result;
756}
757
Damien Millere2754432006-07-24 14:06:47 +1000758#define WHITESPACE " \t\r\n"
759
Damien Miller33322122011-06-20 14:43:11 +1000760/* Multistate option parsing */
761struct multistate {
762 char *key;
763 int value;
764};
765static const struct multistate multistate_addressfamily[] = {
766 { "inet", AF_INET },
767 { "inet6", AF_INET6 },
768 { "any", AF_UNSPEC },
769 { NULL, -1 }
770};
771static const struct multistate multistate_permitrootlogin[] = {
772 { "without-password", PERMIT_NO_PASSWD },
773 { "forced-commands-only", PERMIT_FORCED_ONLY },
774 { "yes", PERMIT_YES },
775 { "no", PERMIT_NO },
776 { NULL, -1 }
777};
778static const struct multistate multistate_compression[] = {
779 { "delayed", COMP_DELAYED },
780 { "yes", COMP_ZLIB },
781 { "no", COMP_NONE },
782 { NULL, -1 }
783};
784static const struct multistate multistate_gatewayports[] = {
785 { "clientspecified", 2 },
786 { "yes", 1 },
787 { "no", 0 },
788 { NULL, -1 }
789};
Damien Miller69ff1df2011-06-23 08:30:03 +1000790static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000791 { "yes", PRIVSEP_NOSANDBOX },
792 { "sandbox", PRIVSEP_ON },
793 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000794 { "no", PRIVSEP_OFF },
795 { NULL, -1 }
796};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100797static const struct multistate multistate_tcpfwd[] = {
798 { "yes", FORWARD_ALLOW },
799 { "all", FORWARD_ALLOW },
800 { "no", FORWARD_DENY },
801 { "remote", FORWARD_REMOTE },
802 { "local", FORWARD_LOCAL },
803 { NULL, -1 }
804};
Damien Miller33322122011-06-20 14:43:11 +1000805
Ben Lindstromade03f62001-12-06 18:22:17 +0000806int
807process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000808 const char *filename, int linenum, int *activep,
809 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000810{
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000811 char *cp, **charptr, *arg, *p, *endofnumber;
812 int cmdline = 0, *intptr, value, value2, n, port, scale;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100813 SyslogFacility *log_facility_ptr;
814 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000815 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000816 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000817 size_t len;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000818 long long orig, val64;
Damien Miller33322122011-06-20 14:43:11 +1000819 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000820
821 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100822 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100823 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000824 /* Ignore leading whitespace */
825 if (*arg == '\0')
826 arg = strdelim(&cp);
827 if (!arg || !*arg || *arg == '#')
828 return 0;
829 intptr = NULL;
830 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000831 opcode = parse_token(arg, filename, linenum, &flags);
832
833 if (activep == NULL) { /* We are processing a command line directive */
834 cmdline = 1;
835 activep = &cmdline;
836 }
837 if (*activep && opcode != sMatch)
838 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
839 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000840 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000841 fatal("%s line %d: Directive '%s' is not allowed "
842 "within a Match block", filename, linenum, arg);
843 } else { /* this is a directive we have already processed */
844 while (arg)
845 arg = strdelim(&cp);
846 return 0;
847 }
848 }
849
Ben Lindstromade03f62001-12-06 18:22:17 +0000850 switch (opcode) {
851 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000852 case sUsePAM:
853 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000854 goto parse_flag;
855
856 /* Standard Options */
857 case sBadOption:
858 return -1;
859 case sPort:
860 /* ignore ports from configfile if cmdline specifies ports */
861 if (options->ports_from_cmdline)
862 return 0;
863 if (options->listen_addrs != NULL)
864 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100865 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000866 if (options->num_ports >= MAX_PORTS)
867 fatal("%s line %d: too many ports.",
868 filename, linenum);
869 arg = strdelim(&cp);
870 if (!arg || *arg == '\0')
871 fatal("%s line %d: missing port number.",
872 filename, linenum);
873 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100874 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000875 fatal("%s line %d: Badly formatted port number.",
876 filename, linenum);
877 break;
878
879 case sServerKeyBits:
880 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000881 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000882 arg = strdelim(&cp);
883 if (!arg || *arg == '\0')
884 fatal("%s line %d: missing integer value.",
885 filename, linenum);
886 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000887 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000888 *intptr = value;
889 break;
890
891 case sLoginGraceTime:
892 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000893 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000894 arg = strdelim(&cp);
895 if (!arg || *arg == '\0')
896 fatal("%s line %d: missing time value.",
897 filename, linenum);
898 if ((value = convtime(arg)) == -1)
899 fatal("%s line %d: invalid time value.",
900 filename, linenum);
901 if (*intptr == -1)
902 *intptr = value;
903 break;
904
905 case sKeyRegenerationTime:
906 intptr = &options->key_regeneration_time;
907 goto parse_time;
908
909 case sListenAddress:
910 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100911 if (arg == NULL || *arg == '\0')
912 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000913 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000914 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
915 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
916 && strchr(p+1, ':') != NULL) {
917 add_listen_addr(options, arg, 0);
918 break;
919 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100920 p = hpdelim(&arg);
921 if (p == NULL)
922 fatal("%s line %d: bad address:port usage",
923 filename, linenum);
924 p = cleanhostname(p);
925 if (arg == NULL)
926 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100927 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100928 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000929
Damien Millerf91ee4c2005-03-01 21:24:33 +1100930 add_listen_addr(options, p, port);
931
Ben Lindstromade03f62001-12-06 18:22:17 +0000932 break;
933
Darren Tucker0f383232005-01-20 10:57:56 +1100934 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000935 intptr = &options->address_family;
936 multistate_ptr = multistate_addressfamily;
937 if (options->listen_addrs != NULL)
938 fatal("%s line %d: address family must be specified "
939 "before ListenAddress.", filename, linenum);
940 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100941 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000942 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000943 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000944 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000945 value = -1;
946 for (i = 0; multistate_ptr[i].key != NULL; i++) {
947 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
948 value = multistate_ptr[i].value;
949 break;
950 }
951 }
952 if (value == -1)
953 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100954 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000955 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100956 *intptr = value;
957 break;
958
Ben Lindstromade03f62001-12-06 18:22:17 +0000959 case sHostKeyFile:
960 intptr = &options->num_host_key_files;
961 if (*intptr >= MAX_HOSTKEYS)
962 fatal("%s line %d: too many host keys specified (max %d).",
963 filename, linenum, MAX_HOSTKEYS);
964 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000965 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000966 arg = strdelim(&cp);
967 if (!arg || *arg == '\0')
968 fatal("%s line %d: missing file name.",
969 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000970 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100971 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000972 /* increase optional counter */
973 if (intptr != NULL)
974 *intptr = *intptr + 1;
975 }
976 break;
977
Damien Miller0a80ca12010-02-27 07:55:05 +1100978 case sHostCertificate:
979 intptr = &options->num_host_cert_files;
980 if (*intptr >= MAX_HOSTKEYS)
981 fatal("%s line %d: too many host certificates "
982 "specified (max %d).", filename, linenum,
983 MAX_HOSTCERTS);
984 charptr = &options->host_cert_files[*intptr];
985 goto parse_filename;
986 break;
987
Ben Lindstromade03f62001-12-06 18:22:17 +0000988 case sPidFile:
989 charptr = &options->pid_file;
990 goto parse_filename;
991
992 case sPermitRootLogin:
993 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +1000994 multistate_ptr = multistate_permitrootlogin;
995 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +0000996
997 case sIgnoreRhosts:
998 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +1000999 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001000 arg = strdelim(&cp);
1001 if (!arg || *arg == '\0')
1002 fatal("%s line %d: missing yes/no argument.",
1003 filename, linenum);
1004 value = 0; /* silence compiler */
1005 if (strcmp(arg, "yes") == 0)
1006 value = 1;
1007 else if (strcmp(arg, "no") == 0)
1008 value = 0;
1009 else
1010 fatal("%s line %d: Bad yes/no argument: %s",
1011 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001012 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001013 *intptr = value;
1014 break;
1015
1016 case sIgnoreUserKnownHosts:
1017 intptr = &options->ignore_user_known_hosts;
1018 goto parse_flag;
1019
Ben Lindstromade03f62001-12-06 18:22:17 +00001020 case sRhostsRSAAuthentication:
1021 intptr = &options->rhosts_rsa_authentication;
1022 goto parse_flag;
1023
1024 case sHostbasedAuthentication:
1025 intptr = &options->hostbased_authentication;
1026 goto parse_flag;
1027
1028 case sHostbasedUsesNameFromPacketOnly:
1029 intptr = &options->hostbased_uses_name_from_packet_only;
1030 goto parse_flag;
1031
1032 case sRSAAuthentication:
1033 intptr = &options->rsa_authentication;
1034 goto parse_flag;
1035
1036 case sPubkeyAuthentication:
1037 intptr = &options->pubkey_authentication;
1038 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001039
Ben Lindstromade03f62001-12-06 18:22:17 +00001040 case sKerberosAuthentication:
1041 intptr = &options->kerberos_authentication;
1042 goto parse_flag;
1043
1044 case sKerberosOrLocalPasswd:
1045 intptr = &options->kerberos_or_local_passwd;
1046 goto parse_flag;
1047
1048 case sKerberosTicketCleanup:
1049 intptr = &options->kerberos_ticket_cleanup;
1050 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001051
Darren Tucker22ef5082003-12-31 11:37:34 +11001052 case sKerberosGetAFSToken:
1053 intptr = &options->kerberos_get_afs_token;
1054 goto parse_flag;
1055
Darren Tucker0efd1552003-08-26 11:49:55 +10001056 case sGssAuthentication:
1057 intptr = &options->gss_authentication;
1058 goto parse_flag;
1059
1060 case sGssCleanupCreds:
1061 intptr = &options->gss_cleanup_creds;
1062 goto parse_flag;
1063
Ben Lindstromade03f62001-12-06 18:22:17 +00001064 case sPasswordAuthentication:
1065 intptr = &options->password_authentication;
1066 goto parse_flag;
1067
Damien Miller01ed2272008-11-05 16:20:46 +11001068 case sZeroKnowledgePasswordAuthentication:
1069 intptr = &options->zero_knowledge_password_authentication;
1070 goto parse_flag;
1071
Ben Lindstromade03f62001-12-06 18:22:17 +00001072 case sKbdInteractiveAuthentication:
1073 intptr = &options->kbd_interactive_authentication;
1074 goto parse_flag;
1075
1076 case sChallengeResponseAuthentication:
1077 intptr = &options->challenge_response_authentication;
1078 goto parse_flag;
1079
1080 case sPrintMotd:
1081 intptr = &options->print_motd;
1082 goto parse_flag;
1083
1084 case sPrintLastLog:
1085 intptr = &options->print_lastlog;
1086 goto parse_flag;
1087
1088 case sX11Forwarding:
1089 intptr = &options->x11_forwarding;
1090 goto parse_flag;
1091
1092 case sX11DisplayOffset:
1093 intptr = &options->x11_display_offset;
1094 goto parse_int;
1095
Damien Miller95c249f2002-02-05 12:11:34 +11001096 case sX11UseLocalhost:
1097 intptr = &options->x11_use_localhost;
1098 goto parse_flag;
1099
Ben Lindstromade03f62001-12-06 18:22:17 +00001100 case sXAuthLocation:
1101 charptr = &options->xauth_location;
1102 goto parse_filename;
1103
1104 case sStrictModes:
1105 intptr = &options->strict_modes;
1106 goto parse_flag;
1107
Damien Miller12c150e2003-12-17 16:31:10 +11001108 case sTCPKeepAlive:
1109 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001110 goto parse_flag;
1111
1112 case sEmptyPasswd:
1113 intptr = &options->permit_empty_passwd;
1114 goto parse_flag;
1115
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001116 case sPermitUserEnvironment:
1117 intptr = &options->permit_user_env;
1118 goto parse_flag;
1119
Ben Lindstromade03f62001-12-06 18:22:17 +00001120 case sUseLogin:
1121 intptr = &options->use_login;
1122 goto parse_flag;
1123
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001124 case sCompression:
1125 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001126 multistate_ptr = multistate_compression;
1127 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001128
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001129 case sRekeyLimit:
1130 arg = strdelim(&cp);
1131 if (!arg || *arg == '\0')
1132 fatal("%.200s line %d: Missing argument.", filename,
1133 linenum);
1134 if (strcmp(arg, "default") == 0) {
1135 val64 = 0;
1136 } else {
1137 if (arg[0] < '0' || arg[0] > '9')
1138 fatal("%.200s line %d: Bad number.", filename,
1139 linenum);
1140 orig = val64 = strtoll(arg, &endofnumber, 10);
1141 if (arg == endofnumber)
1142 fatal("%.200s line %d: Bad number.", filename,
1143 linenum);
1144 switch (toupper(*endofnumber)) {
1145 case '\0':
1146 scale = 1;
1147 break;
1148 case 'K':
1149 scale = 1<<10;
1150 break;
1151 case 'M':
1152 scale = 1<<20;
1153 break;
1154 case 'G':
1155 scale = 1<<30;
1156 break;
1157 default:
1158 fatal("%.200s line %d: Invalid RekeyLimit "
1159 "suffix", filename, linenum);
1160 }
1161 val64 *= scale;
1162 /* detect integer wrap and too-large limits */
1163 if ((val64 / scale) != orig || val64 > UINT_MAX)
1164 fatal("%.200s line %d: RekeyLimit too large",
1165 filename, linenum);
1166 if (val64 != 0 && val64 < 16)
1167 fatal("%.200s line %d: RekeyLimit too small",
1168 filename, linenum);
1169 }
1170 if (*activep && options->rekey_limit == -1)
1171 options->rekey_limit = (u_int32_t)val64;
1172 if (cp != NULL) { /* optional rekey interval present */
1173 if (strcmp(cp, "none") == 0) {
1174 (void)strdelim(&cp); /* discard */
1175 break;
1176 }
1177 intptr = &options->rekey_interval;
1178 goto parse_time;
1179 }
1180 break;
1181
Ben Lindstromade03f62001-12-06 18:22:17 +00001182 case sGatewayPorts:
1183 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001184 multistate_ptr = multistate_gatewayports;
1185 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001186
Damien Miller3a961dc2003-06-03 10:25:48 +10001187 case sUseDNS:
1188 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001189 goto parse_flag;
1190
1191 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001192 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001193 arg = strdelim(&cp);
1194 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001195 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001196 fatal("%.200s line %d: unsupported log facility '%s'",
1197 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001198 if (*log_facility_ptr == -1)
1199 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001200 break;
1201
1202 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001203 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001204 arg = strdelim(&cp);
1205 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001206 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001207 fatal("%.200s line %d: unsupported log level '%s'",
1208 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001209 if (*log_level_ptr == -1)
1210 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001211 break;
1212
1213 case sAllowTcpForwarding:
1214 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001215 multistate_ptr = multistate_tcpfwd;
1216 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001217
Damien Miller4f755cd2008-05-19 14:57:41 +10001218 case sAllowAgentForwarding:
1219 intptr = &options->allow_agent_forwarding;
1220 goto parse_flag;
1221
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001222 case sUsePrivilegeSeparation:
1223 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001224 multistate_ptr = multistate_privsep;
1225 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001226
Ben Lindstromade03f62001-12-06 18:22:17 +00001227 case sAllowUsers:
1228 while ((arg = strdelim(&cp)) && *arg != '\0') {
1229 if (options->num_allow_users >= MAX_ALLOW_USERS)
1230 fatal("%s line %d: too many allow users.",
1231 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001232 if (!*activep)
1233 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001234 options->allow_users[options->num_allow_users++] =
1235 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001236 }
1237 break;
1238
1239 case sDenyUsers:
1240 while ((arg = strdelim(&cp)) && *arg != '\0') {
1241 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001242 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001243 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001244 if (!*activep)
1245 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001246 options->deny_users[options->num_deny_users++] =
1247 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001248 }
1249 break;
1250
1251 case sAllowGroups:
1252 while ((arg = strdelim(&cp)) && *arg != '\0') {
1253 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1254 fatal("%s line %d: too many allow groups.",
1255 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001256 if (!*activep)
1257 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001258 options->allow_groups[options->num_allow_groups++] =
1259 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001260 }
1261 break;
1262
1263 case sDenyGroups:
1264 while ((arg = strdelim(&cp)) && *arg != '\0') {
1265 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1266 fatal("%s line %d: too many deny groups.",
1267 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001268 if (!*activep)
1269 continue;
1270 options->deny_groups[options->num_deny_groups++] =
1271 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001272 }
1273 break;
1274
1275 case sCiphers:
1276 arg = strdelim(&cp);
1277 if (!arg || *arg == '\0')
1278 fatal("%s line %d: Missing argument.", filename, linenum);
1279 if (!ciphers_valid(arg))
1280 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1281 filename, linenum, arg ? arg : "<NONE>");
1282 if (options->ciphers == NULL)
1283 options->ciphers = xstrdup(arg);
1284 break;
1285
1286 case sMacs:
1287 arg = strdelim(&cp);
1288 if (!arg || *arg == '\0')
1289 fatal("%s line %d: Missing argument.", filename, linenum);
1290 if (!mac_valid(arg))
1291 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1292 filename, linenum, arg ? arg : "<NONE>");
1293 if (options->macs == NULL)
1294 options->macs = xstrdup(arg);
1295 break;
1296
Damien Millerd5f62bf2010-09-24 22:11:14 +10001297 case sKexAlgorithms:
1298 arg = strdelim(&cp);
1299 if (!arg || *arg == '\0')
1300 fatal("%s line %d: Missing argument.",
1301 filename, linenum);
1302 if (!kex_names_valid(arg))
1303 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1304 filename, linenum, arg ? arg : "<NONE>");
1305 if (options->kex_algorithms == NULL)
1306 options->kex_algorithms = xstrdup(arg);
1307 break;
1308
Ben Lindstromade03f62001-12-06 18:22:17 +00001309 case sProtocol:
1310 intptr = &options->protocol;
1311 arg = strdelim(&cp);
1312 if (!arg || *arg == '\0')
1313 fatal("%s line %d: Missing argument.", filename, linenum);
1314 value = proto_spec(arg);
1315 if (value == SSH_PROTO_UNKNOWN)
1316 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001317 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001318 if (*intptr == SSH_PROTO_UNKNOWN)
1319 *intptr = value;
1320 break;
1321
1322 case sSubsystem:
1323 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1324 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001325 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001326 }
1327 arg = strdelim(&cp);
1328 if (!arg || *arg == '\0')
1329 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001330 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001331 if (!*activep) {
1332 arg = strdelim(&cp);
1333 break;
1334 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001335 for (i = 0; i < options->num_subsystems; i++)
1336 if (strcmp(arg, options->subsystem_name[i]) == 0)
1337 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001338 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001339 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1340 arg = strdelim(&cp);
1341 if (!arg || *arg == '\0')
1342 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001343 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001344 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001345
1346 /* Collect arguments (separate to executable) */
1347 p = xstrdup(arg);
1348 len = strlen(p) + 1;
1349 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1350 len += 1 + strlen(arg);
1351 p = xrealloc(p, 1, len);
1352 strlcat(p, " ", len);
1353 strlcat(p, arg, len);
1354 }
1355 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001356 options->num_subsystems++;
1357 break;
1358
1359 case sMaxStartups:
1360 arg = strdelim(&cp);
1361 if (!arg || *arg == '\0')
1362 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001363 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001364 if ((n = sscanf(arg, "%d:%d:%d",
1365 &options->max_startups_begin,
1366 &options->max_startups_rate,
1367 &options->max_startups)) == 3) {
1368 if (options->max_startups_begin >
1369 options->max_startups ||
1370 options->max_startups_rate > 100 ||
1371 options->max_startups_rate < 1)
1372 fatal("%s line %d: Illegal MaxStartups spec.",
1373 filename, linenum);
1374 } else if (n != 1)
1375 fatal("%s line %d: Illegal MaxStartups spec.",
1376 filename, linenum);
1377 else
1378 options->max_startups = options->max_startups_begin;
1379 break;
1380
Darren Tucker89413db2004-05-24 10:36:23 +10001381 case sMaxAuthTries:
1382 intptr = &options->max_authtries;
1383 goto parse_int;
1384
Damien Miller7207f642008-05-19 15:34:50 +10001385 case sMaxSessions:
1386 intptr = &options->max_sessions;
1387 goto parse_int;
1388
Ben Lindstromade03f62001-12-06 18:22:17 +00001389 case sBanner:
1390 charptr = &options->banner;
1391 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001392
Ben Lindstromade03f62001-12-06 18:22:17 +00001393 /*
1394 * These options can contain %X options expanded at
1395 * connect time, so that you can specify paths like:
1396 *
1397 * AuthorizedKeysFile /etc/ssh_keys/%u
1398 */
1399 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001400 if (*activep && options->num_authkeys_files == 0) {
1401 while ((arg = strdelim(&cp)) && *arg != '\0') {
1402 if (options->num_authkeys_files >=
1403 MAX_AUTHKEYS_FILES)
1404 fatal("%s line %d: "
1405 "too many authorized keys files.",
1406 filename, linenum);
1407 options->authorized_keys_files[
1408 options->num_authkeys_files++] =
1409 tilde_expand_filename(arg, getuid());
1410 }
1411 }
1412 return 0;
1413
Damien Miller30da3442010-05-10 11:58:03 +10001414 case sAuthorizedPrincipalsFile:
1415 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001416 arg = strdelim(&cp);
1417 if (!arg || *arg == '\0')
1418 fatal("%s line %d: missing file name.",
1419 filename, linenum);
1420 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001421 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001422 /* increase optional counter */
1423 if (intptr != NULL)
1424 *intptr = *intptr + 1;
1425 }
1426 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001427
1428 case sClientAliveInterval:
1429 intptr = &options->client_alive_interval;
1430 goto parse_time;
1431
1432 case sClientAliveCountMax:
1433 intptr = &options->client_alive_count_max;
1434 goto parse_int;
1435
Darren Tucker46bc0752004-05-02 22:11:30 +10001436 case sAcceptEnv:
1437 while ((arg = strdelim(&cp)) && *arg != '\0') {
1438 if (strchr(arg, '=') != NULL)
1439 fatal("%s line %d: Invalid environment name.",
1440 filename, linenum);
1441 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1442 fatal("%s line %d: too many allow env.",
1443 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001444 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001445 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001446 options->accept_env[options->num_accept_env++] =
1447 xstrdup(arg);
1448 }
1449 break;
1450
Damien Millerd27b9472005-12-13 19:29:02 +11001451 case sPermitTunnel:
1452 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001453 arg = strdelim(&cp);
1454 if (!arg || *arg == '\0')
1455 fatal("%s line %d: Missing yes/point-to-point/"
1456 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001457 value = -1;
1458 for (i = 0; tunmode_desc[i].val != -1; i++)
1459 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1460 value = tunmode_desc[i].val;
1461 break;
1462 }
1463 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001464 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1465 "no argument: %s", filename, linenum, arg);
1466 if (*intptr == -1)
1467 *intptr = value;
1468 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001469
Darren Tucker45150472006-07-12 22:34:17 +10001470 case sMatch:
1471 if (cmdline)
1472 fatal("Match directive not supported as a command-line "
1473 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001474 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001475 if (value < 0)
1476 fatal("%s line %d: Bad Match condition", filename,
1477 linenum);
1478 *activep = value;
1479 break;
1480
Damien Miller9b439df2006-07-24 14:04:00 +10001481 case sPermitOpen:
1482 arg = strdelim(&cp);
1483 if (!arg || *arg == '\0')
1484 fatal("%s line %d: missing PermitOpen specification",
1485 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001486 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001487 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001488 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001489 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001490 options->num_permitted_opens = 0;
1491 }
Damien Miller9b439df2006-07-24 14:04:00 +10001492 break;
1493 }
Damien Millerc6081482012-04-22 11:18:53 +10001494 if (strcmp(arg, "none") == 0) {
1495 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001496 options->num_permitted_opens = 1;
1497 channel_disable_adm_local_opens();
1498 }
1499 break;
1500 }
Damien Millera29b95e2007-01-05 16:28:36 +11001501 if (*activep && n == -1)
1502 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001503 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1504 p = hpdelim(&arg);
1505 if (p == NULL)
1506 fatal("%s line %d: missing host in PermitOpen",
1507 filename, linenum);
1508 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001509 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001510 fatal("%s line %d: bad port number in "
1511 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001512 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001513 options->num_permitted_opens =
1514 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001515 }
Damien Miller9b439df2006-07-24 14:04:00 +10001516 break;
1517
Damien Millere2754432006-07-24 14:06:47 +10001518 case sForceCommand:
1519 if (cp == NULL)
1520 fatal("%.200s line %d: Missing argument.", filename,
1521 linenum);
1522 len = strspn(cp, WHITESPACE);
1523 if (*activep && options->adm_forced_command == NULL)
1524 options->adm_forced_command = xstrdup(cp + len);
1525 return 0;
1526
Damien Millerd8cb1f12008-02-10 22:40:12 +11001527 case sChrootDirectory:
1528 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001529
1530 arg = strdelim(&cp);
1531 if (!arg || *arg == '\0')
1532 fatal("%s line %d: missing file name.",
1533 filename, linenum);
1534 if (*activep && *charptr == NULL)
1535 *charptr = xstrdup(arg);
1536 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001537
Damien Miller1aed65e2010-03-04 21:53:35 +11001538 case sTrustedUserCAKeys:
1539 charptr = &options->trusted_user_ca_keys;
1540 goto parse_filename;
1541
1542 case sRevokedKeys:
1543 charptr = &options->revoked_keys_file;
1544 goto parse_filename;
1545
Damien Miller0dac6fb2010-11-20 15:19:38 +11001546 case sIPQoS:
1547 arg = strdelim(&cp);
1548 if ((value = parse_ipqos(arg)) == -1)
1549 fatal("%s line %d: Bad IPQoS value: %s",
1550 filename, linenum, arg);
1551 arg = strdelim(&cp);
1552 if (arg == NULL)
1553 value2 = value;
1554 else if ((value2 = parse_ipqos(arg)) == -1)
1555 fatal("%s line %d: Bad IPQoS value: %s",
1556 filename, linenum, arg);
1557 if (*activep) {
1558 options->ip_qos_interactive = value;
1559 options->ip_qos_bulk = value2;
1560 }
1561 break;
1562
Damien Miller23528812012-04-22 11:24:43 +10001563 case sVersionAddendum:
1564 if (cp == NULL)
1565 fatal("%.200s line %d: Missing argument.", filename,
1566 linenum);
1567 len = strspn(cp, WHITESPACE);
1568 if (*activep && options->version_addendum == NULL) {
1569 if (strcasecmp(cp + len, "none") == 0)
1570 options->version_addendum = xstrdup("");
1571 else if (strchr(cp + len, '\r') != NULL)
1572 fatal("%.200s line %d: Invalid argument",
1573 filename, linenum);
1574 else
1575 options->version_addendum = xstrdup(cp + len);
1576 }
1577 return 0;
1578
Damien Miller09d3e122012-10-31 08:58:58 +11001579 case sAuthorizedKeysCommand:
1580 len = strspn(cp, WHITESPACE);
1581 if (*activep && options->authorized_keys_command == NULL) {
1582 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1583 fatal("%.200s line %d: AuthorizedKeysCommand "
1584 "must be an absolute path",
1585 filename, linenum);
1586 options->authorized_keys_command = xstrdup(cp + len);
1587 }
1588 return 0;
1589
1590 case sAuthorizedKeysCommandUser:
1591 charptr = &options->authorized_keys_command_user;
1592
1593 arg = strdelim(&cp);
1594 if (*activep && *charptr == NULL)
1595 *charptr = xstrdup(arg);
1596 break;
1597
Damien Millera6e3f012012-11-04 23:21:40 +11001598 case sAuthenticationMethods:
1599 if (*activep && options->num_auth_methods == 0) {
1600 while ((arg = strdelim(&cp)) && *arg != '\0') {
1601 if (options->num_auth_methods >=
1602 MAX_AUTH_METHODS)
1603 fatal("%s line %d: "
1604 "too many authentication methods.",
1605 filename, linenum);
1606 if (auth2_methods_valid(arg, 0) != 0)
1607 fatal("%s line %d: invalid "
1608 "authentication method list.",
1609 filename, linenum);
1610 options->auth_methods[
1611 options->num_auth_methods++] = xstrdup(arg);
1612 }
1613 }
1614 return 0;
1615
Ben Lindstromade03f62001-12-06 18:22:17 +00001616 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001617 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001618 filename, linenum, arg);
1619 while (arg)
1620 arg = strdelim(&cp);
1621 break;
1622
Damien Millerf9b3feb2003-05-16 11:38:32 +10001623 case sUnsupported:
1624 logit("%s line %d: Unsupported option %s",
1625 filename, linenum, arg);
1626 while (arg)
1627 arg = strdelim(&cp);
1628 break;
1629
Ben Lindstromade03f62001-12-06 18:22:17 +00001630 default:
1631 fatal("%s line %d: Missing handler for opcode %s (%d)",
1632 filename, linenum, arg, opcode);
1633 }
1634 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1635 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1636 filename, linenum, arg);
1637 return 0;
1638}
1639
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001640/* Reads the server configuration file. */
1641
Damien Miller4af51302000-04-16 11:18:38 +10001642void
Darren Tucker645ab752004-06-25 13:33:20 +10001643load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001644{
Damien Miller46cb75a2012-07-31 12:22:37 +10001645 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001646 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001647 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001648
Darren Tucker645ab752004-06-25 13:33:20 +10001649 debug2("%s: filename %s", __func__, filename);
1650 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001651 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001652 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001653 }
Darren Tucker645ab752004-06-25 13:33:20 +10001654 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001655 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001656 lineno++;
1657 if (strlen(line) == sizeof(line) - 1)
1658 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001659 /*
1660 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001661 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001662 * line numbers later for error messages
1663 */
1664 if ((cp = strchr(line, '#')) != NULL)
1665 memcpy(cp, "\n", 2);
1666 cp = line + strspn(line, " \t\r");
1667
1668 buffer_append(conf, cp, strlen(cp));
1669 }
1670 buffer_append(conf, "\0", 1);
1671 fclose(f);
1672 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1673}
1674
1675void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001676parse_server_match_config(ServerOptions *options,
1677 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001678{
Darren Tucker45150472006-07-12 22:34:17 +10001679 ServerOptions mo;
1680
1681 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001682 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001683 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001684}
1685
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001686int parse_server_match_testspec(struct connection_info *ci, char *spec)
1687{
1688 char *p;
1689
1690 while ((p = strsep(&spec, ",")) && *p != '\0') {
1691 if (strncmp(p, "addr=", 5) == 0) {
1692 ci->address = xstrdup(p + 5);
1693 } else if (strncmp(p, "host=", 5) == 0) {
1694 ci->host = xstrdup(p + 5);
1695 } else if (strncmp(p, "user=", 5) == 0) {
1696 ci->user = xstrdup(p + 5);
1697 } else if (strncmp(p, "laddr=", 6) == 0) {
1698 ci->laddress = xstrdup(p + 6);
1699 } else if (strncmp(p, "lport=", 6) == 0) {
1700 ci->lport = a2port(p + 6);
1701 if (ci->lport == -1) {
1702 fprintf(stderr, "Invalid port '%s' in test mode"
1703 " specification %s\n", p+6, p);
1704 return -1;
1705 }
1706 } else {
1707 fprintf(stderr, "Invalid test mode specification %s\n",
1708 p);
1709 return -1;
1710 }
1711 }
1712 return 0;
1713}
1714
1715/*
1716 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1717 * empty spec.
1718 */
1719int server_match_spec_complete(struct connection_info *ci)
1720{
1721 if (ci->user && ci->host && ci->address)
1722 return 1; /* complete */
1723 if (!ci->user && !ci->host && !ci->address)
1724 return -1; /* empty */
1725 return 0; /* partial */
1726}
1727
Darren Tucker1629c072007-02-19 22:25:37 +11001728/* Helper macros */
1729#define M_CP_INTOPT(n) do {\
1730 if (src->n != -1) \
1731 dst->n = src->n; \
1732} while (0)
1733#define M_CP_STROPT(n) do {\
1734 if (src->n != NULL) { \
1735 if (dst->n != NULL) \
1736 xfree(dst->n); \
1737 dst->n = src->n; \
1738 } \
1739} while(0)
Damien Millerd8478b62011-05-29 21:39:36 +10001740#define M_CP_STRARRAYOPT(n, num_n) do {\
1741 if (src->num_n != 0) { \
1742 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1743 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1744 } \
1745} while(0)
Darren Tucker1629c072007-02-19 22:25:37 +11001746
1747/*
1748 * Copy any supported values that are set.
1749 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001750 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001751 * array values that are not used pre-authentication, because any that we
1752 * do use must be explictly sent in mm_getpwnamallow().
1753 */
Darren Tucker45150472006-07-12 22:34:17 +10001754void
Darren Tucker1629c072007-02-19 22:25:37 +11001755copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001756{
Darren Tucker1629c072007-02-19 22:25:37 +11001757 M_CP_INTOPT(password_authentication);
1758 M_CP_INTOPT(gss_authentication);
1759 M_CP_INTOPT(rsa_authentication);
1760 M_CP_INTOPT(pubkey_authentication);
1761 M_CP_INTOPT(kerberos_authentication);
1762 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001763 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001764 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001765 M_CP_INTOPT(zero_knowledge_password_authentication);
Damien Miller09d3e122012-10-31 08:58:58 +11001766 M_CP_STROPT(authorized_keys_command);
1767 M_CP_STROPT(authorized_keys_command_user);
Darren Tucker15f94272008-01-01 20:36:56 +11001768 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001769 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001770
1771 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001772 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001773 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001774 M_CP_INTOPT(gateway_ports);
1775 M_CP_INTOPT(x11_display_offset);
1776 M_CP_INTOPT(x11_forwarding);
1777 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001778 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001779 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001780 M_CP_INTOPT(ip_qos_interactive);
1781 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001782 M_CP_INTOPT(rekey_limit);
1783 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001784
Damien Millerf2e407e2011-05-20 19:04:14 +10001785 /* See comment in servconf.h */
1786 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001787
Damien Millerc2411902011-05-20 19:03:49 +10001788 /*
1789 * The only things that should be below this point are string options
1790 * which are only used after authentication.
1791 */
Damien Miller5d74e582011-05-20 19:03:31 +10001792 if (preauth)
1793 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001794
Damien Miller5d74e582011-05-20 19:03:31 +10001795 M_CP_STROPT(adm_forced_command);
1796 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001797}
1798
Darren Tucker1629c072007-02-19 22:25:37 +11001799#undef M_CP_INTOPT
1800#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001801#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001802
Darren Tucker45150472006-07-12 22:34:17 +10001803void
1804parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001805 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001806{
1807 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001808 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001809
1810 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1811
Darren Tucker9fbac712004-08-12 22:41:44 +10001812 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001813 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001814 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001815 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001816 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001817 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001818 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001819 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001820 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001821 if (bad_options > 0)
1822 fatal("%s: terminating, %d bad configuration options",
1823 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001824}
Darren Tuckere7140f22008-06-10 23:01:51 +10001825
1826static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001827fmt_multistate_int(int val, const struct multistate *m)
1828{
1829 u_int i;
1830
1831 for (i = 0; m[i].key != NULL; i++) {
1832 if (m[i].value == val)
1833 return m[i].key;
1834 }
1835 return "UNKNOWN";
1836}
1837
1838static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001839fmt_intarg(ServerOpCodes code, int val)
1840{
Damien Miller82c55872011-06-23 08:20:30 +10001841 if (val == -1)
1842 return "unset";
1843 switch (code) {
1844 case sAddressFamily:
1845 return fmt_multistate_int(val, multistate_addressfamily);
1846 case sPermitRootLogin:
1847 return fmt_multistate_int(val, multistate_permitrootlogin);
1848 case sGatewayPorts:
1849 return fmt_multistate_int(val, multistate_gatewayports);
1850 case sCompression:
1851 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001852 case sUsePrivilegeSeparation:
1853 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001854 case sAllowTcpForwarding:
1855 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001856 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001857 switch (val) {
1858 case SSH_PROTO_1:
1859 return "1";
1860 case SSH_PROTO_2:
1861 return "2";
1862 case (SSH_PROTO_1|SSH_PROTO_2):
1863 return "2,1";
1864 default:
1865 return "UNKNOWN";
1866 }
Damien Miller82c55872011-06-23 08:20:30 +10001867 default:
1868 switch (val) {
1869 case 0:
1870 return "no";
1871 case 1:
1872 return "yes";
1873 default:
1874 return "UNKNOWN";
1875 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001876 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001877}
1878
1879static const char *
1880lookup_opcode_name(ServerOpCodes code)
1881{
1882 u_int i;
1883
1884 for (i = 0; keywords[i].name != NULL; i++)
1885 if (keywords[i].opcode == code)
1886 return(keywords[i].name);
1887 return "UNKNOWN";
1888}
1889
1890static void
1891dump_cfg_int(ServerOpCodes code, int val)
1892{
1893 printf("%s %d\n", lookup_opcode_name(code), val);
1894}
1895
1896static void
1897dump_cfg_fmtint(ServerOpCodes code, int val)
1898{
1899 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1900}
1901
1902static void
1903dump_cfg_string(ServerOpCodes code, const char *val)
1904{
1905 if (val == NULL)
1906 return;
1907 printf("%s %s\n", lookup_opcode_name(code), val);
1908}
1909
1910static void
1911dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1912{
1913 u_int i;
1914
1915 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001916 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1917}
1918
1919static void
1920dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1921{
1922 u_int i;
1923
1924 printf("%s", lookup_opcode_name(code));
1925 for (i = 0; i < count; i++)
1926 printf(" %s", vals[i]);
1927 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001928}
1929
1930void
1931dump_config(ServerOptions *o)
1932{
1933 u_int i;
1934 int ret;
1935 struct addrinfo *ai;
1936 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1937
1938 /* these are usually at the top of the config */
1939 for (i = 0; i < o->num_ports; i++)
1940 printf("port %d\n", o->ports[i]);
1941 dump_cfg_fmtint(sProtocol, o->protocol);
1942 dump_cfg_fmtint(sAddressFamily, o->address_family);
1943
1944 /* ListenAddress must be after Port */
1945 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1946 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1947 sizeof(addr), port, sizeof(port),
1948 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1949 error("getnameinfo failed: %.100s",
1950 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1951 strerror(errno));
1952 } else {
1953 if (ai->ai_family == AF_INET6)
1954 printf("listenaddress [%s]:%s\n", addr, port);
1955 else
1956 printf("listenaddress %s:%s\n", addr, port);
1957 }
1958 }
1959
1960 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001961#ifdef USE_PAM
1962 dump_cfg_int(sUsePAM, o->use_pam);
1963#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001964 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1965 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1966 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1967 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1968 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001969 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001970 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1971 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1972
1973 /* formatted integer arguments */
1974 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1975 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1976 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1977 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1978 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1979 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1980 o->hostbased_uses_name_from_packet_only);
1981 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1982 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001983#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001984 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1985 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1986 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001987# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001988 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001989# endif
1990#endif
1991#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001992 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1993 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001994#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001995#ifdef JPAKE
1996 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1997 o->zero_knowledge_password_authentication);
1998#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001999 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2000 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2001 o->kbd_interactive_authentication);
2002 dump_cfg_fmtint(sChallengeResponseAuthentication,
2003 o->challenge_response_authentication);
2004 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2005 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2006 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2007 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
2008 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2009 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2010 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2011 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2012 dump_cfg_fmtint(sUseLogin, o->use_login);
2013 dump_cfg_fmtint(sCompression, o->compression);
2014 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2015 dump_cfg_fmtint(sUseDNS, o->use_dns);
2016 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2017 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2018
2019 /* string arguments */
2020 dump_cfg_string(sPidFile, o->pid_file);
2021 dump_cfg_string(sXAuthLocation, o->xauth_location);
2022 dump_cfg_string(sCiphers, o->ciphers);
2023 dump_cfg_string(sMacs, o->macs);
2024 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002025 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002026 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002027 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2028 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002029 dump_cfg_string(sAuthorizedPrincipalsFile,
2030 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002031 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002032 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2033 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Darren Tuckere7140f22008-06-10 23:01:51 +10002034
2035 /* string arguments requiring a lookup */
2036 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2037 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2038
2039 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002040 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2041 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002042 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2043 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002044 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2045 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002046 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2047 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2048 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2049 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2050 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002051 dump_cfg_strarray_oneline(sAuthenticationMethods,
2052 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002053
2054 /* other arguments */
2055 for (i = 0; i < o->num_subsystems; i++)
2056 printf("subsystem %s %s\n", o->subsystem_name[i],
2057 o->subsystem_args[i]);
2058
2059 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2060 o->max_startups_rate, o->max_startups);
2061
2062 for (i = 0; tunmode_desc[i].val != -1; i++)
2063 if (tunmode_desc[i].val == o->permit_tun) {
2064 s = tunmode_desc[i].text;
2065 break;
2066 }
2067 dump_cfg_string(sPermitTunnel, s);
2068
Damien Miller91475862011-05-05 14:14:34 +10002069 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2070 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002071
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002072 printf("rekeylimit %lld %d\n", o->rekey_limit, o->rekey_interval);
2073
Darren Tuckere7140f22008-06-10 23:01:51 +10002074 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002075}