blob: 145239342e512d2b23067602bbaeab90f086b99a [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Darren Tuckerb7ee8522013-05-16 20:33:10 +10002/* $OpenBSD: servconf.c,v 1.236 2013/05/16 09:12:31 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>
Darren Tuckerb7ee8522013-05-16 20:33:10 +100033#include <util.h>
Damien Millerbe43ebf2006-07-24 13:51:51 +100034
Damien Millerb84886b2008-05-19 15:05:07 +100035#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100036#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100037#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000038#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100041#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000042#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000043#include "misc.h"
44#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100045#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000046#include "kex.h"
47#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100048#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100049#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100050#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100051#include "canohost.h"
52#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110053#include "hostfile.h"
54#include "auth.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000055
Damien Miller3dc71ad2009-01-28 16:31:22 +110056static void add_listen_addr(ServerOptions *, char *, int);
57static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110058
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000059/* Use of privilege separation or not */
60extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100061extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000062
Damien Millerd4a8b7e1999-10-27 13:42:43 +100063/* Initializes the server options to their default values. */
64
Damien Miller4af51302000-04-16 11:18:38 +100065void
Damien Miller95def091999-11-25 00:26:21 +110066initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100067{
Damien Miller95def091999-11-25 00:26:21 +110068 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110069
70 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100071 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110072
73 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110074 options->num_ports = 0;
75 options->ports_from_cmdline = 0;
76 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110077 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110078 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110079 options->num_host_cert_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100080 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110081 options->server_key_bits = -1;
82 options->login_grace_time = -1;
83 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000084 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110085 options->ignore_rhosts = -1;
86 options->ignore_user_known_hosts = -1;
87 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000088 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110089 options->x11_forwarding = -1;
90 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110091 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100092 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110093 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110094 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110095 options->log_facility = SYSLOG_FACILITY_NOT_SET;
96 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110097 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000098 options->hostbased_authentication = -1;
99 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +1100100 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100101 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->kerberos_authentication = -1;
103 options->kerberos_or_local_passwd = -1;
104 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100105 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000106 options->gss_authentication=-1;
107 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100108 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100109 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000110 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000112 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100113 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000114 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000115 options->rekey_limit = -1;
116 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100117 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000118 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100119 options->num_allow_users = 0;
120 options->num_deny_users = 0;
121 options->num_allow_groups = 0;
122 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000123 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000124 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000125 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000126 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000127 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000128 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000129 options->max_startups_begin = -1;
130 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000131 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000132 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000133 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000134 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000135 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000136 options->client_alive_interval = -1;
137 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000138 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000139 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100140 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000141 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000142 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100143 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100144 options->authorized_keys_command = NULL;
145 options->authorized_keys_command_user = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100146 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100147 options->revoked_keys_file = NULL;
148 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000149 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100150 options->ip_qos_interactive = -1;
151 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000152 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000153}
154
Damien Miller4af51302000-04-16 11:18:38 +1000155void
Damien Miller95def091999-11-25 00:26:21 +1100156fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000157{
Damien Miller726273e2001-11-12 11:40:11 +1100158 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000159 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000160 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100161
162 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100163 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100164 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100165 if (options->num_host_key_files == 0) {
166 /* fill default hostkeys for protocols */
167 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100168 options->host_key_files[options->num_host_key_files++] =
169 _PATH_HOST_KEY_FILE;
170 if (options->protocol & SSH_PROTO_2) {
171 options->host_key_files[options->num_host_key_files++] =
172 _PATH_HOST_RSA_KEY_FILE;
173 options->host_key_files[options->num_host_key_files++] =
174 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100175#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000176 options->host_key_files[options->num_host_key_files++] =
177 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100178#endif
Damien Miller7fc23732002-01-22 23:19:11 +1100179 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100180 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100181 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100182 if (options->num_ports == 0)
183 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
184 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000185 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000186 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000187 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100188 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000189 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100190 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000191 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->key_regeneration_time == -1)
193 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000194 if (options->permit_root_login == PERMIT_NOT_SET)
195 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100196 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100197 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->ignore_user_known_hosts == -1)
199 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100200 if (options->print_motd == -1)
201 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000202 if (options->print_lastlog == -1)
203 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100205 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100206 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100207 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100208 if (options->x11_use_localhost == -1)
209 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000210 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000211 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100212 if (options->strict_modes == -1)
213 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100214 if (options->tcp_keep_alive == -1)
215 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100216 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100217 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100218 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000219 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100221 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000222 if (options->hostbased_authentication == -1)
223 options->hostbased_authentication = 0;
224 if (options->hostbased_uses_name_from_packet_only == -1)
225 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->rsa_authentication == -1)
227 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100228 if (options->pubkey_authentication == -1)
229 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000231 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100232 if (options->kerberos_or_local_passwd == -1)
233 options->kerberos_or_local_passwd = 1;
234 if (options->kerberos_ticket_cleanup == -1)
235 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100236 if (options->kerberos_get_afs_token == -1)
237 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000238 if (options->gss_authentication == -1)
239 options->gss_authentication = 0;
240 if (options->gss_cleanup_creds == -1)
241 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100242 if (options->password_authentication == -1)
243 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100244 if (options->kbd_interactive_authentication == -1)
245 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000246 if (options->challenge_response_authentication == -1)
247 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100248 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100249 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000250 if (options->permit_user_env == -1)
251 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100252 if (options->use_login == -1)
253 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000254 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000255 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000256 if (options->rekey_limit == -1)
257 options->rekey_limit = 0;
258 if (options->rekey_interval == -1)
259 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100260 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100261 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000262 if (options->allow_agent_forwarding == -1)
263 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000264 if (options->gateway_ports == -1)
265 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000266 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100267 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000268 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100269 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000270 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100271 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000272 if (options->max_authtries == -1)
273 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000274 if (options->max_sessions == -1)
275 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000276 if (options->use_dns == -1)
277 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000278 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100279 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000280 if (options->client_alive_count_max == -1)
281 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000282 if (options->num_authkeys_files == 0) {
283 options->authorized_keys_files[options->num_authkeys_files++] =
284 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
285 options->authorized_keys_files[options->num_authkeys_files++] =
286 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
287 }
Damien Millerd27b9472005-12-13 19:29:02 +1100288 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100289 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100290 if (options->zero_knowledge_password_authentication == -1)
291 options->zero_knowledge_password_authentication = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100292 if (options->ip_qos_interactive == -1)
293 options->ip_qos_interactive = IPTOS_LOWDELAY;
294 if (options->ip_qos_bulk == -1)
295 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000296 if (options->version_addendum == NULL)
297 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000298 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000299 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000300 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000301
Tim Rice40017b02002-07-14 13:36:49 -0700302#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000303 if (use_privsep && options->compression == 1) {
304 error("This platform does not support both privilege "
305 "separation and compression");
306 error("Compression disabled");
307 options->compression = 0;
308 }
309#endif
310
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000311}
312
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000313/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100314typedef enum {
315 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100316 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000317 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100318 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100319 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
320 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000321 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100322 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100323 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000324 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100325 sPasswordAuthentication, sKbdInteractiveAuthentication,
326 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000327 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100328 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100329 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000330 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000331 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000332 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000333 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000334 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000335 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100336 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000337 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100338 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100339 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100340 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100341 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000342 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000343 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100344 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Millera6e3f012012-11-04 23:21:40 +1100345 sAuthenticationMethods,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000346 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000347} ServerOpCodes;
348
Darren Tucker45150472006-07-12 22:34:17 +1000349#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
350#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
351#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
352
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000353/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100354static struct {
355 const char *name;
356 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000357 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100358} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100359 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000360#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000361 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000362#else
Darren Tucker45150472006-07-12 22:34:17 +1000363 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000364#endif
Darren Tucker45150472006-07-12 22:34:17 +1000365 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100366 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000367 { "port", sPort, SSHCFG_GLOBAL },
368 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
369 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
370 { "pidfile", sPidFile, SSHCFG_GLOBAL },
371 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
372 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
373 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100374 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000375 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
376 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
377 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100378 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
379 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000380 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100381 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
382 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000383 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000384#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100385 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000386 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
387 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100388#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000389 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000390#else
Darren Tucker45150472006-07-12 22:34:17 +1000391 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100392#endif
393#else
Darren Tucker1629c072007-02-19 22:25:37 +1100394 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
396 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
397 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000398#endif
Darren Tucker45150472006-07-12 22:34:17 +1000399 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
400 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000401#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100402 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000403 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000404#else
Darren Tucker1629c072007-02-19 22:25:37 +1100405 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000406 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000407#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100408 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
409 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100410 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000411 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100412#ifdef JPAKE
413 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
414#else
415 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
416#endif
Darren Tucker45150472006-07-12 22:34:17 +1000417 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
418 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
419 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
420 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
421 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
422 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
423 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000424 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
425 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
426 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000427 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
428 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100429 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000430 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
431 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
432 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000433 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000434 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
435 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
436 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000437 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000438 { "allowusers", sAllowUsers, SSHCFG_ALL },
439 { "denyusers", sDenyUsers, SSHCFG_ALL },
440 { "allowgroups", sAllowGroups, SSHCFG_ALL },
441 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "ciphers", sCiphers, SSHCFG_GLOBAL },
443 { "macs", sMacs, SSHCFG_GLOBAL },
444 { "protocol", sProtocol, SSHCFG_GLOBAL },
445 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
446 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
447 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000448 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000449 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100450 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "usedns", sUseDNS, SSHCFG_GLOBAL },
452 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
453 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
454 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
455 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000456 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000457 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000458 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000459 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000460 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000461 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000462 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000463 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100464 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100465 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100466 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
467 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000468 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000469 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100470 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100471 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
472 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000473 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100474 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000475 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000476};
477
Darren Tuckere7140f22008-06-10 23:01:51 +1000478static struct {
479 int val;
480 char *text;
481} tunmode_desc[] = {
482 { SSH_TUNMODE_NO, "no" },
483 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
484 { SSH_TUNMODE_ETHERNET, "ethernet" },
485 { SSH_TUNMODE_YES, "yes" },
486 { -1, NULL }
487};
488
Damien Miller5428f641999-11-25 11:54:57 +1100489/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000490 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100491 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000492
Damien Miller4af51302000-04-16 11:18:38 +1000493static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100494parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000495 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000496{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000497 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000498
Damien Miller95def091999-11-25 00:26:21 +1100499 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000500 if (strcasecmp(cp, keywords[i].name) == 0) {
501 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100502 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000503 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000504
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000505 error("%s: line %d: Bad configuration option: %s",
506 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100507 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000508}
509
Darren Tucker88b6fb22010-01-13 22:44:29 +1100510char *
511derelativise_path(const char *path)
512{
Damien Miller44451d02010-03-26 10:40:04 +1100513 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100514
515 expanded = tilde_expand_filename(path, getuid());
516 if (*expanded == '/')
517 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100518 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100519 fatal("%s: getcwd: %s", __func__, strerror(errno));
520 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100521 xfree(expanded);
522 return ret;
523}
524
Ben Lindstrombba81212001-06-25 05:01:22 +0000525static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100526add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100527{
Damien Millereccb9de2005-06-17 12:59:34 +1000528 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100529
530 if (options->num_ports == 0)
531 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100532 if (options->address_family == -1)
533 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000534 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000535 for (i = 0; i < options->num_ports; i++)
536 add_one_listen_addr(options, addr, options->ports[i]);
537 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000538 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000539}
540
Ben Lindstrombba81212001-06-25 05:01:22 +0000541static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100542add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000543{
544 struct addrinfo hints, *ai, *aitop;
545 char strport[NI_MAXSERV];
546 int gaierr;
547
548 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100549 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000550 hints.ai_socktype = SOCK_STREAM;
551 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100552 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000553 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
554 fatal("bad addr or host: %s (%s)",
555 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100556 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000557 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
558 ;
559 ai->ai_next = options->listen_addrs;
560 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100561}
562
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000563struct connection_info *
564get_connection_info(int populate, int use_dns)
565{
566 static struct connection_info ci;
567
568 if (!populate)
569 return &ci;
570 ci.host = get_canonical_hostname(use_dns);
571 ci.address = get_remote_ipaddr();
572 ci.laddress = get_local_ipaddr(packet_get_connection_in());
573 ci.lport = get_local_port();
574 return &ci;
575}
576
Darren Tucker45150472006-07-12 22:34:17 +1000577/*
578 * The strategy for the Match blocks is that the config file is parsed twice.
579 *
580 * The first time is at startup. activep is initialized to 1 and the
581 * directives in the global context are processed and acted on. Hitting a
582 * Match directive unsets activep and the directives inside the block are
583 * checked for syntax only.
584 *
585 * The second time is after a connection has been established but before
586 * authentication. activep is initialized to 2 and global config directives
587 * are ignored since they have already been processed. If the criteria in a
588 * Match block is met, activep is set and the subsequent directives
589 * processed and actioned until EOF or another Match block unsets it. Any
590 * options set are copied into the main server config.
591 *
592 * Potential additions/improvements:
593 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
594 *
595 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
596 * Match Address 192.168.0.*
597 * Tag trusted
598 * Match Group wheel
599 * Tag trusted
600 * Match Tag trusted
601 * AllowTcpForwarding yes
602 * GatewayPorts clientspecified
603 * [...]
604 *
605 * - Add a PermittedChannelRequests directive
606 * Match Group shell
607 * PermittedChannelRequests session,forwarded-tcpip
608 */
609
610static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000611match_cfg_line_group(const char *grps, int line, const char *user)
612{
613 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000614 struct passwd *pw;
615
Damien Miller565ca3f2006-08-19 00:23:15 +1000616 if (user == NULL)
617 goto out;
618
619 if ((pw = getpwnam(user)) == NULL) {
620 debug("Can't match group at line %d because user %.100s does "
621 "not exist", line, user);
622 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
623 debug("Can't Match group because user %.100s not in any group "
624 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000625 } else if (ga_match_pattern_list(grps) != 1) {
626 debug("user %.100s does not match group list %.100s at line %d",
627 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000628 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000629 debug("user %.100s matched group list %.100s at line %d", user,
630 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000631 result = 1;
632 }
633out:
634 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000635 return result;
636}
637
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000638/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000639 * All of the attributes on a single Match line are ANDed together, so we need
640 * to check every * attribute and set the result to zero if any attribute does
641 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000642 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000643static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000644match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000645{
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000646 int result = 1, port;
Darren Tucker45150472006-07-12 22:34:17 +1000647 char *arg, *attrib, *cp = *condition;
648 size_t len;
649
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000650 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000651 debug3("checking syntax for 'Match %s'", cp);
652 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000653 debug3("checking match for '%s' user %s host %s addr %s "
654 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
655 ci->host ? ci->host : "(null)",
656 ci->address ? ci->address : "(null)",
657 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000658
659 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
660 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
661 error("Missing Match criteria for %s", attrib);
662 return -1;
663 }
664 len = strlen(arg);
665 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000666 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000667 result = 0;
668 continue;
669 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000670 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000671 result = 0;
672 else
673 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000674 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000675 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000676 if (ci == NULL || ci->user == NULL) {
677 result = 0;
678 continue;
679 }
680 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000681 case -1:
682 return -1;
683 case 0:
684 result = 0;
685 }
Darren Tucker45150472006-07-12 22:34:17 +1000686 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000687 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000688 result = 0;
689 continue;
690 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000691 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000692 result = 0;
693 else
694 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000696 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000697 if (ci == NULL || ci->address == NULL) {
698 result = 0;
699 continue;
700 }
701 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000702 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000703 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000704 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000705 break;
706 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000707 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000708 result = 0;
709 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000710 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000711 return -1;
712 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000713 } else if (strcasecmp(attrib, "localaddress") == 0){
714 if (ci == NULL || ci->laddress == NULL) {
715 result = 0;
716 continue;
717 }
718 switch (addr_match_list(ci->laddress, arg)) {
719 case 1:
720 debug("connection from %.100s matched "
721 "'LocalAddress %.100s' at line %d",
722 ci->laddress, arg, line);
723 break;
724 case 0:
725 case -1:
726 result = 0;
727 break;
728 case -2:
729 return -1;
730 }
731 } else if (strcasecmp(attrib, "localport") == 0) {
732 if ((port = a2port(arg)) == -1) {
733 error("Invalid LocalPort '%s' on Match line",
734 arg);
735 return -1;
736 }
737 if (ci == NULL || ci->lport == 0) {
738 result = 0;
739 continue;
740 }
741 /* TODO support port lists */
742 if (port == ci->lport)
743 debug("connection from %.100s matched "
744 "'LocalPort %d' at line %d",
745 ci->laddress, port, line);
746 else
747 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000748 } else {
749 error("Unsupported Match attribute %s", attrib);
750 return -1;
751 }
752 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000753 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000754 debug3("match %sfound", result ? "" : "not ");
755 *condition = cp;
756 return result;
757}
758
Damien Millere2754432006-07-24 14:06:47 +1000759#define WHITESPACE " \t\r\n"
760
Damien Miller33322122011-06-20 14:43:11 +1000761/* Multistate option parsing */
762struct multistate {
763 char *key;
764 int value;
765};
766static const struct multistate multistate_addressfamily[] = {
767 { "inet", AF_INET },
768 { "inet6", AF_INET6 },
769 { "any", AF_UNSPEC },
770 { NULL, -1 }
771};
772static const struct multistate multistate_permitrootlogin[] = {
773 { "without-password", PERMIT_NO_PASSWD },
774 { "forced-commands-only", PERMIT_FORCED_ONLY },
775 { "yes", PERMIT_YES },
776 { "no", PERMIT_NO },
777 { NULL, -1 }
778};
779static const struct multistate multistate_compression[] = {
780 { "delayed", COMP_DELAYED },
781 { "yes", COMP_ZLIB },
782 { "no", COMP_NONE },
783 { NULL, -1 }
784};
785static const struct multistate multistate_gatewayports[] = {
786 { "clientspecified", 2 },
787 { "yes", 1 },
788 { "no", 0 },
789 { NULL, -1 }
790};
Damien Miller69ff1df2011-06-23 08:30:03 +1000791static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000792 { "yes", PRIVSEP_NOSANDBOX },
793 { "sandbox", PRIVSEP_ON },
794 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000795 { "no", PRIVSEP_OFF },
796 { NULL, -1 }
797};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100798static const struct multistate multistate_tcpfwd[] = {
799 { "yes", FORWARD_ALLOW },
800 { "all", FORWARD_ALLOW },
801 { "no", FORWARD_DENY },
802 { "remote", FORWARD_REMOTE },
803 { "local", FORWARD_LOCAL },
804 { NULL, -1 }
805};
Damien Miller33322122011-06-20 14:43:11 +1000806
Ben Lindstromade03f62001-12-06 18:22:17 +0000807int
808process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000809 const char *filename, int linenum, int *activep,
810 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000811{
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000812 char *cp, **charptr, *arg, *p, *endofnumber;
813 int cmdline = 0, *intptr, value, value2, n, port, scale;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100814 SyslogFacility *log_facility_ptr;
815 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000816 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000817 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000818 size_t len;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000819 long long orig, val64;
Damien Miller33322122011-06-20 14:43:11 +1000820 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000821
822 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100823 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100824 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000825 /* Ignore leading whitespace */
826 if (*arg == '\0')
827 arg = strdelim(&cp);
828 if (!arg || !*arg || *arg == '#')
829 return 0;
830 intptr = NULL;
831 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000832 opcode = parse_token(arg, filename, linenum, &flags);
833
834 if (activep == NULL) { /* We are processing a command line directive */
835 cmdline = 1;
836 activep = &cmdline;
837 }
838 if (*activep && opcode != sMatch)
839 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
840 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000841 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000842 fatal("%s line %d: Directive '%s' is not allowed "
843 "within a Match block", filename, linenum, arg);
844 } else { /* this is a directive we have already processed */
845 while (arg)
846 arg = strdelim(&cp);
847 return 0;
848 }
849 }
850
Ben Lindstromade03f62001-12-06 18:22:17 +0000851 switch (opcode) {
852 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000853 case sUsePAM:
854 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000855 goto parse_flag;
856
857 /* Standard Options */
858 case sBadOption:
859 return -1;
860 case sPort:
861 /* ignore ports from configfile if cmdline specifies ports */
862 if (options->ports_from_cmdline)
863 return 0;
864 if (options->listen_addrs != NULL)
865 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100866 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000867 if (options->num_ports >= MAX_PORTS)
868 fatal("%s line %d: too many ports.",
869 filename, linenum);
870 arg = strdelim(&cp);
871 if (!arg || *arg == '\0')
872 fatal("%s line %d: missing port number.",
873 filename, linenum);
874 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100875 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000876 fatal("%s line %d: Badly formatted port number.",
877 filename, linenum);
878 break;
879
880 case sServerKeyBits:
881 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000882 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000883 arg = strdelim(&cp);
884 if (!arg || *arg == '\0')
885 fatal("%s line %d: missing integer value.",
886 filename, linenum);
887 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000888 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000889 *intptr = value;
890 break;
891
892 case sLoginGraceTime:
893 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000894 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000895 arg = strdelim(&cp);
896 if (!arg || *arg == '\0')
897 fatal("%s line %d: missing time value.",
898 filename, linenum);
899 if ((value = convtime(arg)) == -1)
900 fatal("%s line %d: invalid time value.",
901 filename, linenum);
902 if (*intptr == -1)
903 *intptr = value;
904 break;
905
906 case sKeyRegenerationTime:
907 intptr = &options->key_regeneration_time;
908 goto parse_time;
909
910 case sListenAddress:
911 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100912 if (arg == NULL || *arg == '\0')
913 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000914 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000915 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
916 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
917 && strchr(p+1, ':') != NULL) {
918 add_listen_addr(options, arg, 0);
919 break;
920 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100921 p = hpdelim(&arg);
922 if (p == NULL)
923 fatal("%s line %d: bad address:port usage",
924 filename, linenum);
925 p = cleanhostname(p);
926 if (arg == NULL)
927 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100928 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100929 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000930
Damien Millerf91ee4c2005-03-01 21:24:33 +1100931 add_listen_addr(options, p, port);
932
Ben Lindstromade03f62001-12-06 18:22:17 +0000933 break;
934
Darren Tucker0f383232005-01-20 10:57:56 +1100935 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000936 intptr = &options->address_family;
937 multistate_ptr = multistate_addressfamily;
938 if (options->listen_addrs != NULL)
939 fatal("%s line %d: address family must be specified "
940 "before ListenAddress.", filename, linenum);
941 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100942 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000943 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000944 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000945 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000946 value = -1;
947 for (i = 0; multistate_ptr[i].key != NULL; i++) {
948 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
949 value = multistate_ptr[i].value;
950 break;
951 }
952 }
953 if (value == -1)
954 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100955 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000956 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100957 *intptr = value;
958 break;
959
Ben Lindstromade03f62001-12-06 18:22:17 +0000960 case sHostKeyFile:
961 intptr = &options->num_host_key_files;
962 if (*intptr >= MAX_HOSTKEYS)
963 fatal("%s line %d: too many host keys specified (max %d).",
964 filename, linenum, MAX_HOSTKEYS);
965 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000966 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000967 arg = strdelim(&cp);
968 if (!arg || *arg == '\0')
969 fatal("%s line %d: missing file name.",
970 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000971 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100972 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000973 /* increase optional counter */
974 if (intptr != NULL)
975 *intptr = *intptr + 1;
976 }
977 break;
978
Damien Miller0a80ca12010-02-27 07:55:05 +1100979 case sHostCertificate:
980 intptr = &options->num_host_cert_files;
981 if (*intptr >= MAX_HOSTKEYS)
982 fatal("%s line %d: too many host certificates "
983 "specified (max %d).", filename, linenum,
984 MAX_HOSTCERTS);
985 charptr = &options->host_cert_files[*intptr];
986 goto parse_filename;
987 break;
988
Ben Lindstromade03f62001-12-06 18:22:17 +0000989 case sPidFile:
990 charptr = &options->pid_file;
991 goto parse_filename;
992
993 case sPermitRootLogin:
994 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +1000995 multistate_ptr = multistate_permitrootlogin;
996 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +0000997
998 case sIgnoreRhosts:
999 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001000 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001001 arg = strdelim(&cp);
1002 if (!arg || *arg == '\0')
1003 fatal("%s line %d: missing yes/no argument.",
1004 filename, linenum);
1005 value = 0; /* silence compiler */
1006 if (strcmp(arg, "yes") == 0)
1007 value = 1;
1008 else if (strcmp(arg, "no") == 0)
1009 value = 0;
1010 else
1011 fatal("%s line %d: Bad yes/no argument: %s",
1012 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001013 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001014 *intptr = value;
1015 break;
1016
1017 case sIgnoreUserKnownHosts:
1018 intptr = &options->ignore_user_known_hosts;
1019 goto parse_flag;
1020
Ben Lindstromade03f62001-12-06 18:22:17 +00001021 case sRhostsRSAAuthentication:
1022 intptr = &options->rhosts_rsa_authentication;
1023 goto parse_flag;
1024
1025 case sHostbasedAuthentication:
1026 intptr = &options->hostbased_authentication;
1027 goto parse_flag;
1028
1029 case sHostbasedUsesNameFromPacketOnly:
1030 intptr = &options->hostbased_uses_name_from_packet_only;
1031 goto parse_flag;
1032
1033 case sRSAAuthentication:
1034 intptr = &options->rsa_authentication;
1035 goto parse_flag;
1036
1037 case sPubkeyAuthentication:
1038 intptr = &options->pubkey_authentication;
1039 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001040
Ben Lindstromade03f62001-12-06 18:22:17 +00001041 case sKerberosAuthentication:
1042 intptr = &options->kerberos_authentication;
1043 goto parse_flag;
1044
1045 case sKerberosOrLocalPasswd:
1046 intptr = &options->kerberos_or_local_passwd;
1047 goto parse_flag;
1048
1049 case sKerberosTicketCleanup:
1050 intptr = &options->kerberos_ticket_cleanup;
1051 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001052
Darren Tucker22ef5082003-12-31 11:37:34 +11001053 case sKerberosGetAFSToken:
1054 intptr = &options->kerberos_get_afs_token;
1055 goto parse_flag;
1056
Darren Tucker0efd1552003-08-26 11:49:55 +10001057 case sGssAuthentication:
1058 intptr = &options->gss_authentication;
1059 goto parse_flag;
1060
1061 case sGssCleanupCreds:
1062 intptr = &options->gss_cleanup_creds;
1063 goto parse_flag;
1064
Ben Lindstromade03f62001-12-06 18:22:17 +00001065 case sPasswordAuthentication:
1066 intptr = &options->password_authentication;
1067 goto parse_flag;
1068
Damien Miller01ed2272008-11-05 16:20:46 +11001069 case sZeroKnowledgePasswordAuthentication:
1070 intptr = &options->zero_knowledge_password_authentication;
1071 goto parse_flag;
1072
Ben Lindstromade03f62001-12-06 18:22:17 +00001073 case sKbdInteractiveAuthentication:
1074 intptr = &options->kbd_interactive_authentication;
1075 goto parse_flag;
1076
1077 case sChallengeResponseAuthentication:
1078 intptr = &options->challenge_response_authentication;
1079 goto parse_flag;
1080
1081 case sPrintMotd:
1082 intptr = &options->print_motd;
1083 goto parse_flag;
1084
1085 case sPrintLastLog:
1086 intptr = &options->print_lastlog;
1087 goto parse_flag;
1088
1089 case sX11Forwarding:
1090 intptr = &options->x11_forwarding;
1091 goto parse_flag;
1092
1093 case sX11DisplayOffset:
1094 intptr = &options->x11_display_offset;
1095 goto parse_int;
1096
Damien Miller95c249f2002-02-05 12:11:34 +11001097 case sX11UseLocalhost:
1098 intptr = &options->x11_use_localhost;
1099 goto parse_flag;
1100
Ben Lindstromade03f62001-12-06 18:22:17 +00001101 case sXAuthLocation:
1102 charptr = &options->xauth_location;
1103 goto parse_filename;
1104
1105 case sStrictModes:
1106 intptr = &options->strict_modes;
1107 goto parse_flag;
1108
Damien Miller12c150e2003-12-17 16:31:10 +11001109 case sTCPKeepAlive:
1110 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001111 goto parse_flag;
1112
1113 case sEmptyPasswd:
1114 intptr = &options->permit_empty_passwd;
1115 goto parse_flag;
1116
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001117 case sPermitUserEnvironment:
1118 intptr = &options->permit_user_env;
1119 goto parse_flag;
1120
Ben Lindstromade03f62001-12-06 18:22:17 +00001121 case sUseLogin:
1122 intptr = &options->use_login;
1123 goto parse_flag;
1124
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001125 case sCompression:
1126 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001127 multistate_ptr = multistate_compression;
1128 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001129
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001130 case sRekeyLimit:
1131 arg = strdelim(&cp);
1132 if (!arg || *arg == '\0')
1133 fatal("%.200s line %d: Missing argument.", filename,
1134 linenum);
1135 if (strcmp(arg, "default") == 0) {
1136 val64 = 0;
1137 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001138 if (scan_scaled(arg, &val64) == -1)
1139 fatal("%.200s line %d: Bad number '%s': %s",
1140 filename, linenum, arg, strerror(errno));
1141 /* check for too-large or too-small limits */
1142 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001143 fatal("%.200s line %d: RekeyLimit too large",
1144 filename, linenum);
1145 if (val64 != 0 && val64 < 16)
1146 fatal("%.200s line %d: RekeyLimit too small",
1147 filename, linenum);
1148 }
1149 if (*activep && options->rekey_limit == -1)
1150 options->rekey_limit = (u_int32_t)val64;
1151 if (cp != NULL) { /* optional rekey interval present */
1152 if (strcmp(cp, "none") == 0) {
1153 (void)strdelim(&cp); /* discard */
1154 break;
1155 }
1156 intptr = &options->rekey_interval;
1157 goto parse_time;
1158 }
1159 break;
1160
Ben Lindstromade03f62001-12-06 18:22:17 +00001161 case sGatewayPorts:
1162 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001163 multistate_ptr = multistate_gatewayports;
1164 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001165
Damien Miller3a961dc2003-06-03 10:25:48 +10001166 case sUseDNS:
1167 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001168 goto parse_flag;
1169
1170 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001171 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001172 arg = strdelim(&cp);
1173 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001174 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001175 fatal("%.200s line %d: unsupported log facility '%s'",
1176 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001177 if (*log_facility_ptr == -1)
1178 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001179 break;
1180
1181 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001182 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001183 arg = strdelim(&cp);
1184 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001185 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001186 fatal("%.200s line %d: unsupported log level '%s'",
1187 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001188 if (*log_level_ptr == -1)
1189 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001190 break;
1191
1192 case sAllowTcpForwarding:
1193 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001194 multistate_ptr = multistate_tcpfwd;
1195 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001196
Damien Miller4f755cd2008-05-19 14:57:41 +10001197 case sAllowAgentForwarding:
1198 intptr = &options->allow_agent_forwarding;
1199 goto parse_flag;
1200
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001201 case sUsePrivilegeSeparation:
1202 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001203 multistate_ptr = multistate_privsep;
1204 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001205
Ben Lindstromade03f62001-12-06 18:22:17 +00001206 case sAllowUsers:
1207 while ((arg = strdelim(&cp)) && *arg != '\0') {
1208 if (options->num_allow_users >= MAX_ALLOW_USERS)
1209 fatal("%s line %d: too many allow users.",
1210 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001211 if (!*activep)
1212 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001213 options->allow_users[options->num_allow_users++] =
1214 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001215 }
1216 break;
1217
1218 case sDenyUsers:
1219 while ((arg = strdelim(&cp)) && *arg != '\0') {
1220 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001221 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001222 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001223 if (!*activep)
1224 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001225 options->deny_users[options->num_deny_users++] =
1226 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001227 }
1228 break;
1229
1230 case sAllowGroups:
1231 while ((arg = strdelim(&cp)) && *arg != '\0') {
1232 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1233 fatal("%s line %d: too many allow groups.",
1234 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001235 if (!*activep)
1236 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001237 options->allow_groups[options->num_allow_groups++] =
1238 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001239 }
1240 break;
1241
1242 case sDenyGroups:
1243 while ((arg = strdelim(&cp)) && *arg != '\0') {
1244 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1245 fatal("%s line %d: too many deny groups.",
1246 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001247 if (!*activep)
1248 continue;
1249 options->deny_groups[options->num_deny_groups++] =
1250 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001251 }
1252 break;
1253
1254 case sCiphers:
1255 arg = strdelim(&cp);
1256 if (!arg || *arg == '\0')
1257 fatal("%s line %d: Missing argument.", filename, linenum);
1258 if (!ciphers_valid(arg))
1259 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1260 filename, linenum, arg ? arg : "<NONE>");
1261 if (options->ciphers == NULL)
1262 options->ciphers = xstrdup(arg);
1263 break;
1264
1265 case sMacs:
1266 arg = strdelim(&cp);
1267 if (!arg || *arg == '\0')
1268 fatal("%s line %d: Missing argument.", filename, linenum);
1269 if (!mac_valid(arg))
1270 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1271 filename, linenum, arg ? arg : "<NONE>");
1272 if (options->macs == NULL)
1273 options->macs = xstrdup(arg);
1274 break;
1275
Damien Millerd5f62bf2010-09-24 22:11:14 +10001276 case sKexAlgorithms:
1277 arg = strdelim(&cp);
1278 if (!arg || *arg == '\0')
1279 fatal("%s line %d: Missing argument.",
1280 filename, linenum);
1281 if (!kex_names_valid(arg))
1282 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1283 filename, linenum, arg ? arg : "<NONE>");
1284 if (options->kex_algorithms == NULL)
1285 options->kex_algorithms = xstrdup(arg);
1286 break;
1287
Ben Lindstromade03f62001-12-06 18:22:17 +00001288 case sProtocol:
1289 intptr = &options->protocol;
1290 arg = strdelim(&cp);
1291 if (!arg || *arg == '\0')
1292 fatal("%s line %d: Missing argument.", filename, linenum);
1293 value = proto_spec(arg);
1294 if (value == SSH_PROTO_UNKNOWN)
1295 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001296 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001297 if (*intptr == SSH_PROTO_UNKNOWN)
1298 *intptr = value;
1299 break;
1300
1301 case sSubsystem:
1302 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1303 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001304 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001305 }
1306 arg = strdelim(&cp);
1307 if (!arg || *arg == '\0')
1308 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001309 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001310 if (!*activep) {
1311 arg = strdelim(&cp);
1312 break;
1313 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001314 for (i = 0; i < options->num_subsystems; i++)
1315 if (strcmp(arg, options->subsystem_name[i]) == 0)
1316 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001317 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001318 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1319 arg = strdelim(&cp);
1320 if (!arg || *arg == '\0')
1321 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001322 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001323 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001324
1325 /* Collect arguments (separate to executable) */
1326 p = xstrdup(arg);
1327 len = strlen(p) + 1;
1328 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1329 len += 1 + strlen(arg);
1330 p = xrealloc(p, 1, len);
1331 strlcat(p, " ", len);
1332 strlcat(p, arg, len);
1333 }
1334 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001335 options->num_subsystems++;
1336 break;
1337
1338 case sMaxStartups:
1339 arg = strdelim(&cp);
1340 if (!arg || *arg == '\0')
1341 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001342 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001343 if ((n = sscanf(arg, "%d:%d:%d",
1344 &options->max_startups_begin,
1345 &options->max_startups_rate,
1346 &options->max_startups)) == 3) {
1347 if (options->max_startups_begin >
1348 options->max_startups ||
1349 options->max_startups_rate > 100 ||
1350 options->max_startups_rate < 1)
1351 fatal("%s line %d: Illegal MaxStartups spec.",
1352 filename, linenum);
1353 } else if (n != 1)
1354 fatal("%s line %d: Illegal MaxStartups spec.",
1355 filename, linenum);
1356 else
1357 options->max_startups = options->max_startups_begin;
1358 break;
1359
Darren Tucker89413db2004-05-24 10:36:23 +10001360 case sMaxAuthTries:
1361 intptr = &options->max_authtries;
1362 goto parse_int;
1363
Damien Miller7207f642008-05-19 15:34:50 +10001364 case sMaxSessions:
1365 intptr = &options->max_sessions;
1366 goto parse_int;
1367
Ben Lindstromade03f62001-12-06 18:22:17 +00001368 case sBanner:
1369 charptr = &options->banner;
1370 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001371
Ben Lindstromade03f62001-12-06 18:22:17 +00001372 /*
1373 * These options can contain %X options expanded at
1374 * connect time, so that you can specify paths like:
1375 *
1376 * AuthorizedKeysFile /etc/ssh_keys/%u
1377 */
1378 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001379 if (*activep && options->num_authkeys_files == 0) {
1380 while ((arg = strdelim(&cp)) && *arg != '\0') {
1381 if (options->num_authkeys_files >=
1382 MAX_AUTHKEYS_FILES)
1383 fatal("%s line %d: "
1384 "too many authorized keys files.",
1385 filename, linenum);
1386 options->authorized_keys_files[
1387 options->num_authkeys_files++] =
1388 tilde_expand_filename(arg, getuid());
1389 }
1390 }
1391 return 0;
1392
Damien Miller30da3442010-05-10 11:58:03 +10001393 case sAuthorizedPrincipalsFile:
1394 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001395 arg = strdelim(&cp);
1396 if (!arg || *arg == '\0')
1397 fatal("%s line %d: missing file name.",
1398 filename, linenum);
1399 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001400 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001401 /* increase optional counter */
1402 if (intptr != NULL)
1403 *intptr = *intptr + 1;
1404 }
1405 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001406
1407 case sClientAliveInterval:
1408 intptr = &options->client_alive_interval;
1409 goto parse_time;
1410
1411 case sClientAliveCountMax:
1412 intptr = &options->client_alive_count_max;
1413 goto parse_int;
1414
Darren Tucker46bc0752004-05-02 22:11:30 +10001415 case sAcceptEnv:
1416 while ((arg = strdelim(&cp)) && *arg != '\0') {
1417 if (strchr(arg, '=') != NULL)
1418 fatal("%s line %d: Invalid environment name.",
1419 filename, linenum);
1420 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1421 fatal("%s line %d: too many allow env.",
1422 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001423 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001424 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001425 options->accept_env[options->num_accept_env++] =
1426 xstrdup(arg);
1427 }
1428 break;
1429
Damien Millerd27b9472005-12-13 19:29:02 +11001430 case sPermitTunnel:
1431 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001432 arg = strdelim(&cp);
1433 if (!arg || *arg == '\0')
1434 fatal("%s line %d: Missing yes/point-to-point/"
1435 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001436 value = -1;
1437 for (i = 0; tunmode_desc[i].val != -1; i++)
1438 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1439 value = tunmode_desc[i].val;
1440 break;
1441 }
1442 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001443 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1444 "no argument: %s", filename, linenum, arg);
1445 if (*intptr == -1)
1446 *intptr = value;
1447 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001448
Darren Tucker45150472006-07-12 22:34:17 +10001449 case sMatch:
1450 if (cmdline)
1451 fatal("Match directive not supported as a command-line "
1452 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001453 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001454 if (value < 0)
1455 fatal("%s line %d: Bad Match condition", filename,
1456 linenum);
1457 *activep = value;
1458 break;
1459
Damien Miller9b439df2006-07-24 14:04:00 +10001460 case sPermitOpen:
1461 arg = strdelim(&cp);
1462 if (!arg || *arg == '\0')
1463 fatal("%s line %d: missing PermitOpen specification",
1464 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001465 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001466 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001467 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001468 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001469 options->num_permitted_opens = 0;
1470 }
Damien Miller9b439df2006-07-24 14:04:00 +10001471 break;
1472 }
Damien Millerc6081482012-04-22 11:18:53 +10001473 if (strcmp(arg, "none") == 0) {
1474 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001475 options->num_permitted_opens = 1;
1476 channel_disable_adm_local_opens();
1477 }
1478 break;
1479 }
Damien Millera29b95e2007-01-05 16:28:36 +11001480 if (*activep && n == -1)
1481 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001482 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1483 p = hpdelim(&arg);
1484 if (p == NULL)
1485 fatal("%s line %d: missing host in PermitOpen",
1486 filename, linenum);
1487 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001488 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001489 fatal("%s line %d: bad port number in "
1490 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001491 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001492 options->num_permitted_opens =
1493 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001494 }
Damien Miller9b439df2006-07-24 14:04:00 +10001495 break;
1496
Damien Millere2754432006-07-24 14:06:47 +10001497 case sForceCommand:
1498 if (cp == NULL)
1499 fatal("%.200s line %d: Missing argument.", filename,
1500 linenum);
1501 len = strspn(cp, WHITESPACE);
1502 if (*activep && options->adm_forced_command == NULL)
1503 options->adm_forced_command = xstrdup(cp + len);
1504 return 0;
1505
Damien Millerd8cb1f12008-02-10 22:40:12 +11001506 case sChrootDirectory:
1507 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001508
1509 arg = strdelim(&cp);
1510 if (!arg || *arg == '\0')
1511 fatal("%s line %d: missing file name.",
1512 filename, linenum);
1513 if (*activep && *charptr == NULL)
1514 *charptr = xstrdup(arg);
1515 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001516
Damien Miller1aed65e2010-03-04 21:53:35 +11001517 case sTrustedUserCAKeys:
1518 charptr = &options->trusted_user_ca_keys;
1519 goto parse_filename;
1520
1521 case sRevokedKeys:
1522 charptr = &options->revoked_keys_file;
1523 goto parse_filename;
1524
Damien Miller0dac6fb2010-11-20 15:19:38 +11001525 case sIPQoS:
1526 arg = strdelim(&cp);
1527 if ((value = parse_ipqos(arg)) == -1)
1528 fatal("%s line %d: Bad IPQoS value: %s",
1529 filename, linenum, arg);
1530 arg = strdelim(&cp);
1531 if (arg == NULL)
1532 value2 = value;
1533 else if ((value2 = parse_ipqos(arg)) == -1)
1534 fatal("%s line %d: Bad IPQoS value: %s",
1535 filename, linenum, arg);
1536 if (*activep) {
1537 options->ip_qos_interactive = value;
1538 options->ip_qos_bulk = value2;
1539 }
1540 break;
1541
Damien Miller23528812012-04-22 11:24:43 +10001542 case sVersionAddendum:
1543 if (cp == NULL)
1544 fatal("%.200s line %d: Missing argument.", filename,
1545 linenum);
1546 len = strspn(cp, WHITESPACE);
1547 if (*activep && options->version_addendum == NULL) {
1548 if (strcasecmp(cp + len, "none") == 0)
1549 options->version_addendum = xstrdup("");
1550 else if (strchr(cp + len, '\r') != NULL)
1551 fatal("%.200s line %d: Invalid argument",
1552 filename, linenum);
1553 else
1554 options->version_addendum = xstrdup(cp + len);
1555 }
1556 return 0;
1557
Damien Miller09d3e122012-10-31 08:58:58 +11001558 case sAuthorizedKeysCommand:
1559 len = strspn(cp, WHITESPACE);
1560 if (*activep && options->authorized_keys_command == NULL) {
1561 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1562 fatal("%.200s line %d: AuthorizedKeysCommand "
1563 "must be an absolute path",
1564 filename, linenum);
1565 options->authorized_keys_command = xstrdup(cp + len);
1566 }
1567 return 0;
1568
1569 case sAuthorizedKeysCommandUser:
1570 charptr = &options->authorized_keys_command_user;
1571
1572 arg = strdelim(&cp);
1573 if (*activep && *charptr == NULL)
1574 *charptr = xstrdup(arg);
1575 break;
1576
Damien Millera6e3f012012-11-04 23:21:40 +11001577 case sAuthenticationMethods:
1578 if (*activep && options->num_auth_methods == 0) {
1579 while ((arg = strdelim(&cp)) && *arg != '\0') {
1580 if (options->num_auth_methods >=
1581 MAX_AUTH_METHODS)
1582 fatal("%s line %d: "
1583 "too many authentication methods.",
1584 filename, linenum);
1585 if (auth2_methods_valid(arg, 0) != 0)
1586 fatal("%s line %d: invalid "
1587 "authentication method list.",
1588 filename, linenum);
1589 options->auth_methods[
1590 options->num_auth_methods++] = xstrdup(arg);
1591 }
1592 }
1593 return 0;
1594
Ben Lindstromade03f62001-12-06 18:22:17 +00001595 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001596 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001597 filename, linenum, arg);
1598 while (arg)
1599 arg = strdelim(&cp);
1600 break;
1601
Damien Millerf9b3feb2003-05-16 11:38:32 +10001602 case sUnsupported:
1603 logit("%s line %d: Unsupported option %s",
1604 filename, linenum, arg);
1605 while (arg)
1606 arg = strdelim(&cp);
1607 break;
1608
Ben Lindstromade03f62001-12-06 18:22:17 +00001609 default:
1610 fatal("%s line %d: Missing handler for opcode %s (%d)",
1611 filename, linenum, arg, opcode);
1612 }
1613 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1614 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1615 filename, linenum, arg);
1616 return 0;
1617}
1618
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001619/* Reads the server configuration file. */
1620
Damien Miller4af51302000-04-16 11:18:38 +10001621void
Darren Tucker645ab752004-06-25 13:33:20 +10001622load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001623{
Damien Miller46cb75a2012-07-31 12:22:37 +10001624 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001625 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001626 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001627
Darren Tucker645ab752004-06-25 13:33:20 +10001628 debug2("%s: filename %s", __func__, filename);
1629 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001630 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001631 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001632 }
Darren Tucker645ab752004-06-25 13:33:20 +10001633 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001634 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001635 lineno++;
1636 if (strlen(line) == sizeof(line) - 1)
1637 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001638 /*
1639 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001640 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001641 * line numbers later for error messages
1642 */
1643 if ((cp = strchr(line, '#')) != NULL)
1644 memcpy(cp, "\n", 2);
1645 cp = line + strspn(line, " \t\r");
1646
1647 buffer_append(conf, cp, strlen(cp));
1648 }
1649 buffer_append(conf, "\0", 1);
1650 fclose(f);
1651 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1652}
1653
1654void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001655parse_server_match_config(ServerOptions *options,
1656 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001657{
Darren Tucker45150472006-07-12 22:34:17 +10001658 ServerOptions mo;
1659
1660 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001661 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001662 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001663}
1664
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001665int parse_server_match_testspec(struct connection_info *ci, char *spec)
1666{
1667 char *p;
1668
1669 while ((p = strsep(&spec, ",")) && *p != '\0') {
1670 if (strncmp(p, "addr=", 5) == 0) {
1671 ci->address = xstrdup(p + 5);
1672 } else if (strncmp(p, "host=", 5) == 0) {
1673 ci->host = xstrdup(p + 5);
1674 } else if (strncmp(p, "user=", 5) == 0) {
1675 ci->user = xstrdup(p + 5);
1676 } else if (strncmp(p, "laddr=", 6) == 0) {
1677 ci->laddress = xstrdup(p + 6);
1678 } else if (strncmp(p, "lport=", 6) == 0) {
1679 ci->lport = a2port(p + 6);
1680 if (ci->lport == -1) {
1681 fprintf(stderr, "Invalid port '%s' in test mode"
1682 " specification %s\n", p+6, p);
1683 return -1;
1684 }
1685 } else {
1686 fprintf(stderr, "Invalid test mode specification %s\n",
1687 p);
1688 return -1;
1689 }
1690 }
1691 return 0;
1692}
1693
1694/*
1695 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1696 * empty spec.
1697 */
1698int server_match_spec_complete(struct connection_info *ci)
1699{
1700 if (ci->user && ci->host && ci->address)
1701 return 1; /* complete */
1702 if (!ci->user && !ci->host && !ci->address)
1703 return -1; /* empty */
1704 return 0; /* partial */
1705}
1706
Darren Tucker1629c072007-02-19 22:25:37 +11001707/* Helper macros */
1708#define M_CP_INTOPT(n) do {\
1709 if (src->n != -1) \
1710 dst->n = src->n; \
1711} while (0)
1712#define M_CP_STROPT(n) do {\
1713 if (src->n != NULL) { \
1714 if (dst->n != NULL) \
1715 xfree(dst->n); \
1716 dst->n = src->n; \
1717 } \
1718} while(0)
Damien Millerd8478b62011-05-29 21:39:36 +10001719#define M_CP_STRARRAYOPT(n, num_n) do {\
1720 if (src->num_n != 0) { \
1721 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1722 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1723 } \
1724} while(0)
Darren Tucker1629c072007-02-19 22:25:37 +11001725
1726/*
1727 * Copy any supported values that are set.
1728 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001729 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001730 * array values that are not used pre-authentication, because any that we
1731 * do use must be explictly sent in mm_getpwnamallow().
1732 */
Darren Tucker45150472006-07-12 22:34:17 +10001733void
Darren Tucker1629c072007-02-19 22:25:37 +11001734copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001735{
Darren Tucker1629c072007-02-19 22:25:37 +11001736 M_CP_INTOPT(password_authentication);
1737 M_CP_INTOPT(gss_authentication);
1738 M_CP_INTOPT(rsa_authentication);
1739 M_CP_INTOPT(pubkey_authentication);
1740 M_CP_INTOPT(kerberos_authentication);
1741 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001742 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001743 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001744 M_CP_INTOPT(zero_knowledge_password_authentication);
Damien Miller09d3e122012-10-31 08:58:58 +11001745 M_CP_STROPT(authorized_keys_command);
1746 M_CP_STROPT(authorized_keys_command_user);
Darren Tucker15f94272008-01-01 20:36:56 +11001747 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001748 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001749
1750 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001751 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001752 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001753 M_CP_INTOPT(gateway_ports);
1754 M_CP_INTOPT(x11_display_offset);
1755 M_CP_INTOPT(x11_forwarding);
1756 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001757 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001758 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001759 M_CP_INTOPT(ip_qos_interactive);
1760 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001761 M_CP_INTOPT(rekey_limit);
1762 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001763
Damien Millerf2e407e2011-05-20 19:04:14 +10001764 /* See comment in servconf.h */
1765 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001766
Damien Millerc2411902011-05-20 19:03:49 +10001767 /*
1768 * The only things that should be below this point are string options
1769 * which are only used after authentication.
1770 */
Damien Miller5d74e582011-05-20 19:03:31 +10001771 if (preauth)
1772 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001773
Damien Miller5d74e582011-05-20 19:03:31 +10001774 M_CP_STROPT(adm_forced_command);
1775 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001776}
1777
Darren Tucker1629c072007-02-19 22:25:37 +11001778#undef M_CP_INTOPT
1779#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001780#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001781
Darren Tucker45150472006-07-12 22:34:17 +10001782void
1783parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001784 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001785{
1786 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001787 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001788
1789 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1790
Darren Tucker9fbac712004-08-12 22:41:44 +10001791 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001792 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001793 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001794 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001795 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001796 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001797 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001798 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001799 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001800 if (bad_options > 0)
1801 fatal("%s: terminating, %d bad configuration options",
1802 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001803}
Darren Tuckere7140f22008-06-10 23:01:51 +10001804
1805static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001806fmt_multistate_int(int val, const struct multistate *m)
1807{
1808 u_int i;
1809
1810 for (i = 0; m[i].key != NULL; i++) {
1811 if (m[i].value == val)
1812 return m[i].key;
1813 }
1814 return "UNKNOWN";
1815}
1816
1817static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001818fmt_intarg(ServerOpCodes code, int val)
1819{
Damien Miller82c55872011-06-23 08:20:30 +10001820 if (val == -1)
1821 return "unset";
1822 switch (code) {
1823 case sAddressFamily:
1824 return fmt_multistate_int(val, multistate_addressfamily);
1825 case sPermitRootLogin:
1826 return fmt_multistate_int(val, multistate_permitrootlogin);
1827 case sGatewayPorts:
1828 return fmt_multistate_int(val, multistate_gatewayports);
1829 case sCompression:
1830 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001831 case sUsePrivilegeSeparation:
1832 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001833 case sAllowTcpForwarding:
1834 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001835 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001836 switch (val) {
1837 case SSH_PROTO_1:
1838 return "1";
1839 case SSH_PROTO_2:
1840 return "2";
1841 case (SSH_PROTO_1|SSH_PROTO_2):
1842 return "2,1";
1843 default:
1844 return "UNKNOWN";
1845 }
Damien Miller82c55872011-06-23 08:20:30 +10001846 default:
1847 switch (val) {
1848 case 0:
1849 return "no";
1850 case 1:
1851 return "yes";
1852 default:
1853 return "UNKNOWN";
1854 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001855 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001856}
1857
1858static const char *
1859lookup_opcode_name(ServerOpCodes code)
1860{
1861 u_int i;
1862
1863 for (i = 0; keywords[i].name != NULL; i++)
1864 if (keywords[i].opcode == code)
1865 return(keywords[i].name);
1866 return "UNKNOWN";
1867}
1868
1869static void
1870dump_cfg_int(ServerOpCodes code, int val)
1871{
1872 printf("%s %d\n", lookup_opcode_name(code), val);
1873}
1874
1875static void
1876dump_cfg_fmtint(ServerOpCodes code, int val)
1877{
1878 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1879}
1880
1881static void
1882dump_cfg_string(ServerOpCodes code, const char *val)
1883{
1884 if (val == NULL)
1885 return;
1886 printf("%s %s\n", lookup_opcode_name(code), val);
1887}
1888
1889static void
1890dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1891{
1892 u_int i;
1893
1894 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001895 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1896}
1897
1898static void
1899dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1900{
1901 u_int i;
1902
1903 printf("%s", lookup_opcode_name(code));
1904 for (i = 0; i < count; i++)
1905 printf(" %s", vals[i]);
1906 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001907}
1908
1909void
1910dump_config(ServerOptions *o)
1911{
1912 u_int i;
1913 int ret;
1914 struct addrinfo *ai;
1915 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1916
1917 /* these are usually at the top of the config */
1918 for (i = 0; i < o->num_ports; i++)
1919 printf("port %d\n", o->ports[i]);
1920 dump_cfg_fmtint(sProtocol, o->protocol);
1921 dump_cfg_fmtint(sAddressFamily, o->address_family);
1922
1923 /* ListenAddress must be after Port */
1924 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1925 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1926 sizeof(addr), port, sizeof(port),
1927 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1928 error("getnameinfo failed: %.100s",
1929 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1930 strerror(errno));
1931 } else {
1932 if (ai->ai_family == AF_INET6)
1933 printf("listenaddress [%s]:%s\n", addr, port);
1934 else
1935 printf("listenaddress %s:%s\n", addr, port);
1936 }
1937 }
1938
1939 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001940#ifdef USE_PAM
1941 dump_cfg_int(sUsePAM, o->use_pam);
1942#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001943 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1944 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1945 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1946 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1947 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001948 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001949 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1950 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1951
1952 /* formatted integer arguments */
1953 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1954 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1955 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1956 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1957 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1958 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1959 o->hostbased_uses_name_from_packet_only);
1960 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1961 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001962#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001963 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1964 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1965 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001966# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001967 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001968# endif
1969#endif
1970#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001971 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1972 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001973#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001974#ifdef JPAKE
1975 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1976 o->zero_knowledge_password_authentication);
1977#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001978 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1979 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1980 o->kbd_interactive_authentication);
1981 dump_cfg_fmtint(sChallengeResponseAuthentication,
1982 o->challenge_response_authentication);
1983 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1984 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1985 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1986 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1987 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1988 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1989 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1990 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1991 dump_cfg_fmtint(sUseLogin, o->use_login);
1992 dump_cfg_fmtint(sCompression, o->compression);
1993 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1994 dump_cfg_fmtint(sUseDNS, o->use_dns);
1995 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1996 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1997
1998 /* string arguments */
1999 dump_cfg_string(sPidFile, o->pid_file);
2000 dump_cfg_string(sXAuthLocation, o->xauth_location);
2001 dump_cfg_string(sCiphers, o->ciphers);
2002 dump_cfg_string(sMacs, o->macs);
2003 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002004 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002005 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002006 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2007 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002008 dump_cfg_string(sAuthorizedPrincipalsFile,
2009 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002010 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002011 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2012 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Darren Tuckere7140f22008-06-10 23:01:51 +10002013
2014 /* string arguments requiring a lookup */
2015 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2016 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2017
2018 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002019 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2020 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002021 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2022 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002023 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2024 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002025 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2026 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2027 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2028 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2029 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002030 dump_cfg_strarray_oneline(sAuthenticationMethods,
2031 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002032
2033 /* other arguments */
2034 for (i = 0; i < o->num_subsystems; i++)
2035 printf("subsystem %s %s\n", o->subsystem_name[i],
2036 o->subsystem_args[i]);
2037
2038 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2039 o->max_startups_rate, o->max_startups);
2040
2041 for (i = 0; tunmode_desc[i].val != -1; i++)
2042 if (tunmode_desc[i].val == o->permit_tun) {
2043 s = tunmode_desc[i].text;
2044 break;
2045 }
2046 dump_cfg_string(sPermitTunnel, s);
2047
Damien Miller91475862011-05-05 14:14:34 +10002048 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2049 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002050
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002051 printf("rekeylimit %lld %d\n", o->rekey_limit, o->rekey_interval);
2052
Darren Tuckere7140f22008-06-10 23:01:51 +10002053 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002054}