blob: 747edde6c5f9e9bb72ed164ad1fbdc603a6931ce [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Miller85b45e02013-07-20 13:21:52 +10002/* $OpenBSD: servconf.c,v 1.240 2013/07/19 07:37:48 markus Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
14#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millere3b60b52006-07-10 21:08:03 +100016#include <sys/types.h>
17#include <sys/socket.h>
18
Damien Miller0dac6fb2010-11-20 15:19:38 +110019#include <netinet/in.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22
Darren Tucker5f96f3b2013-05-16 20:29:28 +100023#include <ctype.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100024#include <netdb.h>
Damien Miller565ca3f2006-08-19 00:23:15 +100025#include <pwd.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100026#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100027#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100028#include <string.h>
Damien Millerd7834352006-08-05 12:39:39 +100029#include <signal.h>
Damien Millere6b3b612006-07-24 14:01:23 +100030#include <unistd.h>
Damien Millerd7834352006-08-05 12:39:39 +100031#include <stdarg.h>
Darren Tuckere7140f22008-06-10 23:01:51 +100032#include <errno.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100033#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100034#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100035#endif
Damien Millerbe43ebf2006-07-24 13:51:51 +100036
Damien Millerb84886b2008-05-19 15:05:07 +100037#include "openbsd-compat/sys-queue.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100041#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100042#include "servconf.h"
Damien Miller78928792000-04-12 20:17:38 +100043#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000044#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000045#include "misc.h"
46#include "cipher.h"
Damien Millerd7834352006-08-05 12:39:39 +100047#include "key.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000048#include "kex.h"
49#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100050#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100051#include "channels.h"
Damien Miller565ca3f2006-08-19 00:23:15 +100052#include "groupaccess.h"
Darren Tuckerfbcf8272012-05-19 19:37:01 +100053#include "canohost.h"
54#include "packet.h"
Damien Millera6e3f012012-11-04 23:21:40 +110055#include "hostfile.h"
56#include "auth.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000057
Damien Miller3dc71ad2009-01-28 16:31:22 +110058static void add_listen_addr(ServerOptions *, char *, int);
59static void add_one_listen_addr(ServerOptions *, char *, int);
Damien Miller34132e52000-01-14 15:45:46 +110060
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000061/* Use of privilege separation or not */
62extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100063extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000064
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065/* Initializes the server options to their default values. */
66
Damien Miller4af51302000-04-16 11:18:38 +100067void
Damien Miller95def091999-11-25 00:26:21 +110068initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100069{
Damien Miller95def091999-11-25 00:26:21 +110070 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110071
72 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100073 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110074
75 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110076 options->num_ports = 0;
77 options->ports_from_cmdline = 0;
78 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110079 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110080 options->num_host_key_files = 0;
Damien Miller0a80ca12010-02-27 07:55:05 +110081 options->num_host_cert_files = 0;
Damien Miller85b45e02013-07-20 13:21:52 +100082 options->host_key_agent = NULL;
Damien Miller6f83b8e2000-05-02 09:23:45 +100083 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110084 options->server_key_bits = -1;
85 options->login_grace_time = -1;
86 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000087 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110088 options->ignore_rhosts = -1;
89 options->ignore_user_known_hosts = -1;
90 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000091 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110092 options->x11_forwarding = -1;
93 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110094 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100095 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110096 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110097 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110098 options->log_facility = SYSLOG_FACILITY_NOT_SET;
99 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +1100100 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000101 options->hostbased_authentication = -1;
102 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100104 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100105 options->kerberos_authentication = -1;
106 options->kerberos_or_local_passwd = -1;
107 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100108 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000109 options->gss_authentication=-1;
110 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100112 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000113 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100114 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000115 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100116 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000117 options->compression = -1;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000118 options->rekey_limit = -1;
119 options->rekey_interval = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100120 options->allow_tcp_forwarding = -1;
Damien Miller4f755cd2008-05-19 14:57:41 +1000121 options->allow_agent_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100122 options->num_allow_users = 0;
123 options->num_deny_users = 0;
124 options->num_allow_groups = 0;
125 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000126 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000127 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +1000128 options->kex_algorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000129 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000130 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000131 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000132 options->max_startups_begin = -1;
133 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000134 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000135 options->max_authtries = -1;
Damien Miller7207f642008-05-19 15:34:50 +1000136 options->max_sessions = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000137 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000138 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000139 options->client_alive_interval = -1;
140 options->client_alive_count_max = -1;
Damien Millerd8478b62011-05-29 21:39:36 +1000141 options->num_authkeys_files = 0;
Darren Tucker46bc0752004-05-02 22:11:30 +1000142 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100143 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000144 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000145 options->adm_forced_command = NULL;
Damien Millerd8cb1f12008-02-10 22:40:12 +1100146 options->chroot_directory = NULL;
Damien Miller09d3e122012-10-31 08:58:58 +1100147 options->authorized_keys_command = NULL;
148 options->authorized_keys_command_user = NULL;
Damien Miller01ed2272008-11-05 16:20:46 +1100149 options->zero_knowledge_password_authentication = -1;
Damien Miller1aed65e2010-03-04 21:53:35 +1100150 options->revoked_keys_file = NULL;
151 options->trusted_user_ca_keys = NULL;
Damien Miller30da3442010-05-10 11:58:03 +1000152 options->authorized_principals_file = NULL;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100153 options->ip_qos_interactive = -1;
154 options->ip_qos_bulk = -1;
Damien Miller23528812012-04-22 11:24:43 +1000155 options->version_addendum = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000156}
157
Damien Miller4af51302000-04-16 11:18:38 +1000158void
Damien Miller95def091999-11-25 00:26:21 +1100159fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000160{
Damien Miller726273e2001-11-12 11:40:11 +1100161 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000162 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000163 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100164
165 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100166 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +1100167 options->protocol = SSH_PROTO_2;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100168 if (options->num_host_key_files == 0) {
169 /* fill default hostkeys for protocols */
170 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100171 options->host_key_files[options->num_host_key_files++] =
172 _PATH_HOST_KEY_FILE;
173 if (options->protocol & SSH_PROTO_2) {
174 options->host_key_files[options->num_host_key_files++] =
175 _PATH_HOST_RSA_KEY_FILE;
176 options->host_key_files[options->num_host_key_files++] =
177 _PATH_HOST_DSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100178#ifdef OPENSSL_HAS_ECC
Damien Millere13cadf2010-09-10 11:15:33 +1000179 options->host_key_files[options->num_host_key_files++] =
180 _PATH_HOST_ECDSA_KEY_FILE;
Damien Millerdd190dd2010-11-11 14:17:02 +1100181#endif
Damien Miller7fc23732002-01-22 23:19:11 +1100182 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100183 }
Damien Miller0a80ca12010-02-27 07:55:05 +1100184 /* No certificates by default */
Damien Miller34132e52000-01-14 15:45:46 +1100185 if (options->num_ports == 0)
186 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
187 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000188 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000189 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000190 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->server_key_bits == -1)
Darren Tucker7499b0c2008-07-02 22:35:43 +1000192 options->server_key_bits = 1024;
Damien Miller95def091999-11-25 00:26:21 +1100193 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000194 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100195 if (options->key_regeneration_time == -1)
196 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000197 if (options->permit_root_login == PERMIT_NOT_SET)
198 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100200 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->ignore_user_known_hosts == -1)
202 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->print_motd == -1)
204 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000205 if (options->print_lastlog == -1)
206 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100208 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100210 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100211 if (options->x11_use_localhost == -1)
212 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000213 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000214 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100215 if (options->strict_modes == -1)
216 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100217 if (options->tcp_keep_alive == -1)
218 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100219 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100220 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100221 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000222 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100223 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100224 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000225 if (options->hostbased_authentication == -1)
226 options->hostbased_authentication = 0;
227 if (options->hostbased_uses_name_from_packet_only == -1)
228 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->rsa_authentication == -1)
230 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100231 if (options->pubkey_authentication == -1)
232 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100233 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000234 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100235 if (options->kerberos_or_local_passwd == -1)
236 options->kerberos_or_local_passwd = 1;
237 if (options->kerberos_ticket_cleanup == -1)
238 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100239 if (options->kerberos_get_afs_token == -1)
240 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000241 if (options->gss_authentication == -1)
242 options->gss_authentication = 0;
243 if (options->gss_cleanup_creds == -1)
244 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100245 if (options->password_authentication == -1)
246 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100247 if (options->kbd_interactive_authentication == -1)
248 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000249 if (options->challenge_response_authentication == -1)
250 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100251 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100252 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000253 if (options->permit_user_env == -1)
254 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100255 if (options->use_login == -1)
256 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000257 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000258 options->compression = COMP_DELAYED;
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000259 if (options->rekey_limit == -1)
260 options->rekey_limit = 0;
261 if (options->rekey_interval == -1)
262 options->rekey_interval = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100263 if (options->allow_tcp_forwarding == -1)
Damien Milleraa5b3f82012-12-03 09:50:54 +1100264 options->allow_tcp_forwarding = FORWARD_ALLOW;
Damien Miller4f755cd2008-05-19 14:57:41 +1000265 if (options->allow_agent_forwarding == -1)
266 options->allow_agent_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000267 if (options->gateway_ports == -1)
268 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000269 if (options->max_startups == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100270 options->max_startups = 100;
Damien Miller942da032000-08-18 13:59:06 +1000271 if (options->max_startups_rate == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100272 options->max_startups_rate = 30; /* 30% */
Damien Miller942da032000-08-18 13:59:06 +1000273 if (options->max_startups_begin == -1)
Damien Miller1f583df2013-02-12 11:02:08 +1100274 options->max_startups_begin = 10;
Darren Tucker89413db2004-05-24 10:36:23 +1000275 if (options->max_authtries == -1)
276 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller7207f642008-05-19 15:34:50 +1000277 if (options->max_sessions == -1)
278 options->max_sessions = DEFAULT_SESSIONS_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000279 if (options->use_dns == -1)
280 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000281 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100282 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000283 if (options->client_alive_count_max == -1)
284 options->client_alive_count_max = 3;
Damien Millerd8478b62011-05-29 21:39:36 +1000285 if (options->num_authkeys_files == 0) {
286 options->authorized_keys_files[options->num_authkeys_files++] =
287 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
288 options->authorized_keys_files[options->num_authkeys_files++] =
289 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
290 }
Damien Millerd27b9472005-12-13 19:29:02 +1100291 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100292 options->permit_tun = SSH_TUNMODE_NO;
Damien Miller01ed2272008-11-05 16:20:46 +1100293 if (options->zero_knowledge_password_authentication == -1)
294 options->zero_knowledge_password_authentication = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +1100295 if (options->ip_qos_interactive == -1)
296 options->ip_qos_interactive = IPTOS_LOWDELAY;
297 if (options->ip_qos_bulk == -1)
298 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller23528812012-04-22 11:24:43 +1000299 if (options->version_addendum == NULL)
300 options->version_addendum = xstrdup("");
Ben Lindstromfb62a692002-06-06 19:47:11 +0000301 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000302 if (use_privsep == -1)
Damien Miller5a5c2b92012-07-31 12:21:34 +1000303 use_privsep = PRIVSEP_NOSANDBOX;
Damien Miller4903eb42002-06-21 16:20:44 +1000304
Tim Rice40017b02002-07-14 13:36:49 -0700305#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000306 if (use_privsep && options->compression == 1) {
307 error("This platform does not support both privilege "
308 "separation and compression");
309 error("Compression disabled");
310 options->compression = 0;
311 }
312#endif
313
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000314}
315
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000316/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100317typedef enum {
318 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100319 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000320 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100321 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100322 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
323 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000324 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100325 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100326 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000327 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100328 sPasswordAuthentication, sKbdInteractiveAuthentication,
329 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000330 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100331 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100332 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000333 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000334 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000335 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000336 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Damien Miller7207f642008-05-19 15:34:50 +1000337 sMaxStartups, sMaxAuthTries, sMaxSessions,
Damien Miller3a961dc2003-06-03 10:25:48 +1000338 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100339 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Damien Millerec2eaa32011-05-20 18:57:14 +1000340 sClientAliveCountMax, sAuthorizedKeysFile,
Damien Millerd27b9472005-12-13 19:29:02 +1100341 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millerd8cb1f12008-02-10 22:40:12 +1100342 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Darren Tucker7bd98e72010-01-10 10:31:12 +1100343 sUsePrivilegeSeparation, sAllowAgentForwarding,
Damien Miller0a80ca12010-02-27 07:55:05 +1100344 sZeroKnowledgePasswordAuthentication, sHostCertificate,
Damien Miller30da3442010-05-10 11:58:03 +1000345 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
Damien Miller23528812012-04-22 11:24:43 +1000346 sKexAlgorithms, sIPQoS, sVersionAddendum,
Damien Miller09d3e122012-10-31 08:58:58 +1100347 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
Damien Miller85b45e02013-07-20 13:21:52 +1000348 sAuthenticationMethods, sHostKeyAgent,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000349 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000350} ServerOpCodes;
351
Darren Tucker45150472006-07-12 22:34:17 +1000352#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
353#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
354#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
355
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000356/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100357static struct {
358 const char *name;
359 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000360 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100361} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100362 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000363#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000364 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000365#else
Darren Tucker45150472006-07-12 22:34:17 +1000366 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000367#endif
Darren Tucker45150472006-07-12 22:34:17 +1000368 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100369 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000370 { "port", sPort, SSHCFG_GLOBAL },
371 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
372 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
Damien Miller85b45e02013-07-20 13:21:52 +1000373 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000374 { "pidfile", sPidFile, SSHCFG_GLOBAL },
375 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
376 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
377 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
Darren Tucker15f94272008-01-01 20:36:56 +1100378 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000379 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
380 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
381 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
Darren Tucker1629c072007-02-19 22:25:37 +1100382 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
383 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000384 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100385 { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
386 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000387 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000388#ifdef KRB5
Darren Tucker1629c072007-02-19 22:25:37 +1100389 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000390 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
391 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100392#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000393 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000394#else
Darren Tucker45150472006-07-12 22:34:17 +1000395 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100396#endif
397#else
Darren Tucker1629c072007-02-19 22:25:37 +1100398 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000399 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
400 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
401 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000402#endif
Darren Tucker45150472006-07-12 22:34:17 +1000403 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
404 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000405#ifdef GSSAPI
Darren Tucker1629c072007-02-19 22:25:37 +1100406 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000407 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000408#else
Darren Tucker1629c072007-02-19 22:25:37 +1100409 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000410 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000411#endif
Darren Tucker1629c072007-02-19 22:25:37 +1100412 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
413 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Darren Tucker1d75f222007-03-01 21:31:28 +1100414 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
Darren Tucker45150472006-07-12 22:34:17 +1000415 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
Damien Miller01ed2272008-11-05 16:20:46 +1100416#ifdef JPAKE
417 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
418#else
419 { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
420#endif
Darren Tucker45150472006-07-12 22:34:17 +1000421 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
422 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
423 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
424 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
425 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
426 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
427 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000428 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
429 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
430 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000431 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
432 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
Damien Miller51bde602008-11-03 19:23:10 +1100433 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000434 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
435 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
436 { "compression", sCompression, SSHCFG_GLOBAL },
Darren Tucker5f96f3b2013-05-16 20:29:28 +1000437 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000438 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
439 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
440 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
Damien Miller4f755cd2008-05-19 14:57:41 +1000441 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
Damien Millerc24da772012-06-20 21:53:58 +1000442 { "allowusers", sAllowUsers, SSHCFG_ALL },
443 { "denyusers", sDenyUsers, SSHCFG_ALL },
444 { "allowgroups", sAllowGroups, SSHCFG_ALL },
445 { "denygroups", sDenyGroups, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000446 { "ciphers", sCiphers, SSHCFG_GLOBAL },
447 { "macs", sMacs, SSHCFG_GLOBAL },
448 { "protocol", sProtocol, SSHCFG_GLOBAL },
449 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
450 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
451 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
Damien Miller307c1d12008-06-16 07:56:20 +1000452 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
Damien Miller7207f642008-05-19 15:34:50 +1000453 { "maxsessions", sMaxSessions, SSHCFG_ALL },
Darren Tucker1629c072007-02-19 22:25:37 +1100454 { "banner", sBanner, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000455 { "usedns", sUseDNS, SSHCFG_GLOBAL },
456 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
457 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
458 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
459 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
Damien Millerab6de352010-06-26 09:38:45 +1000460 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
Damien Millerd8478b62011-05-29 21:39:36 +1000461 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000462 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
Damien Millerc24da772012-06-20 21:53:58 +1000463 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000464 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
Darren Tucker64cee362009-06-21 20:26:17 +1000465 { "match", sMatch, SSHCFG_ALL },
Damien Miller9b439df2006-07-24 14:04:00 +1000466 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000467 { "forcecommand", sForceCommand, SSHCFG_ALL },
Damien Millerd8cb1f12008-02-10 22:40:12 +1100468 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
Damien Miller0a80ca12010-02-27 07:55:05 +1100469 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
Damien Miller1aed65e2010-03-04 21:53:35 +1100470 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
471 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
Damien Millerab6de352010-06-26 09:38:45 +1000472 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000473 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100474 { "ipqos", sIPQoS, SSHCFG_ALL },
Damien Miller09d3e122012-10-31 08:58:58 +1100475 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
476 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
Damien Miller23528812012-04-22 11:24:43 +1000477 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
Damien Millera6e3f012012-11-04 23:21:40 +1100478 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000479 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000480};
481
Darren Tuckere7140f22008-06-10 23:01:51 +1000482static struct {
483 int val;
484 char *text;
485} tunmode_desc[] = {
486 { SSH_TUNMODE_NO, "no" },
487 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
488 { SSH_TUNMODE_ETHERNET, "ethernet" },
489 { SSH_TUNMODE_YES, "yes" },
490 { -1, NULL }
491};
492
Damien Miller5428f641999-11-25 11:54:57 +1100493/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000494 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100495 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000496
Damien Miller4af51302000-04-16 11:18:38 +1000497static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100498parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000499 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000500{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000501 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000502
Damien Miller95def091999-11-25 00:26:21 +1100503 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000504 if (strcasecmp(cp, keywords[i].name) == 0) {
505 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100506 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000507 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000508
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000509 error("%s: line %d: Bad configuration option: %s",
510 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100511 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000512}
513
Darren Tucker88b6fb22010-01-13 22:44:29 +1100514char *
515derelativise_path(const char *path)
516{
Damien Miller44451d02010-03-26 10:40:04 +1100517 char *expanded, *ret, cwd[MAXPATHLEN];
Darren Tucker88b6fb22010-01-13 22:44:29 +1100518
519 expanded = tilde_expand_filename(path, getuid());
520 if (*expanded == '/')
521 return expanded;
Damien Miller44451d02010-03-26 10:40:04 +1100522 if (getcwd(cwd, sizeof(cwd)) == NULL)
Darren Tucker88b6fb22010-01-13 22:44:29 +1100523 fatal("%s: getcwd: %s", __func__, strerror(errno));
524 xasprintf(&ret, "%s/%s", cwd, expanded);
Darren Tuckera627d422013-06-02 07:31:17 +1000525 free(expanded);
Darren Tucker88b6fb22010-01-13 22:44:29 +1100526 return ret;
527}
528
Ben Lindstrombba81212001-06-25 05:01:22 +0000529static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100530add_listen_addr(ServerOptions *options, char *addr, int port)
Damien Miller34132e52000-01-14 15:45:46 +1100531{
Damien Millereccb9de2005-06-17 12:59:34 +1000532 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100533
534 if (options->num_ports == 0)
535 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100536 if (options->address_family == -1)
537 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000538 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000539 for (i = 0; i < options->num_ports; i++)
540 add_one_listen_addr(options, addr, options->ports[i]);
541 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000542 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000543}
544
Ben Lindstrombba81212001-06-25 05:01:22 +0000545static void
Damien Miller3dc71ad2009-01-28 16:31:22 +1100546add_one_listen_addr(ServerOptions *options, char *addr, int port)
Ben Lindstromc510af42001-04-07 17:25:48 +0000547{
548 struct addrinfo hints, *ai, *aitop;
549 char strport[NI_MAXSERV];
550 int gaierr;
551
552 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100553 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000554 hints.ai_socktype = SOCK_STREAM;
555 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100556 snprintf(strport, sizeof strport, "%d", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000557 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
558 fatal("bad addr or host: %s (%s)",
559 addr ? addr : "<NULL>",
Darren Tucker4abde772007-12-29 02:43:51 +1100560 ssh_gai_strerror(gaierr));
Ben Lindstromc510af42001-04-07 17:25:48 +0000561 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
562 ;
563 ai->ai_next = options->listen_addrs;
564 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100565}
566
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000567struct connection_info *
568get_connection_info(int populate, int use_dns)
569{
570 static struct connection_info ci;
571
572 if (!populate)
573 return &ci;
574 ci.host = get_canonical_hostname(use_dns);
575 ci.address = get_remote_ipaddr();
576 ci.laddress = get_local_ipaddr(packet_get_connection_in());
577 ci.lport = get_local_port();
578 return &ci;
579}
580
Darren Tucker45150472006-07-12 22:34:17 +1000581/*
582 * The strategy for the Match blocks is that the config file is parsed twice.
583 *
584 * The first time is at startup. activep is initialized to 1 and the
585 * directives in the global context are processed and acted on. Hitting a
586 * Match directive unsets activep and the directives inside the block are
587 * checked for syntax only.
588 *
589 * The second time is after a connection has been established but before
590 * authentication. activep is initialized to 2 and global config directives
591 * are ignored since they have already been processed. If the criteria in a
592 * Match block is met, activep is set and the subsequent directives
593 * processed and actioned until EOF or another Match block unsets it. Any
594 * options set are copied into the main server config.
595 *
596 * Potential additions/improvements:
597 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
598 *
599 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
600 * Match Address 192.168.0.*
601 * Tag trusted
602 * Match Group wheel
603 * Tag trusted
604 * Match Tag trusted
605 * AllowTcpForwarding yes
606 * GatewayPorts clientspecified
607 * [...]
608 *
609 * - Add a PermittedChannelRequests directive
610 * Match Group shell
611 * PermittedChannelRequests session,forwarded-tcpip
612 */
613
614static int
Damien Miller565ca3f2006-08-19 00:23:15 +1000615match_cfg_line_group(const char *grps, int line, const char *user)
616{
617 int result = 0;
Damien Miller565ca3f2006-08-19 00:23:15 +1000618 struct passwd *pw;
619
Damien Miller565ca3f2006-08-19 00:23:15 +1000620 if (user == NULL)
621 goto out;
622
623 if ((pw = getpwnam(user)) == NULL) {
624 debug("Can't match group at line %d because user %.100s does "
625 "not exist", line, user);
626 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
627 debug("Can't Match group because user %.100s not in any group "
628 "at line %d", user, line);
Darren Tuckerb03fd022008-07-04 13:51:12 +1000629 } else if (ga_match_pattern_list(grps) != 1) {
630 debug("user %.100s does not match group list %.100s at line %d",
631 user, grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000632 } else {
Darren Tuckerb03fd022008-07-04 13:51:12 +1000633 debug("user %.100s matched group list %.100s at line %d", user,
634 grps, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000635 result = 1;
636 }
637out:
638 ga_free();
Damien Miller565ca3f2006-08-19 00:23:15 +1000639 return result;
640}
641
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000642/*
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000643 * All of the attributes on a single Match line are ANDed together, so we need
644 * to check every * attribute and set the result to zero if any attribute does
645 * not match.
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000646 */
Damien Miller565ca3f2006-08-19 00:23:15 +1000647static int
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000648match_cfg_line(char **condition, int line, struct connection_info *ci)
Darren Tucker45150472006-07-12 22:34:17 +1000649{
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000650 int result = 1, port;
Darren Tucker45150472006-07-12 22:34:17 +1000651 char *arg, *attrib, *cp = *condition;
652 size_t len;
653
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000654 if (ci == NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000655 debug3("checking syntax for 'Match %s'", cp);
656 else
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000657 debug3("checking match for '%s' user %s host %s addr %s "
658 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
659 ci->host ? ci->host : "(null)",
660 ci->address ? ci->address : "(null)",
661 ci->laddress ? ci->laddress : "(null)", ci->lport);
Darren Tucker45150472006-07-12 22:34:17 +1000662
663 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
664 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
665 error("Missing Match criteria for %s", attrib);
666 return -1;
667 }
668 len = strlen(arg);
669 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000670 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000671 result = 0;
672 continue;
673 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000674 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000675 result = 0;
676 else
677 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000678 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000679 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000680 if (ci == NULL || ci->user == NULL) {
681 result = 0;
682 continue;
683 }
684 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000685 case -1:
686 return -1;
687 case 0:
688 result = 0;
689 }
Darren Tucker45150472006-07-12 22:34:17 +1000690 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000691 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000692 result = 0;
693 continue;
694 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000695 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000696 result = 0;
697 else
698 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000699 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000700 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000701 if (ci == NULL || ci->address == NULL) {
702 result = 0;
703 continue;
704 }
705 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000706 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000707 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000708 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000709 break;
710 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000711 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000712 result = 0;
713 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000714 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000715 return -1;
716 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000717 } else if (strcasecmp(attrib, "localaddress") == 0){
718 if (ci == NULL || ci->laddress == NULL) {
719 result = 0;
720 continue;
721 }
722 switch (addr_match_list(ci->laddress, arg)) {
723 case 1:
724 debug("connection from %.100s matched "
725 "'LocalAddress %.100s' at line %d",
726 ci->laddress, arg, line);
727 break;
728 case 0:
729 case -1:
730 result = 0;
731 break;
732 case -2:
733 return -1;
734 }
735 } else if (strcasecmp(attrib, "localport") == 0) {
736 if ((port = a2port(arg)) == -1) {
737 error("Invalid LocalPort '%s' on Match line",
738 arg);
739 return -1;
740 }
741 if (ci == NULL || ci->lport == 0) {
742 result = 0;
743 continue;
744 }
745 /* TODO support port lists */
746 if (port == ci->lport)
747 debug("connection from %.100s matched "
748 "'LocalPort %d' at line %d",
749 ci->laddress, port, line);
750 else
751 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000752 } else {
753 error("Unsupported Match attribute %s", attrib);
754 return -1;
755 }
756 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000757 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000758 debug3("match %sfound", result ? "" : "not ");
759 *condition = cp;
760 return result;
761}
762
Damien Millere2754432006-07-24 14:06:47 +1000763#define WHITESPACE " \t\r\n"
764
Damien Miller33322122011-06-20 14:43:11 +1000765/* Multistate option parsing */
766struct multistate {
767 char *key;
768 int value;
769};
770static const struct multistate multistate_addressfamily[] = {
771 { "inet", AF_INET },
772 { "inet6", AF_INET6 },
773 { "any", AF_UNSPEC },
774 { NULL, -1 }
775};
776static const struct multistate multistate_permitrootlogin[] = {
777 { "without-password", PERMIT_NO_PASSWD },
778 { "forced-commands-only", PERMIT_FORCED_ONLY },
779 { "yes", PERMIT_YES },
780 { "no", PERMIT_NO },
781 { NULL, -1 }
782};
783static const struct multistate multistate_compression[] = {
784 { "delayed", COMP_DELAYED },
785 { "yes", COMP_ZLIB },
786 { "no", COMP_NONE },
787 { NULL, -1 }
788};
789static const struct multistate multistate_gatewayports[] = {
790 { "clientspecified", 2 },
791 { "yes", 1 },
792 { "no", 0 },
793 { NULL, -1 }
794};
Damien Miller69ff1df2011-06-23 08:30:03 +1000795static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000796 { "yes", PRIVSEP_NOSANDBOX },
797 { "sandbox", PRIVSEP_ON },
798 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000799 { "no", PRIVSEP_OFF },
800 { NULL, -1 }
801};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100802static const struct multistate multistate_tcpfwd[] = {
803 { "yes", FORWARD_ALLOW },
804 { "all", FORWARD_ALLOW },
805 { "no", FORWARD_DENY },
806 { "remote", FORWARD_REMOTE },
807 { "local", FORWARD_LOCAL },
808 { NULL, -1 }
809};
Damien Miller33322122011-06-20 14:43:11 +1000810
Ben Lindstromade03f62001-12-06 18:22:17 +0000811int
812process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000813 const char *filename, int linenum, int *activep,
814 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000815{
Darren Tucker09c0f032013-05-16 20:48:57 +1000816 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000817 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100818 SyslogFacility *log_facility_ptr;
819 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000820 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000821 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000822 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000823 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000824 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000825
826 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100827 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100828 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000829 /* Ignore leading whitespace */
830 if (*arg == '\0')
831 arg = strdelim(&cp);
832 if (!arg || !*arg || *arg == '#')
833 return 0;
834 intptr = NULL;
835 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000836 opcode = parse_token(arg, filename, linenum, &flags);
837
838 if (activep == NULL) { /* We are processing a command line directive */
839 cmdline = 1;
840 activep = &cmdline;
841 }
842 if (*activep && opcode != sMatch)
843 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
844 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000845 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000846 fatal("%s line %d: Directive '%s' is not allowed "
847 "within a Match block", filename, linenum, arg);
848 } else { /* this is a directive we have already processed */
849 while (arg)
850 arg = strdelim(&cp);
851 return 0;
852 }
853 }
854
Ben Lindstromade03f62001-12-06 18:22:17 +0000855 switch (opcode) {
856 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000857 case sUsePAM:
858 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000859 goto parse_flag;
860
861 /* Standard Options */
862 case sBadOption:
863 return -1;
864 case sPort:
865 /* ignore ports from configfile if cmdline specifies ports */
866 if (options->ports_from_cmdline)
867 return 0;
868 if (options->listen_addrs != NULL)
869 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100870 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000871 if (options->num_ports >= MAX_PORTS)
872 fatal("%s line %d: too many ports.",
873 filename, linenum);
874 arg = strdelim(&cp);
875 if (!arg || *arg == '\0')
876 fatal("%s line %d: missing port number.",
877 filename, linenum);
878 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100879 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000880 fatal("%s line %d: Badly formatted port number.",
881 filename, linenum);
882 break;
883
884 case sServerKeyBits:
885 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000886 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000887 arg = strdelim(&cp);
888 if (!arg || *arg == '\0')
889 fatal("%s line %d: missing integer value.",
890 filename, linenum);
891 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000892 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000893 *intptr = value;
894 break;
895
896 case sLoginGraceTime:
897 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000898 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000899 arg = strdelim(&cp);
900 if (!arg || *arg == '\0')
901 fatal("%s line %d: missing time value.",
902 filename, linenum);
903 if ((value = convtime(arg)) == -1)
904 fatal("%s line %d: invalid time value.",
905 filename, linenum);
906 if (*intptr == -1)
907 *intptr = value;
908 break;
909
910 case sKeyRegenerationTime:
911 intptr = &options->key_regeneration_time;
912 goto parse_time;
913
914 case sListenAddress:
915 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100916 if (arg == NULL || *arg == '\0')
917 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000918 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000919 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
920 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
921 && strchr(p+1, ':') != NULL) {
922 add_listen_addr(options, arg, 0);
923 break;
924 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100925 p = hpdelim(&arg);
926 if (p == NULL)
927 fatal("%s line %d: bad address:port usage",
928 filename, linenum);
929 p = cleanhostname(p);
930 if (arg == NULL)
931 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100932 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100933 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000934
Damien Millerf91ee4c2005-03-01 21:24:33 +1100935 add_listen_addr(options, p, port);
936
Ben Lindstromade03f62001-12-06 18:22:17 +0000937 break;
938
Darren Tucker0f383232005-01-20 10:57:56 +1100939 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000940 intptr = &options->address_family;
941 multistate_ptr = multistate_addressfamily;
942 if (options->listen_addrs != NULL)
943 fatal("%s line %d: address family must be specified "
944 "before ListenAddress.", filename, linenum);
945 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100946 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000947 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000948 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000949 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000950 value = -1;
951 for (i = 0; multistate_ptr[i].key != NULL; i++) {
952 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
953 value = multistate_ptr[i].value;
954 break;
955 }
956 }
957 if (value == -1)
958 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100959 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000960 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100961 *intptr = value;
962 break;
963
Ben Lindstromade03f62001-12-06 18:22:17 +0000964 case sHostKeyFile:
965 intptr = &options->num_host_key_files;
966 if (*intptr >= MAX_HOSTKEYS)
967 fatal("%s line %d: too many host keys specified (max %d).",
968 filename, linenum, MAX_HOSTKEYS);
969 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000970 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000971 arg = strdelim(&cp);
972 if (!arg || *arg == '\0')
973 fatal("%s line %d: missing file name.",
974 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000975 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100976 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000977 /* increase optional counter */
978 if (intptr != NULL)
979 *intptr = *intptr + 1;
980 }
981 break;
982
Damien Miller85b45e02013-07-20 13:21:52 +1000983 case sHostKeyAgent:
984 charptr = &options->host_key_agent;
985 arg = strdelim(&cp);
986 if (!arg || *arg == '\0')
987 fatal("%s line %d: missing socket name.",
988 filename, linenum);
989 if (*activep && *charptr == NULL)
990 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
991 xstrdup(arg) : derelativise_path(arg);
992 break;
993
Damien Miller0a80ca12010-02-27 07:55:05 +1100994 case sHostCertificate:
995 intptr = &options->num_host_cert_files;
996 if (*intptr >= MAX_HOSTKEYS)
997 fatal("%s line %d: too many host certificates "
998 "specified (max %d).", filename, linenum,
999 MAX_HOSTCERTS);
1000 charptr = &options->host_cert_files[*intptr];
1001 goto parse_filename;
1002 break;
1003
Ben Lindstromade03f62001-12-06 18:22:17 +00001004 case sPidFile:
1005 charptr = &options->pid_file;
1006 goto parse_filename;
1007
1008 case sPermitRootLogin:
1009 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001010 multistate_ptr = multistate_permitrootlogin;
1011 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001012
1013 case sIgnoreRhosts:
1014 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001015 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001016 arg = strdelim(&cp);
1017 if (!arg || *arg == '\0')
1018 fatal("%s line %d: missing yes/no argument.",
1019 filename, linenum);
1020 value = 0; /* silence compiler */
1021 if (strcmp(arg, "yes") == 0)
1022 value = 1;
1023 else if (strcmp(arg, "no") == 0)
1024 value = 0;
1025 else
1026 fatal("%s line %d: Bad yes/no argument: %s",
1027 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001028 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001029 *intptr = value;
1030 break;
1031
1032 case sIgnoreUserKnownHosts:
1033 intptr = &options->ignore_user_known_hosts;
1034 goto parse_flag;
1035
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 case sRhostsRSAAuthentication:
1037 intptr = &options->rhosts_rsa_authentication;
1038 goto parse_flag;
1039
1040 case sHostbasedAuthentication:
1041 intptr = &options->hostbased_authentication;
1042 goto parse_flag;
1043
1044 case sHostbasedUsesNameFromPacketOnly:
1045 intptr = &options->hostbased_uses_name_from_packet_only;
1046 goto parse_flag;
1047
1048 case sRSAAuthentication:
1049 intptr = &options->rsa_authentication;
1050 goto parse_flag;
1051
1052 case sPubkeyAuthentication:
1053 intptr = &options->pubkey_authentication;
1054 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001055
Ben Lindstromade03f62001-12-06 18:22:17 +00001056 case sKerberosAuthentication:
1057 intptr = &options->kerberos_authentication;
1058 goto parse_flag;
1059
1060 case sKerberosOrLocalPasswd:
1061 intptr = &options->kerberos_or_local_passwd;
1062 goto parse_flag;
1063
1064 case sKerberosTicketCleanup:
1065 intptr = &options->kerberos_ticket_cleanup;
1066 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001067
Darren Tucker22ef5082003-12-31 11:37:34 +11001068 case sKerberosGetAFSToken:
1069 intptr = &options->kerberos_get_afs_token;
1070 goto parse_flag;
1071
Darren Tucker0efd1552003-08-26 11:49:55 +10001072 case sGssAuthentication:
1073 intptr = &options->gss_authentication;
1074 goto parse_flag;
1075
1076 case sGssCleanupCreds:
1077 intptr = &options->gss_cleanup_creds;
1078 goto parse_flag;
1079
Ben Lindstromade03f62001-12-06 18:22:17 +00001080 case sPasswordAuthentication:
1081 intptr = &options->password_authentication;
1082 goto parse_flag;
1083
Damien Miller01ed2272008-11-05 16:20:46 +11001084 case sZeroKnowledgePasswordAuthentication:
1085 intptr = &options->zero_knowledge_password_authentication;
1086 goto parse_flag;
1087
Ben Lindstromade03f62001-12-06 18:22:17 +00001088 case sKbdInteractiveAuthentication:
1089 intptr = &options->kbd_interactive_authentication;
1090 goto parse_flag;
1091
1092 case sChallengeResponseAuthentication:
1093 intptr = &options->challenge_response_authentication;
1094 goto parse_flag;
1095
1096 case sPrintMotd:
1097 intptr = &options->print_motd;
1098 goto parse_flag;
1099
1100 case sPrintLastLog:
1101 intptr = &options->print_lastlog;
1102 goto parse_flag;
1103
1104 case sX11Forwarding:
1105 intptr = &options->x11_forwarding;
1106 goto parse_flag;
1107
1108 case sX11DisplayOffset:
1109 intptr = &options->x11_display_offset;
1110 goto parse_int;
1111
Damien Miller95c249f2002-02-05 12:11:34 +11001112 case sX11UseLocalhost:
1113 intptr = &options->x11_use_localhost;
1114 goto parse_flag;
1115
Ben Lindstromade03f62001-12-06 18:22:17 +00001116 case sXAuthLocation:
1117 charptr = &options->xauth_location;
1118 goto parse_filename;
1119
1120 case sStrictModes:
1121 intptr = &options->strict_modes;
1122 goto parse_flag;
1123
Damien Miller12c150e2003-12-17 16:31:10 +11001124 case sTCPKeepAlive:
1125 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001126 goto parse_flag;
1127
1128 case sEmptyPasswd:
1129 intptr = &options->permit_empty_passwd;
1130 goto parse_flag;
1131
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001132 case sPermitUserEnvironment:
1133 intptr = &options->permit_user_env;
1134 goto parse_flag;
1135
Ben Lindstromade03f62001-12-06 18:22:17 +00001136 case sUseLogin:
1137 intptr = &options->use_login;
1138 goto parse_flag;
1139
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001140 case sCompression:
1141 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001142 multistate_ptr = multistate_compression;
1143 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001144
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001145 case sRekeyLimit:
1146 arg = strdelim(&cp);
1147 if (!arg || *arg == '\0')
1148 fatal("%.200s line %d: Missing argument.", filename,
1149 linenum);
1150 if (strcmp(arg, "default") == 0) {
1151 val64 = 0;
1152 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001153 if (scan_scaled(arg, &val64) == -1)
1154 fatal("%.200s line %d: Bad number '%s': %s",
1155 filename, linenum, arg, strerror(errno));
1156 /* check for too-large or too-small limits */
1157 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001158 fatal("%.200s line %d: RekeyLimit too large",
1159 filename, linenum);
1160 if (val64 != 0 && val64 < 16)
1161 fatal("%.200s line %d: RekeyLimit too small",
1162 filename, linenum);
1163 }
1164 if (*activep && options->rekey_limit == -1)
1165 options->rekey_limit = (u_int32_t)val64;
1166 if (cp != NULL) { /* optional rekey interval present */
1167 if (strcmp(cp, "none") == 0) {
1168 (void)strdelim(&cp); /* discard */
1169 break;
1170 }
1171 intptr = &options->rekey_interval;
1172 goto parse_time;
1173 }
1174 break;
1175
Ben Lindstromade03f62001-12-06 18:22:17 +00001176 case sGatewayPorts:
1177 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001178 multistate_ptr = multistate_gatewayports;
1179 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001180
Damien Miller3a961dc2003-06-03 10:25:48 +10001181 case sUseDNS:
1182 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001183 goto parse_flag;
1184
1185 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001186 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001187 arg = strdelim(&cp);
1188 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001189 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001190 fatal("%.200s line %d: unsupported log facility '%s'",
1191 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001192 if (*log_facility_ptr == -1)
1193 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001194 break;
1195
1196 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001197 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001198 arg = strdelim(&cp);
1199 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001200 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001201 fatal("%.200s line %d: unsupported log level '%s'",
1202 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001203 if (*log_level_ptr == -1)
1204 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001205 break;
1206
1207 case sAllowTcpForwarding:
1208 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001209 multistate_ptr = multistate_tcpfwd;
1210 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001211
Damien Miller4f755cd2008-05-19 14:57:41 +10001212 case sAllowAgentForwarding:
1213 intptr = &options->allow_agent_forwarding;
1214 goto parse_flag;
1215
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001216 case sUsePrivilegeSeparation:
1217 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001218 multistate_ptr = multistate_privsep;
1219 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001220
Ben Lindstromade03f62001-12-06 18:22:17 +00001221 case sAllowUsers:
1222 while ((arg = strdelim(&cp)) && *arg != '\0') {
1223 if (options->num_allow_users >= MAX_ALLOW_USERS)
1224 fatal("%s line %d: too many allow users.",
1225 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001226 if (!*activep)
1227 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001228 options->allow_users[options->num_allow_users++] =
1229 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001230 }
1231 break;
1232
1233 case sDenyUsers:
1234 while ((arg = strdelim(&cp)) && *arg != '\0') {
1235 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001236 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001237 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001238 if (!*activep)
1239 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001240 options->deny_users[options->num_deny_users++] =
1241 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001242 }
1243 break;
1244
1245 case sAllowGroups:
1246 while ((arg = strdelim(&cp)) && *arg != '\0') {
1247 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1248 fatal("%s line %d: too many allow groups.",
1249 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001250 if (!*activep)
1251 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001252 options->allow_groups[options->num_allow_groups++] =
1253 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001254 }
1255 break;
1256
1257 case sDenyGroups:
1258 while ((arg = strdelim(&cp)) && *arg != '\0') {
1259 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1260 fatal("%s line %d: too many deny groups.",
1261 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001262 if (!*activep)
1263 continue;
1264 options->deny_groups[options->num_deny_groups++] =
1265 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001266 }
1267 break;
1268
1269 case sCiphers:
1270 arg = strdelim(&cp);
1271 if (!arg || *arg == '\0')
1272 fatal("%s line %d: Missing argument.", filename, linenum);
1273 if (!ciphers_valid(arg))
1274 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1275 filename, linenum, arg ? arg : "<NONE>");
1276 if (options->ciphers == NULL)
1277 options->ciphers = xstrdup(arg);
1278 break;
1279
1280 case sMacs:
1281 arg = strdelim(&cp);
1282 if (!arg || *arg == '\0')
1283 fatal("%s line %d: Missing argument.", filename, linenum);
1284 if (!mac_valid(arg))
1285 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1286 filename, linenum, arg ? arg : "<NONE>");
1287 if (options->macs == NULL)
1288 options->macs = xstrdup(arg);
1289 break;
1290
Damien Millerd5f62bf2010-09-24 22:11:14 +10001291 case sKexAlgorithms:
1292 arg = strdelim(&cp);
1293 if (!arg || *arg == '\0')
1294 fatal("%s line %d: Missing argument.",
1295 filename, linenum);
1296 if (!kex_names_valid(arg))
1297 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1298 filename, linenum, arg ? arg : "<NONE>");
1299 if (options->kex_algorithms == NULL)
1300 options->kex_algorithms = xstrdup(arg);
1301 break;
1302
Ben Lindstromade03f62001-12-06 18:22:17 +00001303 case sProtocol:
1304 intptr = &options->protocol;
1305 arg = strdelim(&cp);
1306 if (!arg || *arg == '\0')
1307 fatal("%s line %d: Missing argument.", filename, linenum);
1308 value = proto_spec(arg);
1309 if (value == SSH_PROTO_UNKNOWN)
1310 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001311 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001312 if (*intptr == SSH_PROTO_UNKNOWN)
1313 *intptr = value;
1314 break;
1315
1316 case sSubsystem:
1317 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1318 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001319 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001320 }
1321 arg = strdelim(&cp);
1322 if (!arg || *arg == '\0')
1323 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001324 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001325 if (!*activep) {
1326 arg = strdelim(&cp);
1327 break;
1328 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001329 for (i = 0; i < options->num_subsystems; i++)
1330 if (strcmp(arg, options->subsystem_name[i]) == 0)
1331 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001332 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001333 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1334 arg = strdelim(&cp);
1335 if (!arg || *arg == '\0')
1336 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001337 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001338 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001339
1340 /* Collect arguments (separate to executable) */
1341 p = xstrdup(arg);
1342 len = strlen(p) + 1;
1343 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1344 len += 1 + strlen(arg);
1345 p = xrealloc(p, 1, len);
1346 strlcat(p, " ", len);
1347 strlcat(p, arg, len);
1348 }
1349 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001350 options->num_subsystems++;
1351 break;
1352
1353 case sMaxStartups:
1354 arg = strdelim(&cp);
1355 if (!arg || *arg == '\0')
1356 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001357 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001358 if ((n = sscanf(arg, "%d:%d:%d",
1359 &options->max_startups_begin,
1360 &options->max_startups_rate,
1361 &options->max_startups)) == 3) {
1362 if (options->max_startups_begin >
1363 options->max_startups ||
1364 options->max_startups_rate > 100 ||
1365 options->max_startups_rate < 1)
1366 fatal("%s line %d: Illegal MaxStartups spec.",
1367 filename, linenum);
1368 } else if (n != 1)
1369 fatal("%s line %d: Illegal MaxStartups spec.",
1370 filename, linenum);
1371 else
1372 options->max_startups = options->max_startups_begin;
1373 break;
1374
Darren Tucker89413db2004-05-24 10:36:23 +10001375 case sMaxAuthTries:
1376 intptr = &options->max_authtries;
1377 goto parse_int;
1378
Damien Miller7207f642008-05-19 15:34:50 +10001379 case sMaxSessions:
1380 intptr = &options->max_sessions;
1381 goto parse_int;
1382
Ben Lindstromade03f62001-12-06 18:22:17 +00001383 case sBanner:
1384 charptr = &options->banner;
1385 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001386
Ben Lindstromade03f62001-12-06 18:22:17 +00001387 /*
1388 * These options can contain %X options expanded at
1389 * connect time, so that you can specify paths like:
1390 *
1391 * AuthorizedKeysFile /etc/ssh_keys/%u
1392 */
1393 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001394 if (*activep && options->num_authkeys_files == 0) {
1395 while ((arg = strdelim(&cp)) && *arg != '\0') {
1396 if (options->num_authkeys_files >=
1397 MAX_AUTHKEYS_FILES)
1398 fatal("%s line %d: "
1399 "too many authorized keys files.",
1400 filename, linenum);
1401 options->authorized_keys_files[
1402 options->num_authkeys_files++] =
1403 tilde_expand_filename(arg, getuid());
1404 }
1405 }
1406 return 0;
1407
Damien Miller30da3442010-05-10 11:58:03 +10001408 case sAuthorizedPrincipalsFile:
1409 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001410 arg = strdelim(&cp);
1411 if (!arg || *arg == '\0')
1412 fatal("%s line %d: missing file name.",
1413 filename, linenum);
1414 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001415 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001416 /* increase optional counter */
1417 if (intptr != NULL)
1418 *intptr = *intptr + 1;
1419 }
1420 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001421
1422 case sClientAliveInterval:
1423 intptr = &options->client_alive_interval;
1424 goto parse_time;
1425
1426 case sClientAliveCountMax:
1427 intptr = &options->client_alive_count_max;
1428 goto parse_int;
1429
Darren Tucker46bc0752004-05-02 22:11:30 +10001430 case sAcceptEnv:
1431 while ((arg = strdelim(&cp)) && *arg != '\0') {
1432 if (strchr(arg, '=') != NULL)
1433 fatal("%s line %d: Invalid environment name.",
1434 filename, linenum);
1435 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1436 fatal("%s line %d: too many allow env.",
1437 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001438 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001439 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001440 options->accept_env[options->num_accept_env++] =
1441 xstrdup(arg);
1442 }
1443 break;
1444
Damien Millerd27b9472005-12-13 19:29:02 +11001445 case sPermitTunnel:
1446 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001447 arg = strdelim(&cp);
1448 if (!arg || *arg == '\0')
1449 fatal("%s line %d: Missing yes/point-to-point/"
1450 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001451 value = -1;
1452 for (i = 0; tunmode_desc[i].val != -1; i++)
1453 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1454 value = tunmode_desc[i].val;
1455 break;
1456 }
1457 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001458 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1459 "no argument: %s", filename, linenum, arg);
1460 if (*intptr == -1)
1461 *intptr = value;
1462 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001463
Darren Tucker45150472006-07-12 22:34:17 +10001464 case sMatch:
1465 if (cmdline)
1466 fatal("Match directive not supported as a command-line "
1467 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001468 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001469 if (value < 0)
1470 fatal("%s line %d: Bad Match condition", filename,
1471 linenum);
1472 *activep = value;
1473 break;
1474
Damien Miller9b439df2006-07-24 14:04:00 +10001475 case sPermitOpen:
1476 arg = strdelim(&cp);
1477 if (!arg || *arg == '\0')
1478 fatal("%s line %d: missing PermitOpen specification",
1479 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001480 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001481 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001482 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001483 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001484 options->num_permitted_opens = 0;
1485 }
Damien Miller9b439df2006-07-24 14:04:00 +10001486 break;
1487 }
Damien Millerc6081482012-04-22 11:18:53 +10001488 if (strcmp(arg, "none") == 0) {
1489 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001490 options->num_permitted_opens = 1;
1491 channel_disable_adm_local_opens();
1492 }
1493 break;
1494 }
Damien Millera29b95e2007-01-05 16:28:36 +11001495 if (*activep && n == -1)
1496 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001497 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1498 p = hpdelim(&arg);
1499 if (p == NULL)
1500 fatal("%s line %d: missing host in PermitOpen",
1501 filename, linenum);
1502 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001503 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001504 fatal("%s line %d: bad port number in "
1505 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001506 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001507 options->num_permitted_opens =
1508 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001509 }
Damien Miller9b439df2006-07-24 14:04:00 +10001510 break;
1511
Damien Millere2754432006-07-24 14:06:47 +10001512 case sForceCommand:
1513 if (cp == NULL)
1514 fatal("%.200s line %d: Missing argument.", filename,
1515 linenum);
1516 len = strspn(cp, WHITESPACE);
1517 if (*activep && options->adm_forced_command == NULL)
1518 options->adm_forced_command = xstrdup(cp + len);
1519 return 0;
1520
Damien Millerd8cb1f12008-02-10 22:40:12 +11001521 case sChrootDirectory:
1522 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001523
1524 arg = strdelim(&cp);
1525 if (!arg || *arg == '\0')
1526 fatal("%s line %d: missing file name.",
1527 filename, linenum);
1528 if (*activep && *charptr == NULL)
1529 *charptr = xstrdup(arg);
1530 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001531
Damien Miller1aed65e2010-03-04 21:53:35 +11001532 case sTrustedUserCAKeys:
1533 charptr = &options->trusted_user_ca_keys;
1534 goto parse_filename;
1535
1536 case sRevokedKeys:
1537 charptr = &options->revoked_keys_file;
1538 goto parse_filename;
1539
Damien Miller0dac6fb2010-11-20 15:19:38 +11001540 case sIPQoS:
1541 arg = strdelim(&cp);
1542 if ((value = parse_ipqos(arg)) == -1)
1543 fatal("%s line %d: Bad IPQoS value: %s",
1544 filename, linenum, arg);
1545 arg = strdelim(&cp);
1546 if (arg == NULL)
1547 value2 = value;
1548 else if ((value2 = parse_ipqos(arg)) == -1)
1549 fatal("%s line %d: Bad IPQoS value: %s",
1550 filename, linenum, arg);
1551 if (*activep) {
1552 options->ip_qos_interactive = value;
1553 options->ip_qos_bulk = value2;
1554 }
1555 break;
1556
Damien Miller23528812012-04-22 11:24:43 +10001557 case sVersionAddendum:
1558 if (cp == NULL)
1559 fatal("%.200s line %d: Missing argument.", filename,
1560 linenum);
1561 len = strspn(cp, WHITESPACE);
1562 if (*activep && options->version_addendum == NULL) {
1563 if (strcasecmp(cp + len, "none") == 0)
1564 options->version_addendum = xstrdup("");
1565 else if (strchr(cp + len, '\r') != NULL)
1566 fatal("%.200s line %d: Invalid argument",
1567 filename, linenum);
1568 else
1569 options->version_addendum = xstrdup(cp + len);
1570 }
1571 return 0;
1572
Damien Miller09d3e122012-10-31 08:58:58 +11001573 case sAuthorizedKeysCommand:
1574 len = strspn(cp, WHITESPACE);
1575 if (*activep && options->authorized_keys_command == NULL) {
1576 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1577 fatal("%.200s line %d: AuthorizedKeysCommand "
1578 "must be an absolute path",
1579 filename, linenum);
1580 options->authorized_keys_command = xstrdup(cp + len);
1581 }
1582 return 0;
1583
1584 case sAuthorizedKeysCommandUser:
1585 charptr = &options->authorized_keys_command_user;
1586
1587 arg = strdelim(&cp);
1588 if (*activep && *charptr == NULL)
1589 *charptr = xstrdup(arg);
1590 break;
1591
Damien Millera6e3f012012-11-04 23:21:40 +11001592 case sAuthenticationMethods:
1593 if (*activep && options->num_auth_methods == 0) {
1594 while ((arg = strdelim(&cp)) && *arg != '\0') {
1595 if (options->num_auth_methods >=
1596 MAX_AUTH_METHODS)
1597 fatal("%s line %d: "
1598 "too many authentication methods.",
1599 filename, linenum);
1600 if (auth2_methods_valid(arg, 0) != 0)
1601 fatal("%s line %d: invalid "
1602 "authentication method list.",
1603 filename, linenum);
1604 options->auth_methods[
1605 options->num_auth_methods++] = xstrdup(arg);
1606 }
1607 }
1608 return 0;
1609
Ben Lindstromade03f62001-12-06 18:22:17 +00001610 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001611 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001612 filename, linenum, arg);
1613 while (arg)
1614 arg = strdelim(&cp);
1615 break;
1616
Damien Millerf9b3feb2003-05-16 11:38:32 +10001617 case sUnsupported:
1618 logit("%s line %d: Unsupported option %s",
1619 filename, linenum, arg);
1620 while (arg)
1621 arg = strdelim(&cp);
1622 break;
1623
Ben Lindstromade03f62001-12-06 18:22:17 +00001624 default:
1625 fatal("%s line %d: Missing handler for opcode %s (%d)",
1626 filename, linenum, arg, opcode);
1627 }
1628 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1629 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1630 filename, linenum, arg);
1631 return 0;
1632}
1633
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001634/* Reads the server configuration file. */
1635
Damien Miller4af51302000-04-16 11:18:38 +10001636void
Darren Tucker645ab752004-06-25 13:33:20 +10001637load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001638{
Damien Miller46cb75a2012-07-31 12:22:37 +10001639 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001640 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001641 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001642
Darren Tucker645ab752004-06-25 13:33:20 +10001643 debug2("%s: filename %s", __func__, filename);
1644 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001645 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001646 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001647 }
Darren Tucker645ab752004-06-25 13:33:20 +10001648 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001649 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001650 lineno++;
1651 if (strlen(line) == sizeof(line) - 1)
1652 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001653 /*
1654 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001655 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001656 * line numbers later for error messages
1657 */
1658 if ((cp = strchr(line, '#')) != NULL)
1659 memcpy(cp, "\n", 2);
1660 cp = line + strspn(line, " \t\r");
1661
1662 buffer_append(conf, cp, strlen(cp));
1663 }
1664 buffer_append(conf, "\0", 1);
1665 fclose(f);
1666 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1667}
1668
1669void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001670parse_server_match_config(ServerOptions *options,
1671 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001672{
Darren Tucker45150472006-07-12 22:34:17 +10001673 ServerOptions mo;
1674
1675 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001676 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001677 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001678}
1679
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001680int parse_server_match_testspec(struct connection_info *ci, char *spec)
1681{
1682 char *p;
1683
1684 while ((p = strsep(&spec, ",")) && *p != '\0') {
1685 if (strncmp(p, "addr=", 5) == 0) {
1686 ci->address = xstrdup(p + 5);
1687 } else if (strncmp(p, "host=", 5) == 0) {
1688 ci->host = xstrdup(p + 5);
1689 } else if (strncmp(p, "user=", 5) == 0) {
1690 ci->user = xstrdup(p + 5);
1691 } else if (strncmp(p, "laddr=", 6) == 0) {
1692 ci->laddress = xstrdup(p + 6);
1693 } else if (strncmp(p, "lport=", 6) == 0) {
1694 ci->lport = a2port(p + 6);
1695 if (ci->lport == -1) {
1696 fprintf(stderr, "Invalid port '%s' in test mode"
1697 " specification %s\n", p+6, p);
1698 return -1;
1699 }
1700 } else {
1701 fprintf(stderr, "Invalid test mode specification %s\n",
1702 p);
1703 return -1;
1704 }
1705 }
1706 return 0;
1707}
1708
1709/*
1710 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1711 * empty spec.
1712 */
1713int server_match_spec_complete(struct connection_info *ci)
1714{
1715 if (ci->user && ci->host && ci->address)
1716 return 1; /* complete */
1717 if (!ci->user && !ci->host && !ci->address)
1718 return -1; /* empty */
1719 return 0; /* partial */
1720}
1721
Darren Tucker1629c072007-02-19 22:25:37 +11001722/* Helper macros */
1723#define M_CP_INTOPT(n) do {\
1724 if (src->n != -1) \
1725 dst->n = src->n; \
1726} while (0)
1727#define M_CP_STROPT(n) do {\
1728 if (src->n != NULL) { \
Darren Tuckera627d422013-06-02 07:31:17 +10001729 free(dst->n); \
Darren Tucker1629c072007-02-19 22:25:37 +11001730 dst->n = src->n; \
1731 } \
1732} while(0)
Damien Millerd8478b62011-05-29 21:39:36 +10001733#define M_CP_STRARRAYOPT(n, num_n) do {\
1734 if (src->num_n != 0) { \
1735 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1736 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1737 } \
1738} while(0)
Darren Tucker1629c072007-02-19 22:25:37 +11001739
1740/*
1741 * Copy any supported values that are set.
1742 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001743 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001744 * array values that are not used pre-authentication, because any that we
1745 * do use must be explictly sent in mm_getpwnamallow().
1746 */
Darren Tucker45150472006-07-12 22:34:17 +10001747void
Darren Tucker1629c072007-02-19 22:25:37 +11001748copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001749{
Darren Tucker1629c072007-02-19 22:25:37 +11001750 M_CP_INTOPT(password_authentication);
1751 M_CP_INTOPT(gss_authentication);
1752 M_CP_INTOPT(rsa_authentication);
1753 M_CP_INTOPT(pubkey_authentication);
1754 M_CP_INTOPT(kerberos_authentication);
1755 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001756 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001757 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001758 M_CP_INTOPT(zero_knowledge_password_authentication);
Damien Miller09d3e122012-10-31 08:58:58 +11001759 M_CP_STROPT(authorized_keys_command);
1760 M_CP_STROPT(authorized_keys_command_user);
Darren Tucker15f94272008-01-01 20:36:56 +11001761 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001762 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001763
1764 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001765 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001766 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001767 M_CP_INTOPT(gateway_ports);
1768 M_CP_INTOPT(x11_display_offset);
1769 M_CP_INTOPT(x11_forwarding);
1770 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001771 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001772 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001773 M_CP_INTOPT(ip_qos_interactive);
1774 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001775 M_CP_INTOPT(rekey_limit);
1776 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001777
Damien Millerf2e407e2011-05-20 19:04:14 +10001778 /* See comment in servconf.h */
1779 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001780
Damien Millerc2411902011-05-20 19:03:49 +10001781 /*
1782 * The only things that should be below this point are string options
1783 * which are only used after authentication.
1784 */
Damien Miller5d74e582011-05-20 19:03:31 +10001785 if (preauth)
1786 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001787
Damien Miller5d74e582011-05-20 19:03:31 +10001788 M_CP_STROPT(adm_forced_command);
1789 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001790}
1791
Darren Tucker1629c072007-02-19 22:25:37 +11001792#undef M_CP_INTOPT
1793#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001794#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001795
Darren Tucker45150472006-07-12 22:34:17 +10001796void
1797parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001798 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001799{
1800 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001801 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001802
1803 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1804
Darren Tucker9fbac712004-08-12 22:41:44 +10001805 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001806 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001807 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001808 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001809 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001810 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001811 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001812 }
Darren Tuckera627d422013-06-02 07:31:17 +10001813 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001814 if (bad_options > 0)
1815 fatal("%s: terminating, %d bad configuration options",
1816 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001817}
Darren Tuckere7140f22008-06-10 23:01:51 +10001818
1819static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001820fmt_multistate_int(int val, const struct multistate *m)
1821{
1822 u_int i;
1823
1824 for (i = 0; m[i].key != NULL; i++) {
1825 if (m[i].value == val)
1826 return m[i].key;
1827 }
1828 return "UNKNOWN";
1829}
1830
1831static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001832fmt_intarg(ServerOpCodes code, int val)
1833{
Damien Miller82c55872011-06-23 08:20:30 +10001834 if (val == -1)
1835 return "unset";
1836 switch (code) {
1837 case sAddressFamily:
1838 return fmt_multistate_int(val, multistate_addressfamily);
1839 case sPermitRootLogin:
1840 return fmt_multistate_int(val, multistate_permitrootlogin);
1841 case sGatewayPorts:
1842 return fmt_multistate_int(val, multistate_gatewayports);
1843 case sCompression:
1844 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001845 case sUsePrivilegeSeparation:
1846 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001847 case sAllowTcpForwarding:
1848 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001849 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001850 switch (val) {
1851 case SSH_PROTO_1:
1852 return "1";
1853 case SSH_PROTO_2:
1854 return "2";
1855 case (SSH_PROTO_1|SSH_PROTO_2):
1856 return "2,1";
1857 default:
1858 return "UNKNOWN";
1859 }
Damien Miller82c55872011-06-23 08:20:30 +10001860 default:
1861 switch (val) {
1862 case 0:
1863 return "no";
1864 case 1:
1865 return "yes";
1866 default:
1867 return "UNKNOWN";
1868 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001869 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001870}
1871
1872static const char *
1873lookup_opcode_name(ServerOpCodes code)
1874{
1875 u_int i;
1876
1877 for (i = 0; keywords[i].name != NULL; i++)
1878 if (keywords[i].opcode == code)
1879 return(keywords[i].name);
1880 return "UNKNOWN";
1881}
1882
1883static void
1884dump_cfg_int(ServerOpCodes code, int val)
1885{
1886 printf("%s %d\n", lookup_opcode_name(code), val);
1887}
1888
1889static void
1890dump_cfg_fmtint(ServerOpCodes code, int val)
1891{
1892 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1893}
1894
1895static void
1896dump_cfg_string(ServerOpCodes code, const char *val)
1897{
1898 if (val == NULL)
1899 return;
1900 printf("%s %s\n", lookup_opcode_name(code), val);
1901}
1902
1903static void
1904dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1905{
1906 u_int i;
1907
1908 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001909 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1910}
1911
1912static void
1913dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1914{
1915 u_int i;
1916
1917 printf("%s", lookup_opcode_name(code));
1918 for (i = 0; i < count; i++)
1919 printf(" %s", vals[i]);
1920 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001921}
1922
1923void
1924dump_config(ServerOptions *o)
1925{
1926 u_int i;
1927 int ret;
1928 struct addrinfo *ai;
1929 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1930
1931 /* these are usually at the top of the config */
1932 for (i = 0; i < o->num_ports; i++)
1933 printf("port %d\n", o->ports[i]);
1934 dump_cfg_fmtint(sProtocol, o->protocol);
1935 dump_cfg_fmtint(sAddressFamily, o->address_family);
1936
1937 /* ListenAddress must be after Port */
1938 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1939 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1940 sizeof(addr), port, sizeof(port),
1941 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1942 error("getnameinfo failed: %.100s",
1943 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1944 strerror(errno));
1945 } else {
1946 if (ai->ai_family == AF_INET6)
1947 printf("listenaddress [%s]:%s\n", addr, port);
1948 else
1949 printf("listenaddress %s:%s\n", addr, port);
1950 }
1951 }
1952
1953 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001954#ifdef USE_PAM
1955 dump_cfg_int(sUsePAM, o->use_pam);
1956#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001957 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1958 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1959 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1960 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1961 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001962 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001963 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1964 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1965
1966 /* formatted integer arguments */
1967 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1968 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1969 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1970 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1971 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1972 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1973 o->hostbased_uses_name_from_packet_only);
1974 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1975 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001976#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001977 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1978 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1979 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001980# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001981 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001982# endif
1983#endif
1984#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10001985 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1986 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10001987#endif
Damien Miller01ed2272008-11-05 16:20:46 +11001988#ifdef JPAKE
1989 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
1990 o->zero_knowledge_password_authentication);
1991#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001992 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
1993 dump_cfg_fmtint(sKbdInteractiveAuthentication,
1994 o->kbd_interactive_authentication);
1995 dump_cfg_fmtint(sChallengeResponseAuthentication,
1996 o->challenge_response_authentication);
1997 dump_cfg_fmtint(sPrintMotd, o->print_motd);
1998 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
1999 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2000 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
2001 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2002 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2003 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2004 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2005 dump_cfg_fmtint(sUseLogin, o->use_login);
2006 dump_cfg_fmtint(sCompression, o->compression);
2007 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2008 dump_cfg_fmtint(sUseDNS, o->use_dns);
2009 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2010 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2011
2012 /* string arguments */
2013 dump_cfg_string(sPidFile, o->pid_file);
2014 dump_cfg_string(sXAuthLocation, o->xauth_location);
2015 dump_cfg_string(sCiphers, o->ciphers);
2016 dump_cfg_string(sMacs, o->macs);
2017 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002018 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002019 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002020 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2021 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002022 dump_cfg_string(sAuthorizedPrincipalsFile,
2023 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002024 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002025 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2026 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002027 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Darren Tuckere7140f22008-06-10 23:01:51 +10002028
2029 /* string arguments requiring a lookup */
2030 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2031 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2032
2033 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002034 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2035 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002036 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2037 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002038 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2039 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002040 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2041 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2042 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2043 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2044 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002045 dump_cfg_strarray_oneline(sAuthenticationMethods,
2046 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002047
2048 /* other arguments */
2049 for (i = 0; i < o->num_subsystems; i++)
2050 printf("subsystem %s %s\n", o->subsystem_name[i],
2051 o->subsystem_args[i]);
2052
2053 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2054 o->max_startups_rate, o->max_startups);
2055
2056 for (i = 0; tunmode_desc[i].val != -1; i++)
2057 if (tunmode_desc[i].val == o->permit_tun) {
2058 s = tunmode_desc[i].text;
2059 break;
2060 }
2061 dump_cfg_string(sPermitTunnel, s);
2062
Damien Miller91475862011-05-05 14:14:34 +10002063 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2064 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002065
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002066 printf("rekeylimit %lld %d\n", o->rekey_limit, o->rekey_interval);
2067
Darren Tuckere7140f22008-06-10 23:01:51 +10002068 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002069}