blob: 0f1bdd09a8c0e12ac8dc56f2818336815a51dac7 [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Miller5ff30c62013-10-30 22:21:50 +11002/* $OpenBSD: servconf.c,v 1.244 2013/10/29 09:48:02 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 Miller01ed2272008-11-05 16:20:46 +1100150 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100151 options->revoked_keys_file = NULL;
152 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000153 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100154 options->ip_qos_interactive = -1;
155 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000156 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000157}
158
Damien Miller4af51302000-04-16 11:18:38 +1000159void
Damien Miller95def091999-11-25 00:26:21 +1100160fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000161{
Damien Miller726273e2001-11-12 11:40:11 +1100162 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000163 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000164 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100165
166 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100167 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100168 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100169 if (options->num_host_key_files == 0) {
170 /* fill default hostkeys for protocols */
171 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100172 options->host_key_files[options->num_host_key_files++] =
173 _PATH_HOST_KEY_FILE;
174 if (options->protocol & SSH_PROTO_2) {
175 options->host_key_files[options->num_host_key_files++] =
176 _PATH_HOST_RSA_KEY_FILE;
177 options->host_key_files[options->num_host_key_files++] =
178 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100179#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000180 options->host_key_files[options->num_host_key_files++] =
181 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100182#endif
Damien Miller7fc23732002-01-22 23:19:11 +1100183 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100184 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100185 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100186 if (options->num_ports == 0)
187 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
188 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000189 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000190 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000191 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000193 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000195 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100196 if (options->key_regeneration_time == -1)
197 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000198 if (options->permit_root_login == PERMIT_NOT_SET)
199 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100200 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100201 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->ignore_user_known_hosts == -1)
203 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->print_motd == -1)
205 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000206 if (options->print_lastlog == -1)
207 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100209 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100211 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100212 if (options->x11_use_localhost == -1)
213 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000214 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000215 options->xauth_location = _PATH_XAUTH;
Damien Miller5ff30c62013-10-30 22:21:50 +1100216 if (options->permit_tty == -1)
217 options->permit_tty = 1;
Damien Miller95def091999-11-25 00:26:21 +1100218 if (options->strict_modes == -1)
219 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100220 if (options->tcp_keep_alive == -1)
221 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100222 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100223 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100224 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000225 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100227 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000228 if (options->hostbased_authentication == -1)
229 options->hostbased_authentication = 0;
230 if (options->hostbased_uses_name_from_packet_only == -1)
231 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100232 if (options->rsa_authentication == -1)
233 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100234 if (options->pubkey_authentication == -1)
235 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100236 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000237 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100238 if (options->kerberos_or_local_passwd == -1)
239 options->kerberos_or_local_passwd = 1;
240 if (options->kerberos_ticket_cleanup == -1)
241 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100242 if (options->kerberos_get_afs_token == -1)
243 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000244 if (options->gss_authentication == -1)
245 options->gss_authentication = 0;
246 if (options->gss_cleanup_creds == -1)
247 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100248 if (options->password_authentication == -1)
249 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100250 if (options->kbd_interactive_authentication == -1)
251 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000252 if (options->challenge_response_authentication == -1)
253 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100254 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100255 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000256 if (options->permit_user_env == -1)
257 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100258 if (options->use_login == -1)
259 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000260 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000261 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000262 if (options->rekey_limit == -1)
263 options->rekey_limit = 0;
264 if (options->rekey_interval == -1)
265 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100266 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100267 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000268 if (options->allow_agent_forwarding == -1)
269 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000270 if (options->gateway_ports == -1)
271 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000272 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100273 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000274 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100275 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000276 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100277 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000278 if (options->max_authtries == -1)
279 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000280 if (options->max_sessions == -1)
281 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000282 if (options->use_dns == -1)
283 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000284 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100285 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000286 if (options->client_alive_count_max == -1)
287 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000288 if (options->num_authkeys_files == 0) {
289 options->authorized_keys_files[options->num_authkeys_files++] =
290 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
291 options->authorized_keys_files[options->num_authkeys_files++] =
292 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
293 }
Damien Millerd27b9472005-12-13 19:29:02 +1100294 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100295 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100296 if (options->zero_knowledge_password_authentication == -1)
297 options->zero_knowledge_password_authentication = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100298 if (options->ip_qos_interactive == -1)
299 options->ip_qos_interactive = IPTOS_LOWDELAY;
300 if (options->ip_qos_bulk == -1)
301 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000302 if (options->version_addendum == NULL)
303 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000304 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000305 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000306 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000307
Tim Rice40017b02002-07-14 13:36:49 -0700308#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000309 if (use_privsep && options->compression == 1) {
310 error("This platform does not support both privilege "
311 "separation and compression");
312 error("Compression disabled");
313 options->compression = 0;
314 }
315#endif
316
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000317}
318
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000319/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100320typedef enum {
321 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100322 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000323 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100324 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100325 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
326 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000327 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100328 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100329 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000330 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100331 sPasswordAuthentication, sKbdInteractiveAuthentication,
332 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000333 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100334 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller5ff30c62013-10-30 22:21:50 +1100335 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000336 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000337 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000338 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000339 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000340 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000341 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100342 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000343 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100344 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100345 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100346 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100347 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000348 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000349 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100350 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller85b45e02013-07-20 13:21:52 +1000351 sAuthenticationMethods, sHostKeyAgent,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000352 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000353} ServerOpCodes;
354
Darren Tucker45150472006-07-12 22:34:17 +1000355#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
356#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
357#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
358
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000359/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100360static struct {
361 const char *name;
362 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000363 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100364} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100365 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000366#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000367 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000368#else
Darren Tucker45150472006-07-12 22:34:17 +1000369 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000370#endif
Darren Tucker45150472006-07-12 22:34:17 +1000371 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100372 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000373 { "port", sPort, SSHCFG_GLOBAL },
374 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
375 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000376 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000377 { "pidfile", sPidFile, SSHCFG_GLOBAL },
378 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
379 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
380 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100381 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000382 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
383 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
384 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100385 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
386 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000387 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100388 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
389 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000390 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000391#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100392 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000393 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
394 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100395#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000396 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000397#else
Darren Tucker45150472006-07-12 22:34:17 +1000398 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100399#endif
400#else
Darren Tucker1629c072007-02-19 22:25:37 +1100401 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000402 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
403 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
404 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000405#endif
Darren Tucker45150472006-07-12 22:34:17 +1000406 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
407 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000408#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100409 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000410 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000411#else
Darren Tucker1629c072007-02-19 22:25:37 +1100412 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000413 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000414#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100415 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
416 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100417 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000418 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100419#ifdef JPAKE
420 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
421#else
422 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
423#endif
Darren Tucker45150472006-07-12 22:34:17 +1000424 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
425 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
426 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
427 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
428 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
429 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
430 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000431 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
432 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
433 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000434 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
435 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100436 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000437 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
438 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
439 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000440 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000441 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
442 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
443 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000444 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000445 { "allowusers", sAllowUsers, SSHCFG_ALL },
446 { "denyusers", sDenyUsers, SSHCFG_ALL },
447 { "allowgroups", sAllowGroups, SSHCFG_ALL },
448 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000449 { "ciphers", sCiphers, SSHCFG_GLOBAL },
450 { "macs", sMacs, SSHCFG_GLOBAL },
451 { "protocol", sProtocol, SSHCFG_GLOBAL },
452 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
453 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
454 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000455 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000456 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100457 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000458 { "usedns", sUseDNS, SSHCFG_GLOBAL },
459 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
460 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
461 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
462 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000463 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000464 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000465 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000466 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000467 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Damien Miller5ff30c62013-10-30 22:21:50 +1100468 { "permittty", sPermitTTY, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000469 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000470 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000471 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100472 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100473 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100474 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
475 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000476 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000477 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100478 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100479 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
480 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000481 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100482 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000483 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000484};
485
Darren Tuckere7140f22008-06-10 23:01:51 +1000486static struct {
487 int val;
488 char *text;
489} tunmode_desc[] = {
490 { SSH_TUNMODE_NO, "no" },
491 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
492 { SSH_TUNMODE_ETHERNET, "ethernet" },
493 { SSH_TUNMODE_YES, "yes" },
494 { -1, NULL }
495};
496
Damien Miller5428f641999-11-25 11:54:57 +1100497/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000498 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100499 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000500
Damien Miller4af51302000-04-16 11:18:38 +1000501static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100502parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000503 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000504{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000505 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000506
Damien Miller95def091999-11-25 00:26:21 +1100507 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000508 if (strcasecmp(cp, keywords[i].name) == 0) {
509 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100510 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000511 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000512
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000513 error("%s: line %d: Bad configuration option: %s",
514 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100515 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000516}
517
Darren Tucker88b6fb22010-01-13 22:44:29 +1100518char *
519derelativise_path(const char *path)
520{
Damien Miller44451d02010-03-26 10:40:04 +1100521 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100522
523 expanded = tilde_expand_filename(path, getuid());
524 if (*expanded == '/')
525 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100526 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100527 fatal("%s: getcwd: %s", __func__, strerror(errno));
528 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000529 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100530 return ret;
531}
532
Ben Lindstrombba81212001-06-25 05:01:22 +0000533static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100534add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100535{
Damien Millereccb9de2005-06-17 12:59:34 +1000536 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100537
538 if (options->num_ports == 0)
539 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100540 if (options->address_family == -1)
541 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000542 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000543 for (i = 0; i < options->num_ports; i++)
544 add_one_listen_addr(options, addr, options->ports[i]);
545 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000546 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000547}
548
Ben Lindstrombba81212001-06-25 05:01:22 +0000549static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100550add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000551{
552 struct addrinfo hints, *ai, *aitop;
553 char strport[NI_MAXSERV];
554 int gaierr;
555
556 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100557 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000558 hints.ai_socktype = SOCK_STREAM;
559 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100560 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000561 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
562 fatal("bad addr or host: %s (%s)",
563 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100564 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000565 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
566 ;
567 ai->ai_next = options->listen_addrs;
568 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100569}
570
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000571struct connection_info *
572get_connection_info(int populate, int use_dns)
573{
574 static struct connection_info ci;
575
576 if (!populate)
577 return &ci;
578 ci.host = get_canonical_hostname(use_dns);
579 ci.address = get_remote_ipaddr();
580 ci.laddress = get_local_ipaddr(packet_get_connection_in());
581 ci.lport = get_local_port();
582 return &ci;
583}
584
Darren Tucker45150472006-07-12 22:34:17 +1000585/*
586 * The strategy for the Match blocks is that the config file is parsed twice.
587 *
588 * The first time is at startup. activep is initialized to 1 and the
589 * directives in the global context are processed and acted on. Hitting a
590 * Match directive unsets activep and the directives inside the block are
591 * checked for syntax only.
592 *
593 * The second time is after a connection has been established but before
594 * authentication. activep is initialized to 2 and global config directives
595 * are ignored since they have already been processed. If the criteria in a
596 * Match block is met, activep is set and the subsequent directives
597 * processed and actioned until EOF or another Match block unsets it. Any
598 * options set are copied into the main server config.
599 *
600 * Potential additions/improvements:
601 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
602 *
603 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
604 * Match Address 192.168.0.*
605 * Tag trusted
606 * Match Group wheel
607 * Tag trusted
608 * Match Tag trusted
609 * AllowTcpForwarding yes
610 * GatewayPorts clientspecified
611 * [...]
612 *
613 * - Add a PermittedChannelRequests directive
614 * Match Group shell
615 * PermittedChannelRequests session,forwarded-tcpip
616 */
617
618static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000619match_cfg_line_group(const char *grps, int line, const char *user)
620{
621 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000622 struct passwd *pw;
623
Damien Miller565ca3f2006-08-19 00:23:15 +1000624 if (user == NULL)
625 goto out;
626
627 if ((pw = getpwnam(user)) == NULL) {
628 debug("Can't match group at line %d because user %.100s does "
629 "not exist", line, user);
630 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
631 debug("Can't Match group because user %.100s not in any group "
632 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000633 } else if (ga_match_pattern_list(grps) != 1) {
634 debug("user %.100s does not match group list %.100s at line %d",
635 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000636 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000637 debug("user %.100s matched group list %.100s at line %d", user,
638 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000639 result = 1;
640 }
641out:
642 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000643 return result;
644}
645
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000646/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000647 * All of the attributes on a single Match line are ANDed together, so we need
Damien Miller03bf2e62013-10-24 21:01:26 +1100648 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000649 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000650 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000651static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000652match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000653{
Damien Millercf31f382013-10-24 21:02:56 +1100654 int result = 1, attributes = 0, port;
Darren Tucker45150472006-07-12 22:34:17 +1000655 char *arg, *attrib, *cp = *condition;
656 size_t len;
657
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000658 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000659 debug3("checking syntax for 'Match %s'", cp);
660 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000661 debug3("checking match for '%s' user %s host %s addr %s "
662 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
663 ci->host ? ci->host : "(null)",
664 ci->address ? ci->address : "(null)",
665 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000666
667 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100668 attributes++;
669 if (strcasecmp(attrib, "all") == 0) {
670 if (attributes != 1 ||
671 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
672 error("'all' cannot be combined with other "
673 "Match attributes");
674 return -1;
675 }
676 *condition = cp;
677 return 1;
678 }
Darren Tucker45150472006-07-12 22:34:17 +1000679 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
680 error("Missing Match criteria for %s", attrib);
681 return -1;
682 }
683 len = strlen(arg);
684 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000685 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000686 result = 0;
687 continue;
688 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000689 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000690 result = 0;
691 else
692 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000693 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000694 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695 if (ci == NULL || ci->user == NULL) {
696 result = 0;
697 continue;
698 }
699 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000700 case -1:
701 return -1;
702 case 0:
703 result = 0;
704 }
Darren Tucker45150472006-07-12 22:34:17 +1000705 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000706 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000707 result = 0;
708 continue;
709 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000710 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000711 result = 0;
712 else
713 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000714 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000715 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000716 if (ci == NULL || ci->address == NULL) {
717 result = 0;
718 continue;
719 }
720 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000721 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000722 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000723 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000724 break;
725 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000726 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000727 result = 0;
728 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000729 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000730 return -1;
731 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000732 } else if (strcasecmp(attrib, "localaddress") == 0){
733 if (ci == NULL || ci->laddress == NULL) {
734 result = 0;
735 continue;
736 }
737 switch (addr_match_list(ci->laddress, arg)) {
738 case 1:
739 debug("connection from %.100s matched "
740 "'LocalAddress %.100s' at line %d",
741 ci->laddress, arg, line);
742 break;
743 case 0:
744 case -1:
745 result = 0;
746 break;
747 case -2:
748 return -1;
749 }
750 } else if (strcasecmp(attrib, "localport") == 0) {
751 if ((port = a2port(arg)) == -1) {
752 error("Invalid LocalPort '%s' on Match line",
753 arg);
754 return -1;
755 }
756 if (ci == NULL || ci->lport == 0) {
757 result = 0;
758 continue;
759 }
760 /* TODO support port lists */
761 if (port == ci->lport)
762 debug("connection from %.100s matched "
763 "'LocalPort %d' at line %d",
764 ci->laddress, port, line);
765 else
766 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000767 } else {
768 error("Unsupported Match attribute %s", attrib);
769 return -1;
770 }
771 }
Damien Millercf31f382013-10-24 21:02:56 +1100772 if (attributes == 0) {
773 error("One or more attributes required for Match");
774 return -1;
775 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000776 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000777 debug3("match %sfound", result ? "" : "not ");
778 *condition = cp;
779 return result;
780}
781
Damien Millere2754432006-07-24 14:06:47 +1000782#define WHITESPACE " \t\r\n"
783
Damien Miller33322122011-06-20 14:43:11 +1000784/* Multistate option parsing */
785struct multistate {
786 char *key;
787 int value;
788};
789static const struct multistate multistate_addressfamily[] = {
790 { "inet", AF_INET },
791 { "inet6", AF_INET6 },
792 { "any", AF_UNSPEC },
793 { NULL, -1 }
794};
795static const struct multistate multistate_permitrootlogin[] = {
796 { "without-password", PERMIT_NO_PASSWD },
797 { "forced-commands-only", PERMIT_FORCED_ONLY },
798 { "yes", PERMIT_YES },
799 { "no", PERMIT_NO },
800 { NULL, -1 }
801};
802static const struct multistate multistate_compression[] = {
803 { "delayed", COMP_DELAYED },
804 { "yes", COMP_ZLIB },
805 { "no", COMP_NONE },
806 { NULL, -1 }
807};
808static const struct multistate multistate_gatewayports[] = {
809 { "clientspecified", 2 },
810 { "yes", 1 },
811 { "no", 0 },
812 { NULL, -1 }
813};
Damien Miller69ff1df2011-06-23 08:30:03 +1000814static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000815 { "yes", PRIVSEP_NOSANDBOX },
816 { "sandbox", PRIVSEP_ON },
817 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000818 { "no", PRIVSEP_OFF },
819 { NULL, -1 }
820};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100821static const struct multistate multistate_tcpfwd[] = {
822 { "yes", FORWARD_ALLOW },
823 { "all", FORWARD_ALLOW },
824 { "no", FORWARD_DENY },
825 { "remote", FORWARD_REMOTE },
826 { "local", FORWARD_LOCAL },
827 { NULL, -1 }
828};
Damien Miller33322122011-06-20 14:43:11 +1000829
Ben Lindstromade03f62001-12-06 18:22:17 +0000830int
831process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000832 const char *filename, int linenum, int *activep,
833 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000834{
Darren Tucker09c0f032013-05-16 20:48:57 +1000835 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000836 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100837 SyslogFacility *log_facility_ptr;
838 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000839 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000840 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000841 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000842 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000843 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000844
845 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100846 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100847 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000848 /* Ignore leading whitespace */
849 if (*arg == '\0')
850 arg = strdelim(&cp);
851 if (!arg || !*arg || *arg == '#')
852 return 0;
853 intptr = NULL;
854 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000855 opcode = parse_token(arg, filename, linenum, &flags);
856
857 if (activep == NULL) { /* We are processing a command line directive */
858 cmdline = 1;
859 activep = &cmdline;
860 }
861 if (*activep && opcode != sMatch)
862 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
863 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000864 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000865 fatal("%s line %d: Directive '%s' is not allowed "
866 "within a Match block", filename, linenum, arg);
867 } else { /* this is a directive we have already processed */
868 while (arg)
869 arg = strdelim(&cp);
870 return 0;
871 }
872 }
873
Ben Lindstromade03f62001-12-06 18:22:17 +0000874 switch (opcode) {
875 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000876 case sUsePAM:
877 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000878 goto parse_flag;
879
880 /* Standard Options */
881 case sBadOption:
882 return -1;
883 case sPort:
884 /* ignore ports from configfile if cmdline specifies ports */
885 if (options->ports_from_cmdline)
886 return 0;
887 if (options->listen_addrs != NULL)
888 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100889 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000890 if (options->num_ports >= MAX_PORTS)
891 fatal("%s line %d: too many ports.",
892 filename, linenum);
893 arg = strdelim(&cp);
894 if (!arg || *arg == '\0')
895 fatal("%s line %d: missing port number.",
896 filename, linenum);
897 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100898 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000899 fatal("%s line %d: Badly formatted port number.",
900 filename, linenum);
901 break;
902
903 case sServerKeyBits:
904 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000905 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000906 arg = strdelim(&cp);
907 if (!arg || *arg == '\0')
908 fatal("%s line %d: missing integer value.",
909 filename, linenum);
910 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000911 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000912 *intptr = value;
913 break;
914
915 case sLoginGraceTime:
916 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000917 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000918 arg = strdelim(&cp);
919 if (!arg || *arg == '\0')
920 fatal("%s line %d: missing time value.",
921 filename, linenum);
922 if ((value = convtime(arg)) == -1)
923 fatal("%s line %d: invalid time value.",
924 filename, linenum);
925 if (*intptr == -1)
926 *intptr = value;
927 break;
928
929 case sKeyRegenerationTime:
930 intptr = &options->key_regeneration_time;
931 goto parse_time;
932
933 case sListenAddress:
934 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100935 if (arg == NULL || *arg == '\0')
936 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000937 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000938 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
939 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
940 && strchr(p+1, ':') != NULL) {
941 add_listen_addr(options, arg, 0);
942 break;
943 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100944 p = hpdelim(&arg);
945 if (p == NULL)
946 fatal("%s line %d: bad address:port usage",
947 filename, linenum);
948 p = cleanhostname(p);
949 if (arg == NULL)
950 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100951 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100952 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000953
Damien Millerf91ee4c2005-03-01 21:24:33 +1100954 add_listen_addr(options, p, port);
955
Ben Lindstromade03f62001-12-06 18:22:17 +0000956 break;
957
Darren Tucker0f383232005-01-20 10:57:56 +1100958 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000959 intptr = &options->address_family;
960 multistate_ptr = multistate_addressfamily;
961 if (options->listen_addrs != NULL)
962 fatal("%s line %d: address family must be specified "
963 "before ListenAddress.", filename, linenum);
964 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100965 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000966 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000967 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000968 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000969 value = -1;
970 for (i = 0; multistate_ptr[i].key != NULL; i++) {
971 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
972 value = multistate_ptr[i].value;
973 break;
974 }
975 }
976 if (value == -1)
977 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100978 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000979 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100980 *intptr = value;
981 break;
982
Ben Lindstromade03f62001-12-06 18:22:17 +0000983 case sHostKeyFile:
984 intptr = &options->num_host_key_files;
985 if (*intptr >= MAX_HOSTKEYS)
986 fatal("%s line %d: too many host keys specified (max %d).",
987 filename, linenum, MAX_HOSTKEYS);
988 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000989 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000990 arg = strdelim(&cp);
991 if (!arg || *arg == '\0')
992 fatal("%s line %d: missing file name.",
993 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000994 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100995 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000996 /* increase optional counter */
997 if (intptr != NULL)
998 *intptr = *intptr + 1;
999 }
1000 break;
1001
Damien Miller85b45e02013-07-20 13:21:52 +10001002 case sHostKeyAgent:
1003 charptr = &options->host_key_agent;
1004 arg = strdelim(&cp);
1005 if (!arg || *arg == '\0')
1006 fatal("%s line %d: missing socket name.",
1007 filename, linenum);
1008 if (*activep && *charptr == NULL)
1009 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1010 xstrdup(arg) : derelativise_path(arg);
1011 break;
1012
Damien Miller0a80ca12010-02-27 07:55:05 +11001013 case sHostCertificate:
1014 intptr = &options->num_host_cert_files;
1015 if (*intptr >= MAX_HOSTKEYS)
1016 fatal("%s line %d: too many host certificates "
1017 "specified (max %d).", filename, linenum,
1018 MAX_HOSTCERTS);
1019 charptr = &options->host_cert_files[*intptr];
1020 goto parse_filename;
1021 break;
1022
Ben Lindstromade03f62001-12-06 18:22:17 +00001023 case sPidFile:
1024 charptr = &options->pid_file;
1025 goto parse_filename;
1026
1027 case sPermitRootLogin:
1028 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001029 multistate_ptr = multistate_permitrootlogin;
1030 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001031
1032 case sIgnoreRhosts:
1033 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001034 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001035 arg = strdelim(&cp);
1036 if (!arg || *arg == '\0')
1037 fatal("%s line %d: missing yes/no argument.",
1038 filename, linenum);
1039 value = 0; /* silence compiler */
1040 if (strcmp(arg, "yes") == 0)
1041 value = 1;
1042 else if (strcmp(arg, "no") == 0)
1043 value = 0;
1044 else
1045 fatal("%s line %d: Bad yes/no argument: %s",
1046 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001047 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001048 *intptr = value;
1049 break;
1050
1051 case sIgnoreUserKnownHosts:
1052 intptr = &options->ignore_user_known_hosts;
1053 goto parse_flag;
1054
Ben Lindstromade03f62001-12-06 18:22:17 +00001055 case sRhostsRSAAuthentication:
1056 intptr = &options->rhosts_rsa_authentication;
1057 goto parse_flag;
1058
1059 case sHostbasedAuthentication:
1060 intptr = &options->hostbased_authentication;
1061 goto parse_flag;
1062
1063 case sHostbasedUsesNameFromPacketOnly:
1064 intptr = &options->hostbased_uses_name_from_packet_only;
1065 goto parse_flag;
1066
1067 case sRSAAuthentication:
1068 intptr = &options->rsa_authentication;
1069 goto parse_flag;
1070
1071 case sPubkeyAuthentication:
1072 intptr = &options->pubkey_authentication;
1073 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001074
Ben Lindstromade03f62001-12-06 18:22:17 +00001075 case sKerberosAuthentication:
1076 intptr = &options->kerberos_authentication;
1077 goto parse_flag;
1078
1079 case sKerberosOrLocalPasswd:
1080 intptr = &options->kerberos_or_local_passwd;
1081 goto parse_flag;
1082
1083 case sKerberosTicketCleanup:
1084 intptr = &options->kerberos_ticket_cleanup;
1085 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001086
Darren Tucker22ef5082003-12-31 11:37:34 +11001087 case sKerberosGetAFSToken:
1088 intptr = &options->kerberos_get_afs_token;
1089 goto parse_flag;
1090
Darren Tucker0efd1552003-08-26 11:49:55 +10001091 case sGssAuthentication:
1092 intptr = &options->gss_authentication;
1093 goto parse_flag;
1094
1095 case sGssCleanupCreds:
1096 intptr = &options->gss_cleanup_creds;
1097 goto parse_flag;
1098
Ben Lindstromade03f62001-12-06 18:22:17 +00001099 case sPasswordAuthentication:
1100 intptr = &options->password_authentication;
1101 goto parse_flag;
1102
Damien Miller01ed2272008-11-05 16:20:46 +11001103 case sZeroKnowledgePasswordAuthentication:
1104 intptr = &options->zero_knowledge_password_authentication;
1105 goto parse_flag;
1106
Ben Lindstromade03f62001-12-06 18:22:17 +00001107 case sKbdInteractiveAuthentication:
1108 intptr = &options->kbd_interactive_authentication;
1109 goto parse_flag;
1110
1111 case sChallengeResponseAuthentication:
1112 intptr = &options->challenge_response_authentication;
1113 goto parse_flag;
1114
1115 case sPrintMotd:
1116 intptr = &options->print_motd;
1117 goto parse_flag;
1118
1119 case sPrintLastLog:
1120 intptr = &options->print_lastlog;
1121 goto parse_flag;
1122
1123 case sX11Forwarding:
1124 intptr = &options->x11_forwarding;
1125 goto parse_flag;
1126
1127 case sX11DisplayOffset:
1128 intptr = &options->x11_display_offset;
1129 goto parse_int;
1130
Damien Miller95c249f2002-02-05 12:11:34 +11001131 case sX11UseLocalhost:
1132 intptr = &options->x11_use_localhost;
1133 goto parse_flag;
1134
Ben Lindstromade03f62001-12-06 18:22:17 +00001135 case sXAuthLocation:
1136 charptr = &options->xauth_location;
1137 goto parse_filename;
1138
Damien Miller5ff30c62013-10-30 22:21:50 +11001139 case sPermitTTY:
1140 intptr = &options->permit_tty;
1141 goto parse_flag;
1142
Ben Lindstromade03f62001-12-06 18:22:17 +00001143 case sStrictModes:
1144 intptr = &options->strict_modes;
1145 goto parse_flag;
1146
Damien Miller12c150e2003-12-17 16:31:10 +11001147 case sTCPKeepAlive:
1148 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001149 goto parse_flag;
1150
1151 case sEmptyPasswd:
1152 intptr = &options->permit_empty_passwd;
1153 goto parse_flag;
1154
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001155 case sPermitUserEnvironment:
1156 intptr = &options->permit_user_env;
1157 goto parse_flag;
1158
Ben Lindstromade03f62001-12-06 18:22:17 +00001159 case sUseLogin:
1160 intptr = &options->use_login;
1161 goto parse_flag;
1162
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001163 case sCompression:
1164 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001165 multistate_ptr = multistate_compression;
1166 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001167
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001168 case sRekeyLimit:
1169 arg = strdelim(&cp);
1170 if (!arg || *arg == '\0')
1171 fatal("%.200s line %d: Missing argument.", filename,
1172 linenum);
1173 if (strcmp(arg, "default") == 0) {
1174 val64 = 0;
1175 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001176 if (scan_scaled(arg, &val64) == -1)
1177 fatal("%.200s line %d: Bad number '%s': %s",
1178 filename, linenum, arg, strerror(errno));
1179 /* check for too-large or too-small limits */
1180 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001181 fatal("%.200s line %d: RekeyLimit too large",
1182 filename, linenum);
1183 if (val64 != 0 && val64 < 16)
1184 fatal("%.200s line %d: RekeyLimit too small",
1185 filename, linenum);
1186 }
1187 if (*activep && options->rekey_limit == -1)
1188 options->rekey_limit = (u_int32_t)val64;
1189 if (cp != NULL) { /* optional rekey interval present */
1190 if (strcmp(cp, "none") == 0) {
1191 (void)strdelim(&cp); /* discard */
1192 break;
1193 }
1194 intptr = &options->rekey_interval;
1195 goto parse_time;
1196 }
1197 break;
1198
Ben Lindstromade03f62001-12-06 18:22:17 +00001199 case sGatewayPorts:
1200 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001201 multistate_ptr = multistate_gatewayports;
1202 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001203
Damien Miller3a961dc2003-06-03 10:25:48 +10001204 case sUseDNS:
1205 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001206 goto parse_flag;
1207
1208 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001209 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001210 arg = strdelim(&cp);
1211 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001212 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001213 fatal("%.200s line %d: unsupported log facility '%s'",
1214 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001215 if (*log_facility_ptr == -1)
1216 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001217 break;
1218
1219 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001220 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001221 arg = strdelim(&cp);
1222 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001223 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001224 fatal("%.200s line %d: unsupported log level '%s'",
1225 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001226 if (*log_level_ptr == -1)
1227 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001228 break;
1229
1230 case sAllowTcpForwarding:
1231 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001232 multistate_ptr = multistate_tcpfwd;
1233 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001234
Damien Miller4f755cd2008-05-19 14:57:41 +10001235 case sAllowAgentForwarding:
1236 intptr = &options->allow_agent_forwarding;
1237 goto parse_flag;
1238
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001239 case sUsePrivilegeSeparation:
1240 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001241 multistate_ptr = multistate_privsep;
1242 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001243
Ben Lindstromade03f62001-12-06 18:22:17 +00001244 case sAllowUsers:
1245 while ((arg = strdelim(&cp)) && *arg != '\0') {
1246 if (options->num_allow_users >= MAX_ALLOW_USERS)
1247 fatal("%s line %d: too many allow users.",
1248 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001249 if (!*activep)
1250 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001251 options->allow_users[options->num_allow_users++] =
1252 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001253 }
1254 break;
1255
1256 case sDenyUsers:
1257 while ((arg = strdelim(&cp)) && *arg != '\0') {
1258 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001259 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001260 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001261 if (!*activep)
1262 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001263 options->deny_users[options->num_deny_users++] =
1264 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001265 }
1266 break;
1267
1268 case sAllowGroups:
1269 while ((arg = strdelim(&cp)) && *arg != '\0') {
1270 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1271 fatal("%s line %d: too many allow groups.",
1272 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001273 if (!*activep)
1274 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001275 options->allow_groups[options->num_allow_groups++] =
1276 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001277 }
1278 break;
1279
1280 case sDenyGroups:
1281 while ((arg = strdelim(&cp)) && *arg != '\0') {
1282 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1283 fatal("%s line %d: too many deny groups.",
1284 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001285 if (!*activep)
1286 continue;
1287 options->deny_groups[options->num_deny_groups++] =
1288 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001289 }
1290 break;
1291
1292 case sCiphers:
1293 arg = strdelim(&cp);
1294 if (!arg || *arg == '\0')
1295 fatal("%s line %d: Missing argument.", filename, linenum);
1296 if (!ciphers_valid(arg))
1297 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1298 filename, linenum, arg ? arg : "<NONE>");
1299 if (options->ciphers == NULL)
1300 options->ciphers = xstrdup(arg);
1301 break;
1302
1303 case sMacs:
1304 arg = strdelim(&cp);
1305 if (!arg || *arg == '\0')
1306 fatal("%s line %d: Missing argument.", filename, linenum);
1307 if (!mac_valid(arg))
1308 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1309 filename, linenum, arg ? arg : "<NONE>");
1310 if (options->macs == NULL)
1311 options->macs = xstrdup(arg);
1312 break;
1313
Damien Millerd5f62bf2010-09-24 22:11:14 +10001314 case sKexAlgorithms:
1315 arg = strdelim(&cp);
1316 if (!arg || *arg == '\0')
1317 fatal("%s line %d: Missing argument.",
1318 filename, linenum);
1319 if (!kex_names_valid(arg))
1320 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1321 filename, linenum, arg ? arg : "<NONE>");
1322 if (options->kex_algorithms == NULL)
1323 options->kex_algorithms = xstrdup(arg);
1324 break;
1325
Ben Lindstromade03f62001-12-06 18:22:17 +00001326 case sProtocol:
1327 intptr = &options->protocol;
1328 arg = strdelim(&cp);
1329 if (!arg || *arg == '\0')
1330 fatal("%s line %d: Missing argument.", filename, linenum);
1331 value = proto_spec(arg);
1332 if (value == SSH_PROTO_UNKNOWN)
1333 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001334 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001335 if (*intptr == SSH_PROTO_UNKNOWN)
1336 *intptr = value;
1337 break;
1338
1339 case sSubsystem:
1340 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1341 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001342 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001343 }
1344 arg = strdelim(&cp);
1345 if (!arg || *arg == '\0')
1346 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001347 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001348 if (!*activep) {
1349 arg = strdelim(&cp);
1350 break;
1351 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001352 for (i = 0; i < options->num_subsystems; i++)
1353 if (strcmp(arg, options->subsystem_name[i]) == 0)
1354 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001355 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001356 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1357 arg = strdelim(&cp);
1358 if (!arg || *arg == '\0')
1359 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001360 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001361 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001362
1363 /* Collect arguments (separate to executable) */
1364 p = xstrdup(arg);
1365 len = strlen(p) + 1;
1366 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1367 len += 1 + strlen(arg);
1368 p = xrealloc(p, 1, len);
1369 strlcat(p, " ", len);
1370 strlcat(p, arg, len);
1371 }
1372 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001373 options->num_subsystems++;
1374 break;
1375
1376 case sMaxStartups:
1377 arg = strdelim(&cp);
1378 if (!arg || *arg == '\0')
1379 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001380 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001381 if ((n = sscanf(arg, "%d:%d:%d",
1382 &options->max_startups_begin,
1383 &options->max_startups_rate,
1384 &options->max_startups)) == 3) {
1385 if (options->max_startups_begin >
1386 options->max_startups ||
1387 options->max_startups_rate > 100 ||
1388 options->max_startups_rate < 1)
1389 fatal("%s line %d: Illegal MaxStartups spec.",
1390 filename, linenum);
1391 } else if (n != 1)
1392 fatal("%s line %d: Illegal MaxStartups spec.",
1393 filename, linenum);
1394 else
1395 options->max_startups = options->max_startups_begin;
1396 break;
1397
Darren Tucker89413db2004-05-24 10:36:23 +10001398 case sMaxAuthTries:
1399 intptr = &options->max_authtries;
1400 goto parse_int;
1401
Damien Miller7207f642008-05-19 15:34:50 +10001402 case sMaxSessions:
1403 intptr = &options->max_sessions;
1404 goto parse_int;
1405
Ben Lindstromade03f62001-12-06 18:22:17 +00001406 case sBanner:
1407 charptr = &options->banner;
1408 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001409
Ben Lindstromade03f62001-12-06 18:22:17 +00001410 /*
1411 * These options can contain %X options expanded at
1412 * connect time, so that you can specify paths like:
1413 *
1414 * AuthorizedKeysFile /etc/ssh_keys/%u
1415 */
1416 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001417 if (*activep && options->num_authkeys_files == 0) {
1418 while ((arg = strdelim(&cp)) && *arg != '\0') {
1419 if (options->num_authkeys_files >=
1420 MAX_AUTHKEYS_FILES)
1421 fatal("%s line %d: "
1422 "too many authorized keys files.",
1423 filename, linenum);
1424 options->authorized_keys_files[
1425 options->num_authkeys_files++] =
1426 tilde_expand_filename(arg, getuid());
1427 }
1428 }
1429 return 0;
1430
Damien Miller30da3442010-05-10 11:58:03 +10001431 case sAuthorizedPrincipalsFile:
1432 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001433 arg = strdelim(&cp);
1434 if (!arg || *arg == '\0')
1435 fatal("%s line %d: missing file name.",
1436 filename, linenum);
1437 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001438 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001439 /* increase optional counter */
1440 if (intptr != NULL)
1441 *intptr = *intptr + 1;
1442 }
1443 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001444
1445 case sClientAliveInterval:
1446 intptr = &options->client_alive_interval;
1447 goto parse_time;
1448
1449 case sClientAliveCountMax:
1450 intptr = &options->client_alive_count_max;
1451 goto parse_int;
1452
Darren Tucker46bc0752004-05-02 22:11:30 +10001453 case sAcceptEnv:
1454 while ((arg = strdelim(&cp)) && *arg != '\0') {
1455 if (strchr(arg, '=') != NULL)
1456 fatal("%s line %d: Invalid environment name.",
1457 filename, linenum);
1458 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1459 fatal("%s line %d: too many allow env.",
1460 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001461 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001462 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001463 options->accept_env[options->num_accept_env++] =
1464 xstrdup(arg);
1465 }
1466 break;
1467
Damien Millerd27b9472005-12-13 19:29:02 +11001468 case sPermitTunnel:
1469 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001470 arg = strdelim(&cp);
1471 if (!arg || *arg == '\0')
1472 fatal("%s line %d: Missing yes/point-to-point/"
1473 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001474 value = -1;
1475 for (i = 0; tunmode_desc[i].val != -1; i++)
1476 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1477 value = tunmode_desc[i].val;
1478 break;
1479 }
1480 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001481 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1482 "no argument: %s", filename, linenum, arg);
1483 if (*intptr == -1)
1484 *intptr = value;
1485 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001486
Darren Tucker45150472006-07-12 22:34:17 +10001487 case sMatch:
1488 if (cmdline)
1489 fatal("Match directive not supported as a command-line "
1490 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001491 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001492 if (value < 0)
1493 fatal("%s line %d: Bad Match condition", filename,
1494 linenum);
1495 *activep = value;
1496 break;
1497
Damien Miller9b439df2006-07-24 14:04:00 +10001498 case sPermitOpen:
1499 arg = strdelim(&cp);
1500 if (!arg || *arg == '\0')
1501 fatal("%s line %d: missing PermitOpen specification",
1502 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001503 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001504 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001505 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001506 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001507 options->num_permitted_opens = 0;
1508 }
Damien Miller9b439df2006-07-24 14:04:00 +10001509 break;
1510 }
Damien Millerc6081482012-04-22 11:18:53 +10001511 if (strcmp(arg, "none") == 0) {
1512 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001513 options->num_permitted_opens = 1;
1514 channel_disable_adm_local_opens();
1515 }
1516 break;
1517 }
Damien Millera29b95e2007-01-05 16:28:36 +11001518 if (*activep && n == -1)
1519 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001520 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1521 p = hpdelim(&arg);
1522 if (p == NULL)
1523 fatal("%s line %d: missing host in PermitOpen",
1524 filename, linenum);
1525 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001526 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001527 fatal("%s line %d: bad port number in "
1528 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001529 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001530 options->num_permitted_opens =
1531 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001532 }
Damien Miller9b439df2006-07-24 14:04:00 +10001533 break;
1534
Damien Millere2754432006-07-24 14:06:47 +10001535 case sForceCommand:
1536 if (cp == NULL)
1537 fatal("%.200s line %d: Missing argument.", filename,
1538 linenum);
1539 len = strspn(cp, WHITESPACE);
1540 if (*activep && options->adm_forced_command == NULL)
1541 options->adm_forced_command = xstrdup(cp + len);
1542 return 0;
1543
Damien Millerd8cb1f12008-02-10 22:40:12 +11001544 case sChrootDirectory:
1545 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001546
1547 arg = strdelim(&cp);
1548 if (!arg || *arg == '\0')
1549 fatal("%s line %d: missing file name.",
1550 filename, linenum);
1551 if (*activep && *charptr == NULL)
1552 *charptr = xstrdup(arg);
1553 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001554
Damien Miller1aed65e2010-03-04 21:53:35 +11001555 case sTrustedUserCAKeys:
1556 charptr = &options->trusted_user_ca_keys;
1557 goto parse_filename;
1558
1559 case sRevokedKeys:
1560 charptr = &options->revoked_keys_file;
1561 goto parse_filename;
1562
Damien Miller0dac6fb2010-11-20 15:19:38 +11001563 case sIPQoS:
1564 arg = strdelim(&cp);
1565 if ((value = parse_ipqos(arg)) == -1)
1566 fatal("%s line %d: Bad IPQoS value: %s",
1567 filename, linenum, arg);
1568 arg = strdelim(&cp);
1569 if (arg == NULL)
1570 value2 = value;
1571 else if ((value2 = parse_ipqos(arg)) == -1)
1572 fatal("%s line %d: Bad IPQoS value: %s",
1573 filename, linenum, arg);
1574 if (*activep) {
1575 options->ip_qos_interactive = value;
1576 options->ip_qos_bulk = value2;
1577 }
1578 break;
1579
Damien Miller23528812012-04-22 11:24:43 +10001580 case sVersionAddendum:
1581 if (cp == NULL)
1582 fatal("%.200s line %d: Missing argument.", filename,
1583 linenum);
1584 len = strspn(cp, WHITESPACE);
1585 if (*activep && options->version_addendum == NULL) {
1586 if (strcasecmp(cp + len, "none") == 0)
1587 options->version_addendum = xstrdup("");
1588 else if (strchr(cp + len, '\r') != NULL)
1589 fatal("%.200s line %d: Invalid argument",
1590 filename, linenum);
1591 else
1592 options->version_addendum = xstrdup(cp + len);
1593 }
1594 return 0;
1595
Damien Miller09d3e122012-10-31 08:58:58 +11001596 case sAuthorizedKeysCommand:
1597 len = strspn(cp, WHITESPACE);
1598 if (*activep && options->authorized_keys_command == NULL) {
1599 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1600 fatal("%.200s line %d: AuthorizedKeysCommand "
1601 "must be an absolute path",
1602 filename, linenum);
1603 options->authorized_keys_command = xstrdup(cp + len);
1604 }
1605 return 0;
1606
1607 case sAuthorizedKeysCommandUser:
1608 charptr = &options->authorized_keys_command_user;
1609
1610 arg = strdelim(&cp);
1611 if (*activep && *charptr == NULL)
1612 *charptr = xstrdup(arg);
1613 break;
1614
Damien Millera6e3f012012-11-04 23:21:40 +11001615 case sAuthenticationMethods:
1616 if (*activep && options->num_auth_methods == 0) {
1617 while ((arg = strdelim(&cp)) && *arg != '\0') {
1618 if (options->num_auth_methods >=
1619 MAX_AUTH_METHODS)
1620 fatal("%s line %d: "
1621 "too many authentication methods.",
1622 filename, linenum);
1623 if (auth2_methods_valid(arg, 0) != 0)
1624 fatal("%s line %d: invalid "
1625 "authentication method list.",
1626 filename, linenum);
1627 options->auth_methods[
1628 options->num_auth_methods++] = xstrdup(arg);
1629 }
1630 }
1631 return 0;
1632
Ben Lindstromade03f62001-12-06 18:22:17 +00001633 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001634 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001635 filename, linenum, arg);
1636 while (arg)
1637 arg = strdelim(&cp);
1638 break;
1639
Damien Millerf9b3feb2003-05-16 11:38:32 +10001640 case sUnsupported:
1641 logit("%s line %d: Unsupported option %s",
1642 filename, linenum, arg);
1643 while (arg)
1644 arg = strdelim(&cp);
1645 break;
1646
Ben Lindstromade03f62001-12-06 18:22:17 +00001647 default:
1648 fatal("%s line %d: Missing handler for opcode %s (%d)",
1649 filename, linenum, arg, opcode);
1650 }
1651 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1652 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1653 filename, linenum, arg);
1654 return 0;
1655}
1656
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001657/* Reads the server configuration file. */
1658
Damien Miller4af51302000-04-16 11:18:38 +10001659void
Darren Tucker645ab752004-06-25 13:33:20 +10001660load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001661{
Damien Miller46cb75a2012-07-31 12:22:37 +10001662 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001663 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001664 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001665
Darren Tucker645ab752004-06-25 13:33:20 +10001666 debug2("%s: filename %s", __func__, filename);
1667 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001668 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001669 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001670 }
Darren Tucker645ab752004-06-25 13:33:20 +10001671 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001672 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001673 lineno++;
1674 if (strlen(line) == sizeof(line) - 1)
1675 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001676 /*
1677 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001678 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001679 * line numbers later for error messages
1680 */
1681 if ((cp = strchr(line, '#')) != NULL)
1682 memcpy(cp, "\n", 2);
1683 cp = line + strspn(line, " \t\r");
1684
1685 buffer_append(conf, cp, strlen(cp));
1686 }
1687 buffer_append(conf, "\0", 1);
1688 fclose(f);
1689 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1690}
1691
1692void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001693parse_server_match_config(ServerOptions *options,
1694 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001695{
Darren Tucker45150472006-07-12 22:34:17 +10001696 ServerOptions mo;
1697
1698 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001699 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001700 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001701}
1702
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001703int parse_server_match_testspec(struct connection_info *ci, char *spec)
1704{
1705 char *p;
1706
1707 while ((p = strsep(&spec, ",")) && *p != '\0') {
1708 if (strncmp(p, "addr=", 5) == 0) {
1709 ci->address = xstrdup(p + 5);
1710 } else if (strncmp(p, "host=", 5) == 0) {
1711 ci->host = xstrdup(p + 5);
1712 } else if (strncmp(p, "user=", 5) == 0) {
1713 ci->user = xstrdup(p + 5);
1714 } else if (strncmp(p, "laddr=", 6) == 0) {
1715 ci->laddress = xstrdup(p + 6);
1716 } else if (strncmp(p, "lport=", 6) == 0) {
1717 ci->lport = a2port(p + 6);
1718 if (ci->lport == -1) {
1719 fprintf(stderr, "Invalid port '%s' in test mode"
1720 " specification %s\n", p+6, p);
1721 return -1;
1722 }
1723 } else {
1724 fprintf(stderr, "Invalid test mode specification %s\n",
1725 p);
1726 return -1;
1727 }
1728 }
1729 return 0;
1730}
1731
1732/*
1733 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1734 * empty spec.
1735 */
1736int server_match_spec_complete(struct connection_info *ci)
1737{
1738 if (ci->user && ci->host && ci->address)
1739 return 1; /* complete */
1740 if (!ci->user && !ci->host && !ci->address)
1741 return -1; /* empty */
1742 return 0; /* partial */
1743}
1744
Darren Tucker1629c072007-02-19 22:25:37 +11001745/* Helper macros */
1746#define M_CP_INTOPT(n) do {\
1747 if (src->n != -1) \
1748 dst->n = src->n; \
1749} while (0)
1750#define M_CP_STROPT(n) do {\
1751 if (src->n != NULL) { \
Darren Tuckera627d422013-06-02 07:31:17 +10001752 free(dst->n); \
Darren Tucker1629c072007-02-19 22:25:37 +11001753 dst->n = src->n; \
1754 } \
1755} while(0)
Damien Millerd8478b62011-05-29 21:39:36 +10001756#define M_CP_STRARRAYOPT(n, num_n) do {\
1757 if (src->num_n != 0) { \
1758 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1759 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1760 } \
1761} while(0)
Darren Tucker1629c072007-02-19 22:25:37 +11001762
1763/*
1764 * Copy any supported values that are set.
1765 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001766 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001767 * array values that are not used pre-authentication, because any that we
1768 * do use must be explictly sent in mm_getpwnamallow().
1769 */
Darren Tucker45150472006-07-12 22:34:17 +10001770void
Darren Tucker1629c072007-02-19 22:25:37 +11001771copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001772{
Darren Tucker1629c072007-02-19 22:25:37 +11001773 M_CP_INTOPT(password_authentication);
1774 M_CP_INTOPT(gss_authentication);
1775 M_CP_INTOPT(rsa_authentication);
1776 M_CP_INTOPT(pubkey_authentication);
1777 M_CP_INTOPT(kerberos_authentication);
1778 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001779 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001780 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001781 M_CP_INTOPT(zero_knowledge_password_authentication);
Damien Miller09d3e122012-10-31 08:58:58 +11001782 M_CP_STROPT(authorized_keys_command);
1783 M_CP_STROPT(authorized_keys_command_user);
Darren Tucker15f94272008-01-01 20:36:56 +11001784 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001785 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001786
1787 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001788 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001789 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001790 M_CP_INTOPT(gateway_ports);
1791 M_CP_INTOPT(x11_display_offset);
1792 M_CP_INTOPT(x11_forwarding);
1793 M_CP_INTOPT(x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11001794 M_CP_INTOPT(permit_tty);
Damien Miller7207f642008-05-19 15:34:50 +10001795 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001796 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001797 M_CP_INTOPT(ip_qos_interactive);
1798 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001799 M_CP_INTOPT(rekey_limit);
1800 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001801
Damien Millerf2e407e2011-05-20 19:04:14 +10001802 /* See comment in servconf.h */
1803 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001804
Damien Millerc2411902011-05-20 19:03:49 +10001805 /*
1806 * The only things that should be below this point are string options
1807 * which are only used after authentication.
1808 */
Damien Miller5d74e582011-05-20 19:03:31 +10001809 if (preauth)
1810 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001811
Damien Miller5d74e582011-05-20 19:03:31 +10001812 M_CP_STROPT(adm_forced_command);
1813 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001814}
1815
Darren Tucker1629c072007-02-19 22:25:37 +11001816#undef M_CP_INTOPT
1817#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001818#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001819
Darren Tucker45150472006-07-12 22:34:17 +10001820void
1821parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001822 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001823{
1824 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001825 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001826
1827 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1828
Darren Tucker9fbac712004-08-12 22:41:44 +10001829 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001830 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001831 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001832 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001833 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001834 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001835 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001836 }
Darren Tuckera627d422013-06-02 07:31:17 +10001837 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001838 if (bad_options > 0)
1839 fatal("%s: terminating, %d bad configuration options",
1840 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001841}
Darren Tuckere7140f22008-06-10 23:01:51 +10001842
1843static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001844fmt_multistate_int(int val, const struct multistate *m)
1845{
1846 u_int i;
1847
1848 for (i = 0; m[i].key != NULL; i++) {
1849 if (m[i].value == val)
1850 return m[i].key;
1851 }
1852 return "UNKNOWN";
1853}
1854
1855static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001856fmt_intarg(ServerOpCodes code, int val)
1857{
Damien Miller82c55872011-06-23 08:20:30 +10001858 if (val == -1)
1859 return "unset";
1860 switch (code) {
1861 case sAddressFamily:
1862 return fmt_multistate_int(val, multistate_addressfamily);
1863 case sPermitRootLogin:
1864 return fmt_multistate_int(val, multistate_permitrootlogin);
1865 case sGatewayPorts:
1866 return fmt_multistate_int(val, multistate_gatewayports);
1867 case sCompression:
1868 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001869 case sUsePrivilegeSeparation:
1870 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001871 case sAllowTcpForwarding:
1872 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001873 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001874 switch (val) {
1875 case SSH_PROTO_1:
1876 return "1";
1877 case SSH_PROTO_2:
1878 return "2";
1879 case (SSH_PROTO_1|SSH_PROTO_2):
1880 return "2,1";
1881 default:
1882 return "UNKNOWN";
1883 }
Damien Miller82c55872011-06-23 08:20:30 +10001884 default:
1885 switch (val) {
1886 case 0:
1887 return "no";
1888 case 1:
1889 return "yes";
1890 default:
1891 return "UNKNOWN";
1892 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001893 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001894}
1895
1896static const char *
1897lookup_opcode_name(ServerOpCodes code)
1898{
1899 u_int i;
1900
1901 for (i = 0; keywords[i].name != NULL; i++)
1902 if (keywords[i].opcode == code)
1903 return(keywords[i].name);
1904 return "UNKNOWN";
1905}
1906
1907static void
1908dump_cfg_int(ServerOpCodes code, int val)
1909{
1910 printf("%s %d\n", lookup_opcode_name(code), val);
1911}
1912
1913static void
1914dump_cfg_fmtint(ServerOpCodes code, int val)
1915{
1916 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1917}
1918
1919static void
1920dump_cfg_string(ServerOpCodes code, const char *val)
1921{
1922 if (val == NULL)
1923 return;
1924 printf("%s %s\n", lookup_opcode_name(code), val);
1925}
1926
1927static void
1928dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1929{
1930 u_int i;
1931
1932 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001933 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1934}
1935
1936static void
1937dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1938{
1939 u_int i;
1940
1941 printf("%s", lookup_opcode_name(code));
1942 for (i = 0; i < count; i++)
1943 printf(" %s", vals[i]);
1944 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001945}
1946
1947void
1948dump_config(ServerOptions *o)
1949{
1950 u_int i;
1951 int ret;
1952 struct addrinfo *ai;
1953 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1954
1955 /* these are usually at the top of the config */
1956 for (i = 0; i < o->num_ports; i++)
1957 printf("port %d\n", o->ports[i]);
1958 dump_cfg_fmtint(sProtocol, o->protocol);
1959 dump_cfg_fmtint(sAddressFamily, o->address_family);
1960
1961 /* ListenAddress must be after Port */
1962 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1963 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1964 sizeof(addr), port, sizeof(port),
1965 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1966 error("getnameinfo failed: %.100s",
1967 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1968 strerror(errno));
1969 } else {
1970 if (ai->ai_family == AF_INET6)
1971 printf("listenaddress [%s]:%s\n", addr, port);
1972 else
1973 printf("listenaddress %s:%s\n", addr, port);
1974 }
1975 }
1976
1977 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001978#ifdef USE_PAM
1979 dump_cfg_int(sUsePAM, o->use_pam);
1980#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001981 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1982 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1983 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1984 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1985 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001986 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001987 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1988 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1989
1990 /* formatted integer arguments */
1991 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1992 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1993 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1994 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1995 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1996 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1997 o->hostbased_uses_name_from_packet_only);
1998 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1999 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10002000#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10002001 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2002 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2003 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10002004# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10002005 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10002006# endif
2007#endif
2008#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002009 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2010 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002011#endif
Damien Miller01ed2272008-11-05 16:20:46 +11002012#ifdef JPAKE
2013 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
2014 o->zero_knowledge_password_authentication);
2015#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002016 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2017 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2018 o->kbd_interactive_authentication);
2019 dump_cfg_fmtint(sChallengeResponseAuthentication,
2020 o->challenge_response_authentication);
2021 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2022 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2023 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2024 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
Damien Miller5ff30c62013-10-30 22:21:50 +11002025 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
Darren Tuckere7140f22008-06-10 23:01:51 +10002026 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2027 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2028 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2029 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2030 dump_cfg_fmtint(sUseLogin, o->use_login);
2031 dump_cfg_fmtint(sCompression, o->compression);
2032 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2033 dump_cfg_fmtint(sUseDNS, o->use_dns);
2034 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2035 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2036
2037 /* string arguments */
2038 dump_cfg_string(sPidFile, o->pid_file);
2039 dump_cfg_string(sXAuthLocation, o->xauth_location);
2040 dump_cfg_string(sCiphers, o->ciphers);
2041 dump_cfg_string(sMacs, o->macs);
2042 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002043 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002044 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002045 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2046 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002047 dump_cfg_string(sAuthorizedPrincipalsFile,
2048 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002049 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002050 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2051 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002052 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Darren Tuckere7140f22008-06-10 23:01:51 +10002053
2054 /* string arguments requiring a lookup */
2055 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2056 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2057
2058 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002059 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2060 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002061 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2062 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002063 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2064 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002065 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2066 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2067 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2068 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2069 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002070 dump_cfg_strarray_oneline(sAuthenticationMethods,
2071 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002072
2073 /* other arguments */
2074 for (i = 0; i < o->num_subsystems; i++)
2075 printf("subsystem %s %s\n", o->subsystem_name[i],
2076 o->subsystem_args[i]);
2077
2078 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2079 o->max_startups_rate, o->max_startups);
2080
2081 for (i = 0; tunmode_desc[i].val != -1; i++)
2082 if (tunmode_desc[i].val == o->permit_tun) {
2083 s = tunmode_desc[i].text;
2084 break;
2085 }
2086 dump_cfg_string(sPermitTunnel, s);
2087
Damien Miller91475862011-05-05 14:14:34 +10002088 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2089 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002090
Damien Millera6d6c1f2013-08-21 02:40:01 +10002091 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2092 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002093
Darren Tuckere7140f22008-06-10 23:01:51 +10002094 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002095}