blob: 99396fb1d642fad924a4ec46f19029a50f3c7cfe [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00002/* $OpenBSD: servconf.c,v 1.255 2014/11/24 03:39:22 jsg 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 Miller7acefbb2014-07-18 14:11:24 +100042#include "misc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100043#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100044#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000045#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046#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"
djm@openbsd.org57d378e2014-08-19 23:58:28 +000057#include "myproposal.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000058
Damien Miller3dc71ad2009-01-28 16:31:22 +110059static void add_listen_addr(ServerOptions *, char *, int);
60static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110061
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000062/* Use of privilege separation or not */
63extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100064extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000065
Damien Millerd4a8b7e1999-10-27 13:42:43 +100066/* Initializes the server options to their default values. */
67
Damien Miller4af51302000-04-16 11:18:38 +100068void
Damien Miller95def091999-11-25 00:26:21 +110069initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100070{
Damien Miller95def091999-11-25 00:26:21 +110071 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110072
73 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100074 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110075
76 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110077 options->num_ports = 0;
78 options->ports_from_cmdline = 0;
79 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110080 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110081 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110082 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100083 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100084 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110085 options->server_key_bits = -1;
86 options->login_grace_time = -1;
87 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000088 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110089 options->ignore_rhosts = -1;
90 options->ignore_user_known_hosts = -1;
91 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000092 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110093 options->x11_forwarding = -1;
94 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110095 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110096 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +100097 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100098 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110099 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +1100100 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100101 options->log_facility = SYSLOG_FACILITY_NOT_SET;
102 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000104 options->hostbased_authentication = -1;
105 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100107 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100108 options->kerberos_authentication = -1;
109 options->kerberos_or_local_passwd = -1;
110 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100111 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000112 options->gss_authentication=-1;
113 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100114 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100115 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000116 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100117 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000118 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100119 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000120 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000121 options->rekey_limit = -1;
122 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100123 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000124 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000125 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100126 options->num_allow_users = 0;
127 options->num_deny_users = 0;
128 options->num_allow_groups = 0;
129 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000130 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000131 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000132 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000133 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller7acefbb2014-07-18 14:11:24 +1000134 options->fwd_opts.gateway_ports = -1;
135 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
136 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000137 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000138 options->max_startups_begin = -1;
139 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000140 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000141 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000142 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000143 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000144 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000145 options->client_alive_interval = -1;
146 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000147 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000148 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100149 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000150 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000151 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100152 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100153 options->authorized_keys_command = NULL;
154 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100155 options->revoked_keys_file = NULL;
156 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000157 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100158 options->ip_qos_interactive = -1;
159 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000160 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000161}
162
Damien Miller4af51302000-04-16 11:18:38 +1000163void
Damien Miller95def091999-11-25 00:26:21 +1100164fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000165{
Damien Miller726273e2001-11-12 11:40:11 +1100166 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000167 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000168 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100169
170 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100171 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100172 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100173 if (options->num_host_key_files == 0) {
174 /* fill default hostkeys for protocols */
175 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100176 options->host_key_files[options->num_host_key_files++] =
177 _PATH_HOST_KEY_FILE;
178 if (options->protocol & SSH_PROTO_2) {
179 options->host_key_files[options->num_host_key_files++] =
180 _PATH_HOST_RSA_KEY_FILE;
181 options->host_key_files[options->num_host_key_files++] =
182 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100183#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000184 options->host_key_files[options->num_host_key_files++] =
185 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100186#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100187 options->host_key_files[options->num_host_key_files++] =
188 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100189 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100190 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100191 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100192 if (options->num_ports == 0)
193 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
194 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000195 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000196 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000197 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000199 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100200 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000201 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->key_regeneration_time == -1)
203 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000204 if (options->permit_root_login == PERMIT_NOT_SET)
205 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100206 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100207 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->ignore_user_known_hosts == -1)
209 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->print_motd == -1)
211 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000212 if (options->print_lastlog == -1)
213 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100214 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100215 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100216 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100217 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100218 if (options->x11_use_localhost == -1)
219 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000220 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000221 options->xauth_location = _PATH_XAUTH;
Damien Miller5ff30c62013-10-30 22:21:50 +1100222 if (options->permit_tty == -1)
223 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000224 if (options->permit_user_rc == -1)
225 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->strict_modes == -1)
227 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100228 if (options->tcp_keep_alive == -1)
229 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100230 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100231 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100232 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000233 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100235 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000236 if (options->hostbased_authentication == -1)
237 options->hostbased_authentication = 0;
238 if (options->hostbased_uses_name_from_packet_only == -1)
239 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100240 if (options->rsa_authentication == -1)
241 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100242 if (options->pubkey_authentication == -1)
243 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100244 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000245 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100246 if (options->kerberos_or_local_passwd == -1)
247 options->kerberos_or_local_passwd = 1;
248 if (options->kerberos_ticket_cleanup == -1)
249 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100250 if (options->kerberos_get_afs_token == -1)
251 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000252 if (options->gss_authentication == -1)
253 options->gss_authentication = 0;
254 if (options->gss_cleanup_creds == -1)
255 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100256 if (options->password_authentication == -1)
257 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100258 if (options->kbd_interactive_authentication == -1)
259 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000260 if (options->challenge_response_authentication == -1)
261 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100262 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100263 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000264 if (options->permit_user_env == -1)
265 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100266 if (options->use_login == -1)
267 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000268 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000269 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000270 if (options->rekey_limit == -1)
271 options->rekey_limit = 0;
272 if (options->rekey_interval == -1)
273 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100274 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100275 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000276 if (options->allow_streamlocal_forwarding == -1)
277 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000278 if (options->allow_agent_forwarding == -1)
279 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000280 if (options->fwd_opts.gateway_ports == -1)
281 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000282 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100283 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000284 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100285 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000286 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100287 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000288 if (options->max_authtries == -1)
289 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000290 if (options->max_sessions == -1)
291 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000292 if (options->use_dns == -1)
293 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000294 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100295 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000296 if (options->client_alive_count_max == -1)
297 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000298 if (options->num_authkeys_files == 0) {
299 options->authorized_keys_files[options->num_authkeys_files++] =
300 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
301 options->authorized_keys_files[options->num_authkeys_files++] =
302 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
303 }
Damien Millerd27b9472005-12-13 19:29:02 +1100304 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100305 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100306 if (options->ip_qos_interactive == -1)
307 options->ip_qos_interactive = IPTOS_LOWDELAY;
308 if (options->ip_qos_bulk == -1)
309 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000310 if (options->version_addendum == NULL)
311 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000312 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
313 options->fwd_opts.streamlocal_bind_mask = 0177;
314 if (options->fwd_opts.streamlocal_bind_unlink == -1)
315 options->fwd_opts.streamlocal_bind_unlink = 0;
Ben Lindstromfb62a692002-06-06 19:47:11 +0000316 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000317 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000318 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000319
Tim Rice40017b02002-07-14 13:36:49 -0700320#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000321 if (use_privsep && options->compression == 1) {
322 error("This platform does not support both privilege "
323 "separation and compression");
324 error("Compression disabled");
325 options->compression = 0;
326 }
327#endif
328
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000329}
330
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000331/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100332typedef enum {
333 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100334 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000335 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100336 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100337 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
338 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000339 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100340 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100341 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000342 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100343 sPasswordAuthentication, sKbdInteractiveAuthentication,
344 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000345 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100346 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100347 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000348 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000349 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000350 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000351 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000352 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000353 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100354 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000355 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100356 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100357 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100358 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100359 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000360 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000361 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100362 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000363 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000364 sStreamLocalBindMask, sStreamLocalBindUnlink,
365 sAllowStreamLocalForwarding,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000366 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000367} ServerOpCodes;
368
Darren Tucker45150472006-07-12 22:34:17 +1000369#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
370#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
371#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
372
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000373/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100374static struct {
375 const char *name;
376 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000377 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100378} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100379 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000380#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000381 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000382#else
Darren Tucker45150472006-07-12 22:34:17 +1000383 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000384#endif
Darren Tucker45150472006-07-12 22:34:17 +1000385 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100386 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000387 { "port", sPort, SSHCFG_GLOBAL },
388 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
389 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000390 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000391 { "pidfile", sPidFile, SSHCFG_GLOBAL },
392 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
393 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
394 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100395 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000396 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
397 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
398 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100399 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
400 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000401 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100402 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
403 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000404 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000405#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100406 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000407 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
408 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100409#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000410 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000411#else
Darren Tucker45150472006-07-12 22:34:17 +1000412 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100413#endif
414#else
Darren Tucker1629c072007-02-19 22:25:37 +1100415 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000416 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
417 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
418 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000419#endif
Darren Tucker45150472006-07-12 22:34:17 +1000420 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
421 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000422#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100423 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000424 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000425#else
Darren Tucker1629c072007-02-19 22:25:37 +1100426 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000427 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000428#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100429 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
430 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100431 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000432 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
433 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
434 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
435 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
436 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
437 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
438 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
439 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000440 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
441 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
442 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000443 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
444 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100445 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
447 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
448 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000449 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000450 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
451 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
452 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000453 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000454 { "allowusers", sAllowUsers, SSHCFG_ALL },
455 { "denyusers", sDenyUsers, SSHCFG_ALL },
456 { "allowgroups", sAllowGroups, SSHCFG_ALL },
457 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000458 { "ciphers", sCiphers, SSHCFG_GLOBAL },
459 { "macs", sMacs, SSHCFG_GLOBAL },
460 { "protocol", sProtocol, SSHCFG_GLOBAL },
461 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
462 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
463 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000464 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000465 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100466 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000467 { "usedns", sUseDNS, SSHCFG_GLOBAL },
468 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
469 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
470 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
471 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000472 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000473 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000474 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000475 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000476 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100477 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000478 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000479 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000480 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000481 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100482 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100483 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100484 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
485 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000486 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000487 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100488 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100489 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
490 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000491 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100492 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000493 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
494 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
495 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000496 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000497};
498
Darren Tuckere7140f22008-06-10 23:01:51 +1000499static struct {
500 int val;
501 char *text;
502} tunmode_desc[] = {
503 { SSH_TUNMODE_NO, "no" },
504 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
505 { SSH_TUNMODE_ETHERNET, "ethernet" },
506 { SSH_TUNMODE_YES, "yes" },
507 { -1, NULL }
508};
509
Damien Miller5428f641999-11-25 11:54:57 +1100510/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000511 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100512 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000513
Damien Miller4af51302000-04-16 11:18:38 +1000514static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100515parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000516 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000517{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000518 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000519
Damien Miller95def091999-11-25 00:26:21 +1100520 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000521 if (strcasecmp(cp, keywords[i].name) == 0) {
522 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100523 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000524 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000525
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000526 error("%s: line %d: Bad configuration option: %s",
527 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100528 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000529}
530
Darren Tucker88b6fb22010-01-13 22:44:29 +1100531char *
532derelativise_path(const char *path)
533{
Damien Miller44451d02010-03-26 10:40:04 +1100534 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100535
536 expanded = tilde_expand_filename(path, getuid());
537 if (*expanded == '/')
538 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100539 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100540 fatal("%s: getcwd: %s", __func__, strerror(errno));
541 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000542 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100543 return ret;
544}
545
Ben Lindstrombba81212001-06-25 05:01:22 +0000546static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100547add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100548{
Damien Millereccb9de2005-06-17 12:59:34 +1000549 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100550
551 if (options->num_ports == 0)
552 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100553 if (options->address_family == -1)
554 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000555 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000556 for (i = 0; i < options->num_ports; i++)
557 add_one_listen_addr(options, addr, options->ports[i]);
558 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000559 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000560}
561
Ben Lindstrombba81212001-06-25 05:01:22 +0000562static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100563add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000564{
565 struct addrinfo hints, *ai, *aitop;
566 char strport[NI_MAXSERV];
567 int gaierr;
568
569 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100570 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000571 hints.ai_socktype = SOCK_STREAM;
572 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100573 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000574 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
575 fatal("bad addr or host: %s (%s)",
576 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100577 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000578 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
579 ;
580 ai->ai_next = options->listen_addrs;
581 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100582}
583
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000584struct connection_info *
585get_connection_info(int populate, int use_dns)
586{
587 static struct connection_info ci;
588
589 if (!populate)
590 return &ci;
591 ci.host = get_canonical_hostname(use_dns);
592 ci.address = get_remote_ipaddr();
593 ci.laddress = get_local_ipaddr(packet_get_connection_in());
594 ci.lport = get_local_port();
595 return &ci;
596}
597
Darren Tucker45150472006-07-12 22:34:17 +1000598/*
599 * The strategy for the Match blocks is that the config file is parsed twice.
600 *
601 * The first time is at startup. activep is initialized to 1 and the
602 * directives in the global context are processed and acted on. Hitting a
603 * Match directive unsets activep and the directives inside the block are
604 * checked for syntax only.
605 *
606 * The second time is after a connection has been established but before
607 * authentication. activep is initialized to 2 and global config directives
608 * are ignored since they have already been processed. If the criteria in a
609 * Match block is met, activep is set and the subsequent directives
610 * processed and actioned until EOF or another Match block unsets it. Any
611 * options set are copied into the main server config.
612 *
613 * Potential additions/improvements:
614 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
615 *
616 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
617 * Match Address 192.168.0.*
618 * Tag trusted
619 * Match Group wheel
620 * Tag trusted
621 * Match Tag trusted
622 * AllowTcpForwarding yes
623 * GatewayPorts clientspecified
624 * [...]
625 *
626 * - Add a PermittedChannelRequests directive
627 * Match Group shell
628 * PermittedChannelRequests session,forwarded-tcpip
629 */
630
631static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000632match_cfg_line_group(const char *grps, int line, const char *user)
633{
634 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000635 struct passwd *pw;
636
Damien Miller565ca3f2006-08-19 00:23:15 +1000637 if (user == NULL)
638 goto out;
639
640 if ((pw = getpwnam(user)) == NULL) {
641 debug("Can't match group at line %d because user %.100s does "
642 "not exist", line, user);
643 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
644 debug("Can't Match group because user %.100s not in any group "
645 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000646 } else if (ga_match_pattern_list(grps) != 1) {
647 debug("user %.100s does not match group list %.100s at line %d",
648 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000649 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000650 debug("user %.100s matched group list %.100s at line %d", user,
651 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000652 result = 1;
653 }
654out:
655 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000656 return result;
657}
658
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000659/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000660 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100661 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000662 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000663 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000664static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000665match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000666{
Damien Millercf31f382013-10-24 21:02:56 +1100667 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000668 char *arg, *attrib, *cp = *condition;
669 size_t len;
670
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000671 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000672 debug3("checking syntax for 'Match %s'", cp);
673 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000674 debug3("checking match for '%s' user %s host %s addr %s "
675 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
676 ci->host ? ci->host : "(null)",
677 ci->address ? ci->address : "(null)",
678 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000679
680 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100681 attributes++;
682 if (strcasecmp(attrib, "all") == 0) {
683 if (attributes != 1 ||
684 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
685 error("'all' cannot be combined with other "
686 "Match attributes");
687 return -1;
688 }
689 *condition = cp;
690 return 1;
691 }
Darren Tucker45150472006-07-12 22:34:17 +1000692 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
693 error("Missing Match criteria for %s", attrib);
694 return -1;
695 }
696 len = strlen(arg);
697 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000698 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000699 result = 0;
700 continue;
701 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000702 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000703 result = 0;
704 else
705 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000706 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000707 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000708 if (ci == NULL || ci->user == NULL) {
709 result = 0;
710 continue;
711 }
712 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000713 case -1:
714 return -1;
715 case 0:
716 result = 0;
717 }
Darren Tucker45150472006-07-12 22:34:17 +1000718 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000719 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000720 result = 0;
721 continue;
722 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000723 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000724 result = 0;
725 else
726 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000727 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000728 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000729 if (ci == NULL || ci->address == NULL) {
730 result = 0;
731 continue;
732 }
733 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000734 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000735 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000736 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000737 break;
738 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000739 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000740 result = 0;
741 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000742 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000743 return -1;
744 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000745 } else if (strcasecmp(attrib, "localaddress") == 0){
746 if (ci == NULL || ci->laddress == NULL) {
747 result = 0;
748 continue;
749 }
750 switch (addr_match_list(ci->laddress, arg)) {
751 case 1:
752 debug("connection from %.100s matched "
753 "'LocalAddress %.100s' at line %d",
754 ci->laddress, arg, line);
755 break;
756 case 0:
757 case -1:
758 result = 0;
759 break;
760 case -2:
761 return -1;
762 }
763 } else if (strcasecmp(attrib, "localport") == 0) {
764 if ((port = a2port(arg)) == -1) {
765 error("Invalid LocalPort '%s' on Match line",
766 arg);
767 return -1;
768 }
769 if (ci == NULL || ci->lport == 0) {
770 result = 0;
771 continue;
772 }
773 /* TODO support port lists */
774 if (port == ci->lport)
775 debug("connection from %.100s matched "
776 "'LocalPort %d' at line %d",
777 ci->laddress, port, line);
778 else
779 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000780 } else {
781 error("Unsupported Match attribute %s", attrib);
782 return -1;
783 }
784 }
Damien Millercf31f382013-10-24 21:02:56 +1100785 if (attributes == 0) {
786 error("One or more attributes required for Match");
787 return -1;
788 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000789 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000790 debug3("match %sfound", result ? "" : "not ");
791 *condition = cp;
792 return result;
793}
794
Damien Millere2754432006-07-24 14:06:47 +1000795#define WHITESPACE " \t\r\n"
796
Damien Miller33322122011-06-20 14:43:11 +1000797/* Multistate option parsing */
798struct multistate {
799 char *key;
800 int value;
801};
802static const struct multistate multistate_addressfamily[] = {
803 { "inet", AF_INET },
804 { "inet6", AF_INET6 },
805 { "any", AF_UNSPEC },
806 { NULL, -1 }
807};
808static const struct multistate multistate_permitrootlogin[] = {
809 { "without-password", PERMIT_NO_PASSWD },
810 { "forced-commands-only", PERMIT_FORCED_ONLY },
811 { "yes", PERMIT_YES },
812 { "no", PERMIT_NO },
813 { NULL, -1 }
814};
815static const struct multistate multistate_compression[] = {
816 { "delayed", COMP_DELAYED },
817 { "yes", COMP_ZLIB },
818 { "no", COMP_NONE },
819 { NULL, -1 }
820};
821static const struct multistate multistate_gatewayports[] = {
822 { "clientspecified", 2 },
823 { "yes", 1 },
824 { "no", 0 },
825 { NULL, -1 }
826};
Damien Miller69ff1df2011-06-23 08:30:03 +1000827static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000828 { "yes", PRIVSEP_NOSANDBOX },
829 { "sandbox", PRIVSEP_ON },
830 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000831 { "no", PRIVSEP_OFF },
832 { NULL, -1 }
833};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100834static const struct multistate multistate_tcpfwd[] = {
835 { "yes", FORWARD_ALLOW },
836 { "all", FORWARD_ALLOW },
837 { "no", FORWARD_DENY },
838 { "remote", FORWARD_REMOTE },
839 { "local", FORWARD_LOCAL },
840 { NULL, -1 }
841};
Damien Miller33322122011-06-20 14:43:11 +1000842
Ben Lindstromade03f62001-12-06 18:22:17 +0000843int
844process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000845 const char *filename, int linenum, int *activep,
846 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000847{
Darren Tucker09c0f032013-05-16 20:48:57 +1000848 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000849 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100850 SyslogFacility *log_facility_ptr;
851 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000852 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000853 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000854 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000855 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000856 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000857
858 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100859 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100860 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000861 /* Ignore leading whitespace */
862 if (*arg == '\0')
863 arg = strdelim(&cp);
864 if (!arg || !*arg || *arg == '#')
865 return 0;
866 intptr = NULL;
867 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000868 opcode = parse_token(arg, filename, linenum, &flags);
869
870 if (activep == NULL) { /* We are processing a command line directive */
871 cmdline = 1;
872 activep = &cmdline;
873 }
874 if (*activep && opcode != sMatch)
875 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
876 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000877 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000878 fatal("%s line %d: Directive '%s' is not allowed "
879 "within a Match block", filename, linenum, arg);
880 } else { /* this is a directive we have already processed */
881 while (arg)
882 arg = strdelim(&cp);
883 return 0;
884 }
885 }
886
Ben Lindstromade03f62001-12-06 18:22:17 +0000887 switch (opcode) {
888 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000889 case sUsePAM:
890 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000891 goto parse_flag;
892
893 /* Standard Options */
894 case sBadOption:
895 return -1;
896 case sPort:
897 /* ignore ports from configfile if cmdline specifies ports */
898 if (options->ports_from_cmdline)
899 return 0;
900 if (options->listen_addrs != NULL)
901 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100902 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000903 if (options->num_ports >= MAX_PORTS)
904 fatal("%s line %d: too many ports.",
905 filename, linenum);
906 arg = strdelim(&cp);
907 if (!arg || *arg == '\0')
908 fatal("%s line %d: missing port number.",
909 filename, linenum);
910 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100911 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000912 fatal("%s line %d: Badly formatted port number.",
913 filename, linenum);
914 break;
915
916 case sServerKeyBits:
917 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000918 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000919 arg = strdelim(&cp);
920 if (!arg || *arg == '\0')
921 fatal("%s line %d: missing integer value.",
922 filename, linenum);
923 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000924 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000925 *intptr = value;
926 break;
927
928 case sLoginGraceTime:
929 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000930 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000931 arg = strdelim(&cp);
932 if (!arg || *arg == '\0')
933 fatal("%s line %d: missing time value.",
934 filename, linenum);
935 if ((value = convtime(arg)) == -1)
936 fatal("%s line %d: invalid time value.",
937 filename, linenum);
938 if (*intptr == -1)
939 *intptr = value;
940 break;
941
942 case sKeyRegenerationTime:
943 intptr = &options->key_regeneration_time;
944 goto parse_time;
945
946 case sListenAddress:
947 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100948 if (arg == NULL || *arg == '\0')
949 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000950 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000951 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
952 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
953 && strchr(p+1, ':') != NULL) {
954 add_listen_addr(options, arg, 0);
955 break;
956 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100957 p = hpdelim(&arg);
958 if (p == NULL)
959 fatal("%s line %d: bad address:port usage",
960 filename, linenum);
961 p = cleanhostname(p);
962 if (arg == NULL)
963 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100964 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100965 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000966
Damien Millerf91ee4c2005-03-01 21:24:33 +1100967 add_listen_addr(options, p, port);
968
Ben Lindstromade03f62001-12-06 18:22:17 +0000969 break;
970
Darren Tucker0f383232005-01-20 10:57:56 +1100971 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000972 intptr = &options->address_family;
973 multistate_ptr = multistate_addressfamily;
974 if (options->listen_addrs != NULL)
975 fatal("%s line %d: address family must be specified "
976 "before ListenAddress.", filename, linenum);
977 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100978 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000979 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000980 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000981 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000982 value = -1;
983 for (i = 0; multistate_ptr[i].key != NULL; i++) {
984 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
985 value = multistate_ptr[i].value;
986 break;
987 }
988 }
989 if (value == -1)
990 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100991 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000992 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100993 *intptr = value;
994 break;
995
Ben Lindstromade03f62001-12-06 18:22:17 +0000996 case sHostKeyFile:
997 intptr = &options->num_host_key_files;
998 if (*intptr >= MAX_HOSTKEYS)
999 fatal("%s line %d: too many host keys specified (max %d).",
1000 filename, linenum, MAX_HOSTKEYS);
1001 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001002 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001003 arg = strdelim(&cp);
1004 if (!arg || *arg == '\0')
1005 fatal("%s line %d: missing file name.",
1006 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001007 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001008 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001009 /* increase optional counter */
1010 if (intptr != NULL)
1011 *intptr = *intptr + 1;
1012 }
1013 break;
1014
Damien Miller85b45e02013-07-20 13:21:52 +10001015 case sHostKeyAgent:
1016 charptr = &options->host_key_agent;
1017 arg = strdelim(&cp);
1018 if (!arg || *arg == '\0')
1019 fatal("%s line %d: missing socket name.",
1020 filename, linenum);
1021 if (*activep && *charptr == NULL)
1022 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1023 xstrdup(arg) : derelativise_path(arg);
1024 break;
1025
Damien Miller0a80ca12010-02-27 07:55:05 +11001026 case sHostCertificate:
1027 intptr = &options->num_host_cert_files;
1028 if (*intptr >= MAX_HOSTKEYS)
1029 fatal("%s line %d: too many host certificates "
1030 "specified (max %d).", filename, linenum,
1031 MAX_HOSTCERTS);
1032 charptr = &options->host_cert_files[*intptr];
1033 goto parse_filename;
1034 break;
1035
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 case sPidFile:
1037 charptr = &options->pid_file;
1038 goto parse_filename;
1039
1040 case sPermitRootLogin:
1041 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001042 multistate_ptr = multistate_permitrootlogin;
1043 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001044
1045 case sIgnoreRhosts:
1046 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001047 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001048 arg = strdelim(&cp);
1049 if (!arg || *arg == '\0')
1050 fatal("%s line %d: missing yes/no argument.",
1051 filename, linenum);
1052 value = 0; /* silence compiler */
1053 if (strcmp(arg, "yes") == 0)
1054 value = 1;
1055 else if (strcmp(arg, "no") == 0)
1056 value = 0;
1057 else
1058 fatal("%s line %d: Bad yes/no argument: %s",
1059 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001060 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001061 *intptr = value;
1062 break;
1063
1064 case sIgnoreUserKnownHosts:
1065 intptr = &options->ignore_user_known_hosts;
1066 goto parse_flag;
1067
Ben Lindstromade03f62001-12-06 18:22:17 +00001068 case sRhostsRSAAuthentication:
1069 intptr = &options->rhosts_rsa_authentication;
1070 goto parse_flag;
1071
1072 case sHostbasedAuthentication:
1073 intptr = &options->hostbased_authentication;
1074 goto parse_flag;
1075
1076 case sHostbasedUsesNameFromPacketOnly:
1077 intptr = &options->hostbased_uses_name_from_packet_only;
1078 goto parse_flag;
1079
1080 case sRSAAuthentication:
1081 intptr = &options->rsa_authentication;
1082 goto parse_flag;
1083
1084 case sPubkeyAuthentication:
1085 intptr = &options->pubkey_authentication;
1086 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001087
Ben Lindstromade03f62001-12-06 18:22:17 +00001088 case sKerberosAuthentication:
1089 intptr = &options->kerberos_authentication;
1090 goto parse_flag;
1091
1092 case sKerberosOrLocalPasswd:
1093 intptr = &options->kerberos_or_local_passwd;
1094 goto parse_flag;
1095
1096 case sKerberosTicketCleanup:
1097 intptr = &options->kerberos_ticket_cleanup;
1098 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001099
Darren Tucker22ef5082003-12-31 11:37:34 +11001100 case sKerberosGetAFSToken:
1101 intptr = &options->kerberos_get_afs_token;
1102 goto parse_flag;
1103
Darren Tucker0efd1552003-08-26 11:49:55 +10001104 case sGssAuthentication:
1105 intptr = &options->gss_authentication;
1106 goto parse_flag;
1107
1108 case sGssCleanupCreds:
1109 intptr = &options->gss_cleanup_creds;
1110 goto parse_flag;
1111
Ben Lindstromade03f62001-12-06 18:22:17 +00001112 case sPasswordAuthentication:
1113 intptr = &options->password_authentication;
1114 goto parse_flag;
1115
1116 case sKbdInteractiveAuthentication:
1117 intptr = &options->kbd_interactive_authentication;
1118 goto parse_flag;
1119
1120 case sChallengeResponseAuthentication:
1121 intptr = &options->challenge_response_authentication;
1122 goto parse_flag;
1123
1124 case sPrintMotd:
1125 intptr = &options->print_motd;
1126 goto parse_flag;
1127
1128 case sPrintLastLog:
1129 intptr = &options->print_lastlog;
1130 goto parse_flag;
1131
1132 case sX11Forwarding:
1133 intptr = &options->x11_forwarding;
1134 goto parse_flag;
1135
1136 case sX11DisplayOffset:
1137 intptr = &options->x11_display_offset;
1138 goto parse_int;
1139
Damien Miller95c249f2002-02-05 12:11:34 +11001140 case sX11UseLocalhost:
1141 intptr = &options->x11_use_localhost;
1142 goto parse_flag;
1143
Ben Lindstromade03f62001-12-06 18:22:17 +00001144 case sXAuthLocation:
1145 charptr = &options->xauth_location;
1146 goto parse_filename;
1147
Damien Miller5ff30c62013-10-30 22:21:50 +11001148 case sPermitTTY:
1149 intptr = &options->permit_tty;
1150 goto parse_flag;
1151
Damien Miller72e6b5c2014-07-04 09:00:04 +10001152 case sPermitUserRC:
1153 intptr = &options->permit_user_rc;
1154 goto parse_flag;
1155
Ben Lindstromade03f62001-12-06 18:22:17 +00001156 case sStrictModes:
1157 intptr = &options->strict_modes;
1158 goto parse_flag;
1159
Damien Miller12c150e2003-12-17 16:31:10 +11001160 case sTCPKeepAlive:
1161 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001162 goto parse_flag;
1163
1164 case sEmptyPasswd:
1165 intptr = &options->permit_empty_passwd;
1166 goto parse_flag;
1167
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001168 case sPermitUserEnvironment:
1169 intptr = &options->permit_user_env;
1170 goto parse_flag;
1171
Ben Lindstromade03f62001-12-06 18:22:17 +00001172 case sUseLogin:
1173 intptr = &options->use_login;
1174 goto parse_flag;
1175
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001176 case sCompression:
1177 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001178 multistate_ptr = multistate_compression;
1179 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001180
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001181 case sRekeyLimit:
1182 arg = strdelim(&cp);
1183 if (!arg || *arg == '\0')
1184 fatal("%.200s line %d: Missing argument.", filename,
1185 linenum);
1186 if (strcmp(arg, "default") == 0) {
1187 val64 = 0;
1188 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001189 if (scan_scaled(arg, &val64) == -1)
1190 fatal("%.200s line %d: Bad number '%s': %s",
1191 filename, linenum, arg, strerror(errno));
1192 /* check for too-large or too-small limits */
1193 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001194 fatal("%.200s line %d: RekeyLimit too large",
1195 filename, linenum);
1196 if (val64 != 0 && val64 < 16)
1197 fatal("%.200s line %d: RekeyLimit too small",
1198 filename, linenum);
1199 }
1200 if (*activep && options->rekey_limit == -1)
1201 options->rekey_limit = (u_int32_t)val64;
1202 if (cp != NULL) { /* optional rekey interval present */
1203 if (strcmp(cp, "none") == 0) {
1204 (void)strdelim(&cp); /* discard */
1205 break;
1206 }
1207 intptr = &options->rekey_interval;
1208 goto parse_time;
1209 }
1210 break;
1211
Ben Lindstromade03f62001-12-06 18:22:17 +00001212 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001213 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001214 multistate_ptr = multistate_gatewayports;
1215 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001216
Damien Miller3a961dc2003-06-03 10:25:48 +10001217 case sUseDNS:
1218 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001219 goto parse_flag;
1220
1221 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001222 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001223 arg = strdelim(&cp);
1224 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001225 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001226 fatal("%.200s line %d: unsupported log facility '%s'",
1227 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001228 if (*log_facility_ptr == -1)
1229 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001230 break;
1231
1232 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001233 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001234 arg = strdelim(&cp);
1235 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001236 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001237 fatal("%.200s line %d: unsupported log level '%s'",
1238 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001239 if (*log_level_ptr == -1)
1240 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001241 break;
1242
1243 case sAllowTcpForwarding:
1244 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001245 multistate_ptr = multistate_tcpfwd;
1246 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001247
Damien Miller7acefbb2014-07-18 14:11:24 +10001248 case sAllowStreamLocalForwarding:
1249 intptr = &options->allow_streamlocal_forwarding;
1250 multistate_ptr = multistate_tcpfwd;
1251 goto parse_multistate;
1252
Damien Miller4f755cd2008-05-19 14:57:41 +10001253 case sAllowAgentForwarding:
1254 intptr = &options->allow_agent_forwarding;
1255 goto parse_flag;
1256
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001257 case sUsePrivilegeSeparation:
1258 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001259 multistate_ptr = multistate_privsep;
1260 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001261
Ben Lindstromade03f62001-12-06 18:22:17 +00001262 case sAllowUsers:
1263 while ((arg = strdelim(&cp)) && *arg != '\0') {
1264 if (options->num_allow_users >= MAX_ALLOW_USERS)
1265 fatal("%s line %d: too many allow users.",
1266 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001267 if (!*activep)
1268 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001269 options->allow_users[options->num_allow_users++] =
1270 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001271 }
1272 break;
1273
1274 case sDenyUsers:
1275 while ((arg = strdelim(&cp)) && *arg != '\0') {
1276 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001277 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001278 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001279 if (!*activep)
1280 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001281 options->deny_users[options->num_deny_users++] =
1282 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001283 }
1284 break;
1285
1286 case sAllowGroups:
1287 while ((arg = strdelim(&cp)) && *arg != '\0') {
1288 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1289 fatal("%s line %d: too many allow groups.",
1290 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001291 if (!*activep)
1292 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001293 options->allow_groups[options->num_allow_groups++] =
1294 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001295 }
1296 break;
1297
1298 case sDenyGroups:
1299 while ((arg = strdelim(&cp)) && *arg != '\0') {
1300 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1301 fatal("%s line %d: too many deny groups.",
1302 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001303 if (!*activep)
1304 continue;
1305 options->deny_groups[options->num_deny_groups++] =
1306 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001307 }
1308 break;
1309
1310 case sCiphers:
1311 arg = strdelim(&cp);
1312 if (!arg || *arg == '\0')
1313 fatal("%s line %d: Missing argument.", filename, linenum);
1314 if (!ciphers_valid(arg))
1315 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1316 filename, linenum, arg ? arg : "<NONE>");
1317 if (options->ciphers == NULL)
1318 options->ciphers = xstrdup(arg);
1319 break;
1320
1321 case sMacs:
1322 arg = strdelim(&cp);
1323 if (!arg || *arg == '\0')
1324 fatal("%s line %d: Missing argument.", filename, linenum);
1325 if (!mac_valid(arg))
1326 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1327 filename, linenum, arg ? arg : "<NONE>");
1328 if (options->macs == NULL)
1329 options->macs = xstrdup(arg);
1330 break;
1331
Damien Millerd5f62bf2010-09-24 22:11:14 +10001332 case sKexAlgorithms:
1333 arg = strdelim(&cp);
1334 if (!arg || *arg == '\0')
1335 fatal("%s line %d: Missing argument.",
1336 filename, linenum);
1337 if (!kex_names_valid(arg))
1338 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1339 filename, linenum, arg ? arg : "<NONE>");
1340 if (options->kex_algorithms == NULL)
1341 options->kex_algorithms = xstrdup(arg);
1342 break;
1343
Ben Lindstromade03f62001-12-06 18:22:17 +00001344 case sProtocol:
1345 intptr = &options->protocol;
1346 arg = strdelim(&cp);
1347 if (!arg || *arg == '\0')
1348 fatal("%s line %d: Missing argument.", filename, linenum);
1349 value = proto_spec(arg);
1350 if (value == SSH_PROTO_UNKNOWN)
1351 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001352 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 if (*intptr == SSH_PROTO_UNKNOWN)
1354 *intptr = value;
1355 break;
1356
1357 case sSubsystem:
1358 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1359 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001360 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001361 }
1362 arg = strdelim(&cp);
1363 if (!arg || *arg == '\0')
1364 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001365 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001366 if (!*activep) {
1367 arg = strdelim(&cp);
1368 break;
1369 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001370 for (i = 0; i < options->num_subsystems; i++)
1371 if (strcmp(arg, options->subsystem_name[i]) == 0)
1372 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001373 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001374 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1375 arg = strdelim(&cp);
1376 if (!arg || *arg == '\0')
1377 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001378 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001379 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001380
1381 /* Collect arguments (separate to executable) */
1382 p = xstrdup(arg);
1383 len = strlen(p) + 1;
1384 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1385 len += 1 + strlen(arg);
1386 p = xrealloc(p, 1, len);
1387 strlcat(p, " ", len);
1388 strlcat(p, arg, len);
1389 }
1390 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001391 options->num_subsystems++;
1392 break;
1393
1394 case sMaxStartups:
1395 arg = strdelim(&cp);
1396 if (!arg || *arg == '\0')
1397 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001398 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001399 if ((n = sscanf(arg, "%d:%d:%d",
1400 &options->max_startups_begin,
1401 &options->max_startups_rate,
1402 &options->max_startups)) == 3) {
1403 if (options->max_startups_begin >
1404 options->max_startups ||
1405 options->max_startups_rate > 100 ||
1406 options->max_startups_rate < 1)
1407 fatal("%s line %d: Illegal MaxStartups spec.",
1408 filename, linenum);
1409 } else if (n != 1)
1410 fatal("%s line %d: Illegal MaxStartups spec.",
1411 filename, linenum);
1412 else
1413 options->max_startups = options->max_startups_begin;
1414 break;
1415
Darren Tucker89413db2004-05-24 10:36:23 +10001416 case sMaxAuthTries:
1417 intptr = &options->max_authtries;
1418 goto parse_int;
1419
Damien Miller7207f642008-05-19 15:34:50 +10001420 case sMaxSessions:
1421 intptr = &options->max_sessions;
1422 goto parse_int;
1423
Ben Lindstromade03f62001-12-06 18:22:17 +00001424 case sBanner:
1425 charptr = &options->banner;
1426 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001427
Ben Lindstromade03f62001-12-06 18:22:17 +00001428 /*
1429 * These options can contain %X options expanded at
1430 * connect time, so that you can specify paths like:
1431 *
1432 * AuthorizedKeysFile /etc/ssh_keys/%u
1433 */
1434 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001435 if (*activep && options->num_authkeys_files == 0) {
1436 while ((arg = strdelim(&cp)) && *arg != '\0') {
1437 if (options->num_authkeys_files >=
1438 MAX_AUTHKEYS_FILES)
1439 fatal("%s line %d: "
1440 "too many authorized keys files.",
1441 filename, linenum);
1442 options->authorized_keys_files[
1443 options->num_authkeys_files++] =
1444 tilde_expand_filename(arg, getuid());
1445 }
1446 }
1447 return 0;
1448
Damien Miller30da3442010-05-10 11:58:03 +10001449 case sAuthorizedPrincipalsFile:
1450 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001451 arg = strdelim(&cp);
1452 if (!arg || *arg == '\0')
1453 fatal("%s line %d: missing file name.",
1454 filename, linenum);
1455 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001456 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001457 /* increase optional counter */
1458 if (intptr != NULL)
1459 *intptr = *intptr + 1;
1460 }
1461 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001462
1463 case sClientAliveInterval:
1464 intptr = &options->client_alive_interval;
1465 goto parse_time;
1466
1467 case sClientAliveCountMax:
1468 intptr = &options->client_alive_count_max;
1469 goto parse_int;
1470
Darren Tucker46bc0752004-05-02 22:11:30 +10001471 case sAcceptEnv:
1472 while ((arg = strdelim(&cp)) && *arg != '\0') {
1473 if (strchr(arg, '=') != NULL)
1474 fatal("%s line %d: Invalid environment name.",
1475 filename, linenum);
1476 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1477 fatal("%s line %d: too many allow env.",
1478 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001479 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001480 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001481 options->accept_env[options->num_accept_env++] =
1482 xstrdup(arg);
1483 }
1484 break;
1485
Damien Millerd27b9472005-12-13 19:29:02 +11001486 case sPermitTunnel:
1487 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001488 arg = strdelim(&cp);
1489 if (!arg || *arg == '\0')
1490 fatal("%s line %d: Missing yes/point-to-point/"
1491 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001492 value = -1;
1493 for (i = 0; tunmode_desc[i].val != -1; i++)
1494 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1495 value = tunmode_desc[i].val;
1496 break;
1497 }
1498 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001499 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1500 "no argument: %s", filename, linenum, arg);
1501 if (*intptr == -1)
1502 *intptr = value;
1503 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001504
Darren Tucker45150472006-07-12 22:34:17 +10001505 case sMatch:
1506 if (cmdline)
1507 fatal("Match directive not supported as a command-line "
1508 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001509 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001510 if (value < 0)
1511 fatal("%s line %d: Bad Match condition", filename,
1512 linenum);
1513 *activep = value;
1514 break;
1515
Damien Miller9b439df2006-07-24 14:04:00 +10001516 case sPermitOpen:
1517 arg = strdelim(&cp);
1518 if (!arg || *arg == '\0')
1519 fatal("%s line %d: missing PermitOpen specification",
1520 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001521 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001522 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001523 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001524 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001525 options->num_permitted_opens = 0;
1526 }
Damien Miller9b439df2006-07-24 14:04:00 +10001527 break;
1528 }
Damien Millerc6081482012-04-22 11:18:53 +10001529 if (strcmp(arg, "none") == 0) {
1530 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001531 options->num_permitted_opens = 1;
1532 channel_disable_adm_local_opens();
1533 }
1534 break;
1535 }
Damien Millera29b95e2007-01-05 16:28:36 +11001536 if (*activep && n == -1)
1537 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001538 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1539 p = hpdelim(&arg);
1540 if (p == NULL)
1541 fatal("%s line %d: missing host in PermitOpen",
1542 filename, linenum);
1543 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001544 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001545 fatal("%s line %d: bad port number in "
1546 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001547 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001548 options->num_permitted_opens =
1549 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001550 }
Damien Miller9b439df2006-07-24 14:04:00 +10001551 break;
1552
Damien Millere2754432006-07-24 14:06:47 +10001553 case sForceCommand:
1554 if (cp == NULL)
1555 fatal("%.200s line %d: Missing argument.", filename,
1556 linenum);
1557 len = strspn(cp, WHITESPACE);
1558 if (*activep && options->adm_forced_command == NULL)
1559 options->adm_forced_command = xstrdup(cp + len);
1560 return 0;
1561
Damien Millerd8cb1f12008-02-10 22:40:12 +11001562 case sChrootDirectory:
1563 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001564
1565 arg = strdelim(&cp);
1566 if (!arg || *arg == '\0')
1567 fatal("%s line %d: missing file name.",
1568 filename, linenum);
1569 if (*activep && *charptr == NULL)
1570 *charptr = xstrdup(arg);
1571 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001572
Damien Miller1aed65e2010-03-04 21:53:35 +11001573 case sTrustedUserCAKeys:
1574 charptr = &options->trusted_user_ca_keys;
1575 goto parse_filename;
1576
1577 case sRevokedKeys:
1578 charptr = &options->revoked_keys_file;
1579 goto parse_filename;
1580
Damien Miller0dac6fb2010-11-20 15:19:38 +11001581 case sIPQoS:
1582 arg = strdelim(&cp);
1583 if ((value = parse_ipqos(arg)) == -1)
1584 fatal("%s line %d: Bad IPQoS value: %s",
1585 filename, linenum, arg);
1586 arg = strdelim(&cp);
1587 if (arg == NULL)
1588 value2 = value;
1589 else if ((value2 = parse_ipqos(arg)) == -1)
1590 fatal("%s line %d: Bad IPQoS value: %s",
1591 filename, linenum, arg);
1592 if (*activep) {
1593 options->ip_qos_interactive = value;
1594 options->ip_qos_bulk = value2;
1595 }
1596 break;
1597
Damien Miller23528812012-04-22 11:24:43 +10001598 case sVersionAddendum:
1599 if (cp == NULL)
1600 fatal("%.200s line %d: Missing argument.", filename,
1601 linenum);
1602 len = strspn(cp, WHITESPACE);
1603 if (*activep && options->version_addendum == NULL) {
1604 if (strcasecmp(cp + len, "none") == 0)
1605 options->version_addendum = xstrdup("");
1606 else if (strchr(cp + len, '\r') != NULL)
1607 fatal("%.200s line %d: Invalid argument",
1608 filename, linenum);
1609 else
1610 options->version_addendum = xstrdup(cp + len);
1611 }
1612 return 0;
1613
Damien Miller09d3e122012-10-31 08:58:58 +11001614 case sAuthorizedKeysCommand:
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001615 if (cp == NULL)
1616 fatal("%.200s line %d: Missing argument.", filename,
1617 linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001618 len = strspn(cp, WHITESPACE);
1619 if (*activep && options->authorized_keys_command == NULL) {
1620 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1621 fatal("%.200s line %d: AuthorizedKeysCommand "
1622 "must be an absolute path",
1623 filename, linenum);
1624 options->authorized_keys_command = xstrdup(cp + len);
1625 }
1626 return 0;
1627
1628 case sAuthorizedKeysCommandUser:
1629 charptr = &options->authorized_keys_command_user;
1630
1631 arg = strdelim(&cp);
jsg@openbsd.org72bba3d2014-11-24 03:39:22 +00001632 if (!arg || *arg == '\0')
1633 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1634 "argument.", filename, linenum);
Damien Miller09d3e122012-10-31 08:58:58 +11001635 if (*activep && *charptr == NULL)
1636 *charptr = xstrdup(arg);
1637 break;
1638
Damien Millera6e3f012012-11-04 23:21:40 +11001639 case sAuthenticationMethods:
1640 if (*activep && options->num_auth_methods == 0) {
1641 while ((arg = strdelim(&cp)) && *arg != '\0') {
1642 if (options->num_auth_methods >=
1643 MAX_AUTH_METHODS)
1644 fatal("%s line %d: "
1645 "too many authentication methods.",
1646 filename, linenum);
1647 if (auth2_methods_valid(arg, 0) != 0)
1648 fatal("%s line %d: invalid "
1649 "authentication method list.",
1650 filename, linenum);
1651 options->auth_methods[
1652 options->num_auth_methods++] = xstrdup(arg);
1653 }
1654 }
1655 return 0;
1656
Damien Miller7acefbb2014-07-18 14:11:24 +10001657 case sStreamLocalBindMask:
1658 arg = strdelim(&cp);
1659 if (!arg || *arg == '\0')
1660 fatal("%s line %d: missing StreamLocalBindMask argument.",
1661 filename, linenum);
1662 /* Parse mode in octal format */
1663 value = strtol(arg, &p, 8);
1664 if (arg == p || value < 0 || value > 0777)
1665 fatal("%s line %d: Bad mask.", filename, linenum);
1666 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1667 break;
1668
1669 case sStreamLocalBindUnlink:
1670 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1671 goto parse_flag;
1672
Ben Lindstromade03f62001-12-06 18:22:17 +00001673 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001674 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001675 filename, linenum, arg);
1676 while (arg)
1677 arg = strdelim(&cp);
1678 break;
1679
Damien Millerf9b3feb2003-05-16 11:38:32 +10001680 case sUnsupported:
1681 logit("%s line %d: Unsupported option %s",
1682 filename, linenum, arg);
1683 while (arg)
1684 arg = strdelim(&cp);
1685 break;
1686
Ben Lindstromade03f62001-12-06 18:22:17 +00001687 default:
1688 fatal("%s line %d: Missing handler for opcode %s (%d)",
1689 filename, linenum, arg, opcode);
1690 }
1691 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1692 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1693 filename, linenum, arg);
1694 return 0;
1695}
1696
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001697/* Reads the server configuration file. */
1698
Damien Miller4af51302000-04-16 11:18:38 +10001699void
Darren Tucker645ab752004-06-25 13:33:20 +10001700load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001701{
Damien Miller46cb75a2012-07-31 12:22:37 +10001702 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001703 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001704 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001705
Darren Tucker645ab752004-06-25 13:33:20 +10001706 debug2("%s: filename %s", __func__, filename);
1707 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001708 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001709 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001710 }
Darren Tucker645ab752004-06-25 13:33:20 +10001711 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001712 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001713 lineno++;
1714 if (strlen(line) == sizeof(line) - 1)
1715 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001716 /*
1717 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001718 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001719 * line numbers later for error messages
1720 */
1721 if ((cp = strchr(line, '#')) != NULL)
1722 memcpy(cp, "\n", 2);
1723 cp = line + strspn(line, " \t\r");
1724
1725 buffer_append(conf, cp, strlen(cp));
1726 }
1727 buffer_append(conf, "\0", 1);
1728 fclose(f);
1729 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1730}
1731
1732void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001733parse_server_match_config(ServerOptions *options,
1734 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001735{
Darren Tucker45150472006-07-12 22:34:17 +10001736 ServerOptions mo;
1737
1738 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001739 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001740 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001741}
1742
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001743int parse_server_match_testspec(struct connection_info *ci, char *spec)
1744{
1745 char *p;
1746
1747 while ((p = strsep(&spec, ",")) && *p != '\0') {
1748 if (strncmp(p, "addr=", 5) == 0) {
1749 ci->address = xstrdup(p + 5);
1750 } else if (strncmp(p, "host=", 5) == 0) {
1751 ci->host = xstrdup(p + 5);
1752 } else if (strncmp(p, "user=", 5) == 0) {
1753 ci->user = xstrdup(p + 5);
1754 } else if (strncmp(p, "laddr=", 6) == 0) {
1755 ci->laddress = xstrdup(p + 6);
1756 } else if (strncmp(p, "lport=", 6) == 0) {
1757 ci->lport = a2port(p + 6);
1758 if (ci->lport == -1) {
1759 fprintf(stderr, "Invalid port '%s' in test mode"
1760 " specification %s\n", p+6, p);
1761 return -1;
1762 }
1763 } else {
1764 fprintf(stderr, "Invalid test mode specification %s\n",
1765 p);
1766 return -1;
1767 }
1768 }
1769 return 0;
1770}
1771
1772/*
1773 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1774 * empty spec.
1775 */
1776int server_match_spec_complete(struct connection_info *ci)
1777{
1778 if (ci->user && ci->host && ci->address)
1779 return 1; /* complete */
1780 if (!ci->user && !ci->host && !ci->address)
1781 return -1; /* empty */
1782 return 0; /* partial */
1783}
1784
Darren Tucker1629c072007-02-19 22:25:37 +11001785/*
1786 * Copy any supported values that are set.
1787 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001788 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001789 * array values that are not used pre-authentication, because any that we
1790 * do use must be explictly sent in mm_getpwnamallow().
1791 */
Darren Tucker45150472006-07-12 22:34:17 +10001792void
Darren Tucker1629c072007-02-19 22:25:37 +11001793copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001794{
Damien Miller534b2cc2013-12-05 14:07:27 +11001795#define M_CP_INTOPT(n) do {\
1796 if (src->n != -1) \
1797 dst->n = src->n; \
1798} while (0)
1799
Darren Tucker1629c072007-02-19 22:25:37 +11001800 M_CP_INTOPT(password_authentication);
1801 M_CP_INTOPT(gss_authentication);
1802 M_CP_INTOPT(rsa_authentication);
1803 M_CP_INTOPT(pubkey_authentication);
1804 M_CP_INTOPT(kerberos_authentication);
1805 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001806 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001807 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001808 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001809 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001810
1811 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001812 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001813 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001814 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001815 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001816 M_CP_INTOPT(x11_display_offset);
1817 M_CP_INTOPT(x11_forwarding);
1818 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001819 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001820 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001821 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001822 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001823 M_CP_INTOPT(ip_qos_interactive);
1824 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001825 M_CP_INTOPT(rekey_limit);
1826 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001827
Damien Miller534b2cc2013-12-05 14:07:27 +11001828 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1829#define M_CP_STROPT(n) do {\
1830 if (src->n != NULL && dst->n != src->n) { \
1831 free(dst->n); \
1832 dst->n = src->n; \
1833 } \
1834} while(0)
1835#define M_CP_STRARRAYOPT(n, num_n) do {\
1836 if (src->num_n != 0) { \
1837 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1838 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1839 } \
1840} while(0)
1841
Damien Millerf2e407e2011-05-20 19:04:14 +10001842 /* See comment in servconf.h */
1843 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001844
Damien Millerc2411902011-05-20 19:03:49 +10001845 /*
1846 * The only things that should be below this point are string options
1847 * which are only used after authentication.
1848 */
Damien Miller5d74e582011-05-20 19:03:31 +10001849 if (preauth)
1850 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001851
Damien Miller5d74e582011-05-20 19:03:31 +10001852 M_CP_STROPT(adm_forced_command);
1853 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001854}
1855
Darren Tucker1629c072007-02-19 22:25:37 +11001856#undef M_CP_INTOPT
1857#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001858#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001859
Darren Tucker45150472006-07-12 22:34:17 +10001860void
1861parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001862 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001863{
1864 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001865 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001866
1867 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1868
Darren Tucker9fbac712004-08-12 22:41:44 +10001869 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001870 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001871 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001872 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001873 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001874 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001875 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001876 }
Darren Tuckera627d422013-06-02 07:31:17 +10001877 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001878 if (bad_options > 0)
1879 fatal("%s: terminating, %d bad configuration options",
1880 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001881}
Darren Tuckere7140f22008-06-10 23:01:51 +10001882
1883static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001884fmt_multistate_int(int val, const struct multistate *m)
1885{
1886 u_int i;
1887
1888 for (i = 0; m[i].key != NULL; i++) {
1889 if (m[i].value == val)
1890 return m[i].key;
1891 }
1892 return "UNKNOWN";
1893}
1894
1895static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001896fmt_intarg(ServerOpCodes code, int val)
1897{
Damien Miller82c55872011-06-23 08:20:30 +10001898 if (val == -1)
1899 return "unset";
1900 switch (code) {
1901 case sAddressFamily:
1902 return fmt_multistate_int(val, multistate_addressfamily);
1903 case sPermitRootLogin:
1904 return fmt_multistate_int(val, multistate_permitrootlogin);
1905 case sGatewayPorts:
1906 return fmt_multistate_int(val, multistate_gatewayports);
1907 case sCompression:
1908 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001909 case sUsePrivilegeSeparation:
1910 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001911 case sAllowTcpForwarding:
1912 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10001913 case sAllowStreamLocalForwarding:
1914 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001915 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001916 switch (val) {
1917 case SSH_PROTO_1:
1918 return "1";
1919 case SSH_PROTO_2:
1920 return "2";
1921 case (SSH_PROTO_1|SSH_PROTO_2):
1922 return "2,1";
1923 default:
1924 return "UNKNOWN";
1925 }
Damien Miller82c55872011-06-23 08:20:30 +10001926 default:
1927 switch (val) {
1928 case 0:
1929 return "no";
1930 case 1:
1931 return "yes";
1932 default:
1933 return "UNKNOWN";
1934 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001935 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001936}
1937
1938static const char *
1939lookup_opcode_name(ServerOpCodes code)
1940{
1941 u_int i;
1942
1943 for (i = 0; keywords[i].name != NULL; i++)
1944 if (keywords[i].opcode == code)
1945 return(keywords[i].name);
1946 return "UNKNOWN";
1947}
1948
1949static void
1950dump_cfg_int(ServerOpCodes code, int val)
1951{
1952 printf("%s %d\n", lookup_opcode_name(code), val);
1953}
1954
1955static void
1956dump_cfg_fmtint(ServerOpCodes code, int val)
1957{
1958 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1959}
1960
1961static void
1962dump_cfg_string(ServerOpCodes code, const char *val)
1963{
1964 if (val == NULL)
1965 return;
1966 printf("%s %s\n", lookup_opcode_name(code), val);
1967}
1968
1969static void
1970dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1971{
1972 u_int i;
1973
1974 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001975 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1976}
1977
1978static void
1979dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1980{
1981 u_int i;
1982
1983 printf("%s", lookup_opcode_name(code));
1984 for (i = 0; i < count; i++)
1985 printf(" %s", vals[i]);
1986 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001987}
1988
1989void
1990dump_config(ServerOptions *o)
1991{
1992 u_int i;
1993 int ret;
1994 struct addrinfo *ai;
1995 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1996
1997 /* these are usually at the top of the config */
1998 for (i = 0; i < o->num_ports; i++)
1999 printf("port %d\n", o->ports[i]);
2000 dump_cfg_fmtint(sProtocol, o->protocol);
2001 dump_cfg_fmtint(sAddressFamily, o->address_family);
2002
2003 /* ListenAddress must be after Port */
2004 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2005 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2006 sizeof(addr), port, sizeof(port),
2007 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2008 error("getnameinfo failed: %.100s",
2009 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2010 strerror(errno));
2011 } else {
2012 if (ai->ai_family == AF_INET6)
2013 printf("listenaddress [%s]:%s\n", addr, port);
2014 else
2015 printf("listenaddress %s:%s\n", addr, port);
2016 }
2017 }
2018
2019 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002020#ifdef USE_PAM
2021 dump_cfg_int(sUsePAM, o->use_pam);
2022#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002023 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2024 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2025 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2026 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2027 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002028 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002029 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2030 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
2031
2032 /* formatted integer arguments */
2033 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2034 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2035 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2036 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2037 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2038 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2039 o->hostbased_uses_name_from_packet_only);
2040 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2041 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002042#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002043 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2044 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2045 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002046# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002047 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002048# endif
2049#endif
2050#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002051 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2052 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002053#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002054 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2055 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2056 o->kbd_interactive_authentication);
2057 dump_cfg_fmtint(sChallengeResponseAuthentication,
2058 o->challenge_response_authentication);
2059 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2060 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2061 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2062 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002063 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002064 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002065 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2066 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2067 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2068 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2069 dump_cfg_fmtint(sUseLogin, o->use_login);
2070 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002071 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002072 dump_cfg_fmtint(sUseDNS, o->use_dns);
2073 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002074 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002075 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2076
2077 /* string arguments */
2078 dump_cfg_string(sPidFile, o->pid_file);
2079 dump_cfg_string(sXAuthLocation, o->xauth_location);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002080 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2081 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Darren Tuckere7140f22008-06-10 23:01:51 +10002082 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002083 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002084 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002085 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2086 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002087 dump_cfg_string(sAuthorizedPrincipalsFile,
2088 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002089 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002090 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2091 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002092 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
djm@openbsd.org57d378e2014-08-19 23:58:28 +00002093 dump_cfg_string(sKexAlgorithms,
djm@openbsd.org259a02e2014-10-13 00:38:35 +00002094 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
Darren Tuckere7140f22008-06-10 23:01:51 +10002095
2096 /* string arguments requiring a lookup */
2097 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2098 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2099
2100 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002101 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2102 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002103 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2104 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002105 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2106 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002107 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2108 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2109 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2110 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2111 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002112 dump_cfg_strarray_oneline(sAuthenticationMethods,
2113 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002114
2115 /* other arguments */
2116 for (i = 0; i < o->num_subsystems; i++)
2117 printf("subsystem %s %s\n", o->subsystem_name[i],
2118 o->subsystem_args[i]);
2119
2120 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2121 o->max_startups_rate, o->max_startups);
2122
2123 for (i = 0; tunmode_desc[i].val != -1; i++)
2124 if (tunmode_desc[i].val == o->permit_tun) {
2125 s = tunmode_desc[i].text;
2126 break;
2127 }
2128 dump_cfg_string(sPermitTunnel, s);
2129
Damien Miller91475862011-05-05 14:14:34 +10002130 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2131 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002132
Damien Millera6d6c1f2013-08-21 02:40:01 +10002133 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2134 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002135
Darren Tuckere7140f22008-06-10 23:01:51 +10002136 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002137}