blob: 7ba65d51df261a74db63f4757067a72bb5c003e3 [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Miller7cc194f2014-02-04 11:12:56 +11002/* $OpenBSD: servconf.c,v 1.249 2014/01/29 06:18:35 djm Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
Damien Millerd7834352006-08-05 12:39:39 +100031#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100032#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100033#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100034#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100035#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100036
Damien Millerb84886b2008-05-19 15:05:07 +100037#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100041#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100042#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100043#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000044#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000045#include "misc.h"
46#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100047#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000048#include "kex.h"
49#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100050#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100051#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100052#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100053#include "canohost.h"
54#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110055#include "hostfile.h"
56#include "auth.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000057
Damien Miller3dc71ad2009-01-28 16:31:22 +110058static void add_listen_addr(ServerOptions *, char *, int);
59static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110060
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000061/* Use of privilege separation or not */
62extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100063extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000064
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065/* Initializes the server options to their default values. */
66
Damien Miller4af51302000-04-16 11:18:38 +100067void
Damien Miller95def091999-11-25 00:26:21 +110068initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069{
Damien Miller95def091999-11-25 00:26:21 +110070 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110071
72 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100073 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110076 options->num_ports = 0;
77 options->ports_from_cmdline = 0;
78 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110079 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110080 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110081 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100082 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100083 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110084 options->server_key_bits = -1;
85 options->login_grace_time = -1;
86 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000087 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110088 options->ignore_rhosts = -1;
89 options->ignore_user_known_hosts = -1;
90 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000091 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110092 options->x11_forwarding = -1;
93 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110094 options->x11_use_localhost = -1;
Damien Miller5ff30c62013-10-30 22:21:50 +110095 options->permit_tty = -1;
Damien 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 Miller1aed65e2010-03-04 21:53:35 +1100150 options->revoked_keys_file = NULL;
151 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000152 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100153 options->ip_qos_interactive = -1;
154 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000155 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000156}
157
Damien Miller4af51302000-04-16 11:18:38 +1000158void
Damien Miller95def091999-11-25 00:26:21 +1100159fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000160{
Damien Miller726273e2001-11-12 11:40:11 +1100161 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000162 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000163 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100164
165 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100166 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100167 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100168 if (options->num_host_key_files == 0) {
169 /* fill default hostkeys for protocols */
170 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100171 options->host_key_files[options->num_host_key_files++] =
172 _PATH_HOST_KEY_FILE;
173 if (options->protocol & SSH_PROTO_2) {
174 options->host_key_files[options->num_host_key_files++] =
175 _PATH_HOST_RSA_KEY_FILE;
176 options->host_key_files[options->num_host_key_files++] =
177 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100178#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000179 options->host_key_files[options->num_host_key_files++] =
180 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100181#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +1100182 options->host_key_files[options->num_host_key_files++] =
183 _PATH_HOST_ED25519_KEY_FILE;
Damien Miller7fc23732002-01-22 23:19:11 +1100184 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100185 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100186 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100187 if (options->num_ports == 0)
188 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
189 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000190 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000191 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000192 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100193 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000194 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100195 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000196 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->key_regeneration_time == -1)
198 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000199 if (options->permit_root_login == PERMIT_NOT_SET)
200 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100202 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->ignore_user_known_hosts == -1)
204 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->print_motd == -1)
206 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000207 if (options->print_lastlog == -1)
208 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100210 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100211 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100212 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100213 if (options->x11_use_localhost == -1)
214 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000215 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000216 options->xauth_location = _PATH_XAUTH;
Damien Miller5ff30c62013-10-30 22:21:50 +1100217 if (options->permit_tty == -1)
218 options->permit_tty = 1;
Damien Miller95def091999-11-25 00:26:21 +1100219 if (options->strict_modes == -1)
220 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100221 if (options->tcp_keep_alive == -1)
222 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100223 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100224 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100225 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000226 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100227 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100228 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000229 if (options->hostbased_authentication == -1)
230 options->hostbased_authentication = 0;
231 if (options->hostbased_uses_name_from_packet_only == -1)
232 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100233 if (options->rsa_authentication == -1)
234 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100235 if (options->pubkey_authentication == -1)
236 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100237 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000238 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100239 if (options->kerberos_or_local_passwd == -1)
240 options->kerberos_or_local_passwd = 1;
241 if (options->kerberos_ticket_cleanup == -1)
242 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100243 if (options->kerberos_get_afs_token == -1)
244 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000245 if (options->gss_authentication == -1)
246 options->gss_authentication = 0;
247 if (options->gss_cleanup_creds == -1)
248 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100249 if (options->password_authentication == -1)
250 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100251 if (options->kbd_interactive_authentication == -1)
252 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000253 if (options->challenge_response_authentication == -1)
254 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100255 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100256 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000257 if (options->permit_user_env == -1)
258 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100259 if (options->use_login == -1)
260 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000261 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000262 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000263 if (options->rekey_limit == -1)
264 options->rekey_limit = 0;
265 if (options->rekey_interval == -1)
266 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100267 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100268 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000269 if (options->allow_agent_forwarding == -1)
270 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000271 if (options->gateway_ports == -1)
272 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000273 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100274 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000275 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100276 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000277 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100278 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000279 if (options->max_authtries == -1)
280 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000281 if (options->max_sessions == -1)
282 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000283 if (options->use_dns == -1)
284 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000285 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100286 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000287 if (options->client_alive_count_max == -1)
288 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000289 if (options->num_authkeys_files == 0) {
290 options->authorized_keys_files[options->num_authkeys_files++] =
291 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
292 options->authorized_keys_files[options->num_authkeys_files++] =
293 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
294 }
Damien Millerd27b9472005-12-13 19:29:02 +1100295 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100296 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100297 if (options->ip_qos_interactive == -1)
298 options->ip_qos_interactive = IPTOS_LOWDELAY;
299 if (options->ip_qos_bulk == -1)
300 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000301 if (options->version_addendum == NULL)
302 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000303 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000304 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000305 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000306
Tim Rice40017b02002-07-14 13:36:49 -0700307#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000308 if (use_privsep && options->compression == 1) {
309 error("This platform does not support both privilege "
310 "separation and compression");
311 error("Compression disabled");
312 options->compression = 0;
313 }
314#endif
315
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000316}
317
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000318/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100319typedef enum {
320 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100321 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000322 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100323 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100324 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
325 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000326 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100327 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100328 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000329 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100330 sPasswordAuthentication, sKbdInteractiveAuthentication,
331 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000332 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100333 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100334 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000335 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000336 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000337 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000338 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000339 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000340 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100341 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000342 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100343 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100344 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100345 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller7cc194f2014-02-04 11:12:56 +1100346 sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000347 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000348 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100349 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller85b45e02013-07-20 13:21:52 +1000350 sAuthenticationMethods, sHostKeyAgent,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000351 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000352} ServerOpCodes;
353
Darren Tucker45150472006-07-12 22:34:17 +1000354#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
355#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
356#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
357
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000358/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100359static struct {
360 const char *name;
361 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000362 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100363} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100364 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000365#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000366 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000367#else
Darren Tucker45150472006-07-12 22:34:17 +1000368 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000369#endif
Darren Tucker45150472006-07-12 22:34:17 +1000370 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100371 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000372 { "port", sPort, SSHCFG_GLOBAL },
373 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
374 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000375 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000376 { "pidfile", sPidFile, SSHCFG_GLOBAL },
377 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
378 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
379 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100380 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000381 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
382 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
383 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100384 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
385 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000386 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100387 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
388 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000389 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000390#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100391 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000392 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
393 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100394#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000396#else
Darren Tucker45150472006-07-12 22:34:17 +1000397 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100398#endif
399#else
Darren Tucker1629c072007-02-19 22:25:37 +1100400 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000401 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
402 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
403 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000404#endif
Darren Tucker45150472006-07-12 22:34:17 +1000405 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
406 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000407#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100408 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000409 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000410#else
Darren Tucker1629c072007-02-19 22:25:37 +1100411 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000412 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000413#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100414 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
415 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100416 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000417 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
418 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
419 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
420 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
421 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
422 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
423 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
424 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000425 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
426 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
427 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000428 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
429 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100430 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000431 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
432 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
433 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000434 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000435 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
436 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
437 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000438 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000439 { "allowusers", sAllowUsers, SSHCFG_ALL },
440 { "denyusers", sDenyUsers, SSHCFG_ALL },
441 { "allowgroups", sAllowGroups, SSHCFG_ALL },
442 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000443 { "ciphers", sCiphers, SSHCFG_GLOBAL },
444 { "macs", sMacs, SSHCFG_GLOBAL },
445 { "protocol", sProtocol, SSHCFG_GLOBAL },
446 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
447 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
448 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000449 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000450 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100451 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000452 { "usedns", sUseDNS, SSHCFG_GLOBAL },
453 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
454 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
455 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
456 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000457 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000458 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000459 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000460 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000461 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100462 { "permittty", sPermitTTY, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000463 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000464 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000465 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100466 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100467 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100468 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
469 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000470 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000471 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100472 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100473 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
474 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000475 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100476 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000477 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000478};
479
Darren Tuckere7140f22008-06-10 23:01:51 +1000480static struct {
481 int val;
482 char *text;
483} tunmode_desc[] = {
484 { SSH_TUNMODE_NO, "no" },
485 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
486 { SSH_TUNMODE_ETHERNET, "ethernet" },
487 { SSH_TUNMODE_YES, "yes" },
488 { -1, NULL }
489};
490
Damien Miller5428f641999-11-25 11:54:57 +1100491/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000492 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100493 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000494
Damien Miller4af51302000-04-16 11:18:38 +1000495static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100496parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000497 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000498{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000499 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000500
Damien Miller95def091999-11-25 00:26:21 +1100501 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000502 if (strcasecmp(cp, keywords[i].name) == 0) {
503 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100504 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000505 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000506
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000507 error("%s: line %d: Bad configuration option: %s",
508 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100509 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000510}
511
Darren Tucker88b6fb22010-01-13 22:44:29 +1100512char *
513derelativise_path(const char *path)
514{
Damien Miller44451d02010-03-26 10:40:04 +1100515 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100516
517 expanded = tilde_expand_filename(path, getuid());
518 if (*expanded == '/')
519 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100520 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100521 fatal("%s: getcwd: %s", __func__, strerror(errno));
522 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000523 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100524 return ret;
525}
526
Ben Lindstrombba81212001-06-25 05:01:22 +0000527static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100528add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100529{
Damien Millereccb9de2005-06-17 12:59:34 +1000530 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100531
532 if (options->num_ports == 0)
533 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100534 if (options->address_family == -1)
535 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000536 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000537 for (i = 0; i < options->num_ports; i++)
538 add_one_listen_addr(options, addr, options->ports[i]);
539 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000540 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000541}
542
Ben Lindstrombba81212001-06-25 05:01:22 +0000543static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100544add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000545{
546 struct addrinfo hints, *ai, *aitop;
547 char strport[NI_MAXSERV];
548 int gaierr;
549
550 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100551 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000552 hints.ai_socktype = SOCK_STREAM;
553 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100554 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000555 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
556 fatal("bad addr or host: %s (%s)",
557 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100558 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000559 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
560 ;
561 ai->ai_next = options->listen_addrs;
562 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100563}
564
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000565struct connection_info *
566get_connection_info(int populate, int use_dns)
567{
568 static struct connection_info ci;
569
570 if (!populate)
571 return &ci;
572 ci.host = get_canonical_hostname(use_dns);
573 ci.address = get_remote_ipaddr();
574 ci.laddress = get_local_ipaddr(packet_get_connection_in());
575 ci.lport = get_local_port();
576 return &ci;
577}
578
Darren Tucker45150472006-07-12 22:34:17 +1000579/*
580 * The strategy for the Match blocks is that the config file is parsed twice.
581 *
582 * The first time is at startup. activep is initialized to 1 and the
583 * directives in the global context are processed and acted on. Hitting a
584 * Match directive unsets activep and the directives inside the block are
585 * checked for syntax only.
586 *
587 * The second time is after a connection has been established but before
588 * authentication. activep is initialized to 2 and global config directives
589 * are ignored since they have already been processed. If the criteria in a
590 * Match block is met, activep is set and the subsequent directives
591 * processed and actioned until EOF or another Match block unsets it. Any
592 * options set are copied into the main server config.
593 *
594 * Potential additions/improvements:
595 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
596 *
597 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
598 * Match Address 192.168.0.*
599 * Tag trusted
600 * Match Group wheel
601 * Tag trusted
602 * Match Tag trusted
603 * AllowTcpForwarding yes
604 * GatewayPorts clientspecified
605 * [...]
606 *
607 * - Add a PermittedChannelRequests directive
608 * Match Group shell
609 * PermittedChannelRequests session,forwarded-tcpip
610 */
611
612static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000613match_cfg_line_group(const char *grps, int line, const char *user)
614{
615 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000616 struct passwd *pw;
617
Damien Miller565ca3f2006-08-19 00:23:15 +1000618 if (user == NULL)
619 goto out;
620
621 if ((pw = getpwnam(user)) == NULL) {
622 debug("Can't match group at line %d because user %.100s does "
623 "not exist", line, user);
624 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
625 debug("Can't Match group because user %.100s not in any group "
626 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000627 } else if (ga_match_pattern_list(grps) != 1) {
628 debug("user %.100s does not match group list %.100s at line %d",
629 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000630 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000631 debug("user %.100s matched group list %.100s at line %d", user,
632 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000633 result = 1;
634 }
635out:
636 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000637 return result;
638}
639
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000640/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000641 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100642 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000643 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000644 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000645static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000646match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000647{
Damien Millercf31f382013-10-24 21:02:56 +1100648 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000649 char *arg, *attrib, *cp = *condition;
650 size_t len;
651
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000652 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000653 debug3("checking syntax for 'Match %s'", cp);
654 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000655 debug3("checking match for '%s' user %s host %s addr %s "
656 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
657 ci->host ? ci->host : "(null)",
658 ci->address ? ci->address : "(null)",
659 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000660
661 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100662 attributes++;
663 if (strcasecmp(attrib, "all") == 0) {
664 if (attributes != 1 ||
665 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
666 error("'all' cannot be combined with other "
667 "Match attributes");
668 return -1;
669 }
670 *condition = cp;
671 return 1;
672 }
Darren Tucker45150472006-07-12 22:34:17 +1000673 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
674 error("Missing Match criteria for %s", attrib);
675 return -1;
676 }
677 len = strlen(arg);
678 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000679 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000680 result = 0;
681 continue;
682 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000683 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000684 result = 0;
685 else
686 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000687 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000688 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000689 if (ci == NULL || ci->user == NULL) {
690 result = 0;
691 continue;
692 }
693 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000694 case -1:
695 return -1;
696 case 0:
697 result = 0;
698 }
Darren Tucker45150472006-07-12 22:34:17 +1000699 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000700 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000701 result = 0;
702 continue;
703 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000704 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000705 result = 0;
706 else
707 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000708 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000709 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000710 if (ci == NULL || ci->address == NULL) {
711 result = 0;
712 continue;
713 }
714 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000715 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000716 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000717 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000718 break;
719 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000720 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000721 result = 0;
722 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000723 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000724 return -1;
725 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000726 } else if (strcasecmp(attrib, "localaddress") == 0){
727 if (ci == NULL || ci->laddress == NULL) {
728 result = 0;
729 continue;
730 }
731 switch (addr_match_list(ci->laddress, arg)) {
732 case 1:
733 debug("connection from %.100s matched "
734 "'LocalAddress %.100s' at line %d",
735 ci->laddress, arg, line);
736 break;
737 case 0:
738 case -1:
739 result = 0;
740 break;
741 case -2:
742 return -1;
743 }
744 } else if (strcasecmp(attrib, "localport") == 0) {
745 if ((port = a2port(arg)) == -1) {
746 error("Invalid LocalPort '%s' on Match line",
747 arg);
748 return -1;
749 }
750 if (ci == NULL || ci->lport == 0) {
751 result = 0;
752 continue;
753 }
754 /* TODO support port lists */
755 if (port == ci->lport)
756 debug("connection from %.100s matched "
757 "'LocalPort %d' at line %d",
758 ci->laddress, port, line);
759 else
760 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000761 } else {
762 error("Unsupported Match attribute %s", attrib);
763 return -1;
764 }
765 }
Damien Millercf31f382013-10-24 21:02:56 +1100766 if (attributes == 0) {
767 error("One or more attributes required for Match");
768 return -1;
769 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000770 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000771 debug3("match %sfound", result ? "" : "not ");
772 *condition = cp;
773 return result;
774}
775
Damien Millere2754432006-07-24 14:06:47 +1000776#define WHITESPACE " \t\r\n"
777
Damien Miller33322122011-06-20 14:43:11 +1000778/* Multistate option parsing */
779struct multistate {
780 char *key;
781 int value;
782};
783static const struct multistate multistate_addressfamily[] = {
784 { "inet", AF_INET },
785 { "inet6", AF_INET6 },
786 { "any", AF_UNSPEC },
787 { NULL, -1 }
788};
789static const struct multistate multistate_permitrootlogin[] = {
790 { "without-password", PERMIT_NO_PASSWD },
791 { "forced-commands-only", PERMIT_FORCED_ONLY },
792 { "yes", PERMIT_YES },
793 { "no", PERMIT_NO },
794 { NULL, -1 }
795};
796static const struct multistate multistate_compression[] = {
797 { "delayed", COMP_DELAYED },
798 { "yes", COMP_ZLIB },
799 { "no", COMP_NONE },
800 { NULL, -1 }
801};
802static const struct multistate multistate_gatewayports[] = {
803 { "clientspecified", 2 },
804 { "yes", 1 },
805 { "no", 0 },
806 { NULL, -1 }
807};
Damien Miller69ff1df2011-06-23 08:30:03 +1000808static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000809 { "yes", PRIVSEP_NOSANDBOX },
810 { "sandbox", PRIVSEP_ON },
811 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000812 { "no", PRIVSEP_OFF },
813 { NULL, -1 }
814};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100815static const struct multistate multistate_tcpfwd[] = {
816 { "yes", FORWARD_ALLOW },
817 { "all", FORWARD_ALLOW },
818 { "no", FORWARD_DENY },
819 { "remote", FORWARD_REMOTE },
820 { "local", FORWARD_LOCAL },
821 { NULL, -1 }
822};
Damien Miller33322122011-06-20 14:43:11 +1000823
Ben Lindstromade03f62001-12-06 18:22:17 +0000824int
825process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000826 const char *filename, int linenum, int *activep,
827 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000828{
Darren Tucker09c0f032013-05-16 20:48:57 +1000829 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000830 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100831 SyslogFacility *log_facility_ptr;
832 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000833 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000834 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000835 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000836 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000837 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000838
839 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100840 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100841 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000842 /* Ignore leading whitespace */
843 if (*arg == '\0')
844 arg = strdelim(&cp);
845 if (!arg || !*arg || *arg == '#')
846 return 0;
847 intptr = NULL;
848 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000849 opcode = parse_token(arg, filename, linenum, &flags);
850
851 if (activep == NULL) { /* We are processing a command line directive */
852 cmdline = 1;
853 activep = &cmdline;
854 }
855 if (*activep && opcode != sMatch)
856 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
857 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000858 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000859 fatal("%s line %d: Directive '%s' is not allowed "
860 "within a Match block", filename, linenum, arg);
861 } else { /* this is a directive we have already processed */
862 while (arg)
863 arg = strdelim(&cp);
864 return 0;
865 }
866 }
867
Ben Lindstromade03f62001-12-06 18:22:17 +0000868 switch (opcode) {
869 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000870 case sUsePAM:
871 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000872 goto parse_flag;
873
874 /* Standard Options */
875 case sBadOption:
876 return -1;
877 case sPort:
878 /* ignore ports from configfile if cmdline specifies ports */
879 if (options->ports_from_cmdline)
880 return 0;
881 if (options->listen_addrs != NULL)
882 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100883 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000884 if (options->num_ports >= MAX_PORTS)
885 fatal("%s line %d: too many ports.",
886 filename, linenum);
887 arg = strdelim(&cp);
888 if (!arg || *arg == '\0')
889 fatal("%s line %d: missing port number.",
890 filename, linenum);
891 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100892 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000893 fatal("%s line %d: Badly formatted port number.",
894 filename, linenum);
895 break;
896
897 case sServerKeyBits:
898 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000899 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000900 arg = strdelim(&cp);
901 if (!arg || *arg == '\0')
902 fatal("%s line %d: missing integer value.",
903 filename, linenum);
904 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000905 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000906 *intptr = value;
907 break;
908
909 case sLoginGraceTime:
910 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000911 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000912 arg = strdelim(&cp);
913 if (!arg || *arg == '\0')
914 fatal("%s line %d: missing time value.",
915 filename, linenum);
916 if ((value = convtime(arg)) == -1)
917 fatal("%s line %d: invalid time value.",
918 filename, linenum);
919 if (*intptr == -1)
920 *intptr = value;
921 break;
922
923 case sKeyRegenerationTime:
924 intptr = &options->key_regeneration_time;
925 goto parse_time;
926
927 case sListenAddress:
928 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100929 if (arg == NULL || *arg == '\0')
930 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000931 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000932 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
933 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
934 && strchr(p+1, ':') != NULL) {
935 add_listen_addr(options, arg, 0);
936 break;
937 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100938 p = hpdelim(&arg);
939 if (p == NULL)
940 fatal("%s line %d: bad address:port usage",
941 filename, linenum);
942 p = cleanhostname(p);
943 if (arg == NULL)
944 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100945 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100946 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000947
Damien Millerf91ee4c2005-03-01 21:24:33 +1100948 add_listen_addr(options, p, port);
949
Ben Lindstromade03f62001-12-06 18:22:17 +0000950 break;
951
Darren Tucker0f383232005-01-20 10:57:56 +1100952 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000953 intptr = &options->address_family;
954 multistate_ptr = multistate_addressfamily;
955 if (options->listen_addrs != NULL)
956 fatal("%s line %d: address family must be specified "
957 "before ListenAddress.", filename, linenum);
958 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100959 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000960 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000961 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000962 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000963 value = -1;
964 for (i = 0; multistate_ptr[i].key != NULL; i++) {
965 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
966 value = multistate_ptr[i].value;
967 break;
968 }
969 }
970 if (value == -1)
971 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100972 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000973 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100974 *intptr = value;
975 break;
976
Ben Lindstromade03f62001-12-06 18:22:17 +0000977 case sHostKeyFile:
978 intptr = &options->num_host_key_files;
979 if (*intptr >= MAX_HOSTKEYS)
980 fatal("%s line %d: too many host keys specified (max %d).",
981 filename, linenum, MAX_HOSTKEYS);
982 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000983 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000984 arg = strdelim(&cp);
985 if (!arg || *arg == '\0')
986 fatal("%s line %d: missing file name.",
987 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000988 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100989 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000990 /* increase optional counter */
991 if (intptr != NULL)
992 *intptr = *intptr + 1;
993 }
994 break;
995
Damien Miller85b45e02013-07-20 13:21:52 +1000996 case sHostKeyAgent:
997 charptr = &options->host_key_agent;
998 arg = strdelim(&cp);
999 if (!arg || *arg == '\0')
1000 fatal("%s line %d: missing socket name.",
1001 filename, linenum);
1002 if (*activep && *charptr == NULL)
1003 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1004 xstrdup(arg) : derelativise_path(arg);
1005 break;
1006
Damien Miller0a80ca12010-02-27 07:55:05 +11001007 case sHostCertificate:
1008 intptr = &options->num_host_cert_files;
1009 if (*intptr >= MAX_HOSTKEYS)
1010 fatal("%s line %d: too many host certificates "
1011 "specified (max %d).", filename, linenum,
1012 MAX_HOSTCERTS);
1013 charptr = &options->host_cert_files[*intptr];
1014 goto parse_filename;
1015 break;
1016
Ben Lindstromade03f62001-12-06 18:22:17 +00001017 case sPidFile:
1018 charptr = &options->pid_file;
1019 goto parse_filename;
1020
1021 case sPermitRootLogin:
1022 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001023 multistate_ptr = multistate_permitrootlogin;
1024 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001025
1026 case sIgnoreRhosts:
1027 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001028 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001029 arg = strdelim(&cp);
1030 if (!arg || *arg == '\0')
1031 fatal("%s line %d: missing yes/no argument.",
1032 filename, linenum);
1033 value = 0; /* silence compiler */
1034 if (strcmp(arg, "yes") == 0)
1035 value = 1;
1036 else if (strcmp(arg, "no") == 0)
1037 value = 0;
1038 else
1039 fatal("%s line %d: Bad yes/no argument: %s",
1040 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001041 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001042 *intptr = value;
1043 break;
1044
1045 case sIgnoreUserKnownHosts:
1046 intptr = &options->ignore_user_known_hosts;
1047 goto parse_flag;
1048
Ben Lindstromade03f62001-12-06 18:22:17 +00001049 case sRhostsRSAAuthentication:
1050 intptr = &options->rhosts_rsa_authentication;
1051 goto parse_flag;
1052
1053 case sHostbasedAuthentication:
1054 intptr = &options->hostbased_authentication;
1055 goto parse_flag;
1056
1057 case sHostbasedUsesNameFromPacketOnly:
1058 intptr = &options->hostbased_uses_name_from_packet_only;
1059 goto parse_flag;
1060
1061 case sRSAAuthentication:
1062 intptr = &options->rsa_authentication;
1063 goto parse_flag;
1064
1065 case sPubkeyAuthentication:
1066 intptr = &options->pubkey_authentication;
1067 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001068
Ben Lindstromade03f62001-12-06 18:22:17 +00001069 case sKerberosAuthentication:
1070 intptr = &options->kerberos_authentication;
1071 goto parse_flag;
1072
1073 case sKerberosOrLocalPasswd:
1074 intptr = &options->kerberos_or_local_passwd;
1075 goto parse_flag;
1076
1077 case sKerberosTicketCleanup:
1078 intptr = &options->kerberos_ticket_cleanup;
1079 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001080
Darren Tucker22ef5082003-12-31 11:37:34 +11001081 case sKerberosGetAFSToken:
1082 intptr = &options->kerberos_get_afs_token;
1083 goto parse_flag;
1084
Darren Tucker0efd1552003-08-26 11:49:55 +10001085 case sGssAuthentication:
1086 intptr = &options->gss_authentication;
1087 goto parse_flag;
1088
1089 case sGssCleanupCreds:
1090 intptr = &options->gss_cleanup_creds;
1091 goto parse_flag;
1092
Ben Lindstromade03f62001-12-06 18:22:17 +00001093 case sPasswordAuthentication:
1094 intptr = &options->password_authentication;
1095 goto parse_flag;
1096
1097 case sKbdInteractiveAuthentication:
1098 intptr = &options->kbd_interactive_authentication;
1099 goto parse_flag;
1100
1101 case sChallengeResponseAuthentication:
1102 intptr = &options->challenge_response_authentication;
1103 goto parse_flag;
1104
1105 case sPrintMotd:
1106 intptr = &options->print_motd;
1107 goto parse_flag;
1108
1109 case sPrintLastLog:
1110 intptr = &options->print_lastlog;
1111 goto parse_flag;
1112
1113 case sX11Forwarding:
1114 intptr = &options->x11_forwarding;
1115 goto parse_flag;
1116
1117 case sX11DisplayOffset:
1118 intptr = &options->x11_display_offset;
1119 goto parse_int;
1120
Damien Miller95c249f2002-02-05 12:11:34 +11001121 case sX11UseLocalhost:
1122 intptr = &options->x11_use_localhost;
1123 goto parse_flag;
1124
Ben Lindstromade03f62001-12-06 18:22:17 +00001125 case sXAuthLocation:
1126 charptr = &options->xauth_location;
1127 goto parse_filename;
1128
Damien Miller5ff30c62013-10-30 22:21:50 +11001129 case sPermitTTY:
1130 intptr = &options->permit_tty;
1131 goto parse_flag;
1132
Ben Lindstromade03f62001-12-06 18:22:17 +00001133 case sStrictModes:
1134 intptr = &options->strict_modes;
1135 goto parse_flag;
1136
Damien Miller12c150e2003-12-17 16:31:10 +11001137 case sTCPKeepAlive:
1138 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001139 goto parse_flag;
1140
1141 case sEmptyPasswd:
1142 intptr = &options->permit_empty_passwd;
1143 goto parse_flag;
1144
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001145 case sPermitUserEnvironment:
1146 intptr = &options->permit_user_env;
1147 goto parse_flag;
1148
Ben Lindstromade03f62001-12-06 18:22:17 +00001149 case sUseLogin:
1150 intptr = &options->use_login;
1151 goto parse_flag;
1152
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001153 case sCompression:
1154 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001155 multistate_ptr = multistate_compression;
1156 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001157
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001158 case sRekeyLimit:
1159 arg = strdelim(&cp);
1160 if (!arg || *arg == '\0')
1161 fatal("%.200s line %d: Missing argument.", filename,
1162 linenum);
1163 if (strcmp(arg, "default") == 0) {
1164 val64 = 0;
1165 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001166 if (scan_scaled(arg, &val64) == -1)
1167 fatal("%.200s line %d: Bad number '%s': %s",
1168 filename, linenum, arg, strerror(errno));
1169 /* check for too-large or too-small limits */
1170 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001171 fatal("%.200s line %d: RekeyLimit too large",
1172 filename, linenum);
1173 if (val64 != 0 && val64 < 16)
1174 fatal("%.200s line %d: RekeyLimit too small",
1175 filename, linenum);
1176 }
1177 if (*activep && options->rekey_limit == -1)
1178 options->rekey_limit = (u_int32_t)val64;
1179 if (cp != NULL) { /* optional rekey interval present */
1180 if (strcmp(cp, "none") == 0) {
1181 (void)strdelim(&cp); /* discard */
1182 break;
1183 }
1184 intptr = &options->rekey_interval;
1185 goto parse_time;
1186 }
1187 break;
1188
Ben Lindstromade03f62001-12-06 18:22:17 +00001189 case sGatewayPorts:
1190 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001191 multistate_ptr = multistate_gatewayports;
1192 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001193
Damien Miller3a961dc2003-06-03 10:25:48 +10001194 case sUseDNS:
1195 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001196 goto parse_flag;
1197
1198 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001199 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001200 arg = strdelim(&cp);
1201 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001202 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001203 fatal("%.200s line %d: unsupported log facility '%s'",
1204 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001205 if (*log_facility_ptr == -1)
1206 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001207 break;
1208
1209 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001210 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001211 arg = strdelim(&cp);
1212 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001213 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001214 fatal("%.200s line %d: unsupported log level '%s'",
1215 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001216 if (*log_level_ptr == -1)
1217 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001218 break;
1219
1220 case sAllowTcpForwarding:
1221 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001222 multistate_ptr = multistate_tcpfwd;
1223 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001224
Damien Miller4f755cd2008-05-19 14:57:41 +10001225 case sAllowAgentForwarding:
1226 intptr = &options->allow_agent_forwarding;
1227 goto parse_flag;
1228
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001229 case sUsePrivilegeSeparation:
1230 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001231 multistate_ptr = multistate_privsep;
1232 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001233
Ben Lindstromade03f62001-12-06 18:22:17 +00001234 case sAllowUsers:
1235 while ((arg = strdelim(&cp)) && *arg != '\0') {
1236 if (options->num_allow_users >= MAX_ALLOW_USERS)
1237 fatal("%s line %d: too many allow users.",
1238 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001239 if (!*activep)
1240 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001241 options->allow_users[options->num_allow_users++] =
1242 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001243 }
1244 break;
1245
1246 case sDenyUsers:
1247 while ((arg = strdelim(&cp)) && *arg != '\0') {
1248 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001249 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001250 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001251 if (!*activep)
1252 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001253 options->deny_users[options->num_deny_users++] =
1254 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001255 }
1256 break;
1257
1258 case sAllowGroups:
1259 while ((arg = strdelim(&cp)) && *arg != '\0') {
1260 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1261 fatal("%s line %d: too many allow groups.",
1262 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001263 if (!*activep)
1264 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001265 options->allow_groups[options->num_allow_groups++] =
1266 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001267 }
1268 break;
1269
1270 case sDenyGroups:
1271 while ((arg = strdelim(&cp)) && *arg != '\0') {
1272 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1273 fatal("%s line %d: too many deny groups.",
1274 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001275 if (!*activep)
1276 continue;
1277 options->deny_groups[options->num_deny_groups++] =
1278 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001279 }
1280 break;
1281
1282 case sCiphers:
1283 arg = strdelim(&cp);
1284 if (!arg || *arg == '\0')
1285 fatal("%s line %d: Missing argument.", filename, linenum);
1286 if (!ciphers_valid(arg))
1287 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1288 filename, linenum, arg ? arg : "<NONE>");
1289 if (options->ciphers == NULL)
1290 options->ciphers = xstrdup(arg);
1291 break;
1292
1293 case sMacs:
1294 arg = strdelim(&cp);
1295 if (!arg || *arg == '\0')
1296 fatal("%s line %d: Missing argument.", filename, linenum);
1297 if (!mac_valid(arg))
1298 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1299 filename, linenum, arg ? arg : "<NONE>");
1300 if (options->macs == NULL)
1301 options->macs = xstrdup(arg);
1302 break;
1303
Damien Millerd5f62bf2010-09-24 22:11:14 +10001304 case sKexAlgorithms:
1305 arg = strdelim(&cp);
1306 if (!arg || *arg == '\0')
1307 fatal("%s line %d: Missing argument.",
1308 filename, linenum);
1309 if (!kex_names_valid(arg))
1310 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1311 filename, linenum, arg ? arg : "<NONE>");
1312 if (options->kex_algorithms == NULL)
1313 options->kex_algorithms = xstrdup(arg);
1314 break;
1315
Ben Lindstromade03f62001-12-06 18:22:17 +00001316 case sProtocol:
1317 intptr = &options->protocol;
1318 arg = strdelim(&cp);
1319 if (!arg || *arg == '\0')
1320 fatal("%s line %d: Missing argument.", filename, linenum);
1321 value = proto_spec(arg);
1322 if (value == SSH_PROTO_UNKNOWN)
1323 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001324 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001325 if (*intptr == SSH_PROTO_UNKNOWN)
1326 *intptr = value;
1327 break;
1328
1329 case sSubsystem:
1330 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1331 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001332 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001333 }
1334 arg = strdelim(&cp);
1335 if (!arg || *arg == '\0')
1336 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001337 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001338 if (!*activep) {
1339 arg = strdelim(&cp);
1340 break;
1341 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001342 for (i = 0; i < options->num_subsystems; i++)
1343 if (strcmp(arg, options->subsystem_name[i]) == 0)
1344 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001345 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001346 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1347 arg = strdelim(&cp);
1348 if (!arg || *arg == '\0')
1349 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001350 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001351 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001352
1353 /* Collect arguments (separate to executable) */
1354 p = xstrdup(arg);
1355 len = strlen(p) + 1;
1356 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1357 len += 1 + strlen(arg);
1358 p = xrealloc(p, 1, len);
1359 strlcat(p, " ", len);
1360 strlcat(p, arg, len);
1361 }
1362 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001363 options->num_subsystems++;
1364 break;
1365
1366 case sMaxStartups:
1367 arg = strdelim(&cp);
1368 if (!arg || *arg == '\0')
1369 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001370 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001371 if ((n = sscanf(arg, "%d:%d:%d",
1372 &options->max_startups_begin,
1373 &options->max_startups_rate,
1374 &options->max_startups)) == 3) {
1375 if (options->max_startups_begin >
1376 options->max_startups ||
1377 options->max_startups_rate > 100 ||
1378 options->max_startups_rate < 1)
1379 fatal("%s line %d: Illegal MaxStartups spec.",
1380 filename, linenum);
1381 } else if (n != 1)
1382 fatal("%s line %d: Illegal MaxStartups spec.",
1383 filename, linenum);
1384 else
1385 options->max_startups = options->max_startups_begin;
1386 break;
1387
Darren Tucker89413db2004-05-24 10:36:23 +10001388 case sMaxAuthTries:
1389 intptr = &options->max_authtries;
1390 goto parse_int;
1391
Damien Miller7207f642008-05-19 15:34:50 +10001392 case sMaxSessions:
1393 intptr = &options->max_sessions;
1394 goto parse_int;
1395
Ben Lindstromade03f62001-12-06 18:22:17 +00001396 case sBanner:
1397 charptr = &options->banner;
1398 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001399
Ben Lindstromade03f62001-12-06 18:22:17 +00001400 /*
1401 * These options can contain %X options expanded at
1402 * connect time, so that you can specify paths like:
1403 *
1404 * AuthorizedKeysFile /etc/ssh_keys/%u
1405 */
1406 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001407 if (*activep && options->num_authkeys_files == 0) {
1408 while ((arg = strdelim(&cp)) && *arg != '\0') {
1409 if (options->num_authkeys_files >=
1410 MAX_AUTHKEYS_FILES)
1411 fatal("%s line %d: "
1412 "too many authorized keys files.",
1413 filename, linenum);
1414 options->authorized_keys_files[
1415 options->num_authkeys_files++] =
1416 tilde_expand_filename(arg, getuid());
1417 }
1418 }
1419 return 0;
1420
Damien Miller30da3442010-05-10 11:58:03 +10001421 case sAuthorizedPrincipalsFile:
1422 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001423 arg = strdelim(&cp);
1424 if (!arg || *arg == '\0')
1425 fatal("%s line %d: missing file name.",
1426 filename, linenum);
1427 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001428 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001429 /* increase optional counter */
1430 if (intptr != NULL)
1431 *intptr = *intptr + 1;
1432 }
1433 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001434
1435 case sClientAliveInterval:
1436 intptr = &options->client_alive_interval;
1437 goto parse_time;
1438
1439 case sClientAliveCountMax:
1440 intptr = &options->client_alive_count_max;
1441 goto parse_int;
1442
Darren Tucker46bc0752004-05-02 22:11:30 +10001443 case sAcceptEnv:
1444 while ((arg = strdelim(&cp)) && *arg != '\0') {
1445 if (strchr(arg, '=') != NULL)
1446 fatal("%s line %d: Invalid environment name.",
1447 filename, linenum);
1448 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1449 fatal("%s line %d: too many allow env.",
1450 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001451 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001452 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001453 options->accept_env[options->num_accept_env++] =
1454 xstrdup(arg);
1455 }
1456 break;
1457
Damien Millerd27b9472005-12-13 19:29:02 +11001458 case sPermitTunnel:
1459 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001460 arg = strdelim(&cp);
1461 if (!arg || *arg == '\0')
1462 fatal("%s line %d: Missing yes/point-to-point/"
1463 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001464 value = -1;
1465 for (i = 0; tunmode_desc[i].val != -1; i++)
1466 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1467 value = tunmode_desc[i].val;
1468 break;
1469 }
1470 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001471 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1472 "no argument: %s", filename, linenum, arg);
1473 if (*intptr == -1)
1474 *intptr = value;
1475 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001476
Darren Tucker45150472006-07-12 22:34:17 +10001477 case sMatch:
1478 if (cmdline)
1479 fatal("Match directive not supported as a command-line "
1480 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001481 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001482 if (value < 0)
1483 fatal("%s line %d: Bad Match condition", filename,
1484 linenum);
1485 *activep = value;
1486 break;
1487
Damien Miller9b439df2006-07-24 14:04:00 +10001488 case sPermitOpen:
1489 arg = strdelim(&cp);
1490 if (!arg || *arg == '\0')
1491 fatal("%s line %d: missing PermitOpen specification",
1492 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001493 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001494 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001495 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001496 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001497 options->num_permitted_opens = 0;
1498 }
Damien Miller9b439df2006-07-24 14:04:00 +10001499 break;
1500 }
Damien Millerc6081482012-04-22 11:18:53 +10001501 if (strcmp(arg, "none") == 0) {
1502 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001503 options->num_permitted_opens = 1;
1504 channel_disable_adm_local_opens();
1505 }
1506 break;
1507 }
Damien Millera29b95e2007-01-05 16:28:36 +11001508 if (*activep && n == -1)
1509 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001510 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1511 p = hpdelim(&arg);
1512 if (p == NULL)
1513 fatal("%s line %d: missing host in PermitOpen",
1514 filename, linenum);
1515 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001516 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001517 fatal("%s line %d: bad port number in "
1518 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001519 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001520 options->num_permitted_opens =
1521 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001522 }
Damien Miller9b439df2006-07-24 14:04:00 +10001523 break;
1524
Damien Millere2754432006-07-24 14:06:47 +10001525 case sForceCommand:
1526 if (cp == NULL)
1527 fatal("%.200s line %d: Missing argument.", filename,
1528 linenum);
1529 len = strspn(cp, WHITESPACE);
1530 if (*activep && options->adm_forced_command == NULL)
1531 options->adm_forced_command = xstrdup(cp + len);
1532 return 0;
1533
Damien Millerd8cb1f12008-02-10 22:40:12 +11001534 case sChrootDirectory:
1535 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001536
1537 arg = strdelim(&cp);
1538 if (!arg || *arg == '\0')
1539 fatal("%s line %d: missing file name.",
1540 filename, linenum);
1541 if (*activep && *charptr == NULL)
1542 *charptr = xstrdup(arg);
1543 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001544
Damien Miller1aed65e2010-03-04 21:53:35 +11001545 case sTrustedUserCAKeys:
1546 charptr = &options->trusted_user_ca_keys;
1547 goto parse_filename;
1548
1549 case sRevokedKeys:
1550 charptr = &options->revoked_keys_file;
1551 goto parse_filename;
1552
Damien Miller0dac6fb2010-11-20 15:19:38 +11001553 case sIPQoS:
1554 arg = strdelim(&cp);
1555 if ((value = parse_ipqos(arg)) == -1)
1556 fatal("%s line %d: Bad IPQoS value: %s",
1557 filename, linenum, arg);
1558 arg = strdelim(&cp);
1559 if (arg == NULL)
1560 value2 = value;
1561 else if ((value2 = parse_ipqos(arg)) == -1)
1562 fatal("%s line %d: Bad IPQoS value: %s",
1563 filename, linenum, arg);
1564 if (*activep) {
1565 options->ip_qos_interactive = value;
1566 options->ip_qos_bulk = value2;
1567 }
1568 break;
1569
Damien Miller23528812012-04-22 11:24:43 +10001570 case sVersionAddendum:
1571 if (cp == NULL)
1572 fatal("%.200s line %d: Missing argument.", filename,
1573 linenum);
1574 len = strspn(cp, WHITESPACE);
1575 if (*activep && options->version_addendum == NULL) {
1576 if (strcasecmp(cp + len, "none") == 0)
1577 options->version_addendum = xstrdup("");
1578 else if (strchr(cp + len, '\r') != NULL)
1579 fatal("%.200s line %d: Invalid argument",
1580 filename, linenum);
1581 else
1582 options->version_addendum = xstrdup(cp + len);
1583 }
1584 return 0;
1585
Damien Miller09d3e122012-10-31 08:58:58 +11001586 case sAuthorizedKeysCommand:
1587 len = strspn(cp, WHITESPACE);
1588 if (*activep && options->authorized_keys_command == NULL) {
1589 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1590 fatal("%.200s line %d: AuthorizedKeysCommand "
1591 "must be an absolute path",
1592 filename, linenum);
1593 options->authorized_keys_command = xstrdup(cp + len);
1594 }
1595 return 0;
1596
1597 case sAuthorizedKeysCommandUser:
1598 charptr = &options->authorized_keys_command_user;
1599
1600 arg = strdelim(&cp);
1601 if (*activep && *charptr == NULL)
1602 *charptr = xstrdup(arg);
1603 break;
1604
Damien Millera6e3f012012-11-04 23:21:40 +11001605 case sAuthenticationMethods:
1606 if (*activep && options->num_auth_methods == 0) {
1607 while ((arg = strdelim(&cp)) && *arg != '\0') {
1608 if (options->num_auth_methods >=
1609 MAX_AUTH_METHODS)
1610 fatal("%s line %d: "
1611 "too many authentication methods.",
1612 filename, linenum);
1613 if (auth2_methods_valid(arg, 0) != 0)
1614 fatal("%s line %d: invalid "
1615 "authentication method list.",
1616 filename, linenum);
1617 options->auth_methods[
1618 options->num_auth_methods++] = xstrdup(arg);
1619 }
1620 }
1621 return 0;
1622
Ben Lindstromade03f62001-12-06 18:22:17 +00001623 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001624 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001625 filename, linenum, arg);
1626 while (arg)
1627 arg = strdelim(&cp);
1628 break;
1629
Damien Millerf9b3feb2003-05-16 11:38:32 +10001630 case sUnsupported:
1631 logit("%s line %d: Unsupported option %s",
1632 filename, linenum, arg);
1633 while (arg)
1634 arg = strdelim(&cp);
1635 break;
1636
Ben Lindstromade03f62001-12-06 18:22:17 +00001637 default:
1638 fatal("%s line %d: Missing handler for opcode %s (%d)",
1639 filename, linenum, arg, opcode);
1640 }
1641 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1642 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1643 filename, linenum, arg);
1644 return 0;
1645}
1646
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001647/* Reads the server configuration file. */
1648
Damien Miller4af51302000-04-16 11:18:38 +10001649void
Darren Tucker645ab752004-06-25 13:33:20 +10001650load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001651{
Damien Miller46cb75a2012-07-31 12:22:37 +10001652 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001653 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001654 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001655
Darren Tucker645ab752004-06-25 13:33:20 +10001656 debug2("%s: filename %s", __func__, filename);
1657 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001658 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001659 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001660 }
Darren Tucker645ab752004-06-25 13:33:20 +10001661 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001662 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001663 lineno++;
1664 if (strlen(line) == sizeof(line) - 1)
1665 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001666 /*
1667 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001668 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001669 * line numbers later for error messages
1670 */
1671 if ((cp = strchr(line, '#')) != NULL)
1672 memcpy(cp, "\n", 2);
1673 cp = line + strspn(line, " \t\r");
1674
1675 buffer_append(conf, cp, strlen(cp));
1676 }
1677 buffer_append(conf, "\0", 1);
1678 fclose(f);
1679 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1680}
1681
1682void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001683parse_server_match_config(ServerOptions *options,
1684 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001685{
Darren Tucker45150472006-07-12 22:34:17 +10001686 ServerOptions mo;
1687
1688 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001689 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001690 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001691}
1692
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001693int parse_server_match_testspec(struct connection_info *ci, char *spec)
1694{
1695 char *p;
1696
1697 while ((p = strsep(&spec, ",")) && *p != '\0') {
1698 if (strncmp(p, "addr=", 5) == 0) {
1699 ci->address = xstrdup(p + 5);
1700 } else if (strncmp(p, "host=", 5) == 0) {
1701 ci->host = xstrdup(p + 5);
1702 } else if (strncmp(p, "user=", 5) == 0) {
1703 ci->user = xstrdup(p + 5);
1704 } else if (strncmp(p, "laddr=", 6) == 0) {
1705 ci->laddress = xstrdup(p + 6);
1706 } else if (strncmp(p, "lport=", 6) == 0) {
1707 ci->lport = a2port(p + 6);
1708 if (ci->lport == -1) {
1709 fprintf(stderr, "Invalid port '%s' in test mode"
1710 " specification %s\n", p+6, p);
1711 return -1;
1712 }
1713 } else {
1714 fprintf(stderr, "Invalid test mode specification %s\n",
1715 p);
1716 return -1;
1717 }
1718 }
1719 return 0;
1720}
1721
1722/*
1723 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1724 * empty spec.
1725 */
1726int server_match_spec_complete(struct connection_info *ci)
1727{
1728 if (ci->user && ci->host && ci->address)
1729 return 1; /* complete */
1730 if (!ci->user && !ci->host && !ci->address)
1731 return -1; /* empty */
1732 return 0; /* partial */
1733}
1734
Darren Tucker1629c072007-02-19 22:25:37 +11001735/*
1736 * Copy any supported values that are set.
1737 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001738 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001739 * array values that are not used pre-authentication, because any that we
1740 * do use must be explictly sent in mm_getpwnamallow().
1741 */
Darren Tucker45150472006-07-12 22:34:17 +10001742void
Darren Tucker1629c072007-02-19 22:25:37 +11001743copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001744{
Damien Miller534b2cc2013-12-05 14:07:27 +11001745#define M_CP_INTOPT(n) do {\
1746 if (src->n != -1) \
1747 dst->n = src->n; \
1748} while (0)
1749
Darren Tucker1629c072007-02-19 22:25:37 +11001750 M_CP_INTOPT(password_authentication);
1751 M_CP_INTOPT(gss_authentication);
1752 M_CP_INTOPT(rsa_authentication);
1753 M_CP_INTOPT(pubkey_authentication);
1754 M_CP_INTOPT(kerberos_authentication);
1755 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001756 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001757 M_CP_INTOPT(kbd_interactive_authentication);
Darren Tucker15f94272008-01-01 20:36:56 +11001758 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001759 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001760
1761 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001762 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001763 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001764 M_CP_INTOPT(gateway_ports);
1765 M_CP_INTOPT(x11_display_offset);
1766 M_CP_INTOPT(x11_forwarding);
1767 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001768 M_CP_INTOPT(permit_tty);
Damien Miller7207f642008-05-19 15:34:50 +10001769 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001770 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001771 M_CP_INTOPT(ip_qos_interactive);
1772 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001773 M_CP_INTOPT(rekey_limit);
1774 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001775
Damien Miller534b2cc2013-12-05 14:07:27 +11001776 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1777#define M_CP_STROPT(n) do {\
1778 if (src->n != NULL && dst->n != src->n) { \
1779 free(dst->n); \
1780 dst->n = src->n; \
1781 } \
1782} while(0)
1783#define M_CP_STRARRAYOPT(n, num_n) do {\
1784 if (src->num_n != 0) { \
1785 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1786 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1787 } \
1788} while(0)
1789
Damien Millerf2e407e2011-05-20 19:04:14 +10001790 /* See comment in servconf.h */
1791 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001792
Damien Millerc2411902011-05-20 19:03:49 +10001793 /*
1794 * The only things that should be below this point are string options
1795 * which are only used after authentication.
1796 */
Damien Miller5d74e582011-05-20 19:03:31 +10001797 if (preauth)
1798 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001799
Damien Miller5d74e582011-05-20 19:03:31 +10001800 M_CP_STROPT(adm_forced_command);
1801 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001802}
1803
Darren Tucker1629c072007-02-19 22:25:37 +11001804#undef M_CP_INTOPT
1805#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001806#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001807
Darren Tucker45150472006-07-12 22:34:17 +10001808void
1809parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001810 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001811{
1812 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001813 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001814
1815 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1816
Darren Tucker9fbac712004-08-12 22:41:44 +10001817 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001818 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001819 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001820 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001821 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001822 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001823 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001824 }
Darren Tuckera627d422013-06-02 07:31:17 +10001825 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001826 if (bad_options > 0)
1827 fatal("%s: terminating, %d bad configuration options",
1828 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001829}
Darren Tuckere7140f22008-06-10 23:01:51 +10001830
1831static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001832fmt_multistate_int(int val, const struct multistate *m)
1833{
1834 u_int i;
1835
1836 for (i = 0; m[i].key != NULL; i++) {
1837 if (m[i].value == val)
1838 return m[i].key;
1839 }
1840 return "UNKNOWN";
1841}
1842
1843static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001844fmt_intarg(ServerOpCodes code, int val)
1845{
Damien Miller82c55872011-06-23 08:20:30 +10001846 if (val == -1)
1847 return "unset";
1848 switch (code) {
1849 case sAddressFamily:
1850 return fmt_multistate_int(val, multistate_addressfamily);
1851 case sPermitRootLogin:
1852 return fmt_multistate_int(val, multistate_permitrootlogin);
1853 case sGatewayPorts:
1854 return fmt_multistate_int(val, multistate_gatewayports);
1855 case sCompression:
1856 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001857 case sUsePrivilegeSeparation:
1858 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001859 case sAllowTcpForwarding:
1860 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001861 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001862 switch (val) {
1863 case SSH_PROTO_1:
1864 return "1";
1865 case SSH_PROTO_2:
1866 return "2";
1867 case (SSH_PROTO_1|SSH_PROTO_2):
1868 return "2,1";
1869 default:
1870 return "UNKNOWN";
1871 }
Damien Miller82c55872011-06-23 08:20:30 +10001872 default:
1873 switch (val) {
1874 case 0:
1875 return "no";
1876 case 1:
1877 return "yes";
1878 default:
1879 return "UNKNOWN";
1880 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001881 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001882}
1883
1884static const char *
1885lookup_opcode_name(ServerOpCodes code)
1886{
1887 u_int i;
1888
1889 for (i = 0; keywords[i].name != NULL; i++)
1890 if (keywords[i].opcode == code)
1891 return(keywords[i].name);
1892 return "UNKNOWN";
1893}
1894
1895static void
1896dump_cfg_int(ServerOpCodes code, int val)
1897{
1898 printf("%s %d\n", lookup_opcode_name(code), val);
1899}
1900
1901static void
1902dump_cfg_fmtint(ServerOpCodes code, int val)
1903{
1904 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1905}
1906
1907static void
1908dump_cfg_string(ServerOpCodes code, const char *val)
1909{
1910 if (val == NULL)
1911 return;
1912 printf("%s %s\n", lookup_opcode_name(code), val);
1913}
1914
1915static void
1916dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1917{
1918 u_int i;
1919
1920 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001921 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1922}
1923
1924static void
1925dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1926{
1927 u_int i;
1928
1929 printf("%s", lookup_opcode_name(code));
1930 for (i = 0; i < count; i++)
1931 printf(" %s", vals[i]);
1932 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001933}
1934
1935void
1936dump_config(ServerOptions *o)
1937{
1938 u_int i;
1939 int ret;
1940 struct addrinfo *ai;
1941 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1942
1943 /* these are usually at the top of the config */
1944 for (i = 0; i < o->num_ports; i++)
1945 printf("port %d\n", o->ports[i]);
1946 dump_cfg_fmtint(sProtocol, o->protocol);
1947 dump_cfg_fmtint(sAddressFamily, o->address_family);
1948
1949 /* ListenAddress must be after Port */
1950 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1951 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1952 sizeof(addr), port, sizeof(port),
1953 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1954 error("getnameinfo failed: %.100s",
1955 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1956 strerror(errno));
1957 } else {
1958 if (ai->ai_family == AF_INET6)
1959 printf("listenaddress [%s]:%s\n", addr, port);
1960 else
1961 printf("listenaddress %s:%s\n", addr, port);
1962 }
1963 }
1964
1965 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001966#ifdef USE_PAM
1967 dump_cfg_int(sUsePAM, o->use_pam);
1968#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001969 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1970 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1971 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1972 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1973 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001974 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001975 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1976 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1977
1978 /* formatted integer arguments */
1979 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1980 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1981 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1982 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1983 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1984 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1985 o->hostbased_uses_name_from_packet_only);
1986 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1987 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001988#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001989 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1990 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1991 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001992# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001993 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001994# endif
1995#endif
1996#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001997 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1998 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001999#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002000 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2001 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2002 o->kbd_interactive_authentication);
2003 dump_cfg_fmtint(sChallengeResponseAuthentication,
2004 o->challenge_response_authentication);
2005 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2006 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2007 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2008 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002009 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Darren Tuckere7140f22008-06-10 23:01:51 +10002010 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2011 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2012 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2013 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2014 dump_cfg_fmtint(sUseLogin, o->use_login);
2015 dump_cfg_fmtint(sCompression, o->compression);
2016 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2017 dump_cfg_fmtint(sUseDNS, o->use_dns);
2018 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2019 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2020
2021 /* string arguments */
2022 dump_cfg_string(sPidFile, o->pid_file);
2023 dump_cfg_string(sXAuthLocation, o->xauth_location);
Damien Miller690d9892013-11-08 12:16:49 +11002024 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers :
Damien Miller0fde8ac2013-11-21 14:12:23 +11002025 cipher_alg_list(',', 0));
Damien Miller690d9892013-11-08 12:16:49 +11002026 dump_cfg_string(sMacs, o->macs ? o->macs : mac_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002027 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002028 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002029 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002030 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2031 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002032 dump_cfg_string(sAuthorizedPrincipalsFile,
2033 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002034 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002035 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2036 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002037 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Damien Miller690d9892013-11-08 12:16:49 +11002038 dump_cfg_string(sKexAlgorithms, o->kex_algorithms ? o->kex_algorithms :
2039 kex_alg_list(','));
Darren Tuckere7140f22008-06-10 23:01:51 +10002040
2041 /* string arguments requiring a lookup */
2042 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2043 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2044
2045 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002046 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2047 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002048 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2049 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002050 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2051 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002052 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2053 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2054 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2055 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2056 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002057 dump_cfg_strarray_oneline(sAuthenticationMethods,
2058 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002059
2060 /* other arguments */
2061 for (i = 0; i < o->num_subsystems; i++)
2062 printf("subsystem %s %s\n", o->subsystem_name[i],
2063 o->subsystem_args[i]);
2064
2065 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2066 o->max_startups_rate, o->max_startups);
2067
2068 for (i = 0; tunmode_desc[i].val != -1; i++)
2069 if (tunmode_desc[i].val == o->permit_tun) {
2070 s = tunmode_desc[i].text;
2071 break;
2072 }
2073 dump_cfg_string(sPermitTunnel, s);
2074
Damien Miller91475862011-05-05 14:14:34 +10002075 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2076 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002077
Damien Millera6d6c1f2013-08-21 02:40:01 +10002078 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2079 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002080
Darren Tuckere7140f22008-06-10 23:01:51 +10002081 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002082}