blob: 36b8efecfde4c9c4daefb92b8af7892c792b0e1c [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Darren Tuckera627d422013-06-02 07:31:17 +10002/* $OpenBSD: servconf.c,v 1.239 2013/05/17 00:13:14 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 Miller6f83b8e2000-05-02 09:23:45 +100082 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110083 options->server_key_bits = -1;
84 options->login_grace_time = -1;
85 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000086 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110087 options->ignore_rhosts = -1;
88 options->ignore_user_known_hosts = -1;
89 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000090 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110091 options->x11_forwarding = -1;
92 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110093 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100094 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110095 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110096 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110097 options->log_facility = SYSLOG_FACILITY_NOT_SET;
98 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110099 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000100 options->hostbased_authentication = -1;
101 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +1100102 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100103 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100104 options->kerberos_authentication = -1;
105 options->kerberos_or_local_passwd = -1;
106 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100107 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000108 options->gss_authentication=-1;
109 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100110 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100111 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000112 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100113 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000114 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100115 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000116 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000117 options->rekey_limit = -1;
118 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100119 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000120 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100121 options->num_allow_users = 0;
122 options->num_deny_users = 0;
123 options->num_allow_groups = 0;
124 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000125 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000126 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000127 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000128 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000129 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000130 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000131 options->max_startups_begin = -1;
132 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000133 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000134 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000135 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000136 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000137 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000138 options->client_alive_interval = -1;
139 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000140 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000141 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100142 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000143 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000144 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100145 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100146 options->authorized_keys_command = NULL;
147 options->authorized_keys_command_user = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100148 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100149 options->revoked_keys_file = NULL;
150 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000151 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100152 options->ip_qos_interactive = -1;
153 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000154 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000155}
156
Damien Miller4af51302000-04-16 11:18:38 +1000157void
Damien Miller95def091999-11-25 00:26:21 +1100158fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000159{
Damien Miller726273e2001-11-12 11:40:11 +1100160 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000161 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000162 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100163
164 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100165 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100166 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100167 if (options->num_host_key_files == 0) {
168 /* fill default hostkeys for protocols */
169 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100170 options->host_key_files[options->num_host_key_files++] =
171 _PATH_HOST_KEY_FILE;
172 if (options->protocol & SSH_PROTO_2) {
173 options->host_key_files[options->num_host_key_files++] =
174 _PATH_HOST_RSA_KEY_FILE;
175 options->host_key_files[options->num_host_key_files++] =
176 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100177#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000178 options->host_key_files[options->num_host_key_files++] =
179 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100180#endif
Damien Miller7fc23732002-01-22 23:19:11 +1100181 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100182 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100183 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100184 if (options->num_ports == 0)
185 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
186 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000187 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000188 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000189 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100190 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000191 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000193 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->key_regeneration_time == -1)
195 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000196 if (options->permit_root_login == PERMIT_NOT_SET)
197 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100199 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100200 if (options->ignore_user_known_hosts == -1)
201 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->print_motd == -1)
203 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000204 if (options->print_lastlog == -1)
205 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100206 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100207 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100209 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100210 if (options->x11_use_localhost == -1)
211 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000212 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000213 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100214 if (options->strict_modes == -1)
215 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100216 if (options->tcp_keep_alive == -1)
217 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100218 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100219 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100220 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000221 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100222 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100223 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000224 if (options->hostbased_authentication == -1)
225 options->hostbased_authentication = 0;
226 if (options->hostbased_uses_name_from_packet_only == -1)
227 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100228 if (options->rsa_authentication == -1)
229 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100230 if (options->pubkey_authentication == -1)
231 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100232 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000233 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100234 if (options->kerberos_or_local_passwd == -1)
235 options->kerberos_or_local_passwd = 1;
236 if (options->kerberos_ticket_cleanup == -1)
237 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100238 if (options->kerberos_get_afs_token == -1)
239 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000240 if (options->gss_authentication == -1)
241 options->gss_authentication = 0;
242 if (options->gss_cleanup_creds == -1)
243 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100244 if (options->password_authentication == -1)
245 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100246 if (options->kbd_interactive_authentication == -1)
247 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000248 if (options->challenge_response_authentication == -1)
249 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100250 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100251 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000252 if (options->permit_user_env == -1)
253 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100254 if (options->use_login == -1)
255 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000256 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000257 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000258 if (options->rekey_limit == -1)
259 options->rekey_limit = 0;
260 if (options->rekey_interval == -1)
261 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100262 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100263 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000264 if (options->allow_agent_forwarding == -1)
265 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000266 if (options->gateway_ports == -1)
267 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000268 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100269 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000270 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100271 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000272 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100273 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000274 if (options->max_authtries == -1)
275 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000276 if (options->max_sessions == -1)
277 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000278 if (options->use_dns == -1)
279 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000280 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100281 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000282 if (options->client_alive_count_max == -1)
283 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000284 if (options->num_authkeys_files == 0) {
285 options->authorized_keys_files[options->num_authkeys_files++] =
286 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
287 options->authorized_keys_files[options->num_authkeys_files++] =
288 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
289 }
Damien Millerd27b9472005-12-13 19:29:02 +1100290 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100291 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100292 if (options->zero_knowledge_password_authentication == -1)
293 options->zero_knowledge_password_authentication = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100294 if (options->ip_qos_interactive == -1)
295 options->ip_qos_interactive = IPTOS_LOWDELAY;
296 if (options->ip_qos_bulk == -1)
297 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000298 if (options->version_addendum == NULL)
299 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000300 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000301 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000302 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000303
Tim Rice40017b02002-07-14 13:36:49 -0700304#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000305 if (use_privsep && options->compression == 1) {
306 error("This platform does not support both privilege "
307 "separation and compression");
308 error("Compression disabled");
309 options->compression = 0;
310 }
311#endif
312
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000313}
314
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000315/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100316typedef enum {
317 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100318 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000319 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100320 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100321 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
322 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000323 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100324 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100325 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000326 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100327 sPasswordAuthentication, sKbdInteractiveAuthentication,
328 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000329 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100330 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100331 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000332 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000333 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000334 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000335 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000336 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000337 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100338 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000339 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100340 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100341 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100342 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100343 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000344 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000345 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100346 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Millera6e3f012012-11-04 23:21:40 +1100347 sAuthenticationMethods,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000348 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000349} ServerOpCodes;
350
Darren Tucker45150472006-07-12 22:34:17 +1000351#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
352#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
353#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
354
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000355/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100356static struct {
357 const char *name;
358 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000359 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100360} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100361 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000362#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000363 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000364#else
Darren Tucker45150472006-07-12 22:34:17 +1000365 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000366#endif
Darren Tucker45150472006-07-12 22:34:17 +1000367 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100368 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000369 { "port", sPort, SSHCFG_GLOBAL },
370 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
371 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
372 { "pidfile", sPidFile, SSHCFG_GLOBAL },
373 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
374 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
375 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100376 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000377 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
378 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
379 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100380 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
381 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000382 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100383 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
384 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000385 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000386#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100387 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000388 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
389 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100390#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000391 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000392#else
Darren Tucker45150472006-07-12 22:34:17 +1000393 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100394#endif
395#else
Darren Tucker1629c072007-02-19 22:25:37 +1100396 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000397 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
398 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
399 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000400#endif
Darren Tucker45150472006-07-12 22:34:17 +1000401 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
402 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000403#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100404 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000405 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000406#else
Darren Tucker1629c072007-02-19 22:25:37 +1100407 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000408 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000409#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100410 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
411 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100412 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000413 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100414#ifdef JPAKE
415 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
416#else
417 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
418#endif
Darren Tucker45150472006-07-12 22:34:17 +1000419 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
420 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
421 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
422 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
423 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
424 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
425 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000426 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
427 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
428 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000429 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
430 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100431 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000432 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
433 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
434 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000435 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000436 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
437 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
438 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000439 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000440 { "allowusers", sAllowUsers, SSHCFG_ALL },
441 { "denyusers", sDenyUsers, SSHCFG_ALL },
442 { "allowgroups", sAllowGroups, SSHCFG_ALL },
443 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000444 { "ciphers", sCiphers, SSHCFG_GLOBAL },
445 { "macs", sMacs, SSHCFG_GLOBAL },
446 { "protocol", sProtocol, SSHCFG_GLOBAL },
447 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
448 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
449 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000450 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000451 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100452 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000453 { "usedns", sUseDNS, SSHCFG_GLOBAL },
454 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
455 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
456 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
457 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000458 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000459 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000460 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000461 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000462 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000463 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000464 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000465 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100466 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100467 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100468 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
469 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000470 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000471 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100472 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100473 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
474 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000475 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100476 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000477 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000478};
479
Darren Tuckere7140f22008-06-10 23:01:51 +1000480static struct {
481 int val;
482 char *text;
483} tunmode_desc[] = {
484 { SSH_TUNMODE_NO, "no" },
485 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
486 { SSH_TUNMODE_ETHERNET, "ethernet" },
487 { SSH_TUNMODE_YES, "yes" },
488 { -1, NULL }
489};
490
Damien Miller5428f641999-11-25 11:54:57 +1100491/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000492 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100493 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000494
Damien Miller4af51302000-04-16 11:18:38 +1000495static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100496parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000497 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000498{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000499 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000500
Damien Miller95def091999-11-25 00:26:21 +1100501 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000502 if (strcasecmp(cp, keywords[i].name) == 0) {
503 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100504 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000505 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000506
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000507 error("%s: line %d: Bad configuration option: %s",
508 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100509 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000510}
511
Darren Tucker88b6fb22010-01-13 22:44:29 +1100512char *
513derelativise_path(const char *path)
514{
Damien Miller44451d02010-03-26 10:40:04 +1100515 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100516
517 expanded = tilde_expand_filename(path, getuid());
518 if (*expanded == '/')
519 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100520 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100521 fatal("%s: getcwd: %s", __func__, strerror(errno));
522 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000523 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100524 return ret;
525}
526
Ben Lindstrombba81212001-06-25 05:01:22 +0000527static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100528add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100529{
Damien Millereccb9de2005-06-17 12:59:34 +1000530 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100531
532 if (options->num_ports == 0)
533 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100534 if (options->address_family == -1)
535 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000536 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000537 for (i = 0; i < options->num_ports; i++)
538 add_one_listen_addr(options, addr, options->ports[i]);
539 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000540 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000541}
542
Ben Lindstrombba81212001-06-25 05:01:22 +0000543static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100544add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000545{
546 struct addrinfo hints, *ai, *aitop;
547 char strport[NI_MAXSERV];
548 int gaierr;
549
550 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100551 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000552 hints.ai_socktype = SOCK_STREAM;
553 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100554 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000555 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
556 fatal("bad addr or host: %s (%s)",
557 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100558 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000559 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
560 ;
561 ai->ai_next = options->listen_addrs;
562 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100563}
564
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000565struct connection_info *
566get_connection_info(int populate, int use_dns)
567{
568 static struct connection_info ci;
569
570 if (!populate)
571 return &ci;
572 ci.host = get_canonical_hostname(use_dns);
573 ci.address = get_remote_ipaddr();
574 ci.laddress = get_local_ipaddr(packet_get_connection_in());
575 ci.lport = get_local_port();
576 return &ci;
577}
578
Darren Tucker45150472006-07-12 22:34:17 +1000579/*
580 * The strategy for the Match blocks is that the config file is parsed twice.
581 *
582 * The first time is at startup. activep is initialized to 1 and the
583 * directives in the global context are processed and acted on. Hitting a
584 * Match directive unsets activep and the directives inside the block are
585 * checked for syntax only.
586 *
587 * The second time is after a connection has been established but before
588 * authentication. activep is initialized to 2 and global config directives
589 * are ignored since they have already been processed. If the criteria in a
590 * Match block is met, activep is set and the subsequent directives
591 * processed and actioned until EOF or another Match block unsets it. Any
592 * options set are copied into the main server config.
593 *
594 * Potential additions/improvements:
595 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
596 *
597 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
598 * Match Address 192.168.0.*
599 * Tag trusted
600 * Match Group wheel
601 * Tag trusted
602 * Match Tag trusted
603 * AllowTcpForwarding yes
604 * GatewayPorts clientspecified
605 * [...]
606 *
607 * - Add a PermittedChannelRequests directive
608 * Match Group shell
609 * PermittedChannelRequests session,forwarded-tcpip
610 */
611
612static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000613match_cfg_line_group(const char *grps, int line, const char *user)
614{
615 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000616 struct passwd *pw;
617
Damien Miller565ca3f2006-08-19 00:23:15 +1000618 if (user == NULL)
619 goto out;
620
621 if ((pw = getpwnam(user)) == NULL) {
622 debug("Can't match group at line %d because user %.100s does "
623 "not exist", line, user);
624 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
625 debug("Can't Match group because user %.100s not in any group "
626 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000627 } else if (ga_match_pattern_list(grps) != 1) {
628 debug("user %.100s does not match group list %.100s at line %d",
629 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000630 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000631 debug("user %.100s matched group list %.100s at line %d", user,
632 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000633 result = 1;
634 }
635out:
636 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000637 return result;
638}
639
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000640/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000641 * All of the attributes on a single Match line are ANDed together, so we need
642 * to check every * attribute and set the result to zero if any attribute does
643 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000644 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000645static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000646match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000647{
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000648 int result = 1, port;
Darren Tucker45150472006-07-12 22:34:17 +1000649 char *arg, *attrib, *cp = *condition;
650 size_t len;
651
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000652 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000653 debug3("checking syntax for 'Match %s'", cp);
654 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000655 debug3("checking match for '%s' user %s host %s addr %s "
656 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
657 ci->host ? ci->host : "(null)",
658 ci->address ? ci->address : "(null)",
659 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000660
661 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
662 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
663 error("Missing Match criteria for %s", attrib);
664 return -1;
665 }
666 len = strlen(arg);
667 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000668 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000669 result = 0;
670 continue;
671 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000672 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000673 result = 0;
674 else
675 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000676 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000677 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000678 if (ci == NULL || ci->user == NULL) {
679 result = 0;
680 continue;
681 }
682 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000683 case -1:
684 return -1;
685 case 0:
686 result = 0;
687 }
Darren Tucker45150472006-07-12 22:34:17 +1000688 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000689 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000690 result = 0;
691 continue;
692 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000693 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000694 result = 0;
695 else
696 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000697 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000698 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000699 if (ci == NULL || ci->address == NULL) {
700 result = 0;
701 continue;
702 }
703 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000704 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000705 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000706 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000707 break;
708 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000709 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000710 result = 0;
711 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000712 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000713 return -1;
714 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000715 } else if (strcasecmp(attrib, "localaddress") == 0){
716 if (ci == NULL || ci->laddress == NULL) {
717 result = 0;
718 continue;
719 }
720 switch (addr_match_list(ci->laddress, arg)) {
721 case 1:
722 debug("connection from %.100s matched "
723 "'LocalAddress %.100s' at line %d",
724 ci->laddress, arg, line);
725 break;
726 case 0:
727 case -1:
728 result = 0;
729 break;
730 case -2:
731 return -1;
732 }
733 } else if (strcasecmp(attrib, "localport") == 0) {
734 if ((port = a2port(arg)) == -1) {
735 error("Invalid LocalPort '%s' on Match line",
736 arg);
737 return -1;
738 }
739 if (ci == NULL || ci->lport == 0) {
740 result = 0;
741 continue;
742 }
743 /* TODO support port lists */
744 if (port == ci->lport)
745 debug("connection from %.100s matched "
746 "'LocalPort %d' at line %d",
747 ci->laddress, port, line);
748 else
749 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000750 } else {
751 error("Unsupported Match attribute %s", attrib);
752 return -1;
753 }
754 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000755 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000756 debug3("match %sfound", result ? "" : "not ");
757 *condition = cp;
758 return result;
759}
760
Damien Millere2754432006-07-24 14:06:47 +1000761#define WHITESPACE " \t\r\n"
762
Damien Miller33322122011-06-20 14:43:11 +1000763/* Multistate option parsing */
764struct multistate {
765 char *key;
766 int value;
767};
768static const struct multistate multistate_addressfamily[] = {
769 { "inet", AF_INET },
770 { "inet6", AF_INET6 },
771 { "any", AF_UNSPEC },
772 { NULL, -1 }
773};
774static const struct multistate multistate_permitrootlogin[] = {
775 { "without-password", PERMIT_NO_PASSWD },
776 { "forced-commands-only", PERMIT_FORCED_ONLY },
777 { "yes", PERMIT_YES },
778 { "no", PERMIT_NO },
779 { NULL, -1 }
780};
781static const struct multistate multistate_compression[] = {
782 { "delayed", COMP_DELAYED },
783 { "yes", COMP_ZLIB },
784 { "no", COMP_NONE },
785 { NULL, -1 }
786};
787static const struct multistate multistate_gatewayports[] = {
788 { "clientspecified", 2 },
789 { "yes", 1 },
790 { "no", 0 },
791 { NULL, -1 }
792};
Damien Miller69ff1df2011-06-23 08:30:03 +1000793static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000794 { "yes", PRIVSEP_NOSANDBOX },
795 { "sandbox", PRIVSEP_ON },
796 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000797 { "no", PRIVSEP_OFF },
798 { NULL, -1 }
799};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100800static const struct multistate multistate_tcpfwd[] = {
801 { "yes", FORWARD_ALLOW },
802 { "all", FORWARD_ALLOW },
803 { "no", FORWARD_DENY },
804 { "remote", FORWARD_REMOTE },
805 { "local", FORWARD_LOCAL },
806 { NULL, -1 }
807};
Damien Miller33322122011-06-20 14:43:11 +1000808
Ben Lindstromade03f62001-12-06 18:22:17 +0000809int
810process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000811 const char *filename, int linenum, int *activep,
812 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000813{
Darren Tucker09c0f032013-05-16 20:48:57 +1000814 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000815 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100816 SyslogFacility *log_facility_ptr;
817 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000818 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000819 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000820 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000821 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000822 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000823
824 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100825 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100826 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000827 /* Ignore leading whitespace */
828 if (*arg == '\0')
829 arg = strdelim(&cp);
830 if (!arg || !*arg || *arg == '#')
831 return 0;
832 intptr = NULL;
833 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000834 opcode = parse_token(arg, filename, linenum, &flags);
835
836 if (activep == NULL) { /* We are processing a command line directive */
837 cmdline = 1;
838 activep = &cmdline;
839 }
840 if (*activep && opcode != sMatch)
841 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
842 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000843 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000844 fatal("%s line %d: Directive '%s' is not allowed "
845 "within a Match block", filename, linenum, arg);
846 } else { /* this is a directive we have already processed */
847 while (arg)
848 arg = strdelim(&cp);
849 return 0;
850 }
851 }
852
Ben Lindstromade03f62001-12-06 18:22:17 +0000853 switch (opcode) {
854 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000855 case sUsePAM:
856 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000857 goto parse_flag;
858
859 /* Standard Options */
860 case sBadOption:
861 return -1;
862 case sPort:
863 /* ignore ports from configfile if cmdline specifies ports */
864 if (options->ports_from_cmdline)
865 return 0;
866 if (options->listen_addrs != NULL)
867 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100868 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000869 if (options->num_ports >= MAX_PORTS)
870 fatal("%s line %d: too many ports.",
871 filename, linenum);
872 arg = strdelim(&cp);
873 if (!arg || *arg == '\0')
874 fatal("%s line %d: missing port number.",
875 filename, linenum);
876 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100877 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000878 fatal("%s line %d: Badly formatted port number.",
879 filename, linenum);
880 break;
881
882 case sServerKeyBits:
883 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000884 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000885 arg = strdelim(&cp);
886 if (!arg || *arg == '\0')
887 fatal("%s line %d: missing integer value.",
888 filename, linenum);
889 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000890 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000891 *intptr = value;
892 break;
893
894 case sLoginGraceTime:
895 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000896 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000897 arg = strdelim(&cp);
898 if (!arg || *arg == '\0')
899 fatal("%s line %d: missing time value.",
900 filename, linenum);
901 if ((value = convtime(arg)) == -1)
902 fatal("%s line %d: invalid time value.",
903 filename, linenum);
904 if (*intptr == -1)
905 *intptr = value;
906 break;
907
908 case sKeyRegenerationTime:
909 intptr = &options->key_regeneration_time;
910 goto parse_time;
911
912 case sListenAddress:
913 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100914 if (arg == NULL || *arg == '\0')
915 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000916 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000917 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
918 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
919 && strchr(p+1, ':') != NULL) {
920 add_listen_addr(options, arg, 0);
921 break;
922 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100923 p = hpdelim(&arg);
924 if (p == NULL)
925 fatal("%s line %d: bad address:port usage",
926 filename, linenum);
927 p = cleanhostname(p);
928 if (arg == NULL)
929 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100930 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100931 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000932
Damien Millerf91ee4c2005-03-01 21:24:33 +1100933 add_listen_addr(options, p, port);
934
Ben Lindstromade03f62001-12-06 18:22:17 +0000935 break;
936
Darren Tucker0f383232005-01-20 10:57:56 +1100937 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000938 intptr = &options->address_family;
939 multistate_ptr = multistate_addressfamily;
940 if (options->listen_addrs != NULL)
941 fatal("%s line %d: address family must be specified "
942 "before ListenAddress.", filename, linenum);
943 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100944 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000945 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000946 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000947 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000948 value = -1;
949 for (i = 0; multistate_ptr[i].key != NULL; i++) {
950 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
951 value = multistate_ptr[i].value;
952 break;
953 }
954 }
955 if (value == -1)
956 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100957 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000958 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100959 *intptr = value;
960 break;
961
Ben Lindstromade03f62001-12-06 18:22:17 +0000962 case sHostKeyFile:
963 intptr = &options->num_host_key_files;
964 if (*intptr >= MAX_HOSTKEYS)
965 fatal("%s line %d: too many host keys specified (max %d).",
966 filename, linenum, MAX_HOSTKEYS);
967 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000968 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000969 arg = strdelim(&cp);
970 if (!arg || *arg == '\0')
971 fatal("%s line %d: missing file name.",
972 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000973 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100974 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000975 /* increase optional counter */
976 if (intptr != NULL)
977 *intptr = *intptr + 1;
978 }
979 break;
980
Damien Miller0a80ca12010-02-27 07:55:05 +1100981 case sHostCertificate:
982 intptr = &options->num_host_cert_files;
983 if (*intptr >= MAX_HOSTKEYS)
984 fatal("%s line %d: too many host certificates "
985 "specified (max %d).", filename, linenum,
986 MAX_HOSTCERTS);
987 charptr = &options->host_cert_files[*intptr];
988 goto parse_filename;
989 break;
990
Ben Lindstromade03f62001-12-06 18:22:17 +0000991 case sPidFile:
992 charptr = &options->pid_file;
993 goto parse_filename;
994
995 case sPermitRootLogin:
996 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +1000997 multistate_ptr = multistate_permitrootlogin;
998 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +0000999
1000 case sIgnoreRhosts:
1001 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001002 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001003 arg = strdelim(&cp);
1004 if (!arg || *arg == '\0')
1005 fatal("%s line %d: missing yes/no argument.",
1006 filename, linenum);
1007 value = 0; /* silence compiler */
1008 if (strcmp(arg, "yes") == 0)
1009 value = 1;
1010 else if (strcmp(arg, "no") == 0)
1011 value = 0;
1012 else
1013 fatal("%s line %d: Bad yes/no argument: %s",
1014 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001015 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001016 *intptr = value;
1017 break;
1018
1019 case sIgnoreUserKnownHosts:
1020 intptr = &options->ignore_user_known_hosts;
1021 goto parse_flag;
1022
Ben Lindstromade03f62001-12-06 18:22:17 +00001023 case sRhostsRSAAuthentication:
1024 intptr = &options->rhosts_rsa_authentication;
1025 goto parse_flag;
1026
1027 case sHostbasedAuthentication:
1028 intptr = &options->hostbased_authentication;
1029 goto parse_flag;
1030
1031 case sHostbasedUsesNameFromPacketOnly:
1032 intptr = &options->hostbased_uses_name_from_packet_only;
1033 goto parse_flag;
1034
1035 case sRSAAuthentication:
1036 intptr = &options->rsa_authentication;
1037 goto parse_flag;
1038
1039 case sPubkeyAuthentication:
1040 intptr = &options->pubkey_authentication;
1041 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001042
Ben Lindstromade03f62001-12-06 18:22:17 +00001043 case sKerberosAuthentication:
1044 intptr = &options->kerberos_authentication;
1045 goto parse_flag;
1046
1047 case sKerberosOrLocalPasswd:
1048 intptr = &options->kerberos_or_local_passwd;
1049 goto parse_flag;
1050
1051 case sKerberosTicketCleanup:
1052 intptr = &options->kerberos_ticket_cleanup;
1053 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001054
Darren Tucker22ef5082003-12-31 11:37:34 +11001055 case sKerberosGetAFSToken:
1056 intptr = &options->kerberos_get_afs_token;
1057 goto parse_flag;
1058
Darren Tucker0efd1552003-08-26 11:49:55 +10001059 case sGssAuthentication:
1060 intptr = &options->gss_authentication;
1061 goto parse_flag;
1062
1063 case sGssCleanupCreds:
1064 intptr = &options->gss_cleanup_creds;
1065 goto parse_flag;
1066
Ben Lindstromade03f62001-12-06 18:22:17 +00001067 case sPasswordAuthentication:
1068 intptr = &options->password_authentication;
1069 goto parse_flag;
1070
Damien Miller01ed2272008-11-05 16:20:46 +11001071 case sZeroKnowledgePasswordAuthentication:
1072 intptr = &options->zero_knowledge_password_authentication;
1073 goto parse_flag;
1074
Ben Lindstromade03f62001-12-06 18:22:17 +00001075 case sKbdInteractiveAuthentication:
1076 intptr = &options->kbd_interactive_authentication;
1077 goto parse_flag;
1078
1079 case sChallengeResponseAuthentication:
1080 intptr = &options->challenge_response_authentication;
1081 goto parse_flag;
1082
1083 case sPrintMotd:
1084 intptr = &options->print_motd;
1085 goto parse_flag;
1086
1087 case sPrintLastLog:
1088 intptr = &options->print_lastlog;
1089 goto parse_flag;
1090
1091 case sX11Forwarding:
1092 intptr = &options->x11_forwarding;
1093 goto parse_flag;
1094
1095 case sX11DisplayOffset:
1096 intptr = &options->x11_display_offset;
1097 goto parse_int;
1098
Damien Miller95c249f2002-02-05 12:11:34 +11001099 case sX11UseLocalhost:
1100 intptr = &options->x11_use_localhost;
1101 goto parse_flag;
1102
Ben Lindstromade03f62001-12-06 18:22:17 +00001103 case sXAuthLocation:
1104 charptr = &options->xauth_location;
1105 goto parse_filename;
1106
1107 case sStrictModes:
1108 intptr = &options->strict_modes;
1109 goto parse_flag;
1110
Damien Miller12c150e2003-12-17 16:31:10 +11001111 case sTCPKeepAlive:
1112 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001113 goto parse_flag;
1114
1115 case sEmptyPasswd:
1116 intptr = &options->permit_empty_passwd;
1117 goto parse_flag;
1118
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001119 case sPermitUserEnvironment:
1120 intptr = &options->permit_user_env;
1121 goto parse_flag;
1122
Ben Lindstromade03f62001-12-06 18:22:17 +00001123 case sUseLogin:
1124 intptr = &options->use_login;
1125 goto parse_flag;
1126
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001127 case sCompression:
1128 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001129 multistate_ptr = multistate_compression;
1130 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001131
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001132 case sRekeyLimit:
1133 arg = strdelim(&cp);
1134 if (!arg || *arg == '\0')
1135 fatal("%.200s line %d: Missing argument.", filename,
1136 linenum);
1137 if (strcmp(arg, "default") == 0) {
1138 val64 = 0;
1139 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001140 if (scan_scaled(arg, &val64) == -1)
1141 fatal("%.200s line %d: Bad number '%s': %s",
1142 filename, linenum, arg, strerror(errno));
1143 /* check for too-large or too-small limits */
1144 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001145 fatal("%.200s line %d: RekeyLimit too large",
1146 filename, linenum);
1147 if (val64 != 0 && val64 < 16)
1148 fatal("%.200s line %d: RekeyLimit too small",
1149 filename, linenum);
1150 }
1151 if (*activep && options->rekey_limit == -1)
1152 options->rekey_limit = (u_int32_t)val64;
1153 if (cp != NULL) { /* optional rekey interval present */
1154 if (strcmp(cp, "none") == 0) {
1155 (void)strdelim(&cp); /* discard */
1156 break;
1157 }
1158 intptr = &options->rekey_interval;
1159 goto parse_time;
1160 }
1161 break;
1162
Ben Lindstromade03f62001-12-06 18:22:17 +00001163 case sGatewayPorts:
1164 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001165 multistate_ptr = multistate_gatewayports;
1166 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001167
Damien Miller3a961dc2003-06-03 10:25:48 +10001168 case sUseDNS:
1169 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001170 goto parse_flag;
1171
1172 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001173 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001174 arg = strdelim(&cp);
1175 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001176 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001177 fatal("%.200s line %d: unsupported log facility '%s'",
1178 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001179 if (*log_facility_ptr == -1)
1180 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001181 break;
1182
1183 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001184 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001185 arg = strdelim(&cp);
1186 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001187 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001188 fatal("%.200s line %d: unsupported log level '%s'",
1189 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001190 if (*log_level_ptr == -1)
1191 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001192 break;
1193
1194 case sAllowTcpForwarding:
1195 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001196 multistate_ptr = multistate_tcpfwd;
1197 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001198
Damien Miller4f755cd2008-05-19 14:57:41 +10001199 case sAllowAgentForwarding:
1200 intptr = &options->allow_agent_forwarding;
1201 goto parse_flag;
1202
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001203 case sUsePrivilegeSeparation:
1204 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001205 multistate_ptr = multistate_privsep;
1206 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001207
Ben Lindstromade03f62001-12-06 18:22:17 +00001208 case sAllowUsers:
1209 while ((arg = strdelim(&cp)) && *arg != '\0') {
1210 if (options->num_allow_users >= MAX_ALLOW_USERS)
1211 fatal("%s line %d: too many allow users.",
1212 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001213 if (!*activep)
1214 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001215 options->allow_users[options->num_allow_users++] =
1216 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001217 }
1218 break;
1219
1220 case sDenyUsers:
1221 while ((arg = strdelim(&cp)) && *arg != '\0') {
1222 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001223 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001224 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001225 if (!*activep)
1226 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001227 options->deny_users[options->num_deny_users++] =
1228 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001229 }
1230 break;
1231
1232 case sAllowGroups:
1233 while ((arg = strdelim(&cp)) && *arg != '\0') {
1234 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1235 fatal("%s line %d: too many allow groups.",
1236 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001237 if (!*activep)
1238 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001239 options->allow_groups[options->num_allow_groups++] =
1240 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001241 }
1242 break;
1243
1244 case sDenyGroups:
1245 while ((arg = strdelim(&cp)) && *arg != '\0') {
1246 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1247 fatal("%s line %d: too many deny groups.",
1248 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001249 if (!*activep)
1250 continue;
1251 options->deny_groups[options->num_deny_groups++] =
1252 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001253 }
1254 break;
1255
1256 case sCiphers:
1257 arg = strdelim(&cp);
1258 if (!arg || *arg == '\0')
1259 fatal("%s line %d: Missing argument.", filename, linenum);
1260 if (!ciphers_valid(arg))
1261 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1262 filename, linenum, arg ? arg : "<NONE>");
1263 if (options->ciphers == NULL)
1264 options->ciphers = xstrdup(arg);
1265 break;
1266
1267 case sMacs:
1268 arg = strdelim(&cp);
1269 if (!arg || *arg == '\0')
1270 fatal("%s line %d: Missing argument.", filename, linenum);
1271 if (!mac_valid(arg))
1272 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1273 filename, linenum, arg ? arg : "<NONE>");
1274 if (options->macs == NULL)
1275 options->macs = xstrdup(arg);
1276 break;
1277
Damien Millerd5f62bf2010-09-24 22:11:14 +10001278 case sKexAlgorithms:
1279 arg = strdelim(&cp);
1280 if (!arg || *arg == '\0')
1281 fatal("%s line %d: Missing argument.",
1282 filename, linenum);
1283 if (!kex_names_valid(arg))
1284 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1285 filename, linenum, arg ? arg : "<NONE>");
1286 if (options->kex_algorithms == NULL)
1287 options->kex_algorithms = xstrdup(arg);
1288 break;
1289
Ben Lindstromade03f62001-12-06 18:22:17 +00001290 case sProtocol:
1291 intptr = &options->protocol;
1292 arg = strdelim(&cp);
1293 if (!arg || *arg == '\0')
1294 fatal("%s line %d: Missing argument.", filename, linenum);
1295 value = proto_spec(arg);
1296 if (value == SSH_PROTO_UNKNOWN)
1297 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001298 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001299 if (*intptr == SSH_PROTO_UNKNOWN)
1300 *intptr = value;
1301 break;
1302
1303 case sSubsystem:
1304 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1305 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001306 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001307 }
1308 arg = strdelim(&cp);
1309 if (!arg || *arg == '\0')
1310 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001311 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001312 if (!*activep) {
1313 arg = strdelim(&cp);
1314 break;
1315 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001316 for (i = 0; i < options->num_subsystems; i++)
1317 if (strcmp(arg, options->subsystem_name[i]) == 0)
1318 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001319 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001320 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1321 arg = strdelim(&cp);
1322 if (!arg || *arg == '\0')
1323 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001324 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001325 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001326
1327 /* Collect arguments (separate to executable) */
1328 p = xstrdup(arg);
1329 len = strlen(p) + 1;
1330 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1331 len += 1 + strlen(arg);
1332 p = xrealloc(p, 1, len);
1333 strlcat(p, " ", len);
1334 strlcat(p, arg, len);
1335 }
1336 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001337 options->num_subsystems++;
1338 break;
1339
1340 case sMaxStartups:
1341 arg = strdelim(&cp);
1342 if (!arg || *arg == '\0')
1343 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001344 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001345 if ((n = sscanf(arg, "%d:%d:%d",
1346 &options->max_startups_begin,
1347 &options->max_startups_rate,
1348 &options->max_startups)) == 3) {
1349 if (options->max_startups_begin >
1350 options->max_startups ||
1351 options->max_startups_rate > 100 ||
1352 options->max_startups_rate < 1)
1353 fatal("%s line %d: Illegal MaxStartups spec.",
1354 filename, linenum);
1355 } else if (n != 1)
1356 fatal("%s line %d: Illegal MaxStartups spec.",
1357 filename, linenum);
1358 else
1359 options->max_startups = options->max_startups_begin;
1360 break;
1361
Darren Tucker89413db2004-05-24 10:36:23 +10001362 case sMaxAuthTries:
1363 intptr = &options->max_authtries;
1364 goto parse_int;
1365
Damien Miller7207f642008-05-19 15:34:50 +10001366 case sMaxSessions:
1367 intptr = &options->max_sessions;
1368 goto parse_int;
1369
Ben Lindstromade03f62001-12-06 18:22:17 +00001370 case sBanner:
1371 charptr = &options->banner;
1372 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001373
Ben Lindstromade03f62001-12-06 18:22:17 +00001374 /*
1375 * These options can contain %X options expanded at
1376 * connect time, so that you can specify paths like:
1377 *
1378 * AuthorizedKeysFile /etc/ssh_keys/%u
1379 */
1380 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001381 if (*activep && options->num_authkeys_files == 0) {
1382 while ((arg = strdelim(&cp)) && *arg != '\0') {
1383 if (options->num_authkeys_files >=
1384 MAX_AUTHKEYS_FILES)
1385 fatal("%s line %d: "
1386 "too many authorized keys files.",
1387 filename, linenum);
1388 options->authorized_keys_files[
1389 options->num_authkeys_files++] =
1390 tilde_expand_filename(arg, getuid());
1391 }
1392 }
1393 return 0;
1394
Damien Miller30da3442010-05-10 11:58:03 +10001395 case sAuthorizedPrincipalsFile:
1396 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001397 arg = strdelim(&cp);
1398 if (!arg || *arg == '\0')
1399 fatal("%s line %d: missing file name.",
1400 filename, linenum);
1401 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001402 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001403 /* increase optional counter */
1404 if (intptr != NULL)
1405 *intptr = *intptr + 1;
1406 }
1407 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001408
1409 case sClientAliveInterval:
1410 intptr = &options->client_alive_interval;
1411 goto parse_time;
1412
1413 case sClientAliveCountMax:
1414 intptr = &options->client_alive_count_max;
1415 goto parse_int;
1416
Darren Tucker46bc0752004-05-02 22:11:30 +10001417 case sAcceptEnv:
1418 while ((arg = strdelim(&cp)) && *arg != '\0') {
1419 if (strchr(arg, '=') != NULL)
1420 fatal("%s line %d: Invalid environment name.",
1421 filename, linenum);
1422 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1423 fatal("%s line %d: too many allow env.",
1424 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001425 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001426 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001427 options->accept_env[options->num_accept_env++] =
1428 xstrdup(arg);
1429 }
1430 break;
1431
Damien Millerd27b9472005-12-13 19:29:02 +11001432 case sPermitTunnel:
1433 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001434 arg = strdelim(&cp);
1435 if (!arg || *arg == '\0')
1436 fatal("%s line %d: Missing yes/point-to-point/"
1437 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001438 value = -1;
1439 for (i = 0; tunmode_desc[i].val != -1; i++)
1440 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1441 value = tunmode_desc[i].val;
1442 break;
1443 }
1444 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001445 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1446 "no argument: %s", filename, linenum, arg);
1447 if (*intptr == -1)
1448 *intptr = value;
1449 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001450
Darren Tucker45150472006-07-12 22:34:17 +10001451 case sMatch:
1452 if (cmdline)
1453 fatal("Match directive not supported as a command-line "
1454 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001455 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001456 if (value < 0)
1457 fatal("%s line %d: Bad Match condition", filename,
1458 linenum);
1459 *activep = value;
1460 break;
1461
Damien Miller9b439df2006-07-24 14:04:00 +10001462 case sPermitOpen:
1463 arg = strdelim(&cp);
1464 if (!arg || *arg == '\0')
1465 fatal("%s line %d: missing PermitOpen specification",
1466 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001467 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001468 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001469 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001470 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001471 options->num_permitted_opens = 0;
1472 }
Damien Miller9b439df2006-07-24 14:04:00 +10001473 break;
1474 }
Damien Millerc6081482012-04-22 11:18:53 +10001475 if (strcmp(arg, "none") == 0) {
1476 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001477 options->num_permitted_opens = 1;
1478 channel_disable_adm_local_opens();
1479 }
1480 break;
1481 }
Damien Millera29b95e2007-01-05 16:28:36 +11001482 if (*activep && n == -1)
1483 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001484 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1485 p = hpdelim(&arg);
1486 if (p == NULL)
1487 fatal("%s line %d: missing host in PermitOpen",
1488 filename, linenum);
1489 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001490 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001491 fatal("%s line %d: bad port number in "
1492 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001493 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001494 options->num_permitted_opens =
1495 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001496 }
Damien Miller9b439df2006-07-24 14:04:00 +10001497 break;
1498
Damien Millere2754432006-07-24 14:06:47 +10001499 case sForceCommand:
1500 if (cp == NULL)
1501 fatal("%.200s line %d: Missing argument.", filename,
1502 linenum);
1503 len = strspn(cp, WHITESPACE);
1504 if (*activep && options->adm_forced_command == NULL)
1505 options->adm_forced_command = xstrdup(cp + len);
1506 return 0;
1507
Damien Millerd8cb1f12008-02-10 22:40:12 +11001508 case sChrootDirectory:
1509 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001510
1511 arg = strdelim(&cp);
1512 if (!arg || *arg == '\0')
1513 fatal("%s line %d: missing file name.",
1514 filename, linenum);
1515 if (*activep && *charptr == NULL)
1516 *charptr = xstrdup(arg);
1517 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001518
Damien Miller1aed65e2010-03-04 21:53:35 +11001519 case sTrustedUserCAKeys:
1520 charptr = &options->trusted_user_ca_keys;
1521 goto parse_filename;
1522
1523 case sRevokedKeys:
1524 charptr = &options->revoked_keys_file;
1525 goto parse_filename;
1526
Damien Miller0dac6fb2010-11-20 15:19:38 +11001527 case sIPQoS:
1528 arg = strdelim(&cp);
1529 if ((value = parse_ipqos(arg)) == -1)
1530 fatal("%s line %d: Bad IPQoS value: %s",
1531 filename, linenum, arg);
1532 arg = strdelim(&cp);
1533 if (arg == NULL)
1534 value2 = value;
1535 else if ((value2 = parse_ipqos(arg)) == -1)
1536 fatal("%s line %d: Bad IPQoS value: %s",
1537 filename, linenum, arg);
1538 if (*activep) {
1539 options->ip_qos_interactive = value;
1540 options->ip_qos_bulk = value2;
1541 }
1542 break;
1543
Damien Miller23528812012-04-22 11:24:43 +10001544 case sVersionAddendum:
1545 if (cp == NULL)
1546 fatal("%.200s line %d: Missing argument.", filename,
1547 linenum);
1548 len = strspn(cp, WHITESPACE);
1549 if (*activep && options->version_addendum == NULL) {
1550 if (strcasecmp(cp + len, "none") == 0)
1551 options->version_addendum = xstrdup("");
1552 else if (strchr(cp + len, '\r') != NULL)
1553 fatal("%.200s line %d: Invalid argument",
1554 filename, linenum);
1555 else
1556 options->version_addendum = xstrdup(cp + len);
1557 }
1558 return 0;
1559
Damien Miller09d3e122012-10-31 08:58:58 +11001560 case sAuthorizedKeysCommand:
1561 len = strspn(cp, WHITESPACE);
1562 if (*activep && options->authorized_keys_command == NULL) {
1563 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1564 fatal("%.200s line %d: AuthorizedKeysCommand "
1565 "must be an absolute path",
1566 filename, linenum);
1567 options->authorized_keys_command = xstrdup(cp + len);
1568 }
1569 return 0;
1570
1571 case sAuthorizedKeysCommandUser:
1572 charptr = &options->authorized_keys_command_user;
1573
1574 arg = strdelim(&cp);
1575 if (*activep && *charptr == NULL)
1576 *charptr = xstrdup(arg);
1577 break;
1578
Damien Millera6e3f012012-11-04 23:21:40 +11001579 case sAuthenticationMethods:
1580 if (*activep && options->num_auth_methods == 0) {
1581 while ((arg = strdelim(&cp)) && *arg != '\0') {
1582 if (options->num_auth_methods >=
1583 MAX_AUTH_METHODS)
1584 fatal("%s line %d: "
1585 "too many authentication methods.",
1586 filename, linenum);
1587 if (auth2_methods_valid(arg, 0) != 0)
1588 fatal("%s line %d: invalid "
1589 "authentication method list.",
1590 filename, linenum);
1591 options->auth_methods[
1592 options->num_auth_methods++] = xstrdup(arg);
1593 }
1594 }
1595 return 0;
1596
Ben Lindstromade03f62001-12-06 18:22:17 +00001597 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001598 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001599 filename, linenum, arg);
1600 while (arg)
1601 arg = strdelim(&cp);
1602 break;
1603
Damien Millerf9b3feb2003-05-16 11:38:32 +10001604 case sUnsupported:
1605 logit("%s line %d: Unsupported option %s",
1606 filename, linenum, arg);
1607 while (arg)
1608 arg = strdelim(&cp);
1609 break;
1610
Ben Lindstromade03f62001-12-06 18:22:17 +00001611 default:
1612 fatal("%s line %d: Missing handler for opcode %s (%d)",
1613 filename, linenum, arg, opcode);
1614 }
1615 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1616 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1617 filename, linenum, arg);
1618 return 0;
1619}
1620
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001621/* Reads the server configuration file. */
1622
Damien Miller4af51302000-04-16 11:18:38 +10001623void
Darren Tucker645ab752004-06-25 13:33:20 +10001624load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001625{
Damien Miller46cb75a2012-07-31 12:22:37 +10001626 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001627 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001628 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001629
Darren Tucker645ab752004-06-25 13:33:20 +10001630 debug2("%s: filename %s", __func__, filename);
1631 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001632 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001633 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001634 }
Darren Tucker645ab752004-06-25 13:33:20 +10001635 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001636 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001637 lineno++;
1638 if (strlen(line) == sizeof(line) - 1)
1639 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001640 /*
1641 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001642 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001643 * line numbers later for error messages
1644 */
1645 if ((cp = strchr(line, '#')) != NULL)
1646 memcpy(cp, "\n", 2);
1647 cp = line + strspn(line, " \t\r");
1648
1649 buffer_append(conf, cp, strlen(cp));
1650 }
1651 buffer_append(conf, "\0", 1);
1652 fclose(f);
1653 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1654}
1655
1656void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001657parse_server_match_config(ServerOptions *options,
1658 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001659{
Darren Tucker45150472006-07-12 22:34:17 +10001660 ServerOptions mo;
1661
1662 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001663 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001664 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001665}
1666
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001667int parse_server_match_testspec(struct connection_info *ci, char *spec)
1668{
1669 char *p;
1670
1671 while ((p = strsep(&spec, ",")) && *p != '\0') {
1672 if (strncmp(p, "addr=", 5) == 0) {
1673 ci->address = xstrdup(p + 5);
1674 } else if (strncmp(p, "host=", 5) == 0) {
1675 ci->host = xstrdup(p + 5);
1676 } else if (strncmp(p, "user=", 5) == 0) {
1677 ci->user = xstrdup(p + 5);
1678 } else if (strncmp(p, "laddr=", 6) == 0) {
1679 ci->laddress = xstrdup(p + 6);
1680 } else if (strncmp(p, "lport=", 6) == 0) {
1681 ci->lport = a2port(p + 6);
1682 if (ci->lport == -1) {
1683 fprintf(stderr, "Invalid port '%s' in test mode"
1684 " specification %s\n", p+6, p);
1685 return -1;
1686 }
1687 } else {
1688 fprintf(stderr, "Invalid test mode specification %s\n",
1689 p);
1690 return -1;
1691 }
1692 }
1693 return 0;
1694}
1695
1696/*
1697 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1698 * empty spec.
1699 */
1700int server_match_spec_complete(struct connection_info *ci)
1701{
1702 if (ci->user && ci->host && ci->address)
1703 return 1; /* complete */
1704 if (!ci->user && !ci->host && !ci->address)
1705 return -1; /* empty */
1706 return 0; /* partial */
1707}
1708
Darren Tucker1629c072007-02-19 22:25:37 +11001709/* Helper macros */
1710#define M_CP_INTOPT(n) do {\
1711 if (src->n != -1) \
1712 dst->n = src->n; \
1713} while (0)
1714#define M_CP_STROPT(n) do {\
1715 if (src->n != NULL) { \
Darren Tuckera627d422013-06-02 07:31:17 +10001716 free(dst->n); \
Darren Tucker1629c072007-02-19 22:25:37 +11001717 dst->n = src->n; \
1718 } \
1719} while(0)
Damien Millerd8478b62011-05-29 21:39:36 +10001720#define M_CP_STRARRAYOPT(n, num_n) do {\
1721 if (src->num_n != 0) { \
1722 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1723 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1724 } \
1725} while(0)
Darren Tucker1629c072007-02-19 22:25:37 +11001726
1727/*
1728 * Copy any supported values that are set.
1729 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001730 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001731 * array values that are not used pre-authentication, because any that we
1732 * do use must be explictly sent in mm_getpwnamallow().
1733 */
Darren Tucker45150472006-07-12 22:34:17 +10001734void
Darren Tucker1629c072007-02-19 22:25:37 +11001735copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001736{
Darren Tucker1629c072007-02-19 22:25:37 +11001737 M_CP_INTOPT(password_authentication);
1738 M_CP_INTOPT(gss_authentication);
1739 M_CP_INTOPT(rsa_authentication);
1740 M_CP_INTOPT(pubkey_authentication);
1741 M_CP_INTOPT(kerberos_authentication);
1742 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001743 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001744 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001745 M_CP_INTOPT(zero_knowledge_password_authentication);
Damien Miller09d3e122012-10-31 08:58:58 +11001746 M_CP_STROPT(authorized_keys_command);
1747 M_CP_STROPT(authorized_keys_command_user);
Darren Tucker15f94272008-01-01 20:36:56 +11001748 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001749 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001750
1751 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001752 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001753 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001754 M_CP_INTOPT(gateway_ports);
1755 M_CP_INTOPT(x11_display_offset);
1756 M_CP_INTOPT(x11_forwarding);
1757 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001758 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001759 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001760 M_CP_INTOPT(ip_qos_interactive);
1761 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001762 M_CP_INTOPT(rekey_limit);
1763 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001764
Damien Millerf2e407e2011-05-20 19:04:14 +10001765 /* See comment in servconf.h */
1766 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001767
Damien Millerc2411902011-05-20 19:03:49 +10001768 /*
1769 * The only things that should be below this point are string options
1770 * which are only used after authentication.
1771 */
Damien Miller5d74e582011-05-20 19:03:31 +10001772 if (preauth)
1773 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001774
Damien Miller5d74e582011-05-20 19:03:31 +10001775 M_CP_STROPT(adm_forced_command);
1776 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001777}
1778
Darren Tucker1629c072007-02-19 22:25:37 +11001779#undef M_CP_INTOPT
1780#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001781#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001782
Darren Tucker45150472006-07-12 22:34:17 +10001783void
1784parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001785 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001786{
1787 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001788 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001789
1790 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1791
Darren Tucker9fbac712004-08-12 22:41:44 +10001792 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001793 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001794 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001795 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001796 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001797 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001798 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001799 }
Darren Tuckera627d422013-06-02 07:31:17 +10001800 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001801 if (bad_options > 0)
1802 fatal("%s: terminating, %d bad configuration options",
1803 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001804}
Darren Tuckere7140f22008-06-10 23:01:51 +10001805
1806static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001807fmt_multistate_int(int val, const struct multistate *m)
1808{
1809 u_int i;
1810
1811 for (i = 0; m[i].key != NULL; i++) {
1812 if (m[i].value == val)
1813 return m[i].key;
1814 }
1815 return "UNKNOWN";
1816}
1817
1818static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001819fmt_intarg(ServerOpCodes code, int val)
1820{
Damien Miller82c55872011-06-23 08:20:30 +10001821 if (val == -1)
1822 return "unset";
1823 switch (code) {
1824 case sAddressFamily:
1825 return fmt_multistate_int(val, multistate_addressfamily);
1826 case sPermitRootLogin:
1827 return fmt_multistate_int(val, multistate_permitrootlogin);
1828 case sGatewayPorts:
1829 return fmt_multistate_int(val, multistate_gatewayports);
1830 case sCompression:
1831 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001832 case sUsePrivilegeSeparation:
1833 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001834 case sAllowTcpForwarding:
1835 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001836 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001837 switch (val) {
1838 case SSH_PROTO_1:
1839 return "1";
1840 case SSH_PROTO_2:
1841 return "2";
1842 case (SSH_PROTO_1|SSH_PROTO_2):
1843 return "2,1";
1844 default:
1845 return "UNKNOWN";
1846 }
Damien Miller82c55872011-06-23 08:20:30 +10001847 default:
1848 switch (val) {
1849 case 0:
1850 return "no";
1851 case 1:
1852 return "yes";
1853 default:
1854 return "UNKNOWN";
1855 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001856 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001857}
1858
1859static const char *
1860lookup_opcode_name(ServerOpCodes code)
1861{
1862 u_int i;
1863
1864 for (i = 0; keywords[i].name != NULL; i++)
1865 if (keywords[i].opcode == code)
1866 return(keywords[i].name);
1867 return "UNKNOWN";
1868}
1869
1870static void
1871dump_cfg_int(ServerOpCodes code, int val)
1872{
1873 printf("%s %d\n", lookup_opcode_name(code), val);
1874}
1875
1876static void
1877dump_cfg_fmtint(ServerOpCodes code, int val)
1878{
1879 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1880}
1881
1882static void
1883dump_cfg_string(ServerOpCodes code, const char *val)
1884{
1885 if (val == NULL)
1886 return;
1887 printf("%s %s\n", lookup_opcode_name(code), val);
1888}
1889
1890static void
1891dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1892{
1893 u_int i;
1894
1895 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001896 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1897}
1898
1899static void
1900dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1901{
1902 u_int i;
1903
1904 printf("%s", lookup_opcode_name(code));
1905 for (i = 0; i < count; i++)
1906 printf(" %s", vals[i]);
1907 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001908}
1909
1910void
1911dump_config(ServerOptions *o)
1912{
1913 u_int i;
1914 int ret;
1915 struct addrinfo *ai;
1916 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1917
1918 /* these are usually at the top of the config */
1919 for (i = 0; i < o->num_ports; i++)
1920 printf("port %d\n", o->ports[i]);
1921 dump_cfg_fmtint(sProtocol, o->protocol);
1922 dump_cfg_fmtint(sAddressFamily, o->address_family);
1923
1924 /* ListenAddress must be after Port */
1925 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1926 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1927 sizeof(addr), port, sizeof(port),
1928 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1929 error("getnameinfo failed: %.100s",
1930 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1931 strerror(errno));
1932 } else {
1933 if (ai->ai_family == AF_INET6)
1934 printf("listenaddress [%s]:%s\n", addr, port);
1935 else
1936 printf("listenaddress %s:%s\n", addr, port);
1937 }
1938 }
1939
1940 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001941#ifdef USE_PAM
1942 dump_cfg_int(sUsePAM, o->use_pam);
1943#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001944 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1945 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1946 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1947 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1948 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001949 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001950 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1951 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1952
1953 /* formatted integer arguments */
1954 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1955 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1956 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1957 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1958 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1959 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1960 o->hostbased_uses_name_from_packet_only);
1961 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1962 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001963#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001964 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1965 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1966 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001967# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001968 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001969# endif
1970#endif
1971#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001972 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1973 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001974#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001975#ifdef JPAKE
1976 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1977 o->zero_knowledge_password_authentication);
1978#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001979 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1980 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1981 o->kbd_interactive_authentication);
1982 dump_cfg_fmtint(sChallengeResponseAuthentication,
1983 o->challenge_response_authentication);
1984 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1985 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1986 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
1987 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1988 dump_cfg_fmtint(sStrictModes, o->strict_modes);
1989 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
1990 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
1991 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
1992 dump_cfg_fmtint(sUseLogin, o->use_login);
1993 dump_cfg_fmtint(sCompression, o->compression);
1994 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
1995 dump_cfg_fmtint(sUseDNS, o->use_dns);
1996 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1997 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1998
1999 /* string arguments */
2000 dump_cfg_string(sPidFile, o->pid_file);
2001 dump_cfg_string(sXAuthLocation, o->xauth_location);
2002 dump_cfg_string(sCiphers, o->ciphers);
2003 dump_cfg_string(sMacs, o->macs);
2004 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002005 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002006 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002007 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2008 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002009 dump_cfg_string(sAuthorizedPrincipalsFile,
2010 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002011 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002012 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2013 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Darren Tuckere7140f22008-06-10 23:01:51 +10002014
2015 /* string arguments requiring a lookup */
2016 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2017 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2018
2019 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002020 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2021 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002022 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2023 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002024 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2025 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002026 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2027 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2028 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2029 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2030 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002031 dump_cfg_strarray_oneline(sAuthenticationMethods,
2032 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002033
2034 /* other arguments */
2035 for (i = 0; i < o->num_subsystems; i++)
2036 printf("subsystem %s %s\n", o->subsystem_name[i],
2037 o->subsystem_args[i]);
2038
2039 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2040 o->max_startups_rate, o->max_startups);
2041
2042 for (i = 0; tunmode_desc[i].val != -1; i++)
2043 if (tunmode_desc[i].val == o->permit_tun) {
2044 s = tunmode_desc[i].text;
2045 break;
2046 }
2047 dump_cfg_string(sPermitTunnel, s);
2048
Damien Miller91475862011-05-05 14:14:34 +10002049 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2050 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002051
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002052 printf("rekeylimit %lld %d\n", o->rekey_limit, o->rekey_interval);
2053
Darren Tuckere7140f22008-06-10 23:01:51 +10002054 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002055}