blob: 331716c8f7ddb2617b14933f0fa3906bb6ccf4bc [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Miller72e6b5c2014-07-04 09:00:04 +10002/* $OpenBSD: servconf.c,v 1.250 2014/07/03 22:40:43 djm 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 Tuckere194ba42013-05-16 20:47:31 +100033#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100034#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100035#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100036
Damien Millerb84886b2008-05-19 15:05:07 +100037#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100041#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100042#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100043#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000044#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000045#include "misc.h"
46#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100047#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000048#include "kex.h"
49#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100050#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100051#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100052#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100053#include "canohost.h"
54#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110055#include "hostfile.h"
56#include "auth.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000057
Damien Miller3dc71ad2009-01-28 16:31:22 +110058static void add_listen_addr(ServerOptions *, char *, int);
59static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110060
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000061/* Use of privilege separation or not */
62extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100063extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000064
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065/* Initializes the server options to their default values. */
66
Damien Miller4af51302000-04-16 11:18:38 +100067void
Damien Miller95def091999-11-25 00:26:21 +110068initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069{
Damien Miller95def091999-11-25 00:26:21 +110070 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110071
72 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100073 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110076 options->num_ports = 0;
77 options->ports_from_cmdline = 0;
78 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110079 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110080 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110081 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100082 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100083 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110084 options->server_key_bits = -1;
85 options->login_grace_time = -1;
86 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000087 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110088 options->ignore_rhosts = -1;
89 options->ignore_user_known_hosts = -1;
90 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000091 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110092 options->x11_forwarding = -1;
93 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110094 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110095 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +100096 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100097 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110098 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110099 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100100 options->log_facility = SYSLOG_FACILITY_NOT_SET;
101 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000103 options->hostbased_authentication = -1;
104 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +1100105 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100106 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->kerberos_authentication = -1;
108 options->kerberos_or_local_passwd = -1;
109 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100110 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000111 options->gss_authentication=-1;
112 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100113 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100114 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000115 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100116 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000117 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100118 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000119 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000120 options->rekey_limit = -1;
121 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100122 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000123 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100124 options->num_allow_users = 0;
125 options->num_deny_users = 0;
126 options->num_allow_groups = 0;
127 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000128 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000129 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000130 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000131 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000132 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000133 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000134 options->max_startups_begin = -1;
135 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000136 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000137 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000138 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000139 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000140 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000141 options->client_alive_interval = -1;
142 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000143 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000144 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100145 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000146 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000147 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100148 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100149 options->authorized_keys_command = NULL;
150 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100151 options->revoked_keys_file = NULL;
152 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000153 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100154 options->ip_qos_interactive = -1;
155 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000156 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000157}
158
Damien Miller4af51302000-04-16 11:18:38 +1000159void
Damien Miller95def091999-11-25 00:26:21 +1100160fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000161{
Damien Miller726273e2001-11-12 11:40:11 +1100162 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000163 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000164 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100165
166 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100167 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100168 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100169 if (options->num_host_key_files == 0) {
170 /* fill default hostkeys for protocols */
171 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100172 options->host_key_files[options->num_host_key_files++] =
173 _PATH_HOST_KEY_FILE;
174 if (options->protocol & SSH_PROTO_2) {
175 options->host_key_files[options->num_host_key_files++] =
176 _PATH_HOST_RSA_KEY_FILE;
177 options->host_key_files[options->num_host_key_files++] =
178 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100179#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000180 options->host_key_files[options->num_host_key_files++] =
181 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100182#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100183 options->host_key_files[options->num_host_key_files++] =
184 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100185 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100186 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100187 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100188 if (options->num_ports == 0)
189 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
190 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000191 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000192 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000193 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000195 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100196 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000197 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->key_regeneration_time == -1)
199 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000200 if (options->permit_root_login == PERMIT_NOT_SET)
201 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100203 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->ignore_user_known_hosts == -1)
205 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100206 if (options->print_motd == -1)
207 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000208 if (options->print_lastlog == -1)
209 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100211 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100212 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100213 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100214 if (options->x11_use_localhost == -1)
215 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000216 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000217 options->xauth_location = _PATH_XAUTH;
Damien Miller5ff30c62013-10-30 22:21:50 +1100218 if (options->permit_tty == -1)
219 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000220 if (options->permit_user_rc == -1)
221 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->strict_modes == -1)
223 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100224 if (options->tcp_keep_alive == -1)
225 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100226 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100227 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100228 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000229 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100230 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100231 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000232 if (options->hostbased_authentication == -1)
233 options->hostbased_authentication = 0;
234 if (options->hostbased_uses_name_from_packet_only == -1)
235 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->rsa_authentication == -1)
237 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100238 if (options->pubkey_authentication == -1)
239 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100240 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000241 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100242 if (options->kerberos_or_local_passwd == -1)
243 options->kerberos_or_local_passwd = 1;
244 if (options->kerberos_ticket_cleanup == -1)
245 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100246 if (options->kerberos_get_afs_token == -1)
247 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000248 if (options->gss_authentication == -1)
249 options->gss_authentication = 0;
250 if (options->gss_cleanup_creds == -1)
251 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100252 if (options->password_authentication == -1)
253 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100254 if (options->kbd_interactive_authentication == -1)
255 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000256 if (options->challenge_response_authentication == -1)
257 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100258 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100259 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000260 if (options->permit_user_env == -1)
261 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->use_login == -1)
263 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000264 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000265 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000266 if (options->rekey_limit == -1)
267 options->rekey_limit = 0;
268 if (options->rekey_interval == -1)
269 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100270 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100271 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000272 if (options->allow_agent_forwarding == -1)
273 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000274 if (options->gateway_ports == -1)
275 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000276 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100277 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000278 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100279 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000280 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100281 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000282 if (options->max_authtries == -1)
283 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000284 if (options->max_sessions == -1)
285 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000286 if (options->use_dns == -1)
287 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000288 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100289 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000290 if (options->client_alive_count_max == -1)
291 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000292 if (options->num_authkeys_files == 0) {
293 options->authorized_keys_files[options->num_authkeys_files++] =
294 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
295 options->authorized_keys_files[options->num_authkeys_files++] =
296 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
297 }
Damien Millerd27b9472005-12-13 19:29:02 +1100298 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100299 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100300 if (options->ip_qos_interactive == -1)
301 options->ip_qos_interactive = IPTOS_LOWDELAY;
302 if (options->ip_qos_bulk == -1)
303 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000304 if (options->version_addendum == NULL)
305 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000306 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000307 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000308 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000309
Tim Rice40017b02002-07-14 13:36:49 -0700310#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000311 if (use_privsep && options->compression == 1) {
312 error("This platform does not support both privilege "
313 "separation and compression");
314 error("Compression disabled");
315 options->compression = 0;
316 }
317#endif
318
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000319}
320
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000321/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100322typedef enum {
323 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100324 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000325 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100326 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100327 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
328 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000329 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100330 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100331 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000332 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100333 sPasswordAuthentication, sKbdInteractiveAuthentication,
334 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000335 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100336 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100337 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000338 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000339 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000340 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000341 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000342 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000343 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100344 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000345 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100346 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100347 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100348 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100349 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000350 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000351 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100352 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000353 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000354 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000355} ServerOpCodes;
356
Darren Tucker45150472006-07-12 22:34:17 +1000357#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
358#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
359#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
360
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000361/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100362static struct {
363 const char *name;
364 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000365 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100366} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100367 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000368#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000369 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000370#else
Darren Tucker45150472006-07-12 22:34:17 +1000371 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000372#endif
Darren Tucker45150472006-07-12 22:34:17 +1000373 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100374 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000375 { "port", sPort, SSHCFG_GLOBAL },
376 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
377 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000378 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000379 { "pidfile", sPidFile, SSHCFG_GLOBAL },
380 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
381 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
382 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100383 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000384 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
385 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
386 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100387 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
388 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000389 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100390 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
391 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000392 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000393#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100394 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
396 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100397#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000398 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000399#else
Darren Tucker45150472006-07-12 22:34:17 +1000400 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100401#endif
402#else
Darren Tucker1629c072007-02-19 22:25:37 +1100403 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000404 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
405 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
406 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000407#endif
Darren Tucker45150472006-07-12 22:34:17 +1000408 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
409 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000410#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100411 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000412 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000413#else
Darren Tucker1629c072007-02-19 22:25:37 +1100414 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000415 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000416#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100417 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
418 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100419 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000420 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
421 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
422 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
423 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
424 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
425 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
426 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
427 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000428 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
429 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
430 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000431 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
432 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100433 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000434 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
435 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
436 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000437 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000438 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
439 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
440 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000441 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000442 { "allowusers", sAllowUsers, SSHCFG_ALL },
443 { "denyusers", sDenyUsers, SSHCFG_ALL },
444 { "allowgroups", sAllowGroups, SSHCFG_ALL },
445 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "ciphers", sCiphers, SSHCFG_GLOBAL },
447 { "macs", sMacs, SSHCFG_GLOBAL },
448 { "protocol", sProtocol, SSHCFG_GLOBAL },
449 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
450 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
451 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000452 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000453 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100454 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000455 { "usedns", sUseDNS, SSHCFG_GLOBAL },
456 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
457 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
458 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
459 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000460 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000461 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000462 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000463 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000464 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100465 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000466 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000467 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000468 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000469 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100470 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100471 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100472 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
473 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000474 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000475 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100476 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100477 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
478 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000479 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100480 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000481 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000482};
483
Darren Tuckere7140f22008-06-10 23:01:51 +1000484static struct {
485 int val;
486 char *text;
487} tunmode_desc[] = {
488 { SSH_TUNMODE_NO, "no" },
489 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
490 { SSH_TUNMODE_ETHERNET, "ethernet" },
491 { SSH_TUNMODE_YES, "yes" },
492 { -1, NULL }
493};
494
Damien Miller5428f641999-11-25 11:54:57 +1100495/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000496 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100497 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000498
Damien Miller4af51302000-04-16 11:18:38 +1000499static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100500parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000501 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000502{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000503 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000504
Damien Miller95def091999-11-25 00:26:21 +1100505 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000506 if (strcasecmp(cp, keywords[i].name) == 0) {
507 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100508 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000509 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000510
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000511 error("%s: line %d: Bad configuration option: %s",
512 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100513 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000514}
515
Darren Tucker88b6fb22010-01-13 22:44:29 +1100516char *
517derelativise_path(const char *path)
518{
Damien Miller44451d02010-03-26 10:40:04 +1100519 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100520
521 expanded = tilde_expand_filename(path, getuid());
522 if (*expanded == '/')
523 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100524 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100525 fatal("%s: getcwd: %s", __func__, strerror(errno));
526 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000527 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100528 return ret;
529}
530
Ben Lindstrombba81212001-06-25 05:01:22 +0000531static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100532add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100533{
Damien Millereccb9de2005-06-17 12:59:34 +1000534 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100535
536 if (options->num_ports == 0)
537 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100538 if (options->address_family == -1)
539 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000540 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000541 for (i = 0; i < options->num_ports; i++)
542 add_one_listen_addr(options, addr, options->ports[i]);
543 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000544 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000545}
546
Ben Lindstrombba81212001-06-25 05:01:22 +0000547static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100548add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000549{
550 struct addrinfo hints, *ai, *aitop;
551 char strport[NI_MAXSERV];
552 int gaierr;
553
554 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100555 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000556 hints.ai_socktype = SOCK_STREAM;
557 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100558 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000559 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
560 fatal("bad addr or host: %s (%s)",
561 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100562 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000563 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
564 ;
565 ai->ai_next = options->listen_addrs;
566 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100567}
568
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000569struct connection_info *
570get_connection_info(int populate, int use_dns)
571{
572 static struct connection_info ci;
573
574 if (!populate)
575 return &ci;
576 ci.host = get_canonical_hostname(use_dns);
577 ci.address = get_remote_ipaddr();
578 ci.laddress = get_local_ipaddr(packet_get_connection_in());
579 ci.lport = get_local_port();
580 return &ci;
581}
582
Darren Tucker45150472006-07-12 22:34:17 +1000583/*
584 * The strategy for the Match blocks is that the config file is parsed twice.
585 *
586 * The first time is at startup. activep is initialized to 1 and the
587 * directives in the global context are processed and acted on. Hitting a
588 * Match directive unsets activep and the directives inside the block are
589 * checked for syntax only.
590 *
591 * The second time is after a connection has been established but before
592 * authentication. activep is initialized to 2 and global config directives
593 * are ignored since they have already been processed. If the criteria in a
594 * Match block is met, activep is set and the subsequent directives
595 * processed and actioned until EOF or another Match block unsets it. Any
596 * options set are copied into the main server config.
597 *
598 * Potential additions/improvements:
599 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
600 *
601 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
602 * Match Address 192.168.0.*
603 * Tag trusted
604 * Match Group wheel
605 * Tag trusted
606 * Match Tag trusted
607 * AllowTcpForwarding yes
608 * GatewayPorts clientspecified
609 * [...]
610 *
611 * - Add a PermittedChannelRequests directive
612 * Match Group shell
613 * PermittedChannelRequests session,forwarded-tcpip
614 */
615
616static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000617match_cfg_line_group(const char *grps, int line, const char *user)
618{
619 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000620 struct passwd *pw;
621
Damien Miller565ca3f2006-08-19 00:23:15 +1000622 if (user == NULL)
623 goto out;
624
625 if ((pw = getpwnam(user)) == NULL) {
626 debug("Can't match group at line %d because user %.100s does "
627 "not exist", line, user);
628 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
629 debug("Can't Match group because user %.100s not in any group "
630 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000631 } else if (ga_match_pattern_list(grps) != 1) {
632 debug("user %.100s does not match group list %.100s at line %d",
633 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000634 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000635 debug("user %.100s matched group list %.100s at line %d", user,
636 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000637 result = 1;
638 }
639out:
640 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000641 return result;
642}
643
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000644/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000645 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100646 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000647 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000648 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000649static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000650match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000651{
Damien Millercf31f382013-10-24 21:02:56 +1100652 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000653 char *arg, *attrib, *cp = *condition;
654 size_t len;
655
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000656 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000657 debug3("checking syntax for 'Match %s'", cp);
658 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000659 debug3("checking match for '%s' user %s host %s addr %s "
660 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
661 ci->host ? ci->host : "(null)",
662 ci->address ? ci->address : "(null)",
663 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000664
665 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100666 attributes++;
667 if (strcasecmp(attrib, "all") == 0) {
668 if (attributes != 1 ||
669 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
670 error("'all' cannot be combined with other "
671 "Match attributes");
672 return -1;
673 }
674 *condition = cp;
675 return 1;
676 }
Darren Tucker45150472006-07-12 22:34:17 +1000677 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
678 error("Missing Match criteria for %s", attrib);
679 return -1;
680 }
681 len = strlen(arg);
682 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000683 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000684 result = 0;
685 continue;
686 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000687 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000688 result = 0;
689 else
690 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000691 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000692 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000693 if (ci == NULL || ci->user == NULL) {
694 result = 0;
695 continue;
696 }
697 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000698 case -1:
699 return -1;
700 case 0:
701 result = 0;
702 }
Darren Tucker45150472006-07-12 22:34:17 +1000703 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000704 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000705 result = 0;
706 continue;
707 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000708 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000709 result = 0;
710 else
711 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000712 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000713 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000714 if (ci == NULL || ci->address == NULL) {
715 result = 0;
716 continue;
717 }
718 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000719 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000720 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000721 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000722 break;
723 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000724 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000725 result = 0;
726 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000727 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000728 return -1;
729 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000730 } else if (strcasecmp(attrib, "localaddress") == 0){
731 if (ci == NULL || ci->laddress == NULL) {
732 result = 0;
733 continue;
734 }
735 switch (addr_match_list(ci->laddress, arg)) {
736 case 1:
737 debug("connection from %.100s matched "
738 "'LocalAddress %.100s' at line %d",
739 ci->laddress, arg, line);
740 break;
741 case 0:
742 case -1:
743 result = 0;
744 break;
745 case -2:
746 return -1;
747 }
748 } else if (strcasecmp(attrib, "localport") == 0) {
749 if ((port = a2port(arg)) == -1) {
750 error("Invalid LocalPort '%s' on Match line",
751 arg);
752 return -1;
753 }
754 if (ci == NULL || ci->lport == 0) {
755 result = 0;
756 continue;
757 }
758 /* TODO support port lists */
759 if (port == ci->lport)
760 debug("connection from %.100s matched "
761 "'LocalPort %d' at line %d",
762 ci->laddress, port, line);
763 else
764 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000765 } else {
766 error("Unsupported Match attribute %s", attrib);
767 return -1;
768 }
769 }
Damien Millercf31f382013-10-24 21:02:56 +1100770 if (attributes == 0) {
771 error("One or more attributes required for Match");
772 return -1;
773 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000774 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000775 debug3("match %sfound", result ? "" : "not ");
776 *condition = cp;
777 return result;
778}
779
Damien Millere2754432006-07-24 14:06:47 +1000780#define WHITESPACE " \t\r\n"
781
Damien Miller33322122011-06-20 14:43:11 +1000782/* Multistate option parsing */
783struct multistate {
784 char *key;
785 int value;
786};
787static const struct multistate multistate_addressfamily[] = {
788 { "inet", AF_INET },
789 { "inet6", AF_INET6 },
790 { "any", AF_UNSPEC },
791 { NULL, -1 }
792};
793static const struct multistate multistate_permitrootlogin[] = {
794 { "without-password", PERMIT_NO_PASSWD },
795 { "forced-commands-only", PERMIT_FORCED_ONLY },
796 { "yes", PERMIT_YES },
797 { "no", PERMIT_NO },
798 { NULL, -1 }
799};
800static const struct multistate multistate_compression[] = {
801 { "delayed", COMP_DELAYED },
802 { "yes", COMP_ZLIB },
803 { "no", COMP_NONE },
804 { NULL, -1 }
805};
806static const struct multistate multistate_gatewayports[] = {
807 { "clientspecified", 2 },
808 { "yes", 1 },
809 { "no", 0 },
810 { NULL, -1 }
811};
Damien Miller69ff1df2011-06-23 08:30:03 +1000812static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000813 { "yes", PRIVSEP_NOSANDBOX },
814 { "sandbox", PRIVSEP_ON },
815 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000816 { "no", PRIVSEP_OFF },
817 { NULL, -1 }
818};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100819static const struct multistate multistate_tcpfwd[] = {
820 { "yes", FORWARD_ALLOW },
821 { "all", FORWARD_ALLOW },
822 { "no", FORWARD_DENY },
823 { "remote", FORWARD_REMOTE },
824 { "local", FORWARD_LOCAL },
825 { NULL, -1 }
826};
Damien Miller33322122011-06-20 14:43:11 +1000827
Ben Lindstromade03f62001-12-06 18:22:17 +0000828int
829process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000830 const char *filename, int linenum, int *activep,
831 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000832{
Darren Tucker09c0f032013-05-16 20:48:57 +1000833 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000834 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100835 SyslogFacility *log_facility_ptr;
836 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000837 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000838 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000839 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000840 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000841 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000842
843 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100844 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100845 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000846 /* Ignore leading whitespace */
847 if (*arg == '\0')
848 arg = strdelim(&cp);
849 if (!arg || !*arg || *arg == '#')
850 return 0;
851 intptr = NULL;
852 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000853 opcode = parse_token(arg, filename, linenum, &flags);
854
855 if (activep == NULL) { /* We are processing a command line directive */
856 cmdline = 1;
857 activep = &cmdline;
858 }
859 if (*activep && opcode != sMatch)
860 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
861 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000862 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000863 fatal("%s line %d: Directive '%s' is not allowed "
864 "within a Match block", filename, linenum, arg);
865 } else { /* this is a directive we have already processed */
866 while (arg)
867 arg = strdelim(&cp);
868 return 0;
869 }
870 }
871
Ben Lindstromade03f62001-12-06 18:22:17 +0000872 switch (opcode) {
873 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000874 case sUsePAM:
875 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000876 goto parse_flag;
877
878 /* Standard Options */
879 case sBadOption:
880 return -1;
881 case sPort:
882 /* ignore ports from configfile if cmdline specifies ports */
883 if (options->ports_from_cmdline)
884 return 0;
885 if (options->listen_addrs != NULL)
886 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100887 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000888 if (options->num_ports >= MAX_PORTS)
889 fatal("%s line %d: too many ports.",
890 filename, linenum);
891 arg = strdelim(&cp);
892 if (!arg || *arg == '\0')
893 fatal("%s line %d: missing port number.",
894 filename, linenum);
895 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100896 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000897 fatal("%s line %d: Badly formatted port number.",
898 filename, linenum);
899 break;
900
901 case sServerKeyBits:
902 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000903 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000904 arg = strdelim(&cp);
905 if (!arg || *arg == '\0')
906 fatal("%s line %d: missing integer value.",
907 filename, linenum);
908 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000909 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000910 *intptr = value;
911 break;
912
913 case sLoginGraceTime:
914 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000915 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000916 arg = strdelim(&cp);
917 if (!arg || *arg == '\0')
918 fatal("%s line %d: missing time value.",
919 filename, linenum);
920 if ((value = convtime(arg)) == -1)
921 fatal("%s line %d: invalid time value.",
922 filename, linenum);
923 if (*intptr == -1)
924 *intptr = value;
925 break;
926
927 case sKeyRegenerationTime:
928 intptr = &options->key_regeneration_time;
929 goto parse_time;
930
931 case sListenAddress:
932 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100933 if (arg == NULL || *arg == '\0')
934 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000935 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000936 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
937 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
938 && strchr(p+1, ':') != NULL) {
939 add_listen_addr(options, arg, 0);
940 break;
941 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100942 p = hpdelim(&arg);
943 if (p == NULL)
944 fatal("%s line %d: bad address:port usage",
945 filename, linenum);
946 p = cleanhostname(p);
947 if (arg == NULL)
948 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100949 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100950 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000951
Damien Millerf91ee4c2005-03-01 21:24:33 +1100952 add_listen_addr(options, p, port);
953
Ben Lindstromade03f62001-12-06 18:22:17 +0000954 break;
955
Darren Tucker0f383232005-01-20 10:57:56 +1100956 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000957 intptr = &options->address_family;
958 multistate_ptr = multistate_addressfamily;
959 if (options->listen_addrs != NULL)
960 fatal("%s line %d: address family must be specified "
961 "before ListenAddress.", filename, linenum);
962 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100963 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000964 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000965 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000966 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000967 value = -1;
968 for (i = 0; multistate_ptr[i].key != NULL; i++) {
969 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
970 value = multistate_ptr[i].value;
971 break;
972 }
973 }
974 if (value == -1)
975 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100976 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000977 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100978 *intptr = value;
979 break;
980
Ben Lindstromade03f62001-12-06 18:22:17 +0000981 case sHostKeyFile:
982 intptr = &options->num_host_key_files;
983 if (*intptr >= MAX_HOSTKEYS)
984 fatal("%s line %d: too many host keys specified (max %d).",
985 filename, linenum, MAX_HOSTKEYS);
986 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000987 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000988 arg = strdelim(&cp);
989 if (!arg || *arg == '\0')
990 fatal("%s line %d: missing file name.",
991 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000992 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100993 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000994 /* increase optional counter */
995 if (intptr != NULL)
996 *intptr = *intptr + 1;
997 }
998 break;
999
Damien Miller85b45e02013-07-20 13:21:52 +10001000 case sHostKeyAgent:
1001 charptr = &options->host_key_agent;
1002 arg = strdelim(&cp);
1003 if (!arg || *arg == '\0')
1004 fatal("%s line %d: missing socket name.",
1005 filename, linenum);
1006 if (*activep && *charptr == NULL)
1007 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1008 xstrdup(arg) : derelativise_path(arg);
1009 break;
1010
Damien Miller0a80ca12010-02-27 07:55:05 +11001011 case sHostCertificate:
1012 intptr = &options->num_host_cert_files;
1013 if (*intptr >= MAX_HOSTKEYS)
1014 fatal("%s line %d: too many host certificates "
1015 "specified (max %d).", filename, linenum,
1016 MAX_HOSTCERTS);
1017 charptr = &options->host_cert_files[*intptr];
1018 goto parse_filename;
1019 break;
1020
Ben Lindstromade03f62001-12-06 18:22:17 +00001021 case sPidFile:
1022 charptr = &options->pid_file;
1023 goto parse_filename;
1024
1025 case sPermitRootLogin:
1026 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001027 multistate_ptr = multistate_permitrootlogin;
1028 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001029
1030 case sIgnoreRhosts:
1031 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001032 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001033 arg = strdelim(&cp);
1034 if (!arg || *arg == '\0')
1035 fatal("%s line %d: missing yes/no argument.",
1036 filename, linenum);
1037 value = 0; /* silence compiler */
1038 if (strcmp(arg, "yes") == 0)
1039 value = 1;
1040 else if (strcmp(arg, "no") == 0)
1041 value = 0;
1042 else
1043 fatal("%s line %d: Bad yes/no argument: %s",
1044 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001045 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001046 *intptr = value;
1047 break;
1048
1049 case sIgnoreUserKnownHosts:
1050 intptr = &options->ignore_user_known_hosts;
1051 goto parse_flag;
1052
Ben Lindstromade03f62001-12-06 18:22:17 +00001053 case sRhostsRSAAuthentication:
1054 intptr = &options->rhosts_rsa_authentication;
1055 goto parse_flag;
1056
1057 case sHostbasedAuthentication:
1058 intptr = &options->hostbased_authentication;
1059 goto parse_flag;
1060
1061 case sHostbasedUsesNameFromPacketOnly:
1062 intptr = &options->hostbased_uses_name_from_packet_only;
1063 goto parse_flag;
1064
1065 case sRSAAuthentication:
1066 intptr = &options->rsa_authentication;
1067 goto parse_flag;
1068
1069 case sPubkeyAuthentication:
1070 intptr = &options->pubkey_authentication;
1071 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001072
Ben Lindstromade03f62001-12-06 18:22:17 +00001073 case sKerberosAuthentication:
1074 intptr = &options->kerberos_authentication;
1075 goto parse_flag;
1076
1077 case sKerberosOrLocalPasswd:
1078 intptr = &options->kerberos_or_local_passwd;
1079 goto parse_flag;
1080
1081 case sKerberosTicketCleanup:
1082 intptr = &options->kerberos_ticket_cleanup;
1083 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001084
Darren Tucker22ef5082003-12-31 11:37:34 +11001085 case sKerberosGetAFSToken:
1086 intptr = &options->kerberos_get_afs_token;
1087 goto parse_flag;
1088
Darren Tucker0efd1552003-08-26 11:49:55 +10001089 case sGssAuthentication:
1090 intptr = &options->gss_authentication;
1091 goto parse_flag;
1092
1093 case sGssCleanupCreds:
1094 intptr = &options->gss_cleanup_creds;
1095 goto parse_flag;
1096
Ben Lindstromade03f62001-12-06 18:22:17 +00001097 case sPasswordAuthentication:
1098 intptr = &options->password_authentication;
1099 goto parse_flag;
1100
1101 case sKbdInteractiveAuthentication:
1102 intptr = &options->kbd_interactive_authentication;
1103 goto parse_flag;
1104
1105 case sChallengeResponseAuthentication:
1106 intptr = &options->challenge_response_authentication;
1107 goto parse_flag;
1108
1109 case sPrintMotd:
1110 intptr = &options->print_motd;
1111 goto parse_flag;
1112
1113 case sPrintLastLog:
1114 intptr = &options->print_lastlog;
1115 goto parse_flag;
1116
1117 case sX11Forwarding:
1118 intptr = &options->x11_forwarding;
1119 goto parse_flag;
1120
1121 case sX11DisplayOffset:
1122 intptr = &options->x11_display_offset;
1123 goto parse_int;
1124
Damien Miller95c249f2002-02-05 12:11:34 +11001125 case sX11UseLocalhost:
1126 intptr = &options->x11_use_localhost;
1127 goto parse_flag;
1128
Ben Lindstromade03f62001-12-06 18:22:17 +00001129 case sXAuthLocation:
1130 charptr = &options->xauth_location;
1131 goto parse_filename;
1132
Damien Miller5ff30c62013-10-30 22:21:50 +11001133 case sPermitTTY:
1134 intptr = &options->permit_tty;
1135 goto parse_flag;
1136
Damien Miller72e6b5c2014-07-04 09:00:04 +10001137 case sPermitUserRC:
1138 intptr = &options->permit_user_rc;
1139 goto parse_flag;
1140
Ben Lindstromade03f62001-12-06 18:22:17 +00001141 case sStrictModes:
1142 intptr = &options->strict_modes;
1143 goto parse_flag;
1144
Damien Miller12c150e2003-12-17 16:31:10 +11001145 case sTCPKeepAlive:
1146 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001147 goto parse_flag;
1148
1149 case sEmptyPasswd:
1150 intptr = &options->permit_empty_passwd;
1151 goto parse_flag;
1152
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001153 case sPermitUserEnvironment:
1154 intptr = &options->permit_user_env;
1155 goto parse_flag;
1156
Ben Lindstromade03f62001-12-06 18:22:17 +00001157 case sUseLogin:
1158 intptr = &options->use_login;
1159 goto parse_flag;
1160
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001161 case sCompression:
1162 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001163 multistate_ptr = multistate_compression;
1164 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001165
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001166 case sRekeyLimit:
1167 arg = strdelim(&cp);
1168 if (!arg || *arg == '\0')
1169 fatal("%.200s line %d: Missing argument.", filename,
1170 linenum);
1171 if (strcmp(arg, "default") == 0) {
1172 val64 = 0;
1173 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001174 if (scan_scaled(arg, &val64) == -1)
1175 fatal("%.200s line %d: Bad number '%s': %s",
1176 filename, linenum, arg, strerror(errno));
1177 /* check for too-large or too-small limits */
1178 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001179 fatal("%.200s line %d: RekeyLimit too large",
1180 filename, linenum);
1181 if (val64 != 0 && val64 < 16)
1182 fatal("%.200s line %d: RekeyLimit too small",
1183 filename, linenum);
1184 }
1185 if (*activep && options->rekey_limit == -1)
1186 options->rekey_limit = (u_int32_t)val64;
1187 if (cp != NULL) { /* optional rekey interval present */
1188 if (strcmp(cp, "none") == 0) {
1189 (void)strdelim(&cp); /* discard */
1190 break;
1191 }
1192 intptr = &options->rekey_interval;
1193 goto parse_time;
1194 }
1195 break;
1196
Ben Lindstromade03f62001-12-06 18:22:17 +00001197 case sGatewayPorts:
1198 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001199 multistate_ptr = multistate_gatewayports;
1200 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001201
Damien Miller3a961dc2003-06-03 10:25:48 +10001202 case sUseDNS:
1203 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001204 goto parse_flag;
1205
1206 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001207 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001208 arg = strdelim(&cp);
1209 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001210 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001211 fatal("%.200s line %d: unsupported log facility '%s'",
1212 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001213 if (*log_facility_ptr == -1)
1214 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001215 break;
1216
1217 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001218 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001219 arg = strdelim(&cp);
1220 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001221 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001222 fatal("%.200s line %d: unsupported log level '%s'",
1223 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001224 if (*log_level_ptr == -1)
1225 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001226 break;
1227
1228 case sAllowTcpForwarding:
1229 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001230 multistate_ptr = multistate_tcpfwd;
1231 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001232
Damien Miller4f755cd2008-05-19 14:57:41 +10001233 case sAllowAgentForwarding:
1234 intptr = &options->allow_agent_forwarding;
1235 goto parse_flag;
1236
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001237 case sUsePrivilegeSeparation:
1238 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001239 multistate_ptr = multistate_privsep;
1240 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001241
Ben Lindstromade03f62001-12-06 18:22:17 +00001242 case sAllowUsers:
1243 while ((arg = strdelim(&cp)) && *arg != '\0') {
1244 if (options->num_allow_users >= MAX_ALLOW_USERS)
1245 fatal("%s line %d: too many allow users.",
1246 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001247 if (!*activep)
1248 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001249 options->allow_users[options->num_allow_users++] =
1250 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001251 }
1252 break;
1253
1254 case sDenyUsers:
1255 while ((arg = strdelim(&cp)) && *arg != '\0') {
1256 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001257 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001258 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001259 if (!*activep)
1260 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001261 options->deny_users[options->num_deny_users++] =
1262 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001263 }
1264 break;
1265
1266 case sAllowGroups:
1267 while ((arg = strdelim(&cp)) && *arg != '\0') {
1268 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1269 fatal("%s line %d: too many allow groups.",
1270 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001271 if (!*activep)
1272 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001273 options->allow_groups[options->num_allow_groups++] =
1274 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001275 }
1276 break;
1277
1278 case sDenyGroups:
1279 while ((arg = strdelim(&cp)) && *arg != '\0') {
1280 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1281 fatal("%s line %d: too many deny groups.",
1282 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001283 if (!*activep)
1284 continue;
1285 options->deny_groups[options->num_deny_groups++] =
1286 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001287 }
1288 break;
1289
1290 case sCiphers:
1291 arg = strdelim(&cp);
1292 if (!arg || *arg == '\0')
1293 fatal("%s line %d: Missing argument.", filename, linenum);
1294 if (!ciphers_valid(arg))
1295 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1296 filename, linenum, arg ? arg : "<NONE>");
1297 if (options->ciphers == NULL)
1298 options->ciphers = xstrdup(arg);
1299 break;
1300
1301 case sMacs:
1302 arg = strdelim(&cp);
1303 if (!arg || *arg == '\0')
1304 fatal("%s line %d: Missing argument.", filename, linenum);
1305 if (!mac_valid(arg))
1306 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1307 filename, linenum, arg ? arg : "<NONE>");
1308 if (options->macs == NULL)
1309 options->macs = xstrdup(arg);
1310 break;
1311
Damien Millerd5f62bf2010-09-24 22:11:14 +10001312 case sKexAlgorithms:
1313 arg = strdelim(&cp);
1314 if (!arg || *arg == '\0')
1315 fatal("%s line %d: Missing argument.",
1316 filename, linenum);
1317 if (!kex_names_valid(arg))
1318 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1319 filename, linenum, arg ? arg : "<NONE>");
1320 if (options->kex_algorithms == NULL)
1321 options->kex_algorithms = xstrdup(arg);
1322 break;
1323
Ben Lindstromade03f62001-12-06 18:22:17 +00001324 case sProtocol:
1325 intptr = &options->protocol;
1326 arg = strdelim(&cp);
1327 if (!arg || *arg == '\0')
1328 fatal("%s line %d: Missing argument.", filename, linenum);
1329 value = proto_spec(arg);
1330 if (value == SSH_PROTO_UNKNOWN)
1331 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001332 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001333 if (*intptr == SSH_PROTO_UNKNOWN)
1334 *intptr = value;
1335 break;
1336
1337 case sSubsystem:
1338 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1339 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001340 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001341 }
1342 arg = strdelim(&cp);
1343 if (!arg || *arg == '\0')
1344 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001345 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001346 if (!*activep) {
1347 arg = strdelim(&cp);
1348 break;
1349 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001350 for (i = 0; i < options->num_subsystems; i++)
1351 if (strcmp(arg, options->subsystem_name[i]) == 0)
1352 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001353 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001354 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1355 arg = strdelim(&cp);
1356 if (!arg || *arg == '\0')
1357 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001358 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001359 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001360
1361 /* Collect arguments (separate to executable) */
1362 p = xstrdup(arg);
1363 len = strlen(p) + 1;
1364 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1365 len += 1 + strlen(arg);
1366 p = xrealloc(p, 1, len);
1367 strlcat(p, " ", len);
1368 strlcat(p, arg, len);
1369 }
1370 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 options->num_subsystems++;
1372 break;
1373
1374 case sMaxStartups:
1375 arg = strdelim(&cp);
1376 if (!arg || *arg == '\0')
1377 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001378 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001379 if ((n = sscanf(arg, "%d:%d:%d",
1380 &options->max_startups_begin,
1381 &options->max_startups_rate,
1382 &options->max_startups)) == 3) {
1383 if (options->max_startups_begin >
1384 options->max_startups ||
1385 options->max_startups_rate > 100 ||
1386 options->max_startups_rate < 1)
1387 fatal("%s line %d: Illegal MaxStartups spec.",
1388 filename, linenum);
1389 } else if (n != 1)
1390 fatal("%s line %d: Illegal MaxStartups spec.",
1391 filename, linenum);
1392 else
1393 options->max_startups = options->max_startups_begin;
1394 break;
1395
Darren Tucker89413db2004-05-24 10:36:23 +10001396 case sMaxAuthTries:
1397 intptr = &options->max_authtries;
1398 goto parse_int;
1399
Damien Miller7207f642008-05-19 15:34:50 +10001400 case sMaxSessions:
1401 intptr = &options->max_sessions;
1402 goto parse_int;
1403
Ben Lindstromade03f62001-12-06 18:22:17 +00001404 case sBanner:
1405 charptr = &options->banner;
1406 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001407
Ben Lindstromade03f62001-12-06 18:22:17 +00001408 /*
1409 * These options can contain %X options expanded at
1410 * connect time, so that you can specify paths like:
1411 *
1412 * AuthorizedKeysFile /etc/ssh_keys/%u
1413 */
1414 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001415 if (*activep && options->num_authkeys_files == 0) {
1416 while ((arg = strdelim(&cp)) && *arg != '\0') {
1417 if (options->num_authkeys_files >=
1418 MAX_AUTHKEYS_FILES)
1419 fatal("%s line %d: "
1420 "too many authorized keys files.",
1421 filename, linenum);
1422 options->authorized_keys_files[
1423 options->num_authkeys_files++] =
1424 tilde_expand_filename(arg, getuid());
1425 }
1426 }
1427 return 0;
1428
Damien Miller30da3442010-05-10 11:58:03 +10001429 case sAuthorizedPrincipalsFile:
1430 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001431 arg = strdelim(&cp);
1432 if (!arg || *arg == '\0')
1433 fatal("%s line %d: missing file name.",
1434 filename, linenum);
1435 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001436 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001437 /* increase optional counter */
1438 if (intptr != NULL)
1439 *intptr = *intptr + 1;
1440 }
1441 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001442
1443 case sClientAliveInterval:
1444 intptr = &options->client_alive_interval;
1445 goto parse_time;
1446
1447 case sClientAliveCountMax:
1448 intptr = &options->client_alive_count_max;
1449 goto parse_int;
1450
Darren Tucker46bc0752004-05-02 22:11:30 +10001451 case sAcceptEnv:
1452 while ((arg = strdelim(&cp)) && *arg != '\0') {
1453 if (strchr(arg, '=') != NULL)
1454 fatal("%s line %d: Invalid environment name.",
1455 filename, linenum);
1456 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1457 fatal("%s line %d: too many allow env.",
1458 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001459 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001460 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001461 options->accept_env[options->num_accept_env++] =
1462 xstrdup(arg);
1463 }
1464 break;
1465
Damien Millerd27b9472005-12-13 19:29:02 +11001466 case sPermitTunnel:
1467 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001468 arg = strdelim(&cp);
1469 if (!arg || *arg == '\0')
1470 fatal("%s line %d: Missing yes/point-to-point/"
1471 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001472 value = -1;
1473 for (i = 0; tunmode_desc[i].val != -1; i++)
1474 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1475 value = tunmode_desc[i].val;
1476 break;
1477 }
1478 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001479 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1480 "no argument: %s", filename, linenum, arg);
1481 if (*intptr == -1)
1482 *intptr = value;
1483 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001484
Darren Tucker45150472006-07-12 22:34:17 +10001485 case sMatch:
1486 if (cmdline)
1487 fatal("Match directive not supported as a command-line "
1488 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001489 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001490 if (value < 0)
1491 fatal("%s line %d: Bad Match condition", filename,
1492 linenum);
1493 *activep = value;
1494 break;
1495
Damien Miller9b439df2006-07-24 14:04:00 +10001496 case sPermitOpen:
1497 arg = strdelim(&cp);
1498 if (!arg || *arg == '\0')
1499 fatal("%s line %d: missing PermitOpen specification",
1500 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001501 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001502 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001503 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001504 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001505 options->num_permitted_opens = 0;
1506 }
Damien Miller9b439df2006-07-24 14:04:00 +10001507 break;
1508 }
Damien Millerc6081482012-04-22 11:18:53 +10001509 if (strcmp(arg, "none") == 0) {
1510 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001511 options->num_permitted_opens = 1;
1512 channel_disable_adm_local_opens();
1513 }
1514 break;
1515 }
Damien Millera29b95e2007-01-05 16:28:36 +11001516 if (*activep && n == -1)
1517 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001518 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1519 p = hpdelim(&arg);
1520 if (p == NULL)
1521 fatal("%s line %d: missing host in PermitOpen",
1522 filename, linenum);
1523 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001524 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001525 fatal("%s line %d: bad port number in "
1526 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001527 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001528 options->num_permitted_opens =
1529 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001530 }
Damien Miller9b439df2006-07-24 14:04:00 +10001531 break;
1532
Damien Millere2754432006-07-24 14:06:47 +10001533 case sForceCommand:
1534 if (cp == NULL)
1535 fatal("%.200s line %d: Missing argument.", filename,
1536 linenum);
1537 len = strspn(cp, WHITESPACE);
1538 if (*activep && options->adm_forced_command == NULL)
1539 options->adm_forced_command = xstrdup(cp + len);
1540 return 0;
1541
Damien Millerd8cb1f12008-02-10 22:40:12 +11001542 case sChrootDirectory:
1543 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001544
1545 arg = strdelim(&cp);
1546 if (!arg || *arg == '\0')
1547 fatal("%s line %d: missing file name.",
1548 filename, linenum);
1549 if (*activep && *charptr == NULL)
1550 *charptr = xstrdup(arg);
1551 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001552
Damien Miller1aed65e2010-03-04 21:53:35 +11001553 case sTrustedUserCAKeys:
1554 charptr = &options->trusted_user_ca_keys;
1555 goto parse_filename;
1556
1557 case sRevokedKeys:
1558 charptr = &options->revoked_keys_file;
1559 goto parse_filename;
1560
Damien Miller0dac6fb2010-11-20 15:19:38 +11001561 case sIPQoS:
1562 arg = strdelim(&cp);
1563 if ((value = parse_ipqos(arg)) == -1)
1564 fatal("%s line %d: Bad IPQoS value: %s",
1565 filename, linenum, arg);
1566 arg = strdelim(&cp);
1567 if (arg == NULL)
1568 value2 = value;
1569 else if ((value2 = parse_ipqos(arg)) == -1)
1570 fatal("%s line %d: Bad IPQoS value: %s",
1571 filename, linenum, arg);
1572 if (*activep) {
1573 options->ip_qos_interactive = value;
1574 options->ip_qos_bulk = value2;
1575 }
1576 break;
1577
Damien Miller23528812012-04-22 11:24:43 +10001578 case sVersionAddendum:
1579 if (cp == NULL)
1580 fatal("%.200s line %d: Missing argument.", filename,
1581 linenum);
1582 len = strspn(cp, WHITESPACE);
1583 if (*activep && options->version_addendum == NULL) {
1584 if (strcasecmp(cp + len, "none") == 0)
1585 options->version_addendum = xstrdup("");
1586 else if (strchr(cp + len, '\r') != NULL)
1587 fatal("%.200s line %d: Invalid argument",
1588 filename, linenum);
1589 else
1590 options->version_addendum = xstrdup(cp + len);
1591 }
1592 return 0;
1593
Damien Miller09d3e122012-10-31 08:58:58 +11001594 case sAuthorizedKeysCommand:
1595 len = strspn(cp, WHITESPACE);
1596 if (*activep && options->authorized_keys_command == NULL) {
1597 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1598 fatal("%.200s line %d: AuthorizedKeysCommand "
1599 "must be an absolute path",
1600 filename, linenum);
1601 options->authorized_keys_command = xstrdup(cp + len);
1602 }
1603 return 0;
1604
1605 case sAuthorizedKeysCommandUser:
1606 charptr = &options->authorized_keys_command_user;
1607
1608 arg = strdelim(&cp);
1609 if (*activep && *charptr == NULL)
1610 *charptr = xstrdup(arg);
1611 break;
1612
Damien Millera6e3f012012-11-04 23:21:40 +11001613 case sAuthenticationMethods:
1614 if (*activep && options->num_auth_methods == 0) {
1615 while ((arg = strdelim(&cp)) && *arg != '\0') {
1616 if (options->num_auth_methods >=
1617 MAX_AUTH_METHODS)
1618 fatal("%s line %d: "
1619 "too many authentication methods.",
1620 filename, linenum);
1621 if (auth2_methods_valid(arg, 0) != 0)
1622 fatal("%s line %d: invalid "
1623 "authentication method list.",
1624 filename, linenum);
1625 options->auth_methods[
1626 options->num_auth_methods++] = xstrdup(arg);
1627 }
1628 }
1629 return 0;
1630
Ben Lindstromade03f62001-12-06 18:22:17 +00001631 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001632 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001633 filename, linenum, arg);
1634 while (arg)
1635 arg = strdelim(&cp);
1636 break;
1637
Damien Millerf9b3feb2003-05-16 11:38:32 +10001638 case sUnsupported:
1639 logit("%s line %d: Unsupported option %s",
1640 filename, linenum, arg);
1641 while (arg)
1642 arg = strdelim(&cp);
1643 break;
1644
Ben Lindstromade03f62001-12-06 18:22:17 +00001645 default:
1646 fatal("%s line %d: Missing handler for opcode %s (%d)",
1647 filename, linenum, arg, opcode);
1648 }
1649 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1650 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1651 filename, linenum, arg);
1652 return 0;
1653}
1654
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001655/* Reads the server configuration file. */
1656
Damien Miller4af51302000-04-16 11:18:38 +10001657void
Darren Tucker645ab752004-06-25 13:33:20 +10001658load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001659{
Damien Miller46cb75a2012-07-31 12:22:37 +10001660 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001661 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001662 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001663
Darren Tucker645ab752004-06-25 13:33:20 +10001664 debug2("%s: filename %s", __func__, filename);
1665 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001666 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001667 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001668 }
Darren Tucker645ab752004-06-25 13:33:20 +10001669 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001670 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001671 lineno++;
1672 if (strlen(line) == sizeof(line) - 1)
1673 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001674 /*
1675 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001676 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001677 * line numbers later for error messages
1678 */
1679 if ((cp = strchr(line, '#')) != NULL)
1680 memcpy(cp, "\n", 2);
1681 cp = line + strspn(line, " \t\r");
1682
1683 buffer_append(conf, cp, strlen(cp));
1684 }
1685 buffer_append(conf, "\0", 1);
1686 fclose(f);
1687 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1688}
1689
1690void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001691parse_server_match_config(ServerOptions *options,
1692 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001693{
Darren Tucker45150472006-07-12 22:34:17 +10001694 ServerOptions mo;
1695
1696 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001697 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001698 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001699}
1700
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001701int parse_server_match_testspec(struct connection_info *ci, char *spec)
1702{
1703 char *p;
1704
1705 while ((p = strsep(&spec, ",")) && *p != '\0') {
1706 if (strncmp(p, "addr=", 5) == 0) {
1707 ci->address = xstrdup(p + 5);
1708 } else if (strncmp(p, "host=", 5) == 0) {
1709 ci->host = xstrdup(p + 5);
1710 } else if (strncmp(p, "user=", 5) == 0) {
1711 ci->user = xstrdup(p + 5);
1712 } else if (strncmp(p, "laddr=", 6) == 0) {
1713 ci->laddress = xstrdup(p + 6);
1714 } else if (strncmp(p, "lport=", 6) == 0) {
1715 ci->lport = a2port(p + 6);
1716 if (ci->lport == -1) {
1717 fprintf(stderr, "Invalid port '%s' in test mode"
1718 " specification %s\n", p+6, p);
1719 return -1;
1720 }
1721 } else {
1722 fprintf(stderr, "Invalid test mode specification %s\n",
1723 p);
1724 return -1;
1725 }
1726 }
1727 return 0;
1728}
1729
1730/*
1731 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1732 * empty spec.
1733 */
1734int server_match_spec_complete(struct connection_info *ci)
1735{
1736 if (ci->user && ci->host && ci->address)
1737 return 1; /* complete */
1738 if (!ci->user && !ci->host && !ci->address)
1739 return -1; /* empty */
1740 return 0; /* partial */
1741}
1742
Darren Tucker1629c072007-02-19 22:25:37 +11001743/*
1744 * Copy any supported values that are set.
1745 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001746 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001747 * array values that are not used pre-authentication, because any that we
1748 * do use must be explictly sent in mm_getpwnamallow().
1749 */
Darren Tucker45150472006-07-12 22:34:17 +10001750void
Darren Tucker1629c072007-02-19 22:25:37 +11001751copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001752{
Damien Miller534b2cc2013-12-05 14:07:27 +11001753#define M_CP_INTOPT(n) do {\
1754 if (src->n != -1) \
1755 dst->n = src->n; \
1756} while (0)
1757
Darren Tucker1629c072007-02-19 22:25:37 +11001758 M_CP_INTOPT(password_authentication);
1759 M_CP_INTOPT(gss_authentication);
1760 M_CP_INTOPT(rsa_authentication);
1761 M_CP_INTOPT(pubkey_authentication);
1762 M_CP_INTOPT(kerberos_authentication);
1763 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001764 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001765 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001766 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001767 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001768
1769 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001770 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001771 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001772 M_CP_INTOPT(gateway_ports);
1773 M_CP_INTOPT(x11_display_offset);
1774 M_CP_INTOPT(x11_forwarding);
1775 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001776 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001777 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001778 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001779 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001780 M_CP_INTOPT(ip_qos_interactive);
1781 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001782 M_CP_INTOPT(rekey_limit);
1783 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001784
Damien Miller534b2cc2013-12-05 14:07:27 +11001785 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1786#define M_CP_STROPT(n) do {\
1787 if (src->n != NULL && dst->n != src->n) { \
1788 free(dst->n); \
1789 dst->n = src->n; \
1790 } \
1791} while(0)
1792#define M_CP_STRARRAYOPT(n, num_n) do {\
1793 if (src->num_n != 0) { \
1794 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1795 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1796 } \
1797} while(0)
1798
Damien Millerf2e407e2011-05-20 19:04:14 +10001799 /* See comment in servconf.h */
1800 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001801
Damien Millerc2411902011-05-20 19:03:49 +10001802 /*
1803 * The only things that should be below this point are string options
1804 * which are only used after authentication.
1805 */
Damien Miller5d74e582011-05-20 19:03:31 +10001806 if (preauth)
1807 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001808
Damien Miller5d74e582011-05-20 19:03:31 +10001809 M_CP_STROPT(adm_forced_command);
1810 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001811}
1812
Darren Tucker1629c072007-02-19 22:25:37 +11001813#undef M_CP_INTOPT
1814#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001815#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001816
Darren Tucker45150472006-07-12 22:34:17 +10001817void
1818parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001819 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001820{
1821 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001822 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001823
1824 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1825
Darren Tucker9fbac712004-08-12 22:41:44 +10001826 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001827 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001828 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001829 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001830 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001831 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001832 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001833 }
Darren Tuckera627d422013-06-02 07:31:17 +10001834 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001835 if (bad_options > 0)
1836 fatal("%s: terminating, %d bad configuration options",
1837 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001838}
Darren Tuckere7140f22008-06-10 23:01:51 +10001839
1840static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001841fmt_multistate_int(int val, const struct multistate *m)
1842{
1843 u_int i;
1844
1845 for (i = 0; m[i].key != NULL; i++) {
1846 if (m[i].value == val)
1847 return m[i].key;
1848 }
1849 return "UNKNOWN";
1850}
1851
1852static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001853fmt_intarg(ServerOpCodes code, int val)
1854{
Damien Miller82c55872011-06-23 08:20:30 +10001855 if (val == -1)
1856 return "unset";
1857 switch (code) {
1858 case sAddressFamily:
1859 return fmt_multistate_int(val, multistate_addressfamily);
1860 case sPermitRootLogin:
1861 return fmt_multistate_int(val, multistate_permitrootlogin);
1862 case sGatewayPorts:
1863 return fmt_multistate_int(val, multistate_gatewayports);
1864 case sCompression:
1865 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001866 case sUsePrivilegeSeparation:
1867 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001868 case sAllowTcpForwarding:
1869 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001870 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001871 switch (val) {
1872 case SSH_PROTO_1:
1873 return "1";
1874 case SSH_PROTO_2:
1875 return "2";
1876 case (SSH_PROTO_1|SSH_PROTO_2):
1877 return "2,1";
1878 default:
1879 return "UNKNOWN";
1880 }
Damien Miller82c55872011-06-23 08:20:30 +10001881 default:
1882 switch (val) {
1883 case 0:
1884 return "no";
1885 case 1:
1886 return "yes";
1887 default:
1888 return "UNKNOWN";
1889 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001890 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001891}
1892
1893static const char *
1894lookup_opcode_name(ServerOpCodes code)
1895{
1896 u_int i;
1897
1898 for (i = 0; keywords[i].name != NULL; i++)
1899 if (keywords[i].opcode == code)
1900 return(keywords[i].name);
1901 return "UNKNOWN";
1902}
1903
1904static void
1905dump_cfg_int(ServerOpCodes code, int val)
1906{
1907 printf("%s %d\n", lookup_opcode_name(code), val);
1908}
1909
1910static void
1911dump_cfg_fmtint(ServerOpCodes code, int val)
1912{
1913 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1914}
1915
1916static void
1917dump_cfg_string(ServerOpCodes code, const char *val)
1918{
1919 if (val == NULL)
1920 return;
1921 printf("%s %s\n", lookup_opcode_name(code), val);
1922}
1923
1924static void
1925dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1926{
1927 u_int i;
1928
1929 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001930 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1931}
1932
1933static void
1934dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1935{
1936 u_int i;
1937
1938 printf("%s", lookup_opcode_name(code));
1939 for (i = 0; i < count; i++)
1940 printf(" %s", vals[i]);
1941 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001942}
1943
1944void
1945dump_config(ServerOptions *o)
1946{
1947 u_int i;
1948 int ret;
1949 struct addrinfo *ai;
1950 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1951
1952 /* these are usually at the top of the config */
1953 for (i = 0; i < o->num_ports; i++)
1954 printf("port %d\n", o->ports[i]);
1955 dump_cfg_fmtint(sProtocol, o->protocol);
1956 dump_cfg_fmtint(sAddressFamily, o->address_family);
1957
1958 /* ListenAddress must be after Port */
1959 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1960 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1961 sizeof(addr), port, sizeof(port),
1962 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1963 error("getnameinfo failed: %.100s",
1964 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1965 strerror(errno));
1966 } else {
1967 if (ai->ai_family == AF_INET6)
1968 printf("listenaddress [%s]:%s\n", addr, port);
1969 else
1970 printf("listenaddress %s:%s\n", addr, port);
1971 }
1972 }
1973
1974 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001975#ifdef USE_PAM
1976 dump_cfg_int(sUsePAM, o->use_pam);
1977#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001978 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1979 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1980 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1981 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1982 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001983 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001984 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1985 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1986
1987 /* formatted integer arguments */
1988 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1989 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1990 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1991 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1992 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1993 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1994 o->hostbased_uses_name_from_packet_only);
1995 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1996 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001997#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001998 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1999 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2000 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002001# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002002 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002003# endif
2004#endif
2005#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002006 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2007 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002008#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002009 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2010 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2011 o->kbd_interactive_authentication);
2012 dump_cfg_fmtint(sChallengeResponseAuthentication,
2013 o->challenge_response_authentication);
2014 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2015 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2016 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2017 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002018 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002019 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002020 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2021 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2022 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2023 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2024 dump_cfg_fmtint(sUseLogin, o->use_login);
2025 dump_cfg_fmtint(sCompression, o->compression);
2026 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2027 dump_cfg_fmtint(sUseDNS, o->use_dns);
2028 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2029 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2030
2031 /* string arguments */
2032 dump_cfg_string(sPidFile, o->pid_file);
2033 dump_cfg_string(sXAuthLocation, o->xauth_location);
Damien Miller690d9892013-11-08 12:16:49 +11002034 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers :
Damien Miller0fde8ac2013-11-21 14:12:23 +11002035 cipher_alg_list(',', 0));
Damien Miller690d9892013-11-08 12:16:49 +11002036 dump_cfg_string(sMacs, o->macs ? o->macs : mac_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002037 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002038 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002039 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002040 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2041 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002042 dump_cfg_string(sAuthorizedPrincipalsFile,
2043 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002044 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002045 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2046 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002047 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Damien Miller690d9892013-11-08 12:16:49 +11002048 dump_cfg_string(sKexAlgorithms, o->kex_algorithms ? o->kex_algorithms :
2049 kex_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002050
2051 /* string arguments requiring a lookup */
2052 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2053 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2054
2055 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002056 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2057 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002058 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2059 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002060 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2061 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002062 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2063 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2064 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2065 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2066 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002067 dump_cfg_strarray_oneline(sAuthenticationMethods,
2068 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002069
2070 /* other arguments */
2071 for (i = 0; i < o->num_subsystems; i++)
2072 printf("subsystem %s %s\n", o->subsystem_name[i],
2073 o->subsystem_args[i]);
2074
2075 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2076 o->max_startups_rate, o->max_startups);
2077
2078 for (i = 0; tunmode_desc[i].val != -1; i++)
2079 if (tunmode_desc[i].val == o->permit_tun) {
2080 s = tunmode_desc[i].text;
2081 break;
2082 }
2083 dump_cfg_string(sPermitTunnel, s);
2084
Damien Miller91475862011-05-05 14:14:34 +10002085 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2086 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002087
Damien Millera6d6c1f2013-08-21 02:40:01 +10002088 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2089 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002090
Darren Tuckere7140f22008-06-10 23:01:51 +10002091 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002092}