blob: 9bcd05bf25c017fdad40034e58f6df17396cc05c [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Miller5be9d9e2013-12-07 11:24:01 +11002/* $OpenBSD: servconf.c,v 1.248 2013/12/06 13:39:49 markus Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
Damien Millerd7834352006-08-05 12:39:39 +100031#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100032#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100033#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100034#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100035#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100036
Damien Millerb84886b2008-05-19 15:05:07 +100037#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100041#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100042#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100043#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000044#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000045#include "misc.h"
46#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100047#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000048#include "kex.h"
49#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100050#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100051#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100052#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100053#include "canohost.h"
54#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110055#include "hostfile.h"
56#include "auth.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000057
Damien Miller3dc71ad2009-01-28 16:31:22 +110058static void add_listen_addr(ServerOptions *, char *, int);
59static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110060
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000061/* Use of privilege separation or not */
62extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100063extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000064
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065/* Initializes the server options to their default values. */
66
Damien Miller4af51302000-04-16 11:18:38 +100067void
Damien Miller95def091999-11-25 00:26:21 +110068initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069{
Damien Miller95def091999-11-25 00:26:21 +110070 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110071
72 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100073 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110076 options->num_ports = 0;
77 options->ports_from_cmdline = 0;
78 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110079 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110080 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110081 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100082 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100083 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110084 options->server_key_bits = -1;
85 options->login_grace_time = -1;
86 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000087 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110088 options->ignore_rhosts = -1;
89 options->ignore_user_known_hosts = -1;
90 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000091 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110092 options->x11_forwarding = -1;
93 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110094 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110095 options->permit_tty = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100096 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110097 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110098 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110099 options->log_facility = SYSLOG_FACILITY_NOT_SET;
100 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000102 options->hostbased_authentication = -1;
103 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +1100104 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100105 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->kerberos_authentication = -1;
107 options->kerberos_or_local_passwd = -1;
108 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100109 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000110 options->gss_authentication=-1;
111 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100113 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000114 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100115 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000116 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100117 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000118 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000119 options->rekey_limit = -1;
120 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100121 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000122 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100123 options->num_allow_users = 0;
124 options->num_deny_users = 0;
125 options->num_allow_groups = 0;
126 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000127 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000128 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000129 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000130 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000131 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000132 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000133 options->max_startups_begin = -1;
134 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000135 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000136 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000137 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000138 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000139 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000140 options->client_alive_interval = -1;
141 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000142 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000143 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100144 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000145 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000146 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100147 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100148 options->authorized_keys_command = NULL;
149 options->authorized_keys_command_user = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100150 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100151 options->revoked_keys_file = NULL;
152 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000153 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100154 options->ip_qos_interactive = -1;
155 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000156 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000157}
158
Damien Miller4af51302000-04-16 11:18:38 +1000159void
Damien Miller95def091999-11-25 00:26:21 +1100160fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000161{
Damien Miller726273e2001-11-12 11:40:11 +1100162 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000163 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000164 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100165
166 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100167 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100168 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100169 if (options->num_host_key_files == 0) {
170 /* fill default hostkeys for protocols */
171 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100172 options->host_key_files[options->num_host_key_files++] =
173 _PATH_HOST_KEY_FILE;
174 if (options->protocol & SSH_PROTO_2) {
175 options->host_key_files[options->num_host_key_files++] =
176 _PATH_HOST_RSA_KEY_FILE;
177 options->host_key_files[options->num_host_key_files++] =
178 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100179#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000180 options->host_key_files[options->num_host_key_files++] =
181 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100182#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100183 options->host_key_files[options->num_host_key_files++] =
184 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100185 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100186 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100187 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100188 if (options->num_ports == 0)
189 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
190 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000191 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000192 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000193 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000195 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100196 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000197 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->key_regeneration_time == -1)
199 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000200 if (options->permit_root_login == PERMIT_NOT_SET)
201 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100203 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->ignore_user_known_hosts == -1)
205 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100206 if (options->print_motd == -1)
207 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000208 if (options->print_lastlog == -1)
209 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100211 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100212 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100213 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100214 if (options->x11_use_localhost == -1)
215 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000216 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000217 options->xauth_location = _PATH_XAUTH;
Damien Miller5ff30c62013-10-30 22:21:50 +1100218 if (options->permit_tty == -1)
219 options->permit_tty = 1;
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->strict_modes == -1)
221 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100222 if (options->tcp_keep_alive == -1)
223 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100224 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100225 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100226 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000227 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100229 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000230 if (options->hostbased_authentication == -1)
231 options->hostbased_authentication = 0;
232 if (options->hostbased_uses_name_from_packet_only == -1)
233 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->rsa_authentication == -1)
235 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100236 if (options->pubkey_authentication == -1)
237 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100238 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000239 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100240 if (options->kerberos_or_local_passwd == -1)
241 options->kerberos_or_local_passwd = 1;
242 if (options->kerberos_ticket_cleanup == -1)
243 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100244 if (options->kerberos_get_afs_token == -1)
245 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000246 if (options->gss_authentication == -1)
247 options->gss_authentication = 0;
248 if (options->gss_cleanup_creds == -1)
249 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100250 if (options->password_authentication == -1)
251 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100252 if (options->kbd_interactive_authentication == -1)
253 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000254 if (options->challenge_response_authentication == -1)
255 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100256 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100257 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000258 if (options->permit_user_env == -1)
259 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100260 if (options->use_login == -1)
261 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000262 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000263 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000264 if (options->rekey_limit == -1)
265 options->rekey_limit = 0;
266 if (options->rekey_interval == -1)
267 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100268 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100269 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000270 if (options->allow_agent_forwarding == -1)
271 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000272 if (options->gateway_ports == -1)
273 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000274 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100275 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000276 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100277 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000278 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100279 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000280 if (options->max_authtries == -1)
281 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000282 if (options->max_sessions == -1)
283 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000284 if (options->use_dns == -1)
285 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000286 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100287 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000288 if (options->client_alive_count_max == -1)
289 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000290 if (options->num_authkeys_files == 0) {
291 options->authorized_keys_files[options->num_authkeys_files++] =
292 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
293 options->authorized_keys_files[options->num_authkeys_files++] =
294 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
295 }
Damien Millerd27b9472005-12-13 19:29:02 +1100296 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100297 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100298 if (options->zero_knowledge_password_authentication == -1)
299 options->zero_knowledge_password_authentication = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100300 if (options->ip_qos_interactive == -1)
301 options->ip_qos_interactive = IPTOS_LOWDELAY;
302 if (options->ip_qos_bulk == -1)
303 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000304 if (options->version_addendum == NULL)
305 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000306 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000307 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000308 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000309
Tim Rice40017b02002-07-14 13:36:49 -0700310#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000311 if (use_privsep && options->compression == 1) {
312 error("This platform does not support both privilege "
313 "separation and compression");
314 error("Compression disabled");
315 options->compression = 0;
316 }
317#endif
318
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000319}
320
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000321/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100322typedef enum {
323 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100324 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000325 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100326 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100327 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
328 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000329 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100330 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100331 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000332 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100333 sPasswordAuthentication, sKbdInteractiveAuthentication,
334 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000335 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100336 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100337 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000338 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000339 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000340 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000341 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000342 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000343 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100344 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000345 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100346 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100347 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100348 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100349 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000350 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000351 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100352 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller85b45e02013-07-20 13:21:52 +1000353 sAuthenticationMethods, sHostKeyAgent,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000354 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000355} ServerOpCodes;
356
Darren Tucker45150472006-07-12 22:34:17 +1000357#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
358#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
359#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
360
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000361/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100362static struct {
363 const char *name;
364 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000365 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100366} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100367 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000368#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000369 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000370#else
Darren Tucker45150472006-07-12 22:34:17 +1000371 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000372#endif
Darren Tucker45150472006-07-12 22:34:17 +1000373 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100374 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000375 { "port", sPort, SSHCFG_GLOBAL },
376 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
377 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000378 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000379 { "pidfile", sPidFile, SSHCFG_GLOBAL },
380 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
381 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
382 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100383 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000384 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
385 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
386 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100387 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
388 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000389 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100390 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
391 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000392 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000393#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100394 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
396 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100397#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000398 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000399#else
Darren Tucker45150472006-07-12 22:34:17 +1000400 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100401#endif
402#else
Darren Tucker1629c072007-02-19 22:25:37 +1100403 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000404 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
405 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
406 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000407#endif
Darren Tucker45150472006-07-12 22:34:17 +1000408 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
409 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000410#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100411 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000412 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000413#else
Darren Tucker1629c072007-02-19 22:25:37 +1100414 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000415 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000416#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100417 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
418 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100419 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000420 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100421#ifdef JPAKE
422 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
423#else
424 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
425#endif
Darren Tucker45150472006-07-12 22:34:17 +1000426 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
427 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
428 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
429 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
430 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
431 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
432 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000433 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
434 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
435 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000436 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
437 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100438 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000439 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
440 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
441 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000442 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000443 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
444 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
445 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000446 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000447 { "allowusers", sAllowUsers, SSHCFG_ALL },
448 { "denyusers", sDenyUsers, SSHCFG_ALL },
449 { "allowgroups", sAllowGroups, SSHCFG_ALL },
450 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000451 { "ciphers", sCiphers, SSHCFG_GLOBAL },
452 { "macs", sMacs, SSHCFG_GLOBAL },
453 { "protocol", sProtocol, SSHCFG_GLOBAL },
454 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
455 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
456 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000457 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000458 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100459 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000460 { "usedns", sUseDNS, SSHCFG_GLOBAL },
461 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
462 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
463 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
464 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000465 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000466 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000467 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000468 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000469 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100470 { "permittty", sPermitTTY, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000471 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000472 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000473 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100474 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100475 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100476 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
477 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000478 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000479 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100480 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100481 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
482 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000483 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100484 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000485 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000486};
487
Darren Tuckere7140f22008-06-10 23:01:51 +1000488static struct {
489 int val;
490 char *text;
491} tunmode_desc[] = {
492 { SSH_TUNMODE_NO, "no" },
493 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
494 { SSH_TUNMODE_ETHERNET, "ethernet" },
495 { SSH_TUNMODE_YES, "yes" },
496 { -1, NULL }
497};
498
Damien Miller5428f641999-11-25 11:54:57 +1100499/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000500 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100501 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000502
Damien Miller4af51302000-04-16 11:18:38 +1000503static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100504parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000505 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000506{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000507 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000508
Damien Miller95def091999-11-25 00:26:21 +1100509 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000510 if (strcasecmp(cp, keywords[i].name) == 0) {
511 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100512 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000513 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000514
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000515 error("%s: line %d: Bad configuration option: %s",
516 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100517 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000518}
519
Darren Tucker88b6fb22010-01-13 22:44:29 +1100520char *
521derelativise_path(const char *path)
522{
Damien Miller44451d02010-03-26 10:40:04 +1100523 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100524
525 expanded = tilde_expand_filename(path, getuid());
526 if (*expanded == '/')
527 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100528 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100529 fatal("%s: getcwd: %s", __func__, strerror(errno));
530 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000531 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100532 return ret;
533}
534
Ben Lindstrombba81212001-06-25 05:01:22 +0000535static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100536add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100537{
Damien Millereccb9de2005-06-17 12:59:34 +1000538 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100539
540 if (options->num_ports == 0)
541 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100542 if (options->address_family == -1)
543 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000544 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000545 for (i = 0; i < options->num_ports; i++)
546 add_one_listen_addr(options, addr, options->ports[i]);
547 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000548 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000549}
550
Ben Lindstrombba81212001-06-25 05:01:22 +0000551static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100552add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000553{
554 struct addrinfo hints, *ai, *aitop;
555 char strport[NI_MAXSERV];
556 int gaierr;
557
558 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100559 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000560 hints.ai_socktype = SOCK_STREAM;
561 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100562 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000563 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
564 fatal("bad addr or host: %s (%s)",
565 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100566 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000567 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
568 ;
569 ai->ai_next = options->listen_addrs;
570 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100571}
572
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000573struct connection_info *
574get_connection_info(int populate, int use_dns)
575{
576 static struct connection_info ci;
577
578 if (!populate)
579 return &ci;
580 ci.host = get_canonical_hostname(use_dns);
581 ci.address = get_remote_ipaddr();
582 ci.laddress = get_local_ipaddr(packet_get_connection_in());
583 ci.lport = get_local_port();
584 return &ci;
585}
586
Darren Tucker45150472006-07-12 22:34:17 +1000587/*
588 * The strategy for the Match blocks is that the config file is parsed twice.
589 *
590 * The first time is at startup. activep is initialized to 1 and the
591 * directives in the global context are processed and acted on. Hitting a
592 * Match directive unsets activep and the directives inside the block are
593 * checked for syntax only.
594 *
595 * The second time is after a connection has been established but before
596 * authentication. activep is initialized to 2 and global config directives
597 * are ignored since they have already been processed. If the criteria in a
598 * Match block is met, activep is set and the subsequent directives
599 * processed and actioned until EOF or another Match block unsets it. Any
600 * options set are copied into the main server config.
601 *
602 * Potential additions/improvements:
603 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
604 *
605 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
606 * Match Address 192.168.0.*
607 * Tag trusted
608 * Match Group wheel
609 * Tag trusted
610 * Match Tag trusted
611 * AllowTcpForwarding yes
612 * GatewayPorts clientspecified
613 * [...]
614 *
615 * - Add a PermittedChannelRequests directive
616 * Match Group shell
617 * PermittedChannelRequests session,forwarded-tcpip
618 */
619
620static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000621match_cfg_line_group(const char *grps, int line, const char *user)
622{
623 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000624 struct passwd *pw;
625
Damien Miller565ca3f2006-08-19 00:23:15 +1000626 if (user == NULL)
627 goto out;
628
629 if ((pw = getpwnam(user)) == NULL) {
630 debug("Can't match group at line %d because user %.100s does "
631 "not exist", line, user);
632 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
633 debug("Can't Match group because user %.100s not in any group "
634 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000635 } else if (ga_match_pattern_list(grps) != 1) {
636 debug("user %.100s does not match group list %.100s at line %d",
637 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000638 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000639 debug("user %.100s matched group list %.100s at line %d", user,
640 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000641 result = 1;
642 }
643out:
644 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000645 return result;
646}
647
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000648/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000649 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100650 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000651 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000652 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000653static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000654match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000655{
Damien Millercf31f382013-10-24 21:02:56 +1100656 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000657 char *arg, *attrib, *cp = *condition;
658 size_t len;
659
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000660 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000661 debug3("checking syntax for 'Match %s'", cp);
662 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000663 debug3("checking match for '%s' user %s host %s addr %s "
664 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
665 ci->host ? ci->host : "(null)",
666 ci->address ? ci->address : "(null)",
667 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000668
669 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100670 attributes++;
671 if (strcasecmp(attrib, "all") == 0) {
672 if (attributes != 1 ||
673 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
674 error("'all' cannot be combined with other "
675 "Match attributes");
676 return -1;
677 }
678 *condition = cp;
679 return 1;
680 }
Darren Tucker45150472006-07-12 22:34:17 +1000681 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
682 error("Missing Match criteria for %s", attrib);
683 return -1;
684 }
685 len = strlen(arg);
686 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000687 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000688 result = 0;
689 continue;
690 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000691 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000692 result = 0;
693 else
694 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000696 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000697 if (ci == NULL || ci->user == NULL) {
698 result = 0;
699 continue;
700 }
701 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000702 case -1:
703 return -1;
704 case 0:
705 result = 0;
706 }
Darren Tucker45150472006-07-12 22:34:17 +1000707 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000708 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000709 result = 0;
710 continue;
711 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000712 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000713 result = 0;
714 else
715 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000716 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000717 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000718 if (ci == NULL || ci->address == NULL) {
719 result = 0;
720 continue;
721 }
722 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000723 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000724 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000725 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000726 break;
727 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000728 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000729 result = 0;
730 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000731 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000732 return -1;
733 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000734 } else if (strcasecmp(attrib, "localaddress") == 0){
735 if (ci == NULL || ci->laddress == NULL) {
736 result = 0;
737 continue;
738 }
739 switch (addr_match_list(ci->laddress, arg)) {
740 case 1:
741 debug("connection from %.100s matched "
742 "'LocalAddress %.100s' at line %d",
743 ci->laddress, arg, line);
744 break;
745 case 0:
746 case -1:
747 result = 0;
748 break;
749 case -2:
750 return -1;
751 }
752 } else if (strcasecmp(attrib, "localport") == 0) {
753 if ((port = a2port(arg)) == -1) {
754 error("Invalid LocalPort '%s' on Match line",
755 arg);
756 return -1;
757 }
758 if (ci == NULL || ci->lport == 0) {
759 result = 0;
760 continue;
761 }
762 /* TODO support port lists */
763 if (port == ci->lport)
764 debug("connection from %.100s matched "
765 "'LocalPort %d' at line %d",
766 ci->laddress, port, line);
767 else
768 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000769 } else {
770 error("Unsupported Match attribute %s", attrib);
771 return -1;
772 }
773 }
Damien Millercf31f382013-10-24 21:02:56 +1100774 if (attributes == 0) {
775 error("One or more attributes required for Match");
776 return -1;
777 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000778 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000779 debug3("match %sfound", result ? "" : "not ");
780 *condition = cp;
781 return result;
782}
783
Damien Millere2754432006-07-24 14:06:47 +1000784#define WHITESPACE " \t\r\n"
785
Damien Miller33322122011-06-20 14:43:11 +1000786/* Multistate option parsing */
787struct multistate {
788 char *key;
789 int value;
790};
791static const struct multistate multistate_addressfamily[] = {
792 { "inet", AF_INET },
793 { "inet6", AF_INET6 },
794 { "any", AF_UNSPEC },
795 { NULL, -1 }
796};
797static const struct multistate multistate_permitrootlogin[] = {
798 { "without-password", PERMIT_NO_PASSWD },
799 { "forced-commands-only", PERMIT_FORCED_ONLY },
800 { "yes", PERMIT_YES },
801 { "no", PERMIT_NO },
802 { NULL, -1 }
803};
804static const struct multistate multistate_compression[] = {
805 { "delayed", COMP_DELAYED },
806 { "yes", COMP_ZLIB },
807 { "no", COMP_NONE },
808 { NULL, -1 }
809};
810static const struct multistate multistate_gatewayports[] = {
811 { "clientspecified", 2 },
812 { "yes", 1 },
813 { "no", 0 },
814 { NULL, -1 }
815};
Damien Miller69ff1df2011-06-23 08:30:03 +1000816static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000817 { "yes", PRIVSEP_NOSANDBOX },
818 { "sandbox", PRIVSEP_ON },
819 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000820 { "no", PRIVSEP_OFF },
821 { NULL, -1 }
822};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100823static const struct multistate multistate_tcpfwd[] = {
824 { "yes", FORWARD_ALLOW },
825 { "all", FORWARD_ALLOW },
826 { "no", FORWARD_DENY },
827 { "remote", FORWARD_REMOTE },
828 { "local", FORWARD_LOCAL },
829 { NULL, -1 }
830};
Damien Miller33322122011-06-20 14:43:11 +1000831
Ben Lindstromade03f62001-12-06 18:22:17 +0000832int
833process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000834 const char *filename, int linenum, int *activep,
835 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000836{
Darren Tucker09c0f032013-05-16 20:48:57 +1000837 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000838 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100839 SyslogFacility *log_facility_ptr;
840 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000841 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000842 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000843 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000844 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000845 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000846
847 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100848 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100849 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000850 /* Ignore leading whitespace */
851 if (*arg == '\0')
852 arg = strdelim(&cp);
853 if (!arg || !*arg || *arg == '#')
854 return 0;
855 intptr = NULL;
856 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000857 opcode = parse_token(arg, filename, linenum, &flags);
858
859 if (activep == NULL) { /* We are processing a command line directive */
860 cmdline = 1;
861 activep = &cmdline;
862 }
863 if (*activep && opcode != sMatch)
864 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
865 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000866 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000867 fatal("%s line %d: Directive '%s' is not allowed "
868 "within a Match block", filename, linenum, arg);
869 } else { /* this is a directive we have already processed */
870 while (arg)
871 arg = strdelim(&cp);
872 return 0;
873 }
874 }
875
Ben Lindstromade03f62001-12-06 18:22:17 +0000876 switch (opcode) {
877 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000878 case sUsePAM:
879 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000880 goto parse_flag;
881
882 /* Standard Options */
883 case sBadOption:
884 return -1;
885 case sPort:
886 /* ignore ports from configfile if cmdline specifies ports */
887 if (options->ports_from_cmdline)
888 return 0;
889 if (options->listen_addrs != NULL)
890 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100891 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000892 if (options->num_ports >= MAX_PORTS)
893 fatal("%s line %d: too many ports.",
894 filename, linenum);
895 arg = strdelim(&cp);
896 if (!arg || *arg == '\0')
897 fatal("%s line %d: missing port number.",
898 filename, linenum);
899 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100900 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000901 fatal("%s line %d: Badly formatted port number.",
902 filename, linenum);
903 break;
904
905 case sServerKeyBits:
906 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000907 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000908 arg = strdelim(&cp);
909 if (!arg || *arg == '\0')
910 fatal("%s line %d: missing integer value.",
911 filename, linenum);
912 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000913 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000914 *intptr = value;
915 break;
916
917 case sLoginGraceTime:
918 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000919 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000920 arg = strdelim(&cp);
921 if (!arg || *arg == '\0')
922 fatal("%s line %d: missing time value.",
923 filename, linenum);
924 if ((value = convtime(arg)) == -1)
925 fatal("%s line %d: invalid time value.",
926 filename, linenum);
927 if (*intptr == -1)
928 *intptr = value;
929 break;
930
931 case sKeyRegenerationTime:
932 intptr = &options->key_regeneration_time;
933 goto parse_time;
934
935 case sListenAddress:
936 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100937 if (arg == NULL || *arg == '\0')
938 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000939 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000940 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
941 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
942 && strchr(p+1, ':') != NULL) {
943 add_listen_addr(options, arg, 0);
944 break;
945 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100946 p = hpdelim(&arg);
947 if (p == NULL)
948 fatal("%s line %d: bad address:port usage",
949 filename, linenum);
950 p = cleanhostname(p);
951 if (arg == NULL)
952 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100953 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100954 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000955
Damien Millerf91ee4c2005-03-01 21:24:33 +1100956 add_listen_addr(options, p, port);
957
Ben Lindstromade03f62001-12-06 18:22:17 +0000958 break;
959
Darren Tucker0f383232005-01-20 10:57:56 +1100960 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000961 intptr = &options->address_family;
962 multistate_ptr = multistate_addressfamily;
963 if (options->listen_addrs != NULL)
964 fatal("%s line %d: address family must be specified "
965 "before ListenAddress.", filename, linenum);
966 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100967 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000968 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000969 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000970 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000971 value = -1;
972 for (i = 0; multistate_ptr[i].key != NULL; i++) {
973 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
974 value = multistate_ptr[i].value;
975 break;
976 }
977 }
978 if (value == -1)
979 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100980 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000981 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100982 *intptr = value;
983 break;
984
Ben Lindstromade03f62001-12-06 18:22:17 +0000985 case sHostKeyFile:
986 intptr = &options->num_host_key_files;
987 if (*intptr >= MAX_HOSTKEYS)
988 fatal("%s line %d: too many host keys specified (max %d).",
989 filename, linenum, MAX_HOSTKEYS);
990 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000991 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000992 arg = strdelim(&cp);
993 if (!arg || *arg == '\0')
994 fatal("%s line %d: missing file name.",
995 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000996 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100997 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000998 /* increase optional counter */
999 if (intptr != NULL)
1000 *intptr = *intptr + 1;
1001 }
1002 break;
1003
Damien Miller85b45e02013-07-20 13:21:52 +10001004 case sHostKeyAgent:
1005 charptr = &options->host_key_agent;
1006 arg = strdelim(&cp);
1007 if (!arg || *arg == '\0')
1008 fatal("%s line %d: missing socket name.",
1009 filename, linenum);
1010 if (*activep && *charptr == NULL)
1011 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1012 xstrdup(arg) : derelativise_path(arg);
1013 break;
1014
Damien Miller0a80ca12010-02-27 07:55:05 +11001015 case sHostCertificate:
1016 intptr = &options->num_host_cert_files;
1017 if (*intptr >= MAX_HOSTKEYS)
1018 fatal("%s line %d: too many host certificates "
1019 "specified (max %d).", filename, linenum,
1020 MAX_HOSTCERTS);
1021 charptr = &options->host_cert_files[*intptr];
1022 goto parse_filename;
1023 break;
1024
Ben Lindstromade03f62001-12-06 18:22:17 +00001025 case sPidFile:
1026 charptr = &options->pid_file;
1027 goto parse_filename;
1028
1029 case sPermitRootLogin:
1030 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001031 multistate_ptr = multistate_permitrootlogin;
1032 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001033
1034 case sIgnoreRhosts:
1035 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001036 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001037 arg = strdelim(&cp);
1038 if (!arg || *arg == '\0')
1039 fatal("%s line %d: missing yes/no argument.",
1040 filename, linenum);
1041 value = 0; /* silence compiler */
1042 if (strcmp(arg, "yes") == 0)
1043 value = 1;
1044 else if (strcmp(arg, "no") == 0)
1045 value = 0;
1046 else
1047 fatal("%s line %d: Bad yes/no argument: %s",
1048 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001049 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001050 *intptr = value;
1051 break;
1052
1053 case sIgnoreUserKnownHosts:
1054 intptr = &options->ignore_user_known_hosts;
1055 goto parse_flag;
1056
Ben Lindstromade03f62001-12-06 18:22:17 +00001057 case sRhostsRSAAuthentication:
1058 intptr = &options->rhosts_rsa_authentication;
1059 goto parse_flag;
1060
1061 case sHostbasedAuthentication:
1062 intptr = &options->hostbased_authentication;
1063 goto parse_flag;
1064
1065 case sHostbasedUsesNameFromPacketOnly:
1066 intptr = &options->hostbased_uses_name_from_packet_only;
1067 goto parse_flag;
1068
1069 case sRSAAuthentication:
1070 intptr = &options->rsa_authentication;
1071 goto parse_flag;
1072
1073 case sPubkeyAuthentication:
1074 intptr = &options->pubkey_authentication;
1075 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001076
Ben Lindstromade03f62001-12-06 18:22:17 +00001077 case sKerberosAuthentication:
1078 intptr = &options->kerberos_authentication;
1079 goto parse_flag;
1080
1081 case sKerberosOrLocalPasswd:
1082 intptr = &options->kerberos_or_local_passwd;
1083 goto parse_flag;
1084
1085 case sKerberosTicketCleanup:
1086 intptr = &options->kerberos_ticket_cleanup;
1087 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001088
Darren Tucker22ef5082003-12-31 11:37:34 +11001089 case sKerberosGetAFSToken:
1090 intptr = &options->kerberos_get_afs_token;
1091 goto parse_flag;
1092
Darren Tucker0efd1552003-08-26 11:49:55 +10001093 case sGssAuthentication:
1094 intptr = &options->gss_authentication;
1095 goto parse_flag;
1096
1097 case sGssCleanupCreds:
1098 intptr = &options->gss_cleanup_creds;
1099 goto parse_flag;
1100
Ben Lindstromade03f62001-12-06 18:22:17 +00001101 case sPasswordAuthentication:
1102 intptr = &options->password_authentication;
1103 goto parse_flag;
1104
Damien Miller01ed2272008-11-05 16:20:46 +11001105 case sZeroKnowledgePasswordAuthentication:
1106 intptr = &options->zero_knowledge_password_authentication;
1107 goto parse_flag;
1108
Ben Lindstromade03f62001-12-06 18:22:17 +00001109 case sKbdInteractiveAuthentication:
1110 intptr = &options->kbd_interactive_authentication;
1111 goto parse_flag;
1112
1113 case sChallengeResponseAuthentication:
1114 intptr = &options->challenge_response_authentication;
1115 goto parse_flag;
1116
1117 case sPrintMotd:
1118 intptr = &options->print_motd;
1119 goto parse_flag;
1120
1121 case sPrintLastLog:
1122 intptr = &options->print_lastlog;
1123 goto parse_flag;
1124
1125 case sX11Forwarding:
1126 intptr = &options->x11_forwarding;
1127 goto parse_flag;
1128
1129 case sX11DisplayOffset:
1130 intptr = &options->x11_display_offset;
1131 goto parse_int;
1132
Damien Miller95c249f2002-02-05 12:11:34 +11001133 case sX11UseLocalhost:
1134 intptr = &options->x11_use_localhost;
1135 goto parse_flag;
1136
Ben Lindstromade03f62001-12-06 18:22:17 +00001137 case sXAuthLocation:
1138 charptr = &options->xauth_location;
1139 goto parse_filename;
1140
Damien Miller5ff30c62013-10-30 22:21:50 +11001141 case sPermitTTY:
1142 intptr = &options->permit_tty;
1143 goto parse_flag;
1144
Ben Lindstromade03f62001-12-06 18:22:17 +00001145 case sStrictModes:
1146 intptr = &options->strict_modes;
1147 goto parse_flag;
1148
Damien Miller12c150e2003-12-17 16:31:10 +11001149 case sTCPKeepAlive:
1150 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001151 goto parse_flag;
1152
1153 case sEmptyPasswd:
1154 intptr = &options->permit_empty_passwd;
1155 goto parse_flag;
1156
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001157 case sPermitUserEnvironment:
1158 intptr = &options->permit_user_env;
1159 goto parse_flag;
1160
Ben Lindstromade03f62001-12-06 18:22:17 +00001161 case sUseLogin:
1162 intptr = &options->use_login;
1163 goto parse_flag;
1164
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001165 case sCompression:
1166 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001167 multistate_ptr = multistate_compression;
1168 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001169
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001170 case sRekeyLimit:
1171 arg = strdelim(&cp);
1172 if (!arg || *arg == '\0')
1173 fatal("%.200s line %d: Missing argument.", filename,
1174 linenum);
1175 if (strcmp(arg, "default") == 0) {
1176 val64 = 0;
1177 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001178 if (scan_scaled(arg, &val64) == -1)
1179 fatal("%.200s line %d: Bad number '%s': %s",
1180 filename, linenum, arg, strerror(errno));
1181 /* check for too-large or too-small limits */
1182 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001183 fatal("%.200s line %d: RekeyLimit too large",
1184 filename, linenum);
1185 if (val64 != 0 && val64 < 16)
1186 fatal("%.200s line %d: RekeyLimit too small",
1187 filename, linenum);
1188 }
1189 if (*activep && options->rekey_limit == -1)
1190 options->rekey_limit = (u_int32_t)val64;
1191 if (cp != NULL) { /* optional rekey interval present */
1192 if (strcmp(cp, "none") == 0) {
1193 (void)strdelim(&cp); /* discard */
1194 break;
1195 }
1196 intptr = &options->rekey_interval;
1197 goto parse_time;
1198 }
1199 break;
1200
Ben Lindstromade03f62001-12-06 18:22:17 +00001201 case sGatewayPorts:
1202 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001203 multistate_ptr = multistate_gatewayports;
1204 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001205
Damien Miller3a961dc2003-06-03 10:25:48 +10001206 case sUseDNS:
1207 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001208 goto parse_flag;
1209
1210 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001211 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001212 arg = strdelim(&cp);
1213 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001214 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001215 fatal("%.200s line %d: unsupported log facility '%s'",
1216 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001217 if (*log_facility_ptr == -1)
1218 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001219 break;
1220
1221 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001222 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001223 arg = strdelim(&cp);
1224 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001225 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001226 fatal("%.200s line %d: unsupported log level '%s'",
1227 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001228 if (*log_level_ptr == -1)
1229 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001230 break;
1231
1232 case sAllowTcpForwarding:
1233 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001234 multistate_ptr = multistate_tcpfwd;
1235 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001236
Damien Miller4f755cd2008-05-19 14:57:41 +10001237 case sAllowAgentForwarding:
1238 intptr = &options->allow_agent_forwarding;
1239 goto parse_flag;
1240
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001241 case sUsePrivilegeSeparation:
1242 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001243 multistate_ptr = multistate_privsep;
1244 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001245
Ben Lindstromade03f62001-12-06 18:22:17 +00001246 case sAllowUsers:
1247 while ((arg = strdelim(&cp)) && *arg != '\0') {
1248 if (options->num_allow_users >= MAX_ALLOW_USERS)
1249 fatal("%s line %d: too many allow users.",
1250 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001251 if (!*activep)
1252 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001253 options->allow_users[options->num_allow_users++] =
1254 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001255 }
1256 break;
1257
1258 case sDenyUsers:
1259 while ((arg = strdelim(&cp)) && *arg != '\0') {
1260 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001261 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001262 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001263 if (!*activep)
1264 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001265 options->deny_users[options->num_deny_users++] =
1266 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001267 }
1268 break;
1269
1270 case sAllowGroups:
1271 while ((arg = strdelim(&cp)) && *arg != '\0') {
1272 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1273 fatal("%s line %d: too many allow groups.",
1274 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001275 if (!*activep)
1276 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001277 options->allow_groups[options->num_allow_groups++] =
1278 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001279 }
1280 break;
1281
1282 case sDenyGroups:
1283 while ((arg = strdelim(&cp)) && *arg != '\0') {
1284 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1285 fatal("%s line %d: too many deny groups.",
1286 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001287 if (!*activep)
1288 continue;
1289 options->deny_groups[options->num_deny_groups++] =
1290 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001291 }
1292 break;
1293
1294 case sCiphers:
1295 arg = strdelim(&cp);
1296 if (!arg || *arg == '\0')
1297 fatal("%s line %d: Missing argument.", filename, linenum);
1298 if (!ciphers_valid(arg))
1299 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1300 filename, linenum, arg ? arg : "<NONE>");
1301 if (options->ciphers == NULL)
1302 options->ciphers = xstrdup(arg);
1303 break;
1304
1305 case sMacs:
1306 arg = strdelim(&cp);
1307 if (!arg || *arg == '\0')
1308 fatal("%s line %d: Missing argument.", filename, linenum);
1309 if (!mac_valid(arg))
1310 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1311 filename, linenum, arg ? arg : "<NONE>");
1312 if (options->macs == NULL)
1313 options->macs = xstrdup(arg);
1314 break;
1315
Damien Millerd5f62bf2010-09-24 22:11:14 +10001316 case sKexAlgorithms:
1317 arg = strdelim(&cp);
1318 if (!arg || *arg == '\0')
1319 fatal("%s line %d: Missing argument.",
1320 filename, linenum);
1321 if (!kex_names_valid(arg))
1322 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1323 filename, linenum, arg ? arg : "<NONE>");
1324 if (options->kex_algorithms == NULL)
1325 options->kex_algorithms = xstrdup(arg);
1326 break;
1327
Ben Lindstromade03f62001-12-06 18:22:17 +00001328 case sProtocol:
1329 intptr = &options->protocol;
1330 arg = strdelim(&cp);
1331 if (!arg || *arg == '\0')
1332 fatal("%s line %d: Missing argument.", filename, linenum);
1333 value = proto_spec(arg);
1334 if (value == SSH_PROTO_UNKNOWN)
1335 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001336 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001337 if (*intptr == SSH_PROTO_UNKNOWN)
1338 *intptr = value;
1339 break;
1340
1341 case sSubsystem:
1342 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1343 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001344 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001345 }
1346 arg = strdelim(&cp);
1347 if (!arg || *arg == '\0')
1348 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001349 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001350 if (!*activep) {
1351 arg = strdelim(&cp);
1352 break;
1353 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001354 for (i = 0; i < options->num_subsystems; i++)
1355 if (strcmp(arg, options->subsystem_name[i]) == 0)
1356 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001357 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001358 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1359 arg = strdelim(&cp);
1360 if (!arg || *arg == '\0')
1361 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001362 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001363 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001364
1365 /* Collect arguments (separate to executable) */
1366 p = xstrdup(arg);
1367 len = strlen(p) + 1;
1368 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1369 len += 1 + strlen(arg);
1370 p = xrealloc(p, 1, len);
1371 strlcat(p, " ", len);
1372 strlcat(p, arg, len);
1373 }
1374 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001375 options->num_subsystems++;
1376 break;
1377
1378 case sMaxStartups:
1379 arg = strdelim(&cp);
1380 if (!arg || *arg == '\0')
1381 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001382 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001383 if ((n = sscanf(arg, "%d:%d:%d",
1384 &options->max_startups_begin,
1385 &options->max_startups_rate,
1386 &options->max_startups)) == 3) {
1387 if (options->max_startups_begin >
1388 options->max_startups ||
1389 options->max_startups_rate > 100 ||
1390 options->max_startups_rate < 1)
1391 fatal("%s line %d: Illegal MaxStartups spec.",
1392 filename, linenum);
1393 } else if (n != 1)
1394 fatal("%s line %d: Illegal MaxStartups spec.",
1395 filename, linenum);
1396 else
1397 options->max_startups = options->max_startups_begin;
1398 break;
1399
Darren Tucker89413db2004-05-24 10:36:23 +10001400 case sMaxAuthTries:
1401 intptr = &options->max_authtries;
1402 goto parse_int;
1403
Damien Miller7207f642008-05-19 15:34:50 +10001404 case sMaxSessions:
1405 intptr = &options->max_sessions;
1406 goto parse_int;
1407
Ben Lindstromade03f62001-12-06 18:22:17 +00001408 case sBanner:
1409 charptr = &options->banner;
1410 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001411
Ben Lindstromade03f62001-12-06 18:22:17 +00001412 /*
1413 * These options can contain %X options expanded at
1414 * connect time, so that you can specify paths like:
1415 *
1416 * AuthorizedKeysFile /etc/ssh_keys/%u
1417 */
1418 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001419 if (*activep && options->num_authkeys_files == 0) {
1420 while ((arg = strdelim(&cp)) && *arg != '\0') {
1421 if (options->num_authkeys_files >=
1422 MAX_AUTHKEYS_FILES)
1423 fatal("%s line %d: "
1424 "too many authorized keys files.",
1425 filename, linenum);
1426 options->authorized_keys_files[
1427 options->num_authkeys_files++] =
1428 tilde_expand_filename(arg, getuid());
1429 }
1430 }
1431 return 0;
1432
Damien Miller30da3442010-05-10 11:58:03 +10001433 case sAuthorizedPrincipalsFile:
1434 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001435 arg = strdelim(&cp);
1436 if (!arg || *arg == '\0')
1437 fatal("%s line %d: missing file name.",
1438 filename, linenum);
1439 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001440 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001441 /* increase optional counter */
1442 if (intptr != NULL)
1443 *intptr = *intptr + 1;
1444 }
1445 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001446
1447 case sClientAliveInterval:
1448 intptr = &options->client_alive_interval;
1449 goto parse_time;
1450
1451 case sClientAliveCountMax:
1452 intptr = &options->client_alive_count_max;
1453 goto parse_int;
1454
Darren Tucker46bc0752004-05-02 22:11:30 +10001455 case sAcceptEnv:
1456 while ((arg = strdelim(&cp)) && *arg != '\0') {
1457 if (strchr(arg, '=') != NULL)
1458 fatal("%s line %d: Invalid environment name.",
1459 filename, linenum);
1460 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1461 fatal("%s line %d: too many allow env.",
1462 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001463 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001464 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001465 options->accept_env[options->num_accept_env++] =
1466 xstrdup(arg);
1467 }
1468 break;
1469
Damien Millerd27b9472005-12-13 19:29:02 +11001470 case sPermitTunnel:
1471 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001472 arg = strdelim(&cp);
1473 if (!arg || *arg == '\0')
1474 fatal("%s line %d: Missing yes/point-to-point/"
1475 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001476 value = -1;
1477 for (i = 0; tunmode_desc[i].val != -1; i++)
1478 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1479 value = tunmode_desc[i].val;
1480 break;
1481 }
1482 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001483 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1484 "no argument: %s", filename, linenum, arg);
1485 if (*intptr == -1)
1486 *intptr = value;
1487 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001488
Darren Tucker45150472006-07-12 22:34:17 +10001489 case sMatch:
1490 if (cmdline)
1491 fatal("Match directive not supported as a command-line "
1492 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001493 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001494 if (value < 0)
1495 fatal("%s line %d: Bad Match condition", filename,
1496 linenum);
1497 *activep = value;
1498 break;
1499
Damien Miller9b439df2006-07-24 14:04:00 +10001500 case sPermitOpen:
1501 arg = strdelim(&cp);
1502 if (!arg || *arg == '\0')
1503 fatal("%s line %d: missing PermitOpen specification",
1504 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001505 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001506 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001507 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001508 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001509 options->num_permitted_opens = 0;
1510 }
Damien Miller9b439df2006-07-24 14:04:00 +10001511 break;
1512 }
Damien Millerc6081482012-04-22 11:18:53 +10001513 if (strcmp(arg, "none") == 0) {
1514 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001515 options->num_permitted_opens = 1;
1516 channel_disable_adm_local_opens();
1517 }
1518 break;
1519 }
Damien Millera29b95e2007-01-05 16:28:36 +11001520 if (*activep && n == -1)
1521 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001522 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1523 p = hpdelim(&arg);
1524 if (p == NULL)
1525 fatal("%s line %d: missing host in PermitOpen",
1526 filename, linenum);
1527 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001528 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001529 fatal("%s line %d: bad port number in "
1530 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001531 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001532 options->num_permitted_opens =
1533 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001534 }
Damien Miller9b439df2006-07-24 14:04:00 +10001535 break;
1536
Damien Millere2754432006-07-24 14:06:47 +10001537 case sForceCommand:
1538 if (cp == NULL)
1539 fatal("%.200s line %d: Missing argument.", filename,
1540 linenum);
1541 len = strspn(cp, WHITESPACE);
1542 if (*activep && options->adm_forced_command == NULL)
1543 options->adm_forced_command = xstrdup(cp + len);
1544 return 0;
1545
Damien Millerd8cb1f12008-02-10 22:40:12 +11001546 case sChrootDirectory:
1547 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001548
1549 arg = strdelim(&cp);
1550 if (!arg || *arg == '\0')
1551 fatal("%s line %d: missing file name.",
1552 filename, linenum);
1553 if (*activep && *charptr == NULL)
1554 *charptr = xstrdup(arg);
1555 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001556
Damien Miller1aed65e2010-03-04 21:53:35 +11001557 case sTrustedUserCAKeys:
1558 charptr = &options->trusted_user_ca_keys;
1559 goto parse_filename;
1560
1561 case sRevokedKeys:
1562 charptr = &options->revoked_keys_file;
1563 goto parse_filename;
1564
Damien Miller0dac6fb2010-11-20 15:19:38 +11001565 case sIPQoS:
1566 arg = strdelim(&cp);
1567 if ((value = parse_ipqos(arg)) == -1)
1568 fatal("%s line %d: Bad IPQoS value: %s",
1569 filename, linenum, arg);
1570 arg = strdelim(&cp);
1571 if (arg == NULL)
1572 value2 = value;
1573 else if ((value2 = parse_ipqos(arg)) == -1)
1574 fatal("%s line %d: Bad IPQoS value: %s",
1575 filename, linenum, arg);
1576 if (*activep) {
1577 options->ip_qos_interactive = value;
1578 options->ip_qos_bulk = value2;
1579 }
1580 break;
1581
Damien Miller23528812012-04-22 11:24:43 +10001582 case sVersionAddendum:
1583 if (cp == NULL)
1584 fatal("%.200s line %d: Missing argument.", filename,
1585 linenum);
1586 len = strspn(cp, WHITESPACE);
1587 if (*activep && options->version_addendum == NULL) {
1588 if (strcasecmp(cp + len, "none") == 0)
1589 options->version_addendum = xstrdup("");
1590 else if (strchr(cp + len, '\r') != NULL)
1591 fatal("%.200s line %d: Invalid argument",
1592 filename, linenum);
1593 else
1594 options->version_addendum = xstrdup(cp + len);
1595 }
1596 return 0;
1597
Damien Miller09d3e122012-10-31 08:58:58 +11001598 case sAuthorizedKeysCommand:
1599 len = strspn(cp, WHITESPACE);
1600 if (*activep && options->authorized_keys_command == NULL) {
1601 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1602 fatal("%.200s line %d: AuthorizedKeysCommand "
1603 "must be an absolute path",
1604 filename, linenum);
1605 options->authorized_keys_command = xstrdup(cp + len);
1606 }
1607 return 0;
1608
1609 case sAuthorizedKeysCommandUser:
1610 charptr = &options->authorized_keys_command_user;
1611
1612 arg = strdelim(&cp);
1613 if (*activep && *charptr == NULL)
1614 *charptr = xstrdup(arg);
1615 break;
1616
Damien Millera6e3f012012-11-04 23:21:40 +11001617 case sAuthenticationMethods:
1618 if (*activep && options->num_auth_methods == 0) {
1619 while ((arg = strdelim(&cp)) && *arg != '\0') {
1620 if (options->num_auth_methods >=
1621 MAX_AUTH_METHODS)
1622 fatal("%s line %d: "
1623 "too many authentication methods.",
1624 filename, linenum);
1625 if (auth2_methods_valid(arg, 0) != 0)
1626 fatal("%s line %d: invalid "
1627 "authentication method list.",
1628 filename, linenum);
1629 options->auth_methods[
1630 options->num_auth_methods++] = xstrdup(arg);
1631 }
1632 }
1633 return 0;
1634
Ben Lindstromade03f62001-12-06 18:22:17 +00001635 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001636 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001637 filename, linenum, arg);
1638 while (arg)
1639 arg = strdelim(&cp);
1640 break;
1641
Damien Millerf9b3feb2003-05-16 11:38:32 +10001642 case sUnsupported:
1643 logit("%s line %d: Unsupported option %s",
1644 filename, linenum, arg);
1645 while (arg)
1646 arg = strdelim(&cp);
1647 break;
1648
Ben Lindstromade03f62001-12-06 18:22:17 +00001649 default:
1650 fatal("%s line %d: Missing handler for opcode %s (%d)",
1651 filename, linenum, arg, opcode);
1652 }
1653 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1654 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1655 filename, linenum, arg);
1656 return 0;
1657}
1658
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001659/* Reads the server configuration file. */
1660
Damien Miller4af51302000-04-16 11:18:38 +10001661void
Darren Tucker645ab752004-06-25 13:33:20 +10001662load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001663{
Damien Miller46cb75a2012-07-31 12:22:37 +10001664 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001665 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001666 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001667
Darren Tucker645ab752004-06-25 13:33:20 +10001668 debug2("%s: filename %s", __func__, filename);
1669 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001670 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001671 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001672 }
Darren Tucker645ab752004-06-25 13:33:20 +10001673 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001674 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001675 lineno++;
1676 if (strlen(line) == sizeof(line) - 1)
1677 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001678 /*
1679 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001680 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001681 * line numbers later for error messages
1682 */
1683 if ((cp = strchr(line, '#')) != NULL)
1684 memcpy(cp, "\n", 2);
1685 cp = line + strspn(line, " \t\r");
1686
1687 buffer_append(conf, cp, strlen(cp));
1688 }
1689 buffer_append(conf, "\0", 1);
1690 fclose(f);
1691 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1692}
1693
1694void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001695parse_server_match_config(ServerOptions *options,
1696 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001697{
Darren Tucker45150472006-07-12 22:34:17 +10001698 ServerOptions mo;
1699
1700 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001701 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001702 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001703}
1704
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001705int parse_server_match_testspec(struct connection_info *ci, char *spec)
1706{
1707 char *p;
1708
1709 while ((p = strsep(&spec, ",")) && *p != '\0') {
1710 if (strncmp(p, "addr=", 5) == 0) {
1711 ci->address = xstrdup(p + 5);
1712 } else if (strncmp(p, "host=", 5) == 0) {
1713 ci->host = xstrdup(p + 5);
1714 } else if (strncmp(p, "user=", 5) == 0) {
1715 ci->user = xstrdup(p + 5);
1716 } else if (strncmp(p, "laddr=", 6) == 0) {
1717 ci->laddress = xstrdup(p + 6);
1718 } else if (strncmp(p, "lport=", 6) == 0) {
1719 ci->lport = a2port(p + 6);
1720 if (ci->lport == -1) {
1721 fprintf(stderr, "Invalid port '%s' in test mode"
1722 " specification %s\n", p+6, p);
1723 return -1;
1724 }
1725 } else {
1726 fprintf(stderr, "Invalid test mode specification %s\n",
1727 p);
1728 return -1;
1729 }
1730 }
1731 return 0;
1732}
1733
1734/*
1735 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1736 * empty spec.
1737 */
1738int server_match_spec_complete(struct connection_info *ci)
1739{
1740 if (ci->user && ci->host && ci->address)
1741 return 1; /* complete */
1742 if (!ci->user && !ci->host && !ci->address)
1743 return -1; /* empty */
1744 return 0; /* partial */
1745}
1746
Darren Tucker1629c072007-02-19 22:25:37 +11001747/*
1748 * Copy any supported values that are set.
1749 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001750 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001751 * array values that are not used pre-authentication, because any that we
1752 * do use must be explictly sent in mm_getpwnamallow().
1753 */
Darren Tucker45150472006-07-12 22:34:17 +10001754void
Darren Tucker1629c072007-02-19 22:25:37 +11001755copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001756{
Damien Miller534b2cc2013-12-05 14:07:27 +11001757#define M_CP_INTOPT(n) do {\
1758 if (src->n != -1) \
1759 dst->n = src->n; \
1760} while (0)
1761
Darren Tucker1629c072007-02-19 22:25:37 +11001762 M_CP_INTOPT(password_authentication);
1763 M_CP_INTOPT(gss_authentication);
1764 M_CP_INTOPT(rsa_authentication);
1765 M_CP_INTOPT(pubkey_authentication);
1766 M_CP_INTOPT(kerberos_authentication);
1767 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001768 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001769 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001770 M_CP_INTOPT(zero_knowledge_password_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001771 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001772 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001773
1774 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001775 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001776 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001777 M_CP_INTOPT(gateway_ports);
1778 M_CP_INTOPT(x11_display_offset);
1779 M_CP_INTOPT(x11_forwarding);
1780 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001781 M_CP_INTOPT(permit_tty);
Damien Miller7207f642008-05-19 15:34:50 +10001782 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001783 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001784 M_CP_INTOPT(ip_qos_interactive);
1785 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001786 M_CP_INTOPT(rekey_limit);
1787 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001788
Damien Miller534b2cc2013-12-05 14:07:27 +11001789 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1790#define M_CP_STROPT(n) do {\
1791 if (src->n != NULL && dst->n != src->n) { \
1792 free(dst->n); \
1793 dst->n = src->n; \
1794 } \
1795} while(0)
1796#define M_CP_STRARRAYOPT(n, num_n) do {\
1797 if (src->num_n != 0) { \
1798 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1799 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1800 } \
1801} while(0)
1802
Damien Millerf2e407e2011-05-20 19:04:14 +10001803 /* See comment in servconf.h */
1804 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001805
Damien Millerc2411902011-05-20 19:03:49 +10001806 /*
1807 * The only things that should be below this point are string options
1808 * which are only used after authentication.
1809 */
Damien Miller5d74e582011-05-20 19:03:31 +10001810 if (preauth)
1811 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001812
Damien Miller5d74e582011-05-20 19:03:31 +10001813 M_CP_STROPT(adm_forced_command);
1814 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001815}
1816
Darren Tucker1629c072007-02-19 22:25:37 +11001817#undef M_CP_INTOPT
1818#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001819#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001820
Darren Tucker45150472006-07-12 22:34:17 +10001821void
1822parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001823 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001824{
1825 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001826 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001827
1828 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1829
Darren Tucker9fbac712004-08-12 22:41:44 +10001830 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001831 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001832 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001833 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001834 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001835 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001836 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001837 }
Darren Tuckera627d422013-06-02 07:31:17 +10001838 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001839 if (bad_options > 0)
1840 fatal("%s: terminating, %d bad configuration options",
1841 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001842}
Darren Tuckere7140f22008-06-10 23:01:51 +10001843
1844static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001845fmt_multistate_int(int val, const struct multistate *m)
1846{
1847 u_int i;
1848
1849 for (i = 0; m[i].key != NULL; i++) {
1850 if (m[i].value == val)
1851 return m[i].key;
1852 }
1853 return "UNKNOWN";
1854}
1855
1856static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001857fmt_intarg(ServerOpCodes code, int val)
1858{
Damien Miller82c55872011-06-23 08:20:30 +10001859 if (val == -1)
1860 return "unset";
1861 switch (code) {
1862 case sAddressFamily:
1863 return fmt_multistate_int(val, multistate_addressfamily);
1864 case sPermitRootLogin:
1865 return fmt_multistate_int(val, multistate_permitrootlogin);
1866 case sGatewayPorts:
1867 return fmt_multistate_int(val, multistate_gatewayports);
1868 case sCompression:
1869 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001870 case sUsePrivilegeSeparation:
1871 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001872 case sAllowTcpForwarding:
1873 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001874 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001875 switch (val) {
1876 case SSH_PROTO_1:
1877 return "1";
1878 case SSH_PROTO_2:
1879 return "2";
1880 case (SSH_PROTO_1|SSH_PROTO_2):
1881 return "2,1";
1882 default:
1883 return "UNKNOWN";
1884 }
Damien Miller82c55872011-06-23 08:20:30 +10001885 default:
1886 switch (val) {
1887 case 0:
1888 return "no";
1889 case 1:
1890 return "yes";
1891 default:
1892 return "UNKNOWN";
1893 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001894 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001895}
1896
1897static const char *
1898lookup_opcode_name(ServerOpCodes code)
1899{
1900 u_int i;
1901
1902 for (i = 0; keywords[i].name != NULL; i++)
1903 if (keywords[i].opcode == code)
1904 return(keywords[i].name);
1905 return "UNKNOWN";
1906}
1907
1908static void
1909dump_cfg_int(ServerOpCodes code, int val)
1910{
1911 printf("%s %d\n", lookup_opcode_name(code), val);
1912}
1913
1914static void
1915dump_cfg_fmtint(ServerOpCodes code, int val)
1916{
1917 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1918}
1919
1920static void
1921dump_cfg_string(ServerOpCodes code, const char *val)
1922{
1923 if (val == NULL)
1924 return;
1925 printf("%s %s\n", lookup_opcode_name(code), val);
1926}
1927
1928static void
1929dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1930{
1931 u_int i;
1932
1933 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001934 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1935}
1936
1937static void
1938dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1939{
1940 u_int i;
1941
1942 printf("%s", lookup_opcode_name(code));
1943 for (i = 0; i < count; i++)
1944 printf(" %s", vals[i]);
1945 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001946}
1947
1948void
1949dump_config(ServerOptions *o)
1950{
1951 u_int i;
1952 int ret;
1953 struct addrinfo *ai;
1954 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1955
1956 /* these are usually at the top of the config */
1957 for (i = 0; i < o->num_ports; i++)
1958 printf("port %d\n", o->ports[i]);
1959 dump_cfg_fmtint(sProtocol, o->protocol);
1960 dump_cfg_fmtint(sAddressFamily, o->address_family);
1961
1962 /* ListenAddress must be after Port */
1963 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1964 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1965 sizeof(addr), port, sizeof(port),
1966 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1967 error("getnameinfo failed: %.100s",
1968 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1969 strerror(errno));
1970 } else {
1971 if (ai->ai_family == AF_INET6)
1972 printf("listenaddress [%s]:%s\n", addr, port);
1973 else
1974 printf("listenaddress %s:%s\n", addr, port);
1975 }
1976 }
1977
1978 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001979#ifdef USE_PAM
1980 dump_cfg_int(sUsePAM, o->use_pam);
1981#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001982 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1983 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1984 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1985 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1986 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001987 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001988 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1989 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1990
1991 /* formatted integer arguments */
1992 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1993 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1994 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1995 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1996 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1997 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1998 o->hostbased_uses_name_from_packet_only);
1999 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
2000 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002001#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002002 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2003 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2004 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002005# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002006 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002007# endif
2008#endif
2009#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002010 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2011 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002012#endif
Damien Miller01ed2272008-11-05 16:20:46 +11002013#ifdef JPAKE
2014 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
2015 o->zero_knowledge_password_authentication);
2016#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002017 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2018 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2019 o->kbd_interactive_authentication);
2020 dump_cfg_fmtint(sChallengeResponseAuthentication,
2021 o->challenge_response_authentication);
2022 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2023 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2024 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2025 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002026 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Darren Tuckere7140f22008-06-10 23:01:51 +10002027 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2028 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2029 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2030 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2031 dump_cfg_fmtint(sUseLogin, o->use_login);
2032 dump_cfg_fmtint(sCompression, o->compression);
2033 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2034 dump_cfg_fmtint(sUseDNS, o->use_dns);
2035 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2036 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2037
2038 /* string arguments */
2039 dump_cfg_string(sPidFile, o->pid_file);
2040 dump_cfg_string(sXAuthLocation, o->xauth_location);
Damien Miller690d9892013-11-08 12:16:49 +11002041 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers :
Damien Miller0fde8ac2013-11-21 14:12:23 +11002042 cipher_alg_list(',', 0));
Damien Miller690d9892013-11-08 12:16:49 +11002043 dump_cfg_string(sMacs, o->macs ? o->macs : mac_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002044 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002045 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002046 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002047 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2048 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002049 dump_cfg_string(sAuthorizedPrincipalsFile,
2050 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002051 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002052 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2053 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002054 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Damien Miller690d9892013-11-08 12:16:49 +11002055 dump_cfg_string(sKexAlgorithms, o->kex_algorithms ? o->kex_algorithms :
2056 kex_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002057
2058 /* string arguments requiring a lookup */
2059 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2060 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2061
2062 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002063 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2064 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002065 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2066 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002067 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2068 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002069 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2070 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2071 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2072 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2073 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002074 dump_cfg_strarray_oneline(sAuthenticationMethods,
2075 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002076
2077 /* other arguments */
2078 for (i = 0; i < o->num_subsystems; i++)
2079 printf("subsystem %s %s\n", o->subsystem_name[i],
2080 o->subsystem_args[i]);
2081
2082 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2083 o->max_startups_rate, o->max_startups);
2084
2085 for (i = 0; tunmode_desc[i].val != -1; i++)
2086 if (tunmode_desc[i].val == o->permit_tun) {
2087 s = tunmode_desc[i].text;
2088 break;
2089 }
2090 dump_cfg_string(sPermitTunnel, s);
2091
Damien Miller91475862011-05-05 14:14:34 +10002092 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2093 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002094
Damien Millera6d6c1f2013-08-21 02:40:01 +10002095 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2096 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002097
Darren Tuckere7140f22008-06-10 23:01:51 +10002098 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002099}