blob: b7f32944774d23d8c6c73bf2ece48a8b91b9c4fb [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Miller7acefbb2014-07-18 14:11:24 +10002/* $OpenBSD: servconf.c,v 1.251 2014/07/15 15:54:14 millert 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"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000057
Damien Miller3dc71ad2009-01-28 16:31:22 +110058static void add_listen_addr(ServerOptions *, char *, int);
59static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110060
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000061/* Use of privilege separation or not */
62extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100063extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000064
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065/* Initializes the server options to their default values. */
66
Damien Miller4af51302000-04-16 11:18:38 +100067void
Damien Miller95def091999-11-25 00:26:21 +110068initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069{
Damien Miller95def091999-11-25 00:26:21 +110070 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110071
72 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100073 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110076 options->num_ports = 0;
77 options->ports_from_cmdline = 0;
78 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110079 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110080 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110081 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100082 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100083 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110084 options->server_key_bits = -1;
85 options->login_grace_time = -1;
86 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000087 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110088 options->ignore_rhosts = -1;
89 options->ignore_user_known_hosts = -1;
90 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000091 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110092 options->x11_forwarding = -1;
93 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110094 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110095 options->permit_tty = -1;
Damien Miller72e6b5c2014-07-04 09:00:04 +100096 options->permit_user_rc = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100097 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110098 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110099 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +1100100 options->log_facility = SYSLOG_FACILITY_NOT_SET;
101 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000103 options->hostbased_authentication = -1;
104 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +1100105 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100106 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->kerberos_authentication = -1;
108 options->kerberos_or_local_passwd = -1;
109 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100110 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000111 options->gss_authentication=-1;
112 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100113 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100114 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000115 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100116 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000117 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100118 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000119 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000120 options->rekey_limit = -1;
121 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100122 options->allow_tcp_forwarding = -1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000123 options->allow_streamlocal_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000124 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100125 options->num_allow_users = 0;
126 options->num_deny_users = 0;
127 options->num_allow_groups = 0;
128 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000129 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000130 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000131 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000132 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller7acefbb2014-07-18 14:11:24 +1000133 options->fwd_opts.gateway_ports = -1;
134 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
135 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000136 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000137 options->max_startups_begin = -1;
138 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000139 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000140 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000141 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000142 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000143 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000144 options->client_alive_interval = -1;
145 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000146 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000147 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100148 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000149 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000150 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100151 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100152 options->authorized_keys_command = NULL;
153 options->authorized_keys_command_user = NULL;
Damien Miller1aed65e2010-03-04 21:53:35 +1100154 options->revoked_keys_file = NULL;
155 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000156 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100157 options->ip_qos_interactive = -1;
158 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000159 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000160}
161
Damien Miller4af51302000-04-16 11:18:38 +1000162void
Damien Miller95def091999-11-25 00:26:21 +1100163fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000164{
Damien Miller726273e2001-11-12 11:40:11 +1100165 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000166 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000167 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100168
169 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100170 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100171 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100172 if (options->num_host_key_files == 0) {
173 /* fill default hostkeys for protocols */
174 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100175 options->host_key_files[options->num_host_key_files++] =
176 _PATH_HOST_KEY_FILE;
177 if (options->protocol & SSH_PROTO_2) {
178 options->host_key_files[options->num_host_key_files++] =
179 _PATH_HOST_RSA_KEY_FILE;
180 options->host_key_files[options->num_host_key_files++] =
181 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100182#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000183 options->host_key_files[options->num_host_key_files++] =
184 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100185#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100186 options->host_key_files[options->num_host_key_files++] =
187 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100188 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100189 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100190 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100191 if (options->num_ports == 0)
192 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
193 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000194 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000195 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000196 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000198 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000200 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->key_regeneration_time == -1)
202 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000203 if (options->permit_root_login == PERMIT_NOT_SET)
204 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100206 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->ignore_user_known_hosts == -1)
208 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->print_motd == -1)
210 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000211 if (options->print_lastlog == -1)
212 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100213 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100214 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100215 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100216 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100217 if (options->x11_use_localhost == -1)
218 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000219 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000220 options->xauth_location = _PATH_XAUTH;
Damien Miller5ff30c62013-10-30 22:21:50 +1100221 if (options->permit_tty == -1)
222 options->permit_tty = 1;
Damien Miller72e6b5c2014-07-04 09:00:04 +1000223 if (options->permit_user_rc == -1)
224 options->permit_user_rc = 1;
Damien Miller95def091999-11-25 00:26:21 +1100225 if (options->strict_modes == -1)
226 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100227 if (options->tcp_keep_alive == -1)
228 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100229 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100230 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100231 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000232 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100233 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100234 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000235 if (options->hostbased_authentication == -1)
236 options->hostbased_authentication = 0;
237 if (options->hostbased_uses_name_from_packet_only == -1)
238 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100239 if (options->rsa_authentication == -1)
240 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100241 if (options->pubkey_authentication == -1)
242 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100243 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000244 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100245 if (options->kerberos_or_local_passwd == -1)
246 options->kerberos_or_local_passwd = 1;
247 if (options->kerberos_ticket_cleanup == -1)
248 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100249 if (options->kerberos_get_afs_token == -1)
250 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000251 if (options->gss_authentication == -1)
252 options->gss_authentication = 0;
253 if (options->gss_cleanup_creds == -1)
254 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100255 if (options->password_authentication == -1)
256 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100257 if (options->kbd_interactive_authentication == -1)
258 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000259 if (options->challenge_response_authentication == -1)
260 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100261 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100262 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000263 if (options->permit_user_env == -1)
264 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100265 if (options->use_login == -1)
266 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000267 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000268 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000269 if (options->rekey_limit == -1)
270 options->rekey_limit = 0;
271 if (options->rekey_interval == -1)
272 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100273 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100274 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller7acefbb2014-07-18 14:11:24 +1000275 if (options->allow_streamlocal_forwarding == -1)
276 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000277 if (options->allow_agent_forwarding == -1)
278 options->allow_agent_forwarding = 1;
Damien Miller7acefbb2014-07-18 14:11:24 +1000279 if (options->fwd_opts.gateway_ports == -1)
280 options->fwd_opts.gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000281 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100282 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000283 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100284 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000285 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100286 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000287 if (options->max_authtries == -1)
288 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000289 if (options->max_sessions == -1)
290 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000291 if (options->use_dns == -1)
292 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000293 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100294 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000295 if (options->client_alive_count_max == -1)
296 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000297 if (options->num_authkeys_files == 0) {
298 options->authorized_keys_files[options->num_authkeys_files++] =
299 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
300 options->authorized_keys_files[options->num_authkeys_files++] =
301 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
302 }
Damien Millerd27b9472005-12-13 19:29:02 +1100303 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100304 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100305 if (options->ip_qos_interactive == -1)
306 options->ip_qos_interactive = IPTOS_LOWDELAY;
307 if (options->ip_qos_bulk == -1)
308 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000309 if (options->version_addendum == NULL)
310 options->version_addendum = xstrdup("");
Damien Miller7acefbb2014-07-18 14:11:24 +1000311 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
312 options->fwd_opts.streamlocal_bind_mask = 0177;
313 if (options->fwd_opts.streamlocal_bind_unlink == -1)
314 options->fwd_opts.streamlocal_bind_unlink = 0;
Ben Lindstromfb62a692002-06-06 19:47:11 +0000315 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000316 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000317 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000318
Tim Rice40017b02002-07-14 13:36:49 -0700319#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000320 if (use_privsep && options->compression == 1) {
321 error("This platform does not support both privilege "
322 "separation and compression");
323 error("Compression disabled");
324 options->compression = 0;
325 }
326#endif
327
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000328}
329
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000330/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100331typedef enum {
332 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100333 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000334 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100335 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100336 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
337 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000338 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100339 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100340 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000341 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100342 sPasswordAuthentication, sKbdInteractiveAuthentication,
343 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000344 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100345 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100346 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000347 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000348 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000349 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000350 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000351 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000352 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100353 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000354 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100355 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100356 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100357 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100358 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000359 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000360 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100361 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller72e6b5c2014-07-04 09:00:04 +1000362 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
Damien Miller7acefbb2014-07-18 14:11:24 +1000363 sStreamLocalBindMask, sStreamLocalBindUnlink,
364 sAllowStreamLocalForwarding,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000365 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000366} ServerOpCodes;
367
Darren Tucker45150472006-07-12 22:34:17 +1000368#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
369#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
370#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
371
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000372/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100373static struct {
374 const char *name;
375 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000376 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100377} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100378 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000379#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000380 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000381#else
Darren Tucker45150472006-07-12 22:34:17 +1000382 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000383#endif
Darren Tucker45150472006-07-12 22:34:17 +1000384 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100385 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000386 { "port", sPort, SSHCFG_GLOBAL },
387 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
388 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000389 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000390 { "pidfile", sPidFile, SSHCFG_GLOBAL },
391 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
392 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
393 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100394 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
396 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
397 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100398 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
399 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000400 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100401 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
402 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000403 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000404#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100405 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000406 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
407 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100408#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000409 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000410#else
Darren Tucker45150472006-07-12 22:34:17 +1000411 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100412#endif
413#else
Darren Tucker1629c072007-02-19 22:25:37 +1100414 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000415 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
416 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
417 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000418#endif
Darren Tucker45150472006-07-12 22:34:17 +1000419 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
420 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000421#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100422 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000423 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000424#else
Darren Tucker1629c072007-02-19 22:25:37 +1100425 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000426 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000427#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100428 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
429 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100430 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000431 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
432 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
433 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
434 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
435 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
436 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
437 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
438 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000439 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
440 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
441 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000442 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
443 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100444 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000445 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
446 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
447 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000448 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000449 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
450 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
451 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000452 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000453 { "allowusers", sAllowUsers, SSHCFG_ALL },
454 { "denyusers", sDenyUsers, SSHCFG_ALL },
455 { "allowgroups", sAllowGroups, SSHCFG_ALL },
456 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000457 { "ciphers", sCiphers, SSHCFG_GLOBAL },
458 { "macs", sMacs, SSHCFG_GLOBAL },
459 { "protocol", sProtocol, SSHCFG_GLOBAL },
460 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
461 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
462 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000463 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000464 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100465 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000466 { "usedns", sUseDNS, SSHCFG_GLOBAL },
467 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
468 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
469 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
470 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000471 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000472 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000473 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000474 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000475 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100476 { "permittty", sPermitTTY, SSHCFG_ALL },
Damien Miller72e6b5c2014-07-04 09:00:04 +1000477 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000478 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000479 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000480 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100481 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100482 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100483 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
484 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000485 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000486 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100487 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100488 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
489 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000490 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100491 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Damien Miller7acefbb2014-07-18 14:11:24 +1000492 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
493 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
494 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000495 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000496};
497
Darren Tuckere7140f22008-06-10 23:01:51 +1000498static struct {
499 int val;
500 char *text;
501} tunmode_desc[] = {
502 { SSH_TUNMODE_NO, "no" },
503 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
504 { SSH_TUNMODE_ETHERNET, "ethernet" },
505 { SSH_TUNMODE_YES, "yes" },
506 { -1, NULL }
507};
508
Damien Miller5428f641999-11-25 11:54:57 +1100509/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000510 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100511 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000512
Damien Miller4af51302000-04-16 11:18:38 +1000513static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100514parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000515 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000516{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000517 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000518
Damien Miller95def091999-11-25 00:26:21 +1100519 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000520 if (strcasecmp(cp, keywords[i].name) == 0) {
521 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100522 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000523 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000524
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000525 error("%s: line %d: Bad configuration option: %s",
526 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100527 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000528}
529
Darren Tucker88b6fb22010-01-13 22:44:29 +1100530char *
531derelativise_path(const char *path)
532{
Damien Miller44451d02010-03-26 10:40:04 +1100533 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100534
535 expanded = tilde_expand_filename(path, getuid());
536 if (*expanded == '/')
537 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100538 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100539 fatal("%s: getcwd: %s", __func__, strerror(errno));
540 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000541 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100542 return ret;
543}
544
Ben Lindstrombba81212001-06-25 05:01:22 +0000545static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100546add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100547{
Damien Millereccb9de2005-06-17 12:59:34 +1000548 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100549
550 if (options->num_ports == 0)
551 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100552 if (options->address_family == -1)
553 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000554 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000555 for (i = 0; i < options->num_ports; i++)
556 add_one_listen_addr(options, addr, options->ports[i]);
557 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000558 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000559}
560
Ben Lindstrombba81212001-06-25 05:01:22 +0000561static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100562add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000563{
564 struct addrinfo hints, *ai, *aitop;
565 char strport[NI_MAXSERV];
566 int gaierr;
567
568 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100569 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000570 hints.ai_socktype = SOCK_STREAM;
571 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100572 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000573 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
574 fatal("bad addr or host: %s (%s)",
575 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100576 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000577 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
578 ;
579 ai->ai_next = options->listen_addrs;
580 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100581}
582
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000583struct connection_info *
584get_connection_info(int populate, int use_dns)
585{
586 static struct connection_info ci;
587
588 if (!populate)
589 return &ci;
590 ci.host = get_canonical_hostname(use_dns);
591 ci.address = get_remote_ipaddr();
592 ci.laddress = get_local_ipaddr(packet_get_connection_in());
593 ci.lport = get_local_port();
594 return &ci;
595}
596
Darren Tucker45150472006-07-12 22:34:17 +1000597/*
598 * The strategy for the Match blocks is that the config file is parsed twice.
599 *
600 * The first time is at startup. activep is initialized to 1 and the
601 * directives in the global context are processed and acted on. Hitting a
602 * Match directive unsets activep and the directives inside the block are
603 * checked for syntax only.
604 *
605 * The second time is after a connection has been established but before
606 * authentication. activep is initialized to 2 and global config directives
607 * are ignored since they have already been processed. If the criteria in a
608 * Match block is met, activep is set and the subsequent directives
609 * processed and actioned until EOF or another Match block unsets it. Any
610 * options set are copied into the main server config.
611 *
612 * Potential additions/improvements:
613 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
614 *
615 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
616 * Match Address 192.168.0.*
617 * Tag trusted
618 * Match Group wheel
619 * Tag trusted
620 * Match Tag trusted
621 * AllowTcpForwarding yes
622 * GatewayPorts clientspecified
623 * [...]
624 *
625 * - Add a PermittedChannelRequests directive
626 * Match Group shell
627 * PermittedChannelRequests session,forwarded-tcpip
628 */
629
630static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000631match_cfg_line_group(const char *grps, int line, const char *user)
632{
633 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000634 struct passwd *pw;
635
Damien Miller565ca3f2006-08-19 00:23:15 +1000636 if (user == NULL)
637 goto out;
638
639 if ((pw = getpwnam(user)) == NULL) {
640 debug("Can't match group at line %d because user %.100s does "
641 "not exist", line, user);
642 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
643 debug("Can't Match group because user %.100s not in any group "
644 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000645 } else if (ga_match_pattern_list(grps) != 1) {
646 debug("user %.100s does not match group list %.100s at line %d",
647 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000648 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000649 debug("user %.100s matched group list %.100s at line %d", user,
650 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000651 result = 1;
652 }
653out:
654 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000655 return result;
656}
657
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000658/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000659 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100660 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000661 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000662 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000663static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000664match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000665{
Damien Millercf31f382013-10-24 21:02:56 +1100666 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000667 char *arg, *attrib, *cp = *condition;
668 size_t len;
669
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000670 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000671 debug3("checking syntax for 'Match %s'", cp);
672 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000673 debug3("checking match for '%s' user %s host %s addr %s "
674 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
675 ci->host ? ci->host : "(null)",
676 ci->address ? ci->address : "(null)",
677 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000678
679 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100680 attributes++;
681 if (strcasecmp(attrib, "all") == 0) {
682 if (attributes != 1 ||
683 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
684 error("'all' cannot be combined with other "
685 "Match attributes");
686 return -1;
687 }
688 *condition = cp;
689 return 1;
690 }
Darren Tucker45150472006-07-12 22:34:17 +1000691 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
692 error("Missing Match criteria for %s", attrib);
693 return -1;
694 }
695 len = strlen(arg);
696 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000697 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000698 result = 0;
699 continue;
700 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000701 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000702 result = 0;
703 else
704 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000705 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000706 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000707 if (ci == NULL || ci->user == NULL) {
708 result = 0;
709 continue;
710 }
711 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000712 case -1:
713 return -1;
714 case 0:
715 result = 0;
716 }
Darren Tucker45150472006-07-12 22:34:17 +1000717 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000718 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000719 result = 0;
720 continue;
721 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000722 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000723 result = 0;
724 else
725 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000726 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000727 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000728 if (ci == NULL || ci->address == NULL) {
729 result = 0;
730 continue;
731 }
732 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000733 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000734 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000735 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000736 break;
737 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000738 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000739 result = 0;
740 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000741 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000742 return -1;
743 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000744 } else if (strcasecmp(attrib, "localaddress") == 0){
745 if (ci == NULL || ci->laddress == NULL) {
746 result = 0;
747 continue;
748 }
749 switch (addr_match_list(ci->laddress, arg)) {
750 case 1:
751 debug("connection from %.100s matched "
752 "'LocalAddress %.100s' at line %d",
753 ci->laddress, arg, line);
754 break;
755 case 0:
756 case -1:
757 result = 0;
758 break;
759 case -2:
760 return -1;
761 }
762 } else if (strcasecmp(attrib, "localport") == 0) {
763 if ((port = a2port(arg)) == -1) {
764 error("Invalid LocalPort '%s' on Match line",
765 arg);
766 return -1;
767 }
768 if (ci == NULL || ci->lport == 0) {
769 result = 0;
770 continue;
771 }
772 /* TODO support port lists */
773 if (port == ci->lport)
774 debug("connection from %.100s matched "
775 "'LocalPort %d' at line %d",
776 ci->laddress, port, line);
777 else
778 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000779 } else {
780 error("Unsupported Match attribute %s", attrib);
781 return -1;
782 }
783 }
Damien Millercf31f382013-10-24 21:02:56 +1100784 if (attributes == 0) {
785 error("One or more attributes required for Match");
786 return -1;
787 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000788 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000789 debug3("match %sfound", result ? "" : "not ");
790 *condition = cp;
791 return result;
792}
793
Damien Millere2754432006-07-24 14:06:47 +1000794#define WHITESPACE " \t\r\n"
795
Damien Miller33322122011-06-20 14:43:11 +1000796/* Multistate option parsing */
797struct multistate {
798 char *key;
799 int value;
800};
801static const struct multistate multistate_addressfamily[] = {
802 { "inet", AF_INET },
803 { "inet6", AF_INET6 },
804 { "any", AF_UNSPEC },
805 { NULL, -1 }
806};
807static const struct multistate multistate_permitrootlogin[] = {
808 { "without-password", PERMIT_NO_PASSWD },
809 { "forced-commands-only", PERMIT_FORCED_ONLY },
810 { "yes", PERMIT_YES },
811 { "no", PERMIT_NO },
812 { NULL, -1 }
813};
814static const struct multistate multistate_compression[] = {
815 { "delayed", COMP_DELAYED },
816 { "yes", COMP_ZLIB },
817 { "no", COMP_NONE },
818 { NULL, -1 }
819};
820static const struct multistate multistate_gatewayports[] = {
821 { "clientspecified", 2 },
822 { "yes", 1 },
823 { "no", 0 },
824 { NULL, -1 }
825};
Damien Miller69ff1df2011-06-23 08:30:03 +1000826static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000827 { "yes", PRIVSEP_NOSANDBOX },
828 { "sandbox", PRIVSEP_ON },
829 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000830 { "no", PRIVSEP_OFF },
831 { NULL, -1 }
832};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100833static const struct multistate multistate_tcpfwd[] = {
834 { "yes", FORWARD_ALLOW },
835 { "all", FORWARD_ALLOW },
836 { "no", FORWARD_DENY },
837 { "remote", FORWARD_REMOTE },
838 { "local", FORWARD_LOCAL },
839 { NULL, -1 }
840};
Damien Miller33322122011-06-20 14:43:11 +1000841
Ben Lindstromade03f62001-12-06 18:22:17 +0000842int
843process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000844 const char *filename, int linenum, int *activep,
845 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000846{
Darren Tucker09c0f032013-05-16 20:48:57 +1000847 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000848 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100849 SyslogFacility *log_facility_ptr;
850 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000851 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000852 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000853 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000854 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000855 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000856
857 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100858 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100859 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000860 /* Ignore leading whitespace */
861 if (*arg == '\0')
862 arg = strdelim(&cp);
863 if (!arg || !*arg || *arg == '#')
864 return 0;
865 intptr = NULL;
866 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000867 opcode = parse_token(arg, filename, linenum, &flags);
868
869 if (activep == NULL) { /* We are processing a command line directive */
870 cmdline = 1;
871 activep = &cmdline;
872 }
873 if (*activep && opcode != sMatch)
874 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
875 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000876 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000877 fatal("%s line %d: Directive '%s' is not allowed "
878 "within a Match block", filename, linenum, arg);
879 } else { /* this is a directive we have already processed */
880 while (arg)
881 arg = strdelim(&cp);
882 return 0;
883 }
884 }
885
Ben Lindstromade03f62001-12-06 18:22:17 +0000886 switch (opcode) {
887 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000888 case sUsePAM:
889 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000890 goto parse_flag;
891
892 /* Standard Options */
893 case sBadOption:
894 return -1;
895 case sPort:
896 /* ignore ports from configfile if cmdline specifies ports */
897 if (options->ports_from_cmdline)
898 return 0;
899 if (options->listen_addrs != NULL)
900 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100901 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000902 if (options->num_ports >= MAX_PORTS)
903 fatal("%s line %d: too many ports.",
904 filename, linenum);
905 arg = strdelim(&cp);
906 if (!arg || *arg == '\0')
907 fatal("%s line %d: missing port number.",
908 filename, linenum);
909 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100910 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000911 fatal("%s line %d: Badly formatted port number.",
912 filename, linenum);
913 break;
914
915 case sServerKeyBits:
916 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000917 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000918 arg = strdelim(&cp);
919 if (!arg || *arg == '\0')
920 fatal("%s line %d: missing integer value.",
921 filename, linenum);
922 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000923 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000924 *intptr = value;
925 break;
926
927 case sLoginGraceTime:
928 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000929 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000930 arg = strdelim(&cp);
931 if (!arg || *arg == '\0')
932 fatal("%s line %d: missing time value.",
933 filename, linenum);
934 if ((value = convtime(arg)) == -1)
935 fatal("%s line %d: invalid time value.",
936 filename, linenum);
937 if (*intptr == -1)
938 *intptr = value;
939 break;
940
941 case sKeyRegenerationTime:
942 intptr = &options->key_regeneration_time;
943 goto parse_time;
944
945 case sListenAddress:
946 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100947 if (arg == NULL || *arg == '\0')
948 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000949 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000950 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
951 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
952 && strchr(p+1, ':') != NULL) {
953 add_listen_addr(options, arg, 0);
954 break;
955 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100956 p = hpdelim(&arg);
957 if (p == NULL)
958 fatal("%s line %d: bad address:port usage",
959 filename, linenum);
960 p = cleanhostname(p);
961 if (arg == NULL)
962 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100963 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100964 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000965
Damien Millerf91ee4c2005-03-01 21:24:33 +1100966 add_listen_addr(options, p, port);
967
Ben Lindstromade03f62001-12-06 18:22:17 +0000968 break;
969
Darren Tucker0f383232005-01-20 10:57:56 +1100970 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000971 intptr = &options->address_family;
972 multistate_ptr = multistate_addressfamily;
973 if (options->listen_addrs != NULL)
974 fatal("%s line %d: address family must be specified "
975 "before ListenAddress.", filename, linenum);
976 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100977 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000978 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000979 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000980 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000981 value = -1;
982 for (i = 0; multistate_ptr[i].key != NULL; i++) {
983 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
984 value = multistate_ptr[i].value;
985 break;
986 }
987 }
988 if (value == -1)
989 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100990 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000991 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100992 *intptr = value;
993 break;
994
Ben Lindstromade03f62001-12-06 18:22:17 +0000995 case sHostKeyFile:
996 intptr = &options->num_host_key_files;
997 if (*intptr >= MAX_HOSTKEYS)
998 fatal("%s line %d: too many host keys specified (max %d).",
999 filename, linenum, MAX_HOSTKEYS);
1000 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +10001001 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +00001002 arg = strdelim(&cp);
1003 if (!arg || *arg == '\0')
1004 fatal("%s line %d: missing file name.",
1005 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001006 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +11001007 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001008 /* increase optional counter */
1009 if (intptr != NULL)
1010 *intptr = *intptr + 1;
1011 }
1012 break;
1013
Damien Miller85b45e02013-07-20 13:21:52 +10001014 case sHostKeyAgent:
1015 charptr = &options->host_key_agent;
1016 arg = strdelim(&cp);
1017 if (!arg || *arg == '\0')
1018 fatal("%s line %d: missing socket name.",
1019 filename, linenum);
1020 if (*activep && *charptr == NULL)
1021 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1022 xstrdup(arg) : derelativise_path(arg);
1023 break;
1024
Damien Miller0a80ca12010-02-27 07:55:05 +11001025 case sHostCertificate:
1026 intptr = &options->num_host_cert_files;
1027 if (*intptr >= MAX_HOSTKEYS)
1028 fatal("%s line %d: too many host certificates "
1029 "specified (max %d).", filename, linenum,
1030 MAX_HOSTCERTS);
1031 charptr = &options->host_cert_files[*intptr];
1032 goto parse_filename;
1033 break;
1034
Ben Lindstromade03f62001-12-06 18:22:17 +00001035 case sPidFile:
1036 charptr = &options->pid_file;
1037 goto parse_filename;
1038
1039 case sPermitRootLogin:
1040 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001041 multistate_ptr = multistate_permitrootlogin;
1042 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001043
1044 case sIgnoreRhosts:
1045 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001046 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001047 arg = strdelim(&cp);
1048 if (!arg || *arg == '\0')
1049 fatal("%s line %d: missing yes/no argument.",
1050 filename, linenum);
1051 value = 0; /* silence compiler */
1052 if (strcmp(arg, "yes") == 0)
1053 value = 1;
1054 else if (strcmp(arg, "no") == 0)
1055 value = 0;
1056 else
1057 fatal("%s line %d: Bad yes/no argument: %s",
1058 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001059 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001060 *intptr = value;
1061 break;
1062
1063 case sIgnoreUserKnownHosts:
1064 intptr = &options->ignore_user_known_hosts;
1065 goto parse_flag;
1066
Ben Lindstromade03f62001-12-06 18:22:17 +00001067 case sRhostsRSAAuthentication:
1068 intptr = &options->rhosts_rsa_authentication;
1069 goto parse_flag;
1070
1071 case sHostbasedAuthentication:
1072 intptr = &options->hostbased_authentication;
1073 goto parse_flag;
1074
1075 case sHostbasedUsesNameFromPacketOnly:
1076 intptr = &options->hostbased_uses_name_from_packet_only;
1077 goto parse_flag;
1078
1079 case sRSAAuthentication:
1080 intptr = &options->rsa_authentication;
1081 goto parse_flag;
1082
1083 case sPubkeyAuthentication:
1084 intptr = &options->pubkey_authentication;
1085 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001086
Ben Lindstromade03f62001-12-06 18:22:17 +00001087 case sKerberosAuthentication:
1088 intptr = &options->kerberos_authentication;
1089 goto parse_flag;
1090
1091 case sKerberosOrLocalPasswd:
1092 intptr = &options->kerberos_or_local_passwd;
1093 goto parse_flag;
1094
1095 case sKerberosTicketCleanup:
1096 intptr = &options->kerberos_ticket_cleanup;
1097 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001098
Darren Tucker22ef5082003-12-31 11:37:34 +11001099 case sKerberosGetAFSToken:
1100 intptr = &options->kerberos_get_afs_token;
1101 goto parse_flag;
1102
Darren Tucker0efd1552003-08-26 11:49:55 +10001103 case sGssAuthentication:
1104 intptr = &options->gss_authentication;
1105 goto parse_flag;
1106
1107 case sGssCleanupCreds:
1108 intptr = &options->gss_cleanup_creds;
1109 goto parse_flag;
1110
Ben Lindstromade03f62001-12-06 18:22:17 +00001111 case sPasswordAuthentication:
1112 intptr = &options->password_authentication;
1113 goto parse_flag;
1114
1115 case sKbdInteractiveAuthentication:
1116 intptr = &options->kbd_interactive_authentication;
1117 goto parse_flag;
1118
1119 case sChallengeResponseAuthentication:
1120 intptr = &options->challenge_response_authentication;
1121 goto parse_flag;
1122
1123 case sPrintMotd:
1124 intptr = &options->print_motd;
1125 goto parse_flag;
1126
1127 case sPrintLastLog:
1128 intptr = &options->print_lastlog;
1129 goto parse_flag;
1130
1131 case sX11Forwarding:
1132 intptr = &options->x11_forwarding;
1133 goto parse_flag;
1134
1135 case sX11DisplayOffset:
1136 intptr = &options->x11_display_offset;
1137 goto parse_int;
1138
Damien Miller95c249f2002-02-05 12:11:34 +11001139 case sX11UseLocalhost:
1140 intptr = &options->x11_use_localhost;
1141 goto parse_flag;
1142
Ben Lindstromade03f62001-12-06 18:22:17 +00001143 case sXAuthLocation:
1144 charptr = &options->xauth_location;
1145 goto parse_filename;
1146
Damien Miller5ff30c62013-10-30 22:21:50 +11001147 case sPermitTTY:
1148 intptr = &options->permit_tty;
1149 goto parse_flag;
1150
Damien Miller72e6b5c2014-07-04 09:00:04 +10001151 case sPermitUserRC:
1152 intptr = &options->permit_user_rc;
1153 goto parse_flag;
1154
Ben Lindstromade03f62001-12-06 18:22:17 +00001155 case sStrictModes:
1156 intptr = &options->strict_modes;
1157 goto parse_flag;
1158
Damien Miller12c150e2003-12-17 16:31:10 +11001159 case sTCPKeepAlive:
1160 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001161 goto parse_flag;
1162
1163 case sEmptyPasswd:
1164 intptr = &options->permit_empty_passwd;
1165 goto parse_flag;
1166
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001167 case sPermitUserEnvironment:
1168 intptr = &options->permit_user_env;
1169 goto parse_flag;
1170
Ben Lindstromade03f62001-12-06 18:22:17 +00001171 case sUseLogin:
1172 intptr = &options->use_login;
1173 goto parse_flag;
1174
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001175 case sCompression:
1176 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001177 multistate_ptr = multistate_compression;
1178 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001179
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001180 case sRekeyLimit:
1181 arg = strdelim(&cp);
1182 if (!arg || *arg == '\0')
1183 fatal("%.200s line %d: Missing argument.", filename,
1184 linenum);
1185 if (strcmp(arg, "default") == 0) {
1186 val64 = 0;
1187 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001188 if (scan_scaled(arg, &val64) == -1)
1189 fatal("%.200s line %d: Bad number '%s': %s",
1190 filename, linenum, arg, strerror(errno));
1191 /* check for too-large or too-small limits */
1192 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001193 fatal("%.200s line %d: RekeyLimit too large",
1194 filename, linenum);
1195 if (val64 != 0 && val64 < 16)
1196 fatal("%.200s line %d: RekeyLimit too small",
1197 filename, linenum);
1198 }
1199 if (*activep && options->rekey_limit == -1)
1200 options->rekey_limit = (u_int32_t)val64;
1201 if (cp != NULL) { /* optional rekey interval present */
1202 if (strcmp(cp, "none") == 0) {
1203 (void)strdelim(&cp); /* discard */
1204 break;
1205 }
1206 intptr = &options->rekey_interval;
1207 goto parse_time;
1208 }
1209 break;
1210
Ben Lindstromade03f62001-12-06 18:22:17 +00001211 case sGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +10001212 intptr = &options->fwd_opts.gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001213 multistate_ptr = multistate_gatewayports;
1214 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001215
Damien Miller3a961dc2003-06-03 10:25:48 +10001216 case sUseDNS:
1217 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001218 goto parse_flag;
1219
1220 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001221 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001222 arg = strdelim(&cp);
1223 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001224 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001225 fatal("%.200s line %d: unsupported log facility '%s'",
1226 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001227 if (*log_facility_ptr == -1)
1228 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001229 break;
1230
1231 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001232 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001233 arg = strdelim(&cp);
1234 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001235 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001236 fatal("%.200s line %d: unsupported log level '%s'",
1237 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001238 if (*log_level_ptr == -1)
1239 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001240 break;
1241
1242 case sAllowTcpForwarding:
1243 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001244 multistate_ptr = multistate_tcpfwd;
1245 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001246
Damien Miller7acefbb2014-07-18 14:11:24 +10001247 case sAllowStreamLocalForwarding:
1248 intptr = &options->allow_streamlocal_forwarding;
1249 multistate_ptr = multistate_tcpfwd;
1250 goto parse_multistate;
1251
Damien Miller4f755cd2008-05-19 14:57:41 +10001252 case sAllowAgentForwarding:
1253 intptr = &options->allow_agent_forwarding;
1254 goto parse_flag;
1255
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001256 case sUsePrivilegeSeparation:
1257 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001258 multistate_ptr = multistate_privsep;
1259 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001260
Ben Lindstromade03f62001-12-06 18:22:17 +00001261 case sAllowUsers:
1262 while ((arg = strdelim(&cp)) && *arg != '\0') {
1263 if (options->num_allow_users >= MAX_ALLOW_USERS)
1264 fatal("%s line %d: too many allow users.",
1265 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001266 if (!*activep)
1267 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001268 options->allow_users[options->num_allow_users++] =
1269 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001270 }
1271 break;
1272
1273 case sDenyUsers:
1274 while ((arg = strdelim(&cp)) && *arg != '\0') {
1275 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001276 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001277 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001278 if (!*activep)
1279 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001280 options->deny_users[options->num_deny_users++] =
1281 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001282 }
1283 break;
1284
1285 case sAllowGroups:
1286 while ((arg = strdelim(&cp)) && *arg != '\0') {
1287 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1288 fatal("%s line %d: too many allow groups.",
1289 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001290 if (!*activep)
1291 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001292 options->allow_groups[options->num_allow_groups++] =
1293 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001294 }
1295 break;
1296
1297 case sDenyGroups:
1298 while ((arg = strdelim(&cp)) && *arg != '\0') {
1299 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1300 fatal("%s line %d: too many deny groups.",
1301 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001302 if (!*activep)
1303 continue;
1304 options->deny_groups[options->num_deny_groups++] =
1305 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001306 }
1307 break;
1308
1309 case sCiphers:
1310 arg = strdelim(&cp);
1311 if (!arg || *arg == '\0')
1312 fatal("%s line %d: Missing argument.", filename, linenum);
1313 if (!ciphers_valid(arg))
1314 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1315 filename, linenum, arg ? arg : "<NONE>");
1316 if (options->ciphers == NULL)
1317 options->ciphers = xstrdup(arg);
1318 break;
1319
1320 case sMacs:
1321 arg = strdelim(&cp);
1322 if (!arg || *arg == '\0')
1323 fatal("%s line %d: Missing argument.", filename, linenum);
1324 if (!mac_valid(arg))
1325 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1326 filename, linenum, arg ? arg : "<NONE>");
1327 if (options->macs == NULL)
1328 options->macs = xstrdup(arg);
1329 break;
1330
Damien Millerd5f62bf2010-09-24 22:11:14 +10001331 case sKexAlgorithms:
1332 arg = strdelim(&cp);
1333 if (!arg || *arg == '\0')
1334 fatal("%s line %d: Missing argument.",
1335 filename, linenum);
1336 if (!kex_names_valid(arg))
1337 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1338 filename, linenum, arg ? arg : "<NONE>");
1339 if (options->kex_algorithms == NULL)
1340 options->kex_algorithms = xstrdup(arg);
1341 break;
1342
Ben Lindstromade03f62001-12-06 18:22:17 +00001343 case sProtocol:
1344 intptr = &options->protocol;
1345 arg = strdelim(&cp);
1346 if (!arg || *arg == '\0')
1347 fatal("%s line %d: Missing argument.", filename, linenum);
1348 value = proto_spec(arg);
1349 if (value == SSH_PROTO_UNKNOWN)
1350 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001351 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001352 if (*intptr == SSH_PROTO_UNKNOWN)
1353 *intptr = value;
1354 break;
1355
1356 case sSubsystem:
1357 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1358 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001359 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001360 }
1361 arg = strdelim(&cp);
1362 if (!arg || *arg == '\0')
1363 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001364 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001365 if (!*activep) {
1366 arg = strdelim(&cp);
1367 break;
1368 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001369 for (i = 0; i < options->num_subsystems; i++)
1370 if (strcmp(arg, options->subsystem_name[i]) == 0)
1371 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001372 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001373 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1374 arg = strdelim(&cp);
1375 if (!arg || *arg == '\0')
1376 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001377 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001378 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001379
1380 /* Collect arguments (separate to executable) */
1381 p = xstrdup(arg);
1382 len = strlen(p) + 1;
1383 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1384 len += 1 + strlen(arg);
1385 p = xrealloc(p, 1, len);
1386 strlcat(p, " ", len);
1387 strlcat(p, arg, len);
1388 }
1389 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001390 options->num_subsystems++;
1391 break;
1392
1393 case sMaxStartups:
1394 arg = strdelim(&cp);
1395 if (!arg || *arg == '\0')
1396 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001397 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001398 if ((n = sscanf(arg, "%d:%d:%d",
1399 &options->max_startups_begin,
1400 &options->max_startups_rate,
1401 &options->max_startups)) == 3) {
1402 if (options->max_startups_begin >
1403 options->max_startups ||
1404 options->max_startups_rate > 100 ||
1405 options->max_startups_rate < 1)
1406 fatal("%s line %d: Illegal MaxStartups spec.",
1407 filename, linenum);
1408 } else if (n != 1)
1409 fatal("%s line %d: Illegal MaxStartups spec.",
1410 filename, linenum);
1411 else
1412 options->max_startups = options->max_startups_begin;
1413 break;
1414
Darren Tucker89413db2004-05-24 10:36:23 +10001415 case sMaxAuthTries:
1416 intptr = &options->max_authtries;
1417 goto parse_int;
1418
Damien Miller7207f642008-05-19 15:34:50 +10001419 case sMaxSessions:
1420 intptr = &options->max_sessions;
1421 goto parse_int;
1422
Ben Lindstromade03f62001-12-06 18:22:17 +00001423 case sBanner:
1424 charptr = &options->banner;
1425 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001426
Ben Lindstromade03f62001-12-06 18:22:17 +00001427 /*
1428 * These options can contain %X options expanded at
1429 * connect time, so that you can specify paths like:
1430 *
1431 * AuthorizedKeysFile /etc/ssh_keys/%u
1432 */
1433 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001434 if (*activep && options->num_authkeys_files == 0) {
1435 while ((arg = strdelim(&cp)) && *arg != '\0') {
1436 if (options->num_authkeys_files >=
1437 MAX_AUTHKEYS_FILES)
1438 fatal("%s line %d: "
1439 "too many authorized keys files.",
1440 filename, linenum);
1441 options->authorized_keys_files[
1442 options->num_authkeys_files++] =
1443 tilde_expand_filename(arg, getuid());
1444 }
1445 }
1446 return 0;
1447
Damien Miller30da3442010-05-10 11:58:03 +10001448 case sAuthorizedPrincipalsFile:
1449 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001450 arg = strdelim(&cp);
1451 if (!arg || *arg == '\0')
1452 fatal("%s line %d: missing file name.",
1453 filename, linenum);
1454 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001455 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001456 /* increase optional counter */
1457 if (intptr != NULL)
1458 *intptr = *intptr + 1;
1459 }
1460 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001461
1462 case sClientAliveInterval:
1463 intptr = &options->client_alive_interval;
1464 goto parse_time;
1465
1466 case sClientAliveCountMax:
1467 intptr = &options->client_alive_count_max;
1468 goto parse_int;
1469
Darren Tucker46bc0752004-05-02 22:11:30 +10001470 case sAcceptEnv:
1471 while ((arg = strdelim(&cp)) && *arg != '\0') {
1472 if (strchr(arg, '=') != NULL)
1473 fatal("%s line %d: Invalid environment name.",
1474 filename, linenum);
1475 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1476 fatal("%s line %d: too many allow env.",
1477 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001478 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001479 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001480 options->accept_env[options->num_accept_env++] =
1481 xstrdup(arg);
1482 }
1483 break;
1484
Damien Millerd27b9472005-12-13 19:29:02 +11001485 case sPermitTunnel:
1486 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001487 arg = strdelim(&cp);
1488 if (!arg || *arg == '\0')
1489 fatal("%s line %d: Missing yes/point-to-point/"
1490 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001491 value = -1;
1492 for (i = 0; tunmode_desc[i].val != -1; i++)
1493 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1494 value = tunmode_desc[i].val;
1495 break;
1496 }
1497 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001498 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1499 "no argument: %s", filename, linenum, arg);
1500 if (*intptr == -1)
1501 *intptr = value;
1502 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001503
Darren Tucker45150472006-07-12 22:34:17 +10001504 case sMatch:
1505 if (cmdline)
1506 fatal("Match directive not supported as a command-line "
1507 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001508 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001509 if (value < 0)
1510 fatal("%s line %d: Bad Match condition", filename,
1511 linenum);
1512 *activep = value;
1513 break;
1514
Damien Miller9b439df2006-07-24 14:04:00 +10001515 case sPermitOpen:
1516 arg = strdelim(&cp);
1517 if (!arg || *arg == '\0')
1518 fatal("%s line %d: missing PermitOpen specification",
1519 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001520 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001521 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001522 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001523 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001524 options->num_permitted_opens = 0;
1525 }
Damien Miller9b439df2006-07-24 14:04:00 +10001526 break;
1527 }
Damien Millerc6081482012-04-22 11:18:53 +10001528 if (strcmp(arg, "none") == 0) {
1529 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001530 options->num_permitted_opens = 1;
1531 channel_disable_adm_local_opens();
1532 }
1533 break;
1534 }
Damien Millera29b95e2007-01-05 16:28:36 +11001535 if (*activep && n == -1)
1536 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001537 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1538 p = hpdelim(&arg);
1539 if (p == NULL)
1540 fatal("%s line %d: missing host in PermitOpen",
1541 filename, linenum);
1542 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001543 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001544 fatal("%s line %d: bad port number in "
1545 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001546 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001547 options->num_permitted_opens =
1548 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001549 }
Damien Miller9b439df2006-07-24 14:04:00 +10001550 break;
1551
Damien Millere2754432006-07-24 14:06:47 +10001552 case sForceCommand:
1553 if (cp == NULL)
1554 fatal("%.200s line %d: Missing argument.", filename,
1555 linenum);
1556 len = strspn(cp, WHITESPACE);
1557 if (*activep && options->adm_forced_command == NULL)
1558 options->adm_forced_command = xstrdup(cp + len);
1559 return 0;
1560
Damien Millerd8cb1f12008-02-10 22:40:12 +11001561 case sChrootDirectory:
1562 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001563
1564 arg = strdelim(&cp);
1565 if (!arg || *arg == '\0')
1566 fatal("%s line %d: missing file name.",
1567 filename, linenum);
1568 if (*activep && *charptr == NULL)
1569 *charptr = xstrdup(arg);
1570 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001571
Damien Miller1aed65e2010-03-04 21:53:35 +11001572 case sTrustedUserCAKeys:
1573 charptr = &options->trusted_user_ca_keys;
1574 goto parse_filename;
1575
1576 case sRevokedKeys:
1577 charptr = &options->revoked_keys_file;
1578 goto parse_filename;
1579
Damien Miller0dac6fb2010-11-20 15:19:38 +11001580 case sIPQoS:
1581 arg = strdelim(&cp);
1582 if ((value = parse_ipqos(arg)) == -1)
1583 fatal("%s line %d: Bad IPQoS value: %s",
1584 filename, linenum, arg);
1585 arg = strdelim(&cp);
1586 if (arg == NULL)
1587 value2 = value;
1588 else if ((value2 = parse_ipqos(arg)) == -1)
1589 fatal("%s line %d: Bad IPQoS value: %s",
1590 filename, linenum, arg);
1591 if (*activep) {
1592 options->ip_qos_interactive = value;
1593 options->ip_qos_bulk = value2;
1594 }
1595 break;
1596
Damien Miller23528812012-04-22 11:24:43 +10001597 case sVersionAddendum:
1598 if (cp == NULL)
1599 fatal("%.200s line %d: Missing argument.", filename,
1600 linenum);
1601 len = strspn(cp, WHITESPACE);
1602 if (*activep && options->version_addendum == NULL) {
1603 if (strcasecmp(cp + len, "none") == 0)
1604 options->version_addendum = xstrdup("");
1605 else if (strchr(cp + len, '\r') != NULL)
1606 fatal("%.200s line %d: Invalid argument",
1607 filename, linenum);
1608 else
1609 options->version_addendum = xstrdup(cp + len);
1610 }
1611 return 0;
1612
Damien Miller09d3e122012-10-31 08:58:58 +11001613 case sAuthorizedKeysCommand:
1614 len = strspn(cp, WHITESPACE);
1615 if (*activep && options->authorized_keys_command == NULL) {
1616 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1617 fatal("%.200s line %d: AuthorizedKeysCommand "
1618 "must be an absolute path",
1619 filename, linenum);
1620 options->authorized_keys_command = xstrdup(cp + len);
1621 }
1622 return 0;
1623
1624 case sAuthorizedKeysCommandUser:
1625 charptr = &options->authorized_keys_command_user;
1626
1627 arg = strdelim(&cp);
1628 if (*activep && *charptr == NULL)
1629 *charptr = xstrdup(arg);
1630 break;
1631
Damien Millera6e3f012012-11-04 23:21:40 +11001632 case sAuthenticationMethods:
1633 if (*activep && options->num_auth_methods == 0) {
1634 while ((arg = strdelim(&cp)) && *arg != '\0') {
1635 if (options->num_auth_methods >=
1636 MAX_AUTH_METHODS)
1637 fatal("%s line %d: "
1638 "too many authentication methods.",
1639 filename, linenum);
1640 if (auth2_methods_valid(arg, 0) != 0)
1641 fatal("%s line %d: invalid "
1642 "authentication method list.",
1643 filename, linenum);
1644 options->auth_methods[
1645 options->num_auth_methods++] = xstrdup(arg);
1646 }
1647 }
1648 return 0;
1649
Damien Miller7acefbb2014-07-18 14:11:24 +10001650 case sStreamLocalBindMask:
1651 arg = strdelim(&cp);
1652 if (!arg || *arg == '\0')
1653 fatal("%s line %d: missing StreamLocalBindMask argument.",
1654 filename, linenum);
1655 /* Parse mode in octal format */
1656 value = strtol(arg, &p, 8);
1657 if (arg == p || value < 0 || value > 0777)
1658 fatal("%s line %d: Bad mask.", filename, linenum);
1659 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1660 break;
1661
1662 case sStreamLocalBindUnlink:
1663 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1664 goto parse_flag;
1665
Ben Lindstromade03f62001-12-06 18:22:17 +00001666 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001667 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001668 filename, linenum, arg);
1669 while (arg)
1670 arg = strdelim(&cp);
1671 break;
1672
Damien Millerf9b3feb2003-05-16 11:38:32 +10001673 case sUnsupported:
1674 logit("%s line %d: Unsupported option %s",
1675 filename, linenum, arg);
1676 while (arg)
1677 arg = strdelim(&cp);
1678 break;
1679
Ben Lindstromade03f62001-12-06 18:22:17 +00001680 default:
1681 fatal("%s line %d: Missing handler for opcode %s (%d)",
1682 filename, linenum, arg, opcode);
1683 }
1684 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1685 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1686 filename, linenum, arg);
1687 return 0;
1688}
1689
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001690/* Reads the server configuration file. */
1691
Damien Miller4af51302000-04-16 11:18:38 +10001692void
Darren Tucker645ab752004-06-25 13:33:20 +10001693load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001694{
Damien Miller46cb75a2012-07-31 12:22:37 +10001695 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001696 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001697 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001698
Darren Tucker645ab752004-06-25 13:33:20 +10001699 debug2("%s: filename %s", __func__, filename);
1700 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001701 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001702 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001703 }
Darren Tucker645ab752004-06-25 13:33:20 +10001704 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001705 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001706 lineno++;
1707 if (strlen(line) == sizeof(line) - 1)
1708 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001709 /*
1710 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001711 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001712 * line numbers later for error messages
1713 */
1714 if ((cp = strchr(line, '#')) != NULL)
1715 memcpy(cp, "\n", 2);
1716 cp = line + strspn(line, " \t\r");
1717
1718 buffer_append(conf, cp, strlen(cp));
1719 }
1720 buffer_append(conf, "\0", 1);
1721 fclose(f);
1722 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1723}
1724
1725void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001726parse_server_match_config(ServerOptions *options,
1727 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001728{
Darren Tucker45150472006-07-12 22:34:17 +10001729 ServerOptions mo;
1730
1731 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001732 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001733 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001734}
1735
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001736int parse_server_match_testspec(struct connection_info *ci, char *spec)
1737{
1738 char *p;
1739
1740 while ((p = strsep(&spec, ",")) && *p != '\0') {
1741 if (strncmp(p, "addr=", 5) == 0) {
1742 ci->address = xstrdup(p + 5);
1743 } else if (strncmp(p, "host=", 5) == 0) {
1744 ci->host = xstrdup(p + 5);
1745 } else if (strncmp(p, "user=", 5) == 0) {
1746 ci->user = xstrdup(p + 5);
1747 } else if (strncmp(p, "laddr=", 6) == 0) {
1748 ci->laddress = xstrdup(p + 6);
1749 } else if (strncmp(p, "lport=", 6) == 0) {
1750 ci->lport = a2port(p + 6);
1751 if (ci->lport == -1) {
1752 fprintf(stderr, "Invalid port '%s' in test mode"
1753 " specification %s\n", p+6, p);
1754 return -1;
1755 }
1756 } else {
1757 fprintf(stderr, "Invalid test mode specification %s\n",
1758 p);
1759 return -1;
1760 }
1761 }
1762 return 0;
1763}
1764
1765/*
1766 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1767 * empty spec.
1768 */
1769int server_match_spec_complete(struct connection_info *ci)
1770{
1771 if (ci->user && ci->host && ci->address)
1772 return 1; /* complete */
1773 if (!ci->user && !ci->host && !ci->address)
1774 return -1; /* empty */
1775 return 0; /* partial */
1776}
1777
Darren Tucker1629c072007-02-19 22:25:37 +11001778/*
1779 * Copy any supported values that are set.
1780 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001781 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001782 * array values that are not used pre-authentication, because any that we
1783 * do use must be explictly sent in mm_getpwnamallow().
1784 */
Darren Tucker45150472006-07-12 22:34:17 +10001785void
Darren Tucker1629c072007-02-19 22:25:37 +11001786copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001787{
Damien Miller534b2cc2013-12-05 14:07:27 +11001788#define M_CP_INTOPT(n) do {\
1789 if (src->n != -1) \
1790 dst->n = src->n; \
1791} while (0)
1792
Darren Tucker1629c072007-02-19 22:25:37 +11001793 M_CP_INTOPT(password_authentication);
1794 M_CP_INTOPT(gss_authentication);
1795 M_CP_INTOPT(rsa_authentication);
1796 M_CP_INTOPT(pubkey_authentication);
1797 M_CP_INTOPT(kerberos_authentication);
1798 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001799 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001800 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001801 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001802 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001803
1804 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10001805 M_CP_INTOPT(allow_streamlocal_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001806 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001807 M_CP_INTOPT(permit_tun);
Damien Miller7acefbb2014-07-18 14:11:24 +10001808 M_CP_INTOPT(fwd_opts.gateway_ports);
Darren Tucker1629c072007-02-19 22:25:37 +11001809 M_CP_INTOPT(x11_display_offset);
1810 M_CP_INTOPT(x11_forwarding);
1811 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001812 M_CP_INTOPT(permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10001813 M_CP_INTOPT(permit_user_rc);
Damien Miller7207f642008-05-19 15:34:50 +10001814 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001815 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001816 M_CP_INTOPT(ip_qos_interactive);
1817 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001818 M_CP_INTOPT(rekey_limit);
1819 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001820
Damien Miller534b2cc2013-12-05 14:07:27 +11001821 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1822#define M_CP_STROPT(n) do {\
1823 if (src->n != NULL && dst->n != src->n) { \
1824 free(dst->n); \
1825 dst->n = src->n; \
1826 } \
1827} while(0)
1828#define M_CP_STRARRAYOPT(n, num_n) do {\
1829 if (src->num_n != 0) { \
1830 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1831 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1832 } \
1833} while(0)
1834
Damien Millerf2e407e2011-05-20 19:04:14 +10001835 /* See comment in servconf.h */
1836 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001837
Damien Millerc2411902011-05-20 19:03:49 +10001838 /*
1839 * The only things that should be below this point are string options
1840 * which are only used after authentication.
1841 */
Damien Miller5d74e582011-05-20 19:03:31 +10001842 if (preauth)
1843 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001844
Damien Miller5d74e582011-05-20 19:03:31 +10001845 M_CP_STROPT(adm_forced_command);
1846 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001847}
1848
Darren Tucker1629c072007-02-19 22:25:37 +11001849#undef M_CP_INTOPT
1850#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001851#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001852
Darren Tucker45150472006-07-12 22:34:17 +10001853void
1854parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001855 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001856{
1857 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001858 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001859
1860 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1861
Darren Tucker9fbac712004-08-12 22:41:44 +10001862 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001863 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001864 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001865 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001866 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001867 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001868 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001869 }
Darren Tuckera627d422013-06-02 07:31:17 +10001870 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001871 if (bad_options > 0)
1872 fatal("%s: terminating, %d bad configuration options",
1873 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001874}
Darren Tuckere7140f22008-06-10 23:01:51 +10001875
1876static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001877fmt_multistate_int(int val, const struct multistate *m)
1878{
1879 u_int i;
1880
1881 for (i = 0; m[i].key != NULL; i++) {
1882 if (m[i].value == val)
1883 return m[i].key;
1884 }
1885 return "UNKNOWN";
1886}
1887
1888static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001889fmt_intarg(ServerOpCodes code, int val)
1890{
Damien Miller82c55872011-06-23 08:20:30 +10001891 if (val == -1)
1892 return "unset";
1893 switch (code) {
1894 case sAddressFamily:
1895 return fmt_multistate_int(val, multistate_addressfamily);
1896 case sPermitRootLogin:
1897 return fmt_multistate_int(val, multistate_permitrootlogin);
1898 case sGatewayPorts:
1899 return fmt_multistate_int(val, multistate_gatewayports);
1900 case sCompression:
1901 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001902 case sUsePrivilegeSeparation:
1903 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001904 case sAllowTcpForwarding:
1905 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller7acefbb2014-07-18 14:11:24 +10001906 case sAllowStreamLocalForwarding:
1907 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001908 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001909 switch (val) {
1910 case SSH_PROTO_1:
1911 return "1";
1912 case SSH_PROTO_2:
1913 return "2";
1914 case (SSH_PROTO_1|SSH_PROTO_2):
1915 return "2,1";
1916 default:
1917 return "UNKNOWN";
1918 }
Damien Miller82c55872011-06-23 08:20:30 +10001919 default:
1920 switch (val) {
1921 case 0:
1922 return "no";
1923 case 1:
1924 return "yes";
1925 default:
1926 return "UNKNOWN";
1927 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001928 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001929}
1930
1931static const char *
1932lookup_opcode_name(ServerOpCodes code)
1933{
1934 u_int i;
1935
1936 for (i = 0; keywords[i].name != NULL; i++)
1937 if (keywords[i].opcode == code)
1938 return(keywords[i].name);
1939 return "UNKNOWN";
1940}
1941
1942static void
1943dump_cfg_int(ServerOpCodes code, int val)
1944{
1945 printf("%s %d\n", lookup_opcode_name(code), val);
1946}
1947
1948static void
1949dump_cfg_fmtint(ServerOpCodes code, int val)
1950{
1951 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1952}
1953
1954static void
1955dump_cfg_string(ServerOpCodes code, const char *val)
1956{
1957 if (val == NULL)
1958 return;
1959 printf("%s %s\n", lookup_opcode_name(code), val);
1960}
1961
1962static void
1963dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1964{
1965 u_int i;
1966
1967 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001968 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1969}
1970
1971static void
1972dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1973{
1974 u_int i;
1975
1976 printf("%s", lookup_opcode_name(code));
1977 for (i = 0; i < count; i++)
1978 printf(" %s", vals[i]);
1979 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001980}
1981
1982void
1983dump_config(ServerOptions *o)
1984{
1985 u_int i;
1986 int ret;
1987 struct addrinfo *ai;
1988 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1989
1990 /* these are usually at the top of the config */
1991 for (i = 0; i < o->num_ports; i++)
1992 printf("port %d\n", o->ports[i]);
1993 dump_cfg_fmtint(sProtocol, o->protocol);
1994 dump_cfg_fmtint(sAddressFamily, o->address_family);
1995
1996 /* ListenAddress must be after Port */
1997 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1998 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1999 sizeof(addr), port, sizeof(port),
2000 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2001 error("getnameinfo failed: %.100s",
2002 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2003 strerror(errno));
2004 } else {
2005 if (ai->ai_family == AF_INET6)
2006 printf("listenaddress [%s]:%s\n", addr, port);
2007 else
2008 printf("listenaddress %s:%s\n", addr, port);
2009 }
2010 }
2011
2012 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10002013#ifdef USE_PAM
2014 dump_cfg_int(sUsePAM, o->use_pam);
2015#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002016 dump_cfg_int(sServerKeyBits, o->server_key_bits);
2017 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2018 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
2019 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2020 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11002021 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10002022 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2023 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
2024
2025 /* formatted integer arguments */
2026 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2027 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2028 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2029 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2030 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2031 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2032 o->hostbased_uses_name_from_packet_only);
2033 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2034 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002035#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002036 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2037 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2038 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002039# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002040 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002041# endif
2042#endif
2043#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002044 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2045 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002046#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002047 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2048 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2049 o->kbd_interactive_authentication);
2050 dump_cfg_fmtint(sChallengeResponseAuthentication,
2051 o->challenge_response_authentication);
2052 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2053 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2054 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2055 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002056 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Damien Miller72e6b5c2014-07-04 09:00:04 +10002057 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
Darren Tuckere7140f22008-06-10 23:01:51 +10002058 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2059 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2060 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2061 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2062 dump_cfg_fmtint(sUseLogin, o->use_login);
2063 dump_cfg_fmtint(sCompression, o->compression);
Damien Miller7acefbb2014-07-18 14:11:24 +10002064 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
Darren Tuckere7140f22008-06-10 23:01:51 +10002065 dump_cfg_fmtint(sUseDNS, o->use_dns);
2066 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
Damien Miller7acefbb2014-07-18 14:11:24 +10002067 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
Darren Tuckere7140f22008-06-10 23:01:51 +10002068 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2069
2070 /* string arguments */
2071 dump_cfg_string(sPidFile, o->pid_file);
2072 dump_cfg_string(sXAuthLocation, o->xauth_location);
Damien Miller690d9892013-11-08 12:16:49 +11002073 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers :
Damien Miller0fde8ac2013-11-21 14:12:23 +11002074 cipher_alg_list(',', 0));
Damien Miller690d9892013-11-08 12:16:49 +11002075 dump_cfg_string(sMacs, o->macs ? o->macs : mac_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002076 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002077 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002078 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002079 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2080 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002081 dump_cfg_string(sAuthorizedPrincipalsFile,
2082 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002083 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002084 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2085 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002086 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Damien Miller690d9892013-11-08 12:16:49 +11002087 dump_cfg_string(sKexAlgorithms, o->kex_algorithms ? o->kex_algorithms :
2088 kex_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002089
2090 /* string arguments requiring a lookup */
2091 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2092 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2093
2094 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002095 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2096 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002097 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2098 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002099 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2100 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002101 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2102 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2103 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2104 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2105 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002106 dump_cfg_strarray_oneline(sAuthenticationMethods,
2107 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002108
2109 /* other arguments */
2110 for (i = 0; i < o->num_subsystems; i++)
2111 printf("subsystem %s %s\n", o->subsystem_name[i],
2112 o->subsystem_args[i]);
2113
2114 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2115 o->max_startups_rate, o->max_startups);
2116
2117 for (i = 0; tunmode_desc[i].val != -1; i++)
2118 if (tunmode_desc[i].val == o->permit_tun) {
2119 s = tunmode_desc[i].text;
2120 break;
2121 }
2122 dump_cfg_string(sPermitTunnel, s);
2123
Damien Miller91475862011-05-05 14:14:34 +10002124 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2125 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002126
Damien Millera6d6c1f2013-08-21 02:40:01 +10002127 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2128 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002129
Darren Tuckere7140f22008-06-10 23:01:51 +10002130 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002131}