blob: 82146723fec05b6899d44940ec21ac18c052b78c [file] [log] [blame]
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001
Damien Millercf31f382013-10-24 21:02:56 +11002/* $OpenBSD: servconf.c,v 1.243 2013/10/24 00:51:48 dtucker 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
Damien Miller03bf2e62013-10-24 21:01:26 +1100644 * to check every attribute and set the result to zero if any attribute does
Darren Tuckerbb6cc072012-09-17 13:25:06 +1000645 * 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{
Damien Millercf31f382013-10-24 21:02:56 +1100650 int result = 1, attributes = 0, 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') {
Damien Millercf31f382013-10-24 21:02:56 +1100664 attributes++;
665 if (strcasecmp(attrib, "all") == 0) {
666 if (attributes != 1 ||
667 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
668 error("'all' cannot be combined with other "
669 "Match attributes");
670 return -1;
671 }
672 *condition = cp;
673 return 1;
674 }
Darren Tucker45150472006-07-12 22:34:17 +1000675 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
676 error("Missing Match criteria for %s", attrib);
677 return -1;
678 }
679 len = strlen(arg);
680 if (strcasecmp(attrib, "user") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000681 if (ci == NULL || ci->user == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000682 result = 0;
683 continue;
684 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000685 if (match_pattern_list(ci->user, arg, len, 0) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000686 result = 0;
687 else
688 debug("user %.100s matched 'User %.100s' at "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000689 "line %d", ci->user, arg, line);
Damien Miller565ca3f2006-08-19 00:23:15 +1000690 } else if (strcasecmp(attrib, "group") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000691 if (ci == NULL || ci->user == NULL) {
692 result = 0;
693 continue;
694 }
695 switch (match_cfg_line_group(arg, line, ci->user)) {
Damien Miller565ca3f2006-08-19 00:23:15 +1000696 case -1:
697 return -1;
698 case 0:
699 result = 0;
700 }
Darren Tucker45150472006-07-12 22:34:17 +1000701 } else if (strcasecmp(attrib, "host") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000702 if (ci == NULL || ci->host == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000703 result = 0;
704 continue;
705 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000706 if (match_hostname(ci->host, arg, len) != 1)
Darren Tucker45150472006-07-12 22:34:17 +1000707 result = 0;
708 else
709 debug("connection from %.100s matched 'Host "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000710 "%.100s' at line %d", ci->host, arg, line);
Darren Tucker45150472006-07-12 22:34:17 +1000711 } else if (strcasecmp(attrib, "address") == 0) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000712 if (ci == NULL || ci->address == NULL) {
713 result = 0;
714 continue;
715 }
716 switch (addr_match_list(ci->address, arg)) {
Darren Tucker7a3935d2008-06-10 22:59:10 +1000717 case 1:
Darren Tucker45150472006-07-12 22:34:17 +1000718 debug("connection from %.100s matched 'Address "
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000719 "%.100s' at line %d", ci->address, arg, line);
Darren Tucker7a3935d2008-06-10 22:59:10 +1000720 break;
721 case 0:
Darren Tucker896ad5a2008-06-11 09:34:46 +1000722 case -1:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000723 result = 0;
724 break;
Darren Tucker896ad5a2008-06-11 09:34:46 +1000725 case -2:
Darren Tucker7a3935d2008-06-10 22:59:10 +1000726 return -1;
727 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000728 } else if (strcasecmp(attrib, "localaddress") == 0){
729 if (ci == NULL || ci->laddress == NULL) {
730 result = 0;
731 continue;
732 }
733 switch (addr_match_list(ci->laddress, arg)) {
734 case 1:
735 debug("connection from %.100s matched "
736 "'LocalAddress %.100s' at line %d",
737 ci->laddress, arg, line);
738 break;
739 case 0:
740 case -1:
741 result = 0;
742 break;
743 case -2:
744 return -1;
745 }
746 } else if (strcasecmp(attrib, "localport") == 0) {
747 if ((port = a2port(arg)) == -1) {
748 error("Invalid LocalPort '%s' on Match line",
749 arg);
750 return -1;
751 }
752 if (ci == NULL || ci->lport == 0) {
753 result = 0;
754 continue;
755 }
756 /* TODO support port lists */
757 if (port == ci->lport)
758 debug("connection from %.100s matched "
759 "'LocalPort %d' at line %d",
760 ci->laddress, port, line);
761 else
762 result = 0;
Darren Tucker45150472006-07-12 22:34:17 +1000763 } else {
764 error("Unsupported Match attribute %s", attrib);
765 return -1;
766 }
767 }
Damien Millercf31f382013-10-24 21:02:56 +1100768 if (attributes == 0) {
769 error("One or more attributes required for Match");
770 return -1;
771 }
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000772 if (ci != NULL)
Darren Tucker45150472006-07-12 22:34:17 +1000773 debug3("match %sfound", result ? "" : "not ");
774 *condition = cp;
775 return result;
776}
777
Damien Millere2754432006-07-24 14:06:47 +1000778#define WHITESPACE " \t\r\n"
779
Damien Miller33322122011-06-20 14:43:11 +1000780/* Multistate option parsing */
781struct multistate {
782 char *key;
783 int value;
784};
785static const struct multistate multistate_addressfamily[] = {
786 { "inet", AF_INET },
787 { "inet6", AF_INET6 },
788 { "any", AF_UNSPEC },
789 { NULL, -1 }
790};
791static const struct multistate multistate_permitrootlogin[] = {
792 { "without-password", PERMIT_NO_PASSWD },
793 { "forced-commands-only", PERMIT_FORCED_ONLY },
794 { "yes", PERMIT_YES },
795 { "no", PERMIT_NO },
796 { NULL, -1 }
797};
798static const struct multistate multistate_compression[] = {
799 { "delayed", COMP_DELAYED },
800 { "yes", COMP_ZLIB },
801 { "no", COMP_NONE },
802 { NULL, -1 }
803};
804static const struct multistate multistate_gatewayports[] = {
805 { "clientspecified", 2 },
806 { "yes", 1 },
807 { "no", 0 },
808 { NULL, -1 }
809};
Damien Miller69ff1df2011-06-23 08:30:03 +1000810static const struct multistate multistate_privsep[] = {
Damien Miller5a5c2b92012-07-31 12:21:34 +1000811 { "yes", PRIVSEP_NOSANDBOX },
812 { "sandbox", PRIVSEP_ON },
813 { "nosandbox", PRIVSEP_NOSANDBOX },
Damien Miller69ff1df2011-06-23 08:30:03 +1000814 { "no", PRIVSEP_OFF },
815 { NULL, -1 }
816};
Damien Milleraa5b3f82012-12-03 09:50:54 +1100817static const struct multistate multistate_tcpfwd[] = {
818 { "yes", FORWARD_ALLOW },
819 { "all", FORWARD_ALLOW },
820 { "no", FORWARD_DENY },
821 { "remote", FORWARD_REMOTE },
822 { "local", FORWARD_LOCAL },
823 { NULL, -1 }
824};
Damien Miller33322122011-06-20 14:43:11 +1000825
Ben Lindstromade03f62001-12-06 18:22:17 +0000826int
827process_server_config_line(ServerOptions *options, char *line,
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000828 const char *filename, int linenum, int *activep,
829 struct connection_info *connectinfo)
Ben Lindstromade03f62001-12-06 18:22:17 +0000830{
Darren Tucker09c0f032013-05-16 20:48:57 +1000831 char *cp, **charptr, *arg, *p;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000832 int cmdline = 0, *intptr, value, value2, n, port;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100833 SyslogFacility *log_facility_ptr;
834 LogLevel *log_level_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000835 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000836 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000837 size_t len;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000838 long long val64;
Damien Miller33322122011-06-20 14:43:11 +1000839 const struct multistate *multistate_ptr;
Ben Lindstromade03f62001-12-06 18:22:17 +0000840
841 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100842 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100843 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000844 /* Ignore leading whitespace */
845 if (*arg == '\0')
846 arg = strdelim(&cp);
847 if (!arg || !*arg || *arg == '#')
848 return 0;
849 intptr = NULL;
850 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000851 opcode = parse_token(arg, filename, linenum, &flags);
852
853 if (activep == NULL) { /* We are processing a command line directive */
854 cmdline = 1;
855 activep = &cmdline;
856 }
857 if (*activep && opcode != sMatch)
858 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
859 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
Darren Tuckerfbcf8272012-05-19 19:37:01 +1000860 if (connectinfo == NULL) {
Darren Tucker45150472006-07-12 22:34:17 +1000861 fatal("%s line %d: Directive '%s' is not allowed "
862 "within a Match block", filename, linenum, arg);
863 } else { /* this is a directive we have already processed */
864 while (arg)
865 arg = strdelim(&cp);
866 return 0;
867 }
868 }
869
Ben Lindstromade03f62001-12-06 18:22:17 +0000870 switch (opcode) {
871 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000872 case sUsePAM:
873 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000874 goto parse_flag;
875
876 /* Standard Options */
877 case sBadOption:
878 return -1;
879 case sPort:
880 /* ignore ports from configfile if cmdline specifies ports */
881 if (options->ports_from_cmdline)
882 return 0;
883 if (options->listen_addrs != NULL)
884 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100885 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000886 if (options->num_ports >= MAX_PORTS)
887 fatal("%s line %d: too many ports.",
888 filename, linenum);
889 arg = strdelim(&cp);
890 if (!arg || *arg == '\0')
891 fatal("%s line %d: missing port number.",
892 filename, linenum);
893 options->ports[options->num_ports++] = a2port(arg);
Damien Miller3dc71ad2009-01-28 16:31:22 +1100894 if (options->ports[options->num_ports-1] <= 0)
Ben Lindstromade03f62001-12-06 18:22:17 +0000895 fatal("%s line %d: Badly formatted port number.",
896 filename, linenum);
897 break;
898
899 case sServerKeyBits:
900 intptr = &options->server_key_bits;
Damien Miller7207f642008-05-19 15:34:50 +1000901 parse_int:
Ben Lindstromade03f62001-12-06 18:22:17 +0000902 arg = strdelim(&cp);
903 if (!arg || *arg == '\0')
904 fatal("%s line %d: missing integer value.",
905 filename, linenum);
906 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000907 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000908 *intptr = value;
909 break;
910
911 case sLoginGraceTime:
912 intptr = &options->login_grace_time;
Damien Miller7207f642008-05-19 15:34:50 +1000913 parse_time:
Ben Lindstromade03f62001-12-06 18:22:17 +0000914 arg = strdelim(&cp);
915 if (!arg || *arg == '\0')
916 fatal("%s line %d: missing time value.",
917 filename, linenum);
918 if ((value = convtime(arg)) == -1)
919 fatal("%s line %d: invalid time value.",
920 filename, linenum);
921 if (*intptr == -1)
922 *intptr = value;
923 break;
924
925 case sKeyRegenerationTime:
926 intptr = &options->key_regeneration_time;
927 goto parse_time;
928
929 case sListenAddress:
930 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100931 if (arg == NULL || *arg == '\0')
932 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000933 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000934 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
935 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
936 && strchr(p+1, ':') != NULL) {
937 add_listen_addr(options, arg, 0);
938 break;
939 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100940 p = hpdelim(&arg);
941 if (p == NULL)
942 fatal("%s line %d: bad address:port usage",
943 filename, linenum);
944 p = cleanhostname(p);
945 if (arg == NULL)
946 port = 0;
Damien Miller3dc71ad2009-01-28 16:31:22 +1100947 else if ((port = a2port(arg)) <= 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +1100948 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000949
Damien Millerf91ee4c2005-03-01 21:24:33 +1100950 add_listen_addr(options, p, port);
951
Ben Lindstromade03f62001-12-06 18:22:17 +0000952 break;
953
Darren Tucker0f383232005-01-20 10:57:56 +1100954 case sAddressFamily:
Damien Miller33322122011-06-20 14:43:11 +1000955 intptr = &options->address_family;
956 multistate_ptr = multistate_addressfamily;
957 if (options->listen_addrs != NULL)
958 fatal("%s line %d: address family must be specified "
959 "before ListenAddress.", filename, linenum);
960 parse_multistate:
Darren Tucker0f383232005-01-20 10:57:56 +1100961 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000962 if (!arg || *arg == '\0')
Damien Miller33322122011-06-20 14:43:11 +1000963 fatal("%s line %d: missing argument.",
Damien Miller17b23d82005-05-26 12:11:56 +1000964 filename, linenum);
Damien Miller33322122011-06-20 14:43:11 +1000965 value = -1;
966 for (i = 0; multistate_ptr[i].key != NULL; i++) {
967 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
968 value = multistate_ptr[i].value;
969 break;
970 }
971 }
972 if (value == -1)
973 fatal("%s line %d: unsupported option \"%s\".",
Darren Tucker0f383232005-01-20 10:57:56 +1100974 filename, linenum, arg);
Damien Miller33322122011-06-20 14:43:11 +1000975 if (*activep && *intptr == -1)
Darren Tucker0f383232005-01-20 10:57:56 +1100976 *intptr = value;
977 break;
978
Ben Lindstromade03f62001-12-06 18:22:17 +0000979 case sHostKeyFile:
980 intptr = &options->num_host_key_files;
981 if (*intptr >= MAX_HOSTKEYS)
982 fatal("%s line %d: too many host keys specified (max %d).",
983 filename, linenum, MAX_HOSTKEYS);
984 charptr = &options->host_key_files[*intptr];
Damien Miller7207f642008-05-19 15:34:50 +1000985 parse_filename:
Ben Lindstromade03f62001-12-06 18:22:17 +0000986 arg = strdelim(&cp);
987 if (!arg || *arg == '\0')
988 fatal("%s line %d: missing file name.",
989 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000990 if (*activep && *charptr == NULL) {
Darren Tucker88b6fb22010-01-13 22:44:29 +1100991 *charptr = derelativise_path(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000992 /* increase optional counter */
993 if (intptr != NULL)
994 *intptr = *intptr + 1;
995 }
996 break;
997
Damien Miller85b45e02013-07-20 13:21:52 +1000998 case sHostKeyAgent:
999 charptr = &options->host_key_agent;
1000 arg = strdelim(&cp);
1001 if (!arg || *arg == '\0')
1002 fatal("%s line %d: missing socket name.",
1003 filename, linenum);
1004 if (*activep && *charptr == NULL)
1005 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1006 xstrdup(arg) : derelativise_path(arg);
1007 break;
1008
Damien Miller0a80ca12010-02-27 07:55:05 +11001009 case sHostCertificate:
1010 intptr = &options->num_host_cert_files;
1011 if (*intptr >= MAX_HOSTKEYS)
1012 fatal("%s line %d: too many host certificates "
1013 "specified (max %d).", filename, linenum,
1014 MAX_HOSTCERTS);
1015 charptr = &options->host_cert_files[*intptr];
1016 goto parse_filename;
1017 break;
1018
Ben Lindstromade03f62001-12-06 18:22:17 +00001019 case sPidFile:
1020 charptr = &options->pid_file;
1021 goto parse_filename;
1022
1023 case sPermitRootLogin:
1024 intptr = &options->permit_root_login;
Damien Miller33322122011-06-20 14:43:11 +10001025 multistate_ptr = multistate_permitrootlogin;
1026 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001027
1028 case sIgnoreRhosts:
1029 intptr = &options->ignore_rhosts;
Damien Miller7207f642008-05-19 15:34:50 +10001030 parse_flag:
Ben Lindstromade03f62001-12-06 18:22:17 +00001031 arg = strdelim(&cp);
1032 if (!arg || *arg == '\0')
1033 fatal("%s line %d: missing yes/no argument.",
1034 filename, linenum);
1035 value = 0; /* silence compiler */
1036 if (strcmp(arg, "yes") == 0)
1037 value = 1;
1038 else if (strcmp(arg, "no") == 0)
1039 value = 0;
1040 else
1041 fatal("%s line %d: Bad yes/no argument: %s",
1042 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +10001043 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +00001044 *intptr = value;
1045 break;
1046
1047 case sIgnoreUserKnownHosts:
1048 intptr = &options->ignore_user_known_hosts;
1049 goto parse_flag;
1050
Ben Lindstromade03f62001-12-06 18:22:17 +00001051 case sRhostsRSAAuthentication:
1052 intptr = &options->rhosts_rsa_authentication;
1053 goto parse_flag;
1054
1055 case sHostbasedAuthentication:
1056 intptr = &options->hostbased_authentication;
1057 goto parse_flag;
1058
1059 case sHostbasedUsesNameFromPacketOnly:
1060 intptr = &options->hostbased_uses_name_from_packet_only;
1061 goto parse_flag;
1062
1063 case sRSAAuthentication:
1064 intptr = &options->rsa_authentication;
1065 goto parse_flag;
1066
1067 case sPubkeyAuthentication:
1068 intptr = &options->pubkey_authentication;
1069 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001070
Ben Lindstromade03f62001-12-06 18:22:17 +00001071 case sKerberosAuthentication:
1072 intptr = &options->kerberos_authentication;
1073 goto parse_flag;
1074
1075 case sKerberosOrLocalPasswd:
1076 intptr = &options->kerberos_or_local_passwd;
1077 goto parse_flag;
1078
1079 case sKerberosTicketCleanup:
1080 intptr = &options->kerberos_ticket_cleanup;
1081 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +10001082
Darren Tucker22ef5082003-12-31 11:37:34 +11001083 case sKerberosGetAFSToken:
1084 intptr = &options->kerberos_get_afs_token;
1085 goto parse_flag;
1086
Darren Tucker0efd1552003-08-26 11:49:55 +10001087 case sGssAuthentication:
1088 intptr = &options->gss_authentication;
1089 goto parse_flag;
1090
1091 case sGssCleanupCreds:
1092 intptr = &options->gss_cleanup_creds;
1093 goto parse_flag;
1094
Ben Lindstromade03f62001-12-06 18:22:17 +00001095 case sPasswordAuthentication:
1096 intptr = &options->password_authentication;
1097 goto parse_flag;
1098
Damien Miller01ed2272008-11-05 16:20:46 +11001099 case sZeroKnowledgePasswordAuthentication:
1100 intptr = &options->zero_knowledge_password_authentication;
1101 goto parse_flag;
1102
Ben Lindstromade03f62001-12-06 18:22:17 +00001103 case sKbdInteractiveAuthentication:
1104 intptr = &options->kbd_interactive_authentication;
1105 goto parse_flag;
1106
1107 case sChallengeResponseAuthentication:
1108 intptr = &options->challenge_response_authentication;
1109 goto parse_flag;
1110
1111 case sPrintMotd:
1112 intptr = &options->print_motd;
1113 goto parse_flag;
1114
1115 case sPrintLastLog:
1116 intptr = &options->print_lastlog;
1117 goto parse_flag;
1118
1119 case sX11Forwarding:
1120 intptr = &options->x11_forwarding;
1121 goto parse_flag;
1122
1123 case sX11DisplayOffset:
1124 intptr = &options->x11_display_offset;
1125 goto parse_int;
1126
Damien Miller95c249f2002-02-05 12:11:34 +11001127 case sX11UseLocalhost:
1128 intptr = &options->x11_use_localhost;
1129 goto parse_flag;
1130
Ben Lindstromade03f62001-12-06 18:22:17 +00001131 case sXAuthLocation:
1132 charptr = &options->xauth_location;
1133 goto parse_filename;
1134
1135 case sStrictModes:
1136 intptr = &options->strict_modes;
1137 goto parse_flag;
1138
Damien Miller12c150e2003-12-17 16:31:10 +11001139 case sTCPKeepAlive:
1140 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +00001141 goto parse_flag;
1142
1143 case sEmptyPasswd:
1144 intptr = &options->permit_empty_passwd;
1145 goto parse_flag;
1146
Ben Lindstrom5d860f02002-08-01 01:28:38 +00001147 case sPermitUserEnvironment:
1148 intptr = &options->permit_user_env;
1149 goto parse_flag;
1150
Ben Lindstromade03f62001-12-06 18:22:17 +00001151 case sUseLogin:
1152 intptr = &options->use_login;
1153 goto parse_flag;
1154
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001155 case sCompression:
1156 intptr = &options->compression;
Damien Miller33322122011-06-20 14:43:11 +10001157 multistate_ptr = multistate_compression;
1158 goto parse_multistate;
Ben Lindstrom23e0f662002-06-21 01:09:47 +00001159
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001160 case sRekeyLimit:
1161 arg = strdelim(&cp);
1162 if (!arg || *arg == '\0')
1163 fatal("%.200s line %d: Missing argument.", filename,
1164 linenum);
1165 if (strcmp(arg, "default") == 0) {
1166 val64 = 0;
1167 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001168 if (scan_scaled(arg, &val64) == -1)
1169 fatal("%.200s line %d: Bad number '%s': %s",
1170 filename, linenum, arg, strerror(errno));
1171 /* check for too-large or too-small limits */
1172 if (val64 > UINT_MAX)
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001173 fatal("%.200s line %d: RekeyLimit too large",
1174 filename, linenum);
1175 if (val64 != 0 && val64 < 16)
1176 fatal("%.200s line %d: RekeyLimit too small",
1177 filename, linenum);
1178 }
1179 if (*activep && options->rekey_limit == -1)
1180 options->rekey_limit = (u_int32_t)val64;
1181 if (cp != NULL) { /* optional rekey interval present */
1182 if (strcmp(cp, "none") == 0) {
1183 (void)strdelim(&cp); /* discard */
1184 break;
1185 }
1186 intptr = &options->rekey_interval;
1187 goto parse_time;
1188 }
1189 break;
1190
Ben Lindstromade03f62001-12-06 18:22:17 +00001191 case sGatewayPorts:
1192 intptr = &options->gateway_ports;
Damien Miller33322122011-06-20 14:43:11 +10001193 multistate_ptr = multistate_gatewayports;
1194 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001195
Damien Miller3a961dc2003-06-03 10:25:48 +10001196 case sUseDNS:
1197 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +00001198 goto parse_flag;
1199
1200 case sLogFacility:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001201 log_facility_ptr = &options->log_facility;
Ben Lindstromade03f62001-12-06 18:22:17 +00001202 arg = strdelim(&cp);
1203 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001204 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001205 fatal("%.200s line %d: unsupported log facility '%s'",
1206 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001207 if (*log_facility_ptr == -1)
1208 *log_facility_ptr = (SyslogFacility) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001209 break;
1210
1211 case sLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001212 log_level_ptr = &options->log_level;
Ben Lindstromade03f62001-12-06 18:22:17 +00001213 arg = strdelim(&cp);
1214 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001215 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +00001216 fatal("%.200s line %d: unsupported log level '%s'",
1217 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001218 if (*log_level_ptr == -1)
1219 *log_level_ptr = (LogLevel) value;
Ben Lindstromade03f62001-12-06 18:22:17 +00001220 break;
1221
1222 case sAllowTcpForwarding:
1223 intptr = &options->allow_tcp_forwarding;
Damien Milleraa5b3f82012-12-03 09:50:54 +11001224 multistate_ptr = multistate_tcpfwd;
1225 goto parse_multistate;
Ben Lindstromade03f62001-12-06 18:22:17 +00001226
Damien Miller4f755cd2008-05-19 14:57:41 +10001227 case sAllowAgentForwarding:
1228 intptr = &options->allow_agent_forwarding;
1229 goto parse_flag;
1230
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001231 case sUsePrivilegeSeparation:
1232 intptr = &use_privsep;
Damien Miller69ff1df2011-06-23 08:30:03 +10001233 multistate_ptr = multistate_privsep;
1234 goto parse_multistate;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +00001235
Ben Lindstromade03f62001-12-06 18:22:17 +00001236 case sAllowUsers:
1237 while ((arg = strdelim(&cp)) && *arg != '\0') {
1238 if (options->num_allow_users >= MAX_ALLOW_USERS)
1239 fatal("%s line %d: too many allow users.",
1240 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001241 if (!*activep)
1242 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001243 options->allow_users[options->num_allow_users++] =
1244 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001245 }
1246 break;
1247
1248 case sDenyUsers:
1249 while ((arg = strdelim(&cp)) && *arg != '\0') {
1250 if (options->num_deny_users >= MAX_DENY_USERS)
Damien Miller4dec5d72006-08-05 11:38:40 +10001251 fatal("%s line %d: too many deny users.",
Ben Lindstromade03f62001-12-06 18:22:17 +00001252 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001253 if (!*activep)
1254 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001255 options->deny_users[options->num_deny_users++] =
1256 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001257 }
1258 break;
1259
1260 case sAllowGroups:
1261 while ((arg = strdelim(&cp)) && *arg != '\0') {
1262 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1263 fatal("%s line %d: too many allow groups.",
1264 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001265 if (!*activep)
1266 continue;
Ben Lindstrome1353632002-06-23 21:29:23 +00001267 options->allow_groups[options->num_allow_groups++] =
1268 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001269 }
1270 break;
1271
1272 case sDenyGroups:
1273 while ((arg = strdelim(&cp)) && *arg != '\0') {
1274 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1275 fatal("%s line %d: too many deny groups.",
1276 filename, linenum);
Damien Millerc24da772012-06-20 21:53:58 +10001277 if (!*activep)
1278 continue;
1279 options->deny_groups[options->num_deny_groups++] =
1280 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001281 }
1282 break;
1283
1284 case sCiphers:
1285 arg = strdelim(&cp);
1286 if (!arg || *arg == '\0')
1287 fatal("%s line %d: Missing argument.", filename, linenum);
1288 if (!ciphers_valid(arg))
1289 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1290 filename, linenum, arg ? arg : "<NONE>");
1291 if (options->ciphers == NULL)
1292 options->ciphers = xstrdup(arg);
1293 break;
1294
1295 case sMacs:
1296 arg = strdelim(&cp);
1297 if (!arg || *arg == '\0')
1298 fatal("%s line %d: Missing argument.", filename, linenum);
1299 if (!mac_valid(arg))
1300 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1301 filename, linenum, arg ? arg : "<NONE>");
1302 if (options->macs == NULL)
1303 options->macs = xstrdup(arg);
1304 break;
1305
Damien Millerd5f62bf2010-09-24 22:11:14 +10001306 case sKexAlgorithms:
1307 arg = strdelim(&cp);
1308 if (!arg || *arg == '\0')
1309 fatal("%s line %d: Missing argument.",
1310 filename, linenum);
1311 if (!kex_names_valid(arg))
1312 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1313 filename, linenum, arg ? arg : "<NONE>");
1314 if (options->kex_algorithms == NULL)
1315 options->kex_algorithms = xstrdup(arg);
1316 break;
1317
Ben Lindstromade03f62001-12-06 18:22:17 +00001318 case sProtocol:
1319 intptr = &options->protocol;
1320 arg = strdelim(&cp);
1321 if (!arg || *arg == '\0')
1322 fatal("%s line %d: Missing argument.", filename, linenum);
1323 value = proto_spec(arg);
1324 if (value == SSH_PROTO_UNKNOWN)
1325 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001326 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001327 if (*intptr == SSH_PROTO_UNKNOWN)
1328 *intptr = value;
1329 break;
1330
1331 case sSubsystem:
1332 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1333 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001334 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001335 }
1336 arg = strdelim(&cp);
1337 if (!arg || *arg == '\0')
1338 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001339 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001340 if (!*activep) {
1341 arg = strdelim(&cp);
1342 break;
1343 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001344 for (i = 0; i < options->num_subsystems; i++)
1345 if (strcmp(arg, options->subsystem_name[i]) == 0)
1346 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001347 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001348 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1349 arg = strdelim(&cp);
1350 if (!arg || *arg == '\0')
1351 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001352 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001353 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001354
1355 /* Collect arguments (separate to executable) */
1356 p = xstrdup(arg);
1357 len = strlen(p) + 1;
1358 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1359 len += 1 + strlen(arg);
1360 p = xrealloc(p, 1, len);
1361 strlcat(p, " ", len);
1362 strlcat(p, arg, len);
1363 }
1364 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001365 options->num_subsystems++;
1366 break;
1367
1368 case sMaxStartups:
1369 arg = strdelim(&cp);
1370 if (!arg || *arg == '\0')
1371 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001372 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001373 if ((n = sscanf(arg, "%d:%d:%d",
1374 &options->max_startups_begin,
1375 &options->max_startups_rate,
1376 &options->max_startups)) == 3) {
1377 if (options->max_startups_begin >
1378 options->max_startups ||
1379 options->max_startups_rate > 100 ||
1380 options->max_startups_rate < 1)
1381 fatal("%s line %d: Illegal MaxStartups spec.",
1382 filename, linenum);
1383 } else if (n != 1)
1384 fatal("%s line %d: Illegal MaxStartups spec.",
1385 filename, linenum);
1386 else
1387 options->max_startups = options->max_startups_begin;
1388 break;
1389
Darren Tucker89413db2004-05-24 10:36:23 +10001390 case sMaxAuthTries:
1391 intptr = &options->max_authtries;
1392 goto parse_int;
1393
Damien Miller7207f642008-05-19 15:34:50 +10001394 case sMaxSessions:
1395 intptr = &options->max_sessions;
1396 goto parse_int;
1397
Ben Lindstromade03f62001-12-06 18:22:17 +00001398 case sBanner:
1399 charptr = &options->banner;
1400 goto parse_filename;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001401
Ben Lindstromade03f62001-12-06 18:22:17 +00001402 /*
1403 * These options can contain %X options expanded at
1404 * connect time, so that you can specify paths like:
1405 *
1406 * AuthorizedKeysFile /etc/ssh_keys/%u
1407 */
1408 case sAuthorizedKeysFile:
Damien Millerd8478b62011-05-29 21:39:36 +10001409 if (*activep && options->num_authkeys_files == 0) {
1410 while ((arg = strdelim(&cp)) && *arg != '\0') {
1411 if (options->num_authkeys_files >=
1412 MAX_AUTHKEYS_FILES)
1413 fatal("%s line %d: "
1414 "too many authorized keys files.",
1415 filename, linenum);
1416 options->authorized_keys_files[
1417 options->num_authkeys_files++] =
1418 tilde_expand_filename(arg, getuid());
1419 }
1420 }
1421 return 0;
1422
Damien Miller30da3442010-05-10 11:58:03 +10001423 case sAuthorizedPrincipalsFile:
1424 charptr = &options->authorized_principals_file;
Damien Millerc4cb47b2010-03-22 05:52:26 +11001425 arg = strdelim(&cp);
1426 if (!arg || *arg == '\0')
1427 fatal("%s line %d: missing file name.",
1428 filename, linenum);
1429 if (*activep && *charptr == NULL) {
Damien Miller4a5f0d32010-03-22 05:53:04 +11001430 *charptr = tilde_expand_filename(arg, getuid());
Damien Millerc4cb47b2010-03-22 05:52:26 +11001431 /* increase optional counter */
1432 if (intptr != NULL)
1433 *intptr = *intptr + 1;
1434 }
1435 break;
Ben Lindstromade03f62001-12-06 18:22:17 +00001436
1437 case sClientAliveInterval:
1438 intptr = &options->client_alive_interval;
1439 goto parse_time;
1440
1441 case sClientAliveCountMax:
1442 intptr = &options->client_alive_count_max;
1443 goto parse_int;
1444
Darren Tucker46bc0752004-05-02 22:11:30 +10001445 case sAcceptEnv:
1446 while ((arg = strdelim(&cp)) && *arg != '\0') {
1447 if (strchr(arg, '=') != NULL)
1448 fatal("%s line %d: Invalid environment name.",
1449 filename, linenum);
1450 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1451 fatal("%s line %d: too many allow env.",
1452 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001453 if (!*activep)
Damien Millerc24da772012-06-20 21:53:58 +10001454 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001455 options->accept_env[options->num_accept_env++] =
1456 xstrdup(arg);
1457 }
1458 break;
1459
Damien Millerd27b9472005-12-13 19:29:02 +11001460 case sPermitTunnel:
1461 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001462 arg = strdelim(&cp);
1463 if (!arg || *arg == '\0')
1464 fatal("%s line %d: Missing yes/point-to-point/"
1465 "ethernet/no argument.", filename, linenum);
Darren Tuckere7140f22008-06-10 23:01:51 +10001466 value = -1;
1467 for (i = 0; tunmode_desc[i].val != -1; i++)
1468 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1469 value = tunmode_desc[i].val;
1470 break;
1471 }
1472 if (value == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001473 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1474 "no argument: %s", filename, linenum, arg);
1475 if (*intptr == -1)
1476 *intptr = value;
1477 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001478
Darren Tucker45150472006-07-12 22:34:17 +10001479 case sMatch:
1480 if (cmdline)
1481 fatal("Match directive not supported as a command-line "
1482 "option");
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001483 value = match_cfg_line(&cp, linenum, connectinfo);
Darren Tucker45150472006-07-12 22:34:17 +10001484 if (value < 0)
1485 fatal("%s line %d: Bad Match condition", filename,
1486 linenum);
1487 *activep = value;
1488 break;
1489
Damien Miller9b439df2006-07-24 14:04:00 +10001490 case sPermitOpen:
1491 arg = strdelim(&cp);
1492 if (!arg || *arg == '\0')
1493 fatal("%s line %d: missing PermitOpen specification",
1494 filename, linenum);
Damien Miller9fc6a562007-01-05 16:29:02 +11001495 n = options->num_permitted_opens; /* modified later */
Damien Miller9b439df2006-07-24 14:04:00 +10001496 if (strcmp(arg, "any") == 0) {
Damien Miller9fc6a562007-01-05 16:29:02 +11001497 if (*activep && n == -1) {
Damien Miller9b439df2006-07-24 14:04:00 +10001498 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001499 options->num_permitted_opens = 0;
1500 }
Damien Miller9b439df2006-07-24 14:04:00 +10001501 break;
1502 }
Damien Millerc6081482012-04-22 11:18:53 +10001503 if (strcmp(arg, "none") == 0) {
1504 if (*activep && n == -1) {
Damien Millerc6081482012-04-22 11:18:53 +10001505 options->num_permitted_opens = 1;
1506 channel_disable_adm_local_opens();
1507 }
1508 break;
1509 }
Damien Millera29b95e2007-01-05 16:28:36 +11001510 if (*activep && n == -1)
1511 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001512 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1513 p = hpdelim(&arg);
1514 if (p == NULL)
1515 fatal("%s line %d: missing host in PermitOpen",
1516 filename, linenum);
1517 p = cleanhostname(p);
Darren Tucker1338b9e2011-10-02 18:57:35 +11001518 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
Damien Millera765cf42006-07-24 14:08:13 +10001519 fatal("%s line %d: bad port number in "
1520 "PermitOpen", filename, linenum);
Damien Millera29b95e2007-01-05 16:28:36 +11001521 if (*activep && n == -1)
Damien Millera765cf42006-07-24 14:08:13 +10001522 options->num_permitted_opens =
1523 channel_add_adm_permitted_opens(p, port);
Damien Millera765cf42006-07-24 14:08:13 +10001524 }
Damien Miller9b439df2006-07-24 14:04:00 +10001525 break;
1526
Damien Millere2754432006-07-24 14:06:47 +10001527 case sForceCommand:
1528 if (cp == NULL)
1529 fatal("%.200s line %d: Missing argument.", filename,
1530 linenum);
1531 len = strspn(cp, WHITESPACE);
1532 if (*activep && options->adm_forced_command == NULL)
1533 options->adm_forced_command = xstrdup(cp + len);
1534 return 0;
1535
Damien Millerd8cb1f12008-02-10 22:40:12 +11001536 case sChrootDirectory:
1537 charptr = &options->chroot_directory;
Damien Miller54e37732008-02-10 22:48:55 +11001538
1539 arg = strdelim(&cp);
1540 if (!arg || *arg == '\0')
1541 fatal("%s line %d: missing file name.",
1542 filename, linenum);
1543 if (*activep && *charptr == NULL)
1544 *charptr = xstrdup(arg);
1545 break;
Damien Millerd8cb1f12008-02-10 22:40:12 +11001546
Damien Miller1aed65e2010-03-04 21:53:35 +11001547 case sTrustedUserCAKeys:
1548 charptr = &options->trusted_user_ca_keys;
1549 goto parse_filename;
1550
1551 case sRevokedKeys:
1552 charptr = &options->revoked_keys_file;
1553 goto parse_filename;
1554
Damien Miller0dac6fb2010-11-20 15:19:38 +11001555 case sIPQoS:
1556 arg = strdelim(&cp);
1557 if ((value = parse_ipqos(arg)) == -1)
1558 fatal("%s line %d: Bad IPQoS value: %s",
1559 filename, linenum, arg);
1560 arg = strdelim(&cp);
1561 if (arg == NULL)
1562 value2 = value;
1563 else if ((value2 = parse_ipqos(arg)) == -1)
1564 fatal("%s line %d: Bad IPQoS value: %s",
1565 filename, linenum, arg);
1566 if (*activep) {
1567 options->ip_qos_interactive = value;
1568 options->ip_qos_bulk = value2;
1569 }
1570 break;
1571
Damien Miller23528812012-04-22 11:24:43 +10001572 case sVersionAddendum:
1573 if (cp == NULL)
1574 fatal("%.200s line %d: Missing argument.", filename,
1575 linenum);
1576 len = strspn(cp, WHITESPACE);
1577 if (*activep && options->version_addendum == NULL) {
1578 if (strcasecmp(cp + len, "none") == 0)
1579 options->version_addendum = xstrdup("");
1580 else if (strchr(cp + len, '\r') != NULL)
1581 fatal("%.200s line %d: Invalid argument",
1582 filename, linenum);
1583 else
1584 options->version_addendum = xstrdup(cp + len);
1585 }
1586 return 0;
1587
Damien Miller09d3e122012-10-31 08:58:58 +11001588 case sAuthorizedKeysCommand:
1589 len = strspn(cp, WHITESPACE);
1590 if (*activep && options->authorized_keys_command == NULL) {
1591 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1592 fatal("%.200s line %d: AuthorizedKeysCommand "
1593 "must be an absolute path",
1594 filename, linenum);
1595 options->authorized_keys_command = xstrdup(cp + len);
1596 }
1597 return 0;
1598
1599 case sAuthorizedKeysCommandUser:
1600 charptr = &options->authorized_keys_command_user;
1601
1602 arg = strdelim(&cp);
1603 if (*activep && *charptr == NULL)
1604 *charptr = xstrdup(arg);
1605 break;
1606
Damien Millera6e3f012012-11-04 23:21:40 +11001607 case sAuthenticationMethods:
1608 if (*activep && options->num_auth_methods == 0) {
1609 while ((arg = strdelim(&cp)) && *arg != '\0') {
1610 if (options->num_auth_methods >=
1611 MAX_AUTH_METHODS)
1612 fatal("%s line %d: "
1613 "too many authentication methods.",
1614 filename, linenum);
1615 if (auth2_methods_valid(arg, 0) != 0)
1616 fatal("%s line %d: invalid "
1617 "authentication method list.",
1618 filename, linenum);
1619 options->auth_methods[
1620 options->num_auth_methods++] = xstrdup(arg);
1621 }
1622 }
1623 return 0;
1624
Ben Lindstromade03f62001-12-06 18:22:17 +00001625 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001626 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001627 filename, linenum, arg);
1628 while (arg)
1629 arg = strdelim(&cp);
1630 break;
1631
Damien Millerf9b3feb2003-05-16 11:38:32 +10001632 case sUnsupported:
1633 logit("%s line %d: Unsupported option %s",
1634 filename, linenum, arg);
1635 while (arg)
1636 arg = strdelim(&cp);
1637 break;
1638
Ben Lindstromade03f62001-12-06 18:22:17 +00001639 default:
1640 fatal("%s line %d: Missing handler for opcode %s (%d)",
1641 filename, linenum, arg, opcode);
1642 }
1643 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1644 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1645 filename, linenum, arg);
1646 return 0;
1647}
1648
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001649/* Reads the server configuration file. */
1650
Damien Miller4af51302000-04-16 11:18:38 +10001651void
Darren Tucker645ab752004-06-25 13:33:20 +10001652load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001653{
Damien Miller46cb75a2012-07-31 12:22:37 +10001654 char line[4096], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001655 FILE *f;
Damien Miller46cb75a2012-07-31 12:22:37 +10001656 int lineno = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001657
Darren Tucker645ab752004-06-25 13:33:20 +10001658 debug2("%s: filename %s", __func__, filename);
1659 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001660 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001661 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001662 }
Darren Tucker645ab752004-06-25 13:33:20 +10001663 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001664 while (fgets(line, sizeof(line), f)) {
Damien Miller46cb75a2012-07-31 12:22:37 +10001665 lineno++;
1666 if (strlen(line) == sizeof(line) - 1)
1667 fatal("%s line %d too long", filename, lineno);
Darren Tucker645ab752004-06-25 13:33:20 +10001668 /*
1669 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001670 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001671 * line numbers later for error messages
1672 */
1673 if ((cp = strchr(line, '#')) != NULL)
1674 memcpy(cp, "\n", 2);
1675 cp = line + strspn(line, " \t\r");
1676
1677 buffer_append(conf, cp, strlen(cp));
1678 }
1679 buffer_append(conf, "\0", 1);
1680 fclose(f);
1681 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1682}
1683
1684void
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001685parse_server_match_config(ServerOptions *options,
1686 struct connection_info *connectinfo)
Darren Tucker645ab752004-06-25 13:33:20 +10001687{
Darren Tucker45150472006-07-12 22:34:17 +10001688 ServerOptions mo;
1689
1690 initialize_server_options(&mo);
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001691 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
Darren Tucker1629c072007-02-19 22:25:37 +11001692 copy_set_server_options(options, &mo, 0);
Darren Tucker45150472006-07-12 22:34:17 +10001693}
1694
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001695int parse_server_match_testspec(struct connection_info *ci, char *spec)
1696{
1697 char *p;
1698
1699 while ((p = strsep(&spec, ",")) && *p != '\0') {
1700 if (strncmp(p, "addr=", 5) == 0) {
1701 ci->address = xstrdup(p + 5);
1702 } else if (strncmp(p, "host=", 5) == 0) {
1703 ci->host = xstrdup(p + 5);
1704 } else if (strncmp(p, "user=", 5) == 0) {
1705 ci->user = xstrdup(p + 5);
1706 } else if (strncmp(p, "laddr=", 6) == 0) {
1707 ci->laddress = xstrdup(p + 6);
1708 } else if (strncmp(p, "lport=", 6) == 0) {
1709 ci->lport = a2port(p + 6);
1710 if (ci->lport == -1) {
1711 fprintf(stderr, "Invalid port '%s' in test mode"
1712 " specification %s\n", p+6, p);
1713 return -1;
1714 }
1715 } else {
1716 fprintf(stderr, "Invalid test mode specification %s\n",
1717 p);
1718 return -1;
1719 }
1720 }
1721 return 0;
1722}
1723
1724/*
1725 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1726 * empty spec.
1727 */
1728int server_match_spec_complete(struct connection_info *ci)
1729{
1730 if (ci->user && ci->host && ci->address)
1731 return 1; /* complete */
1732 if (!ci->user && !ci->host && !ci->address)
1733 return -1; /* empty */
1734 return 0; /* partial */
1735}
1736
Darren Tucker1629c072007-02-19 22:25:37 +11001737/* Helper macros */
1738#define M_CP_INTOPT(n) do {\
1739 if (src->n != -1) \
1740 dst->n = src->n; \
1741} while (0)
1742#define M_CP_STROPT(n) do {\
1743 if (src->n != NULL) { \
Darren Tuckera627d422013-06-02 07:31:17 +10001744 free(dst->n); \
Darren Tucker1629c072007-02-19 22:25:37 +11001745 dst->n = src->n; \
1746 } \
1747} while(0)
Damien Millerd8478b62011-05-29 21:39:36 +10001748#define M_CP_STRARRAYOPT(n, num_n) do {\
1749 if (src->num_n != 0) { \
1750 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1751 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1752 } \
1753} while(0)
Darren Tucker1629c072007-02-19 22:25:37 +11001754
1755/*
1756 * Copy any supported values that are set.
1757 *
Darren Tucker3b59dfa2009-06-21 17:54:47 +10001758 * If the preauth flag is set, we do not bother copying the string or
Darren Tucker1629c072007-02-19 22:25:37 +11001759 * array values that are not used pre-authentication, because any that we
1760 * do use must be explictly sent in mm_getpwnamallow().
1761 */
Darren Tucker45150472006-07-12 22:34:17 +10001762void
Darren Tucker1629c072007-02-19 22:25:37 +11001763copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Darren Tucker45150472006-07-12 22:34:17 +10001764{
Darren Tucker1629c072007-02-19 22:25:37 +11001765 M_CP_INTOPT(password_authentication);
1766 M_CP_INTOPT(gss_authentication);
1767 M_CP_INTOPT(rsa_authentication);
1768 M_CP_INTOPT(pubkey_authentication);
1769 M_CP_INTOPT(kerberos_authentication);
1770 M_CP_INTOPT(hostbased_authentication);
Damien Millerab6de352010-06-26 09:38:45 +10001771 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Darren Tucker1629c072007-02-19 22:25:37 +11001772 M_CP_INTOPT(kbd_interactive_authentication);
Damien Miller01ed2272008-11-05 16:20:46 +11001773 M_CP_INTOPT(zero_knowledge_password_authentication);
Damien Miller09d3e122012-10-31 08:58:58 +11001774 M_CP_STROPT(authorized_keys_command);
1775 M_CP_STROPT(authorized_keys_command_user);
Darren Tucker15f94272008-01-01 20:36:56 +11001776 M_CP_INTOPT(permit_root_login);
Damien Miller51bde602008-11-03 19:23:10 +11001777 M_CP_INTOPT(permit_empty_passwd);
Darren Tucker1629c072007-02-19 22:25:37 +11001778
1779 M_CP_INTOPT(allow_tcp_forwarding);
Damien Miller4f755cd2008-05-19 14:57:41 +10001780 M_CP_INTOPT(allow_agent_forwarding);
Damien Millerab6de352010-06-26 09:38:45 +10001781 M_CP_INTOPT(permit_tun);
Darren Tucker1629c072007-02-19 22:25:37 +11001782 M_CP_INTOPT(gateway_ports);
1783 M_CP_INTOPT(x11_display_offset);
1784 M_CP_INTOPT(x11_forwarding);
1785 M_CP_INTOPT(x11_use_localhost);
Damien Miller7207f642008-05-19 15:34:50 +10001786 M_CP_INTOPT(max_sessions);
Damien Miller307c1d12008-06-16 07:56:20 +10001787 M_CP_INTOPT(max_authtries);
Damien Miller0dac6fb2010-11-20 15:19:38 +11001788 M_CP_INTOPT(ip_qos_interactive);
1789 M_CP_INTOPT(ip_qos_bulk);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10001790 M_CP_INTOPT(rekey_limit);
1791 M_CP_INTOPT(rekey_interval);
Darren Tucker1629c072007-02-19 22:25:37 +11001792
Damien Millerf2e407e2011-05-20 19:04:14 +10001793 /* See comment in servconf.h */
1794 COPY_MATCH_STRING_OPTS();
Damien Miller5d74e582011-05-20 19:03:31 +10001795
Damien Millerc2411902011-05-20 19:03:49 +10001796 /*
1797 * The only things that should be below this point are string options
1798 * which are only used after authentication.
1799 */
Damien Miller5d74e582011-05-20 19:03:31 +10001800 if (preauth)
1801 return;
Damien Millerd8478b62011-05-29 21:39:36 +10001802
Damien Miller5d74e582011-05-20 19:03:31 +10001803 M_CP_STROPT(adm_forced_command);
1804 M_CP_STROPT(chroot_directory);
Darren Tucker45150472006-07-12 22:34:17 +10001805}
1806
Darren Tucker1629c072007-02-19 22:25:37 +11001807#undef M_CP_INTOPT
1808#undef M_CP_STROPT
Damien Millerd8478b62011-05-29 21:39:36 +10001809#undef M_CP_STRARRAYOPT
Darren Tucker1629c072007-02-19 22:25:37 +11001810
Darren Tucker45150472006-07-12 22:34:17 +10001811void
1812parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001813 struct connection_info *connectinfo)
Darren Tucker45150472006-07-12 22:34:17 +10001814{
1815 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001816 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001817
1818 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1819
Darren Tucker9fbac712004-08-12 22:41:44 +10001820 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001821 active = connectinfo ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001822 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001823 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001824 if (process_server_config_line(options, cp, filename,
Darren Tuckerfbcf8272012-05-19 19:37:01 +10001825 linenum++, &active, connectinfo) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001826 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001827 }
Darren Tuckera627d422013-06-02 07:31:17 +10001828 free(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001829 if (bad_options > 0)
1830 fatal("%s: terminating, %d bad configuration options",
1831 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001832}
Darren Tuckere7140f22008-06-10 23:01:51 +10001833
1834static const char *
Damien Miller82c55872011-06-23 08:20:30 +10001835fmt_multistate_int(int val, const struct multistate *m)
1836{
1837 u_int i;
1838
1839 for (i = 0; m[i].key != NULL; i++) {
1840 if (m[i].value == val)
1841 return m[i].key;
1842 }
1843 return "UNKNOWN";
1844}
1845
1846static const char *
Darren Tuckere7140f22008-06-10 23:01:51 +10001847fmt_intarg(ServerOpCodes code, int val)
1848{
Damien Miller82c55872011-06-23 08:20:30 +10001849 if (val == -1)
1850 return "unset";
1851 switch (code) {
1852 case sAddressFamily:
1853 return fmt_multistate_int(val, multistate_addressfamily);
1854 case sPermitRootLogin:
1855 return fmt_multistate_int(val, multistate_permitrootlogin);
1856 case sGatewayPorts:
1857 return fmt_multistate_int(val, multistate_gatewayports);
1858 case sCompression:
1859 return fmt_multistate_int(val, multistate_compression);
Damien Miller69ff1df2011-06-23 08:30:03 +10001860 case sUsePrivilegeSeparation:
1861 return fmt_multistate_int(val, multistate_privsep);
Damien Milleraa5b3f82012-12-03 09:50:54 +11001862 case sAllowTcpForwarding:
1863 return fmt_multistate_int(val, multistate_tcpfwd);
Damien Miller82c55872011-06-23 08:20:30 +10001864 case sProtocol:
Darren Tuckere7140f22008-06-10 23:01:51 +10001865 switch (val) {
1866 case SSH_PROTO_1:
1867 return "1";
1868 case SSH_PROTO_2:
1869 return "2";
1870 case (SSH_PROTO_1|SSH_PROTO_2):
1871 return "2,1";
1872 default:
1873 return "UNKNOWN";
1874 }
Damien Miller82c55872011-06-23 08:20:30 +10001875 default:
1876 switch (val) {
1877 case 0:
1878 return "no";
1879 case 1:
1880 return "yes";
1881 default:
1882 return "UNKNOWN";
1883 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001884 }
Darren Tuckere7140f22008-06-10 23:01:51 +10001885}
1886
1887static const char *
1888lookup_opcode_name(ServerOpCodes code)
1889{
1890 u_int i;
1891
1892 for (i = 0; keywords[i].name != NULL; i++)
1893 if (keywords[i].opcode == code)
1894 return(keywords[i].name);
1895 return "UNKNOWN";
1896}
1897
1898static void
1899dump_cfg_int(ServerOpCodes code, int val)
1900{
1901 printf("%s %d\n", lookup_opcode_name(code), val);
1902}
1903
1904static void
1905dump_cfg_fmtint(ServerOpCodes code, int val)
1906{
1907 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1908}
1909
1910static void
1911dump_cfg_string(ServerOpCodes code, const char *val)
1912{
1913 if (val == NULL)
1914 return;
1915 printf("%s %s\n", lookup_opcode_name(code), val);
1916}
1917
1918static void
1919dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1920{
1921 u_int i;
1922
1923 for (i = 0; i < count; i++)
Damien Millerd8478b62011-05-29 21:39:36 +10001924 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1925}
1926
1927static void
1928dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1929{
1930 u_int i;
1931
1932 printf("%s", lookup_opcode_name(code));
1933 for (i = 0; i < count; i++)
1934 printf(" %s", vals[i]);
1935 printf("\n");
Darren Tuckere7140f22008-06-10 23:01:51 +10001936}
1937
1938void
1939dump_config(ServerOptions *o)
1940{
1941 u_int i;
1942 int ret;
1943 struct addrinfo *ai;
1944 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1945
1946 /* these are usually at the top of the config */
1947 for (i = 0; i < o->num_ports; i++)
1948 printf("port %d\n", o->ports[i]);
1949 dump_cfg_fmtint(sProtocol, o->protocol);
1950 dump_cfg_fmtint(sAddressFamily, o->address_family);
1951
1952 /* ListenAddress must be after Port */
1953 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1954 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1955 sizeof(addr), port, sizeof(port),
1956 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1957 error("getnameinfo failed: %.100s",
1958 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1959 strerror(errno));
1960 } else {
1961 if (ai->ai_family == AF_INET6)
1962 printf("listenaddress [%s]:%s\n", addr, port);
1963 else
1964 printf("listenaddress %s:%s\n", addr, port);
1965 }
1966 }
1967
1968 /* integer arguments */
Damien Miller212f0b02008-07-23 17:42:29 +10001969#ifdef USE_PAM
1970 dump_cfg_int(sUsePAM, o->use_pam);
1971#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10001972 dump_cfg_int(sServerKeyBits, o->server_key_bits);
1973 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1974 dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1975 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1976 dump_cfg_int(sMaxAuthTries, o->max_authtries);
Damien Miller7fc5c0f2008-11-05 16:12:11 +11001977 dump_cfg_int(sMaxSessions, o->max_sessions);
Darren Tuckere7140f22008-06-10 23:01:51 +10001978 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1979 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1980
1981 /* formatted integer arguments */
1982 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1983 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1984 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1985 dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1986 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1987 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1988 o->hostbased_uses_name_from_packet_only);
1989 dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1990 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
Damien Miller6ef430d2008-07-23 17:40:04 +10001991#ifdef KRB5
Darren Tuckere7140f22008-06-10 23:01:51 +10001992 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1993 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1994 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
Damien Miller6ef430d2008-07-23 17:40:04 +10001995# ifdef USE_AFS
Darren Tuckere7140f22008-06-10 23:01:51 +10001996 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
Damien Miller6ef430d2008-07-23 17:40:04 +10001997# endif
1998#endif
1999#ifdef GSSAPI
Darren Tuckere7140f22008-06-10 23:01:51 +10002000 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2001 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Damien Miller6ef430d2008-07-23 17:40:04 +10002002#endif
Damien Miller01ed2272008-11-05 16:20:46 +11002003#ifdef JPAKE
2004 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
2005 o->zero_knowledge_password_authentication);
2006#endif
Darren Tuckere7140f22008-06-10 23:01:51 +10002007 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2008 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2009 o->kbd_interactive_authentication);
2010 dump_cfg_fmtint(sChallengeResponseAuthentication,
2011 o->challenge_response_authentication);
2012 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2013 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2014 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2015 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
2016 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2017 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2018 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2019 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2020 dump_cfg_fmtint(sUseLogin, o->use_login);
2021 dump_cfg_fmtint(sCompression, o->compression);
2022 dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2023 dump_cfg_fmtint(sUseDNS, o->use_dns);
2024 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2025 dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2026
2027 /* string arguments */
2028 dump_cfg_string(sPidFile, o->pid_file);
2029 dump_cfg_string(sXAuthLocation, o->xauth_location);
2030 dump_cfg_string(sCiphers, o->ciphers);
2031 dump_cfg_string(sMacs, o->macs);
2032 dump_cfg_string(sBanner, o->banner);
Darren Tuckere7140f22008-06-10 23:01:51 +10002033 dump_cfg_string(sForceCommand, o->adm_forced_command);
Darren Tuckerd3300452010-01-10 19:26:43 +11002034 dump_cfg_string(sChrootDirectory, o->chroot_directory);
Damien Miller1aed65e2010-03-04 21:53:35 +11002035 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2036 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
Damien Miller30da3442010-05-10 11:58:03 +10002037 dump_cfg_string(sAuthorizedPrincipalsFile,
2038 o->authorized_principals_file);
Damien Miller23528812012-04-22 11:24:43 +10002039 dump_cfg_string(sVersionAddendum, o->version_addendum);
Damien Miller09d3e122012-10-31 08:58:58 +11002040 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2041 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Damien Miller85b45e02013-07-20 13:21:52 +10002042 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Darren Tuckere7140f22008-06-10 23:01:51 +10002043
2044 /* string arguments requiring a lookup */
2045 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2046 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2047
2048 /* string array arguments */
Damien Millerd8478b62011-05-29 21:39:36 +10002049 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2050 o->authorized_keys_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002051 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2052 o->host_key_files);
Damien Miller0a80ca12010-02-27 07:55:05 +11002053 dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2054 o->host_cert_files);
Darren Tuckere7140f22008-06-10 23:01:51 +10002055 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2056 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2057 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2058 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2059 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
Damien Millera6e3f012012-11-04 23:21:40 +11002060 dump_cfg_strarray_oneline(sAuthenticationMethods,
2061 o->num_auth_methods, o->auth_methods);
Darren Tuckere7140f22008-06-10 23:01:51 +10002062
2063 /* other arguments */
2064 for (i = 0; i < o->num_subsystems; i++)
2065 printf("subsystem %s %s\n", o->subsystem_name[i],
2066 o->subsystem_args[i]);
2067
2068 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2069 o->max_startups_rate, o->max_startups);
2070
2071 for (i = 0; tunmode_desc[i].val != -1; i++)
2072 if (tunmode_desc[i].val == o->permit_tun) {
2073 s = tunmode_desc[i].text;
2074 break;
2075 }
2076 dump_cfg_string(sPermitTunnel, s);
2077
Damien Miller91475862011-05-05 14:14:34 +10002078 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2079 printf("%s\n", iptos2str(o->ip_qos_bulk));
Damien Miller0dac6fb2010-11-20 15:19:38 +11002080
Damien Millera6d6c1f2013-08-21 02:40:01 +10002081 printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2082 o->rekey_interval);
Darren Tucker5f96f3b2013-05-16 20:29:28 +10002083
Darren Tuckere7140f22008-06-10 23:01:51 +10002084 channel_print_adm_permitted_opens();
Darren Tuckere7140f22008-06-10 23:01:51 +10002085}