blob: dca9508ab48c3ed2034b0cab85cbf6395eb956e5 [file] [log] [blame]
Damien Millere3476ed2006-07-24 14:13:33 +10001/* $OpenBSD: servconf.c,v 1.160 2006/07/22 20:48:23 stevesk Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002/*
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10005 *
Damien Millere4340be2000-09-16 13:29:08 +11006 * As far as I am concerned, the code I have written for this software
7 * can be used freely for any purpose. Any derived versions of this
8 * software must be clearly marked as such, and if the derived work is
9 * incompatible with the protocol description in the RFC file, it must be
10 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110011 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100012
13#include "includes.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
Damien Millere3b60b52006-07-10 21:08:03 +100015#include <sys/types.h>
16#include <sys/socket.h>
17
Damien Millerb8fe89c2006-07-24 14:51:00 +100018#include <netdb.h>
Damien Millere3476ed2006-07-24 14:13:33 +100019#include <string.h>
Damien Millere6b3b612006-07-24 14:01:23 +100020#include <unistd.h>
Damien Millerbe43ebf2006-07-24 13:51:51 +100021
Damien Millerd4a8b7e1999-10-27 13:42:43 +100022#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000023#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024#include "servconf.h"
25#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100026#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000027#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000028#include "misc.h"
29#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000030#include "kex.h"
31#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100032#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100033#include "channels.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000034
Ben Lindstrombba81212001-06-25 05:01:22 +000035static void add_listen_addr(ServerOptions *, char *, u_short);
36static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110037
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000038/* Use of privilege separation or not */
39extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100040extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041
Damien Millerd4a8b7e1999-10-27 13:42:43 +100042/* Initializes the server options to their default values. */
43
Damien Miller4af51302000-04-16 11:18:38 +100044void
Damien Miller95def091999-11-25 00:26:21 +110045initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046{
Damien Miller95def091999-11-25 00:26:21 +110047 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110048
49 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100050 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110051
52 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110053 options->num_ports = 0;
54 options->ports_from_cmdline = 0;
55 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110056 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110057 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100058 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110059 options->server_key_bits = -1;
60 options->login_grace_time = -1;
61 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000062 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110063 options->ignore_rhosts = -1;
64 options->ignore_user_known_hosts = -1;
65 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000066 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110067 options->x11_forwarding = -1;
68 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110069 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100070 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110071 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110072 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110073 options->log_facility = SYSLOG_FACILITY_NOT_SET;
74 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110075 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000076 options->hostbased_authentication = -1;
77 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110078 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110079 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110080 options->kerberos_authentication = -1;
81 options->kerberos_or_local_passwd = -1;
82 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +110083 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +100084 options->gss_authentication=-1;
85 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +110086 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110087 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000088 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110089 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +000090 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +110091 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +000092 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110093 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110094 options->num_allow_users = 0;
95 options->num_deny_users = 0;
96 options->num_allow_groups = 0;
97 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100098 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000099 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000100 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000101 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000102 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000103 options->max_startups_begin = -1;
104 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000105 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000106 options->max_authtries = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000107 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000108 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000109 options->client_alive_interval = -1;
110 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000111 options->authorized_keys_file = NULL;
112 options->authorized_keys_file2 = NULL;
Darren Tucker46bc0752004-05-02 22:11:30 +1000113 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100114 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000115 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000116 options->adm_forced_command = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000117}
118
Damien Miller4af51302000-04-16 11:18:38 +1000119void
Damien Miller95def091999-11-25 00:26:21 +1100120fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000121{
Damien Miller726273e2001-11-12 11:40:11 +1100122 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000123 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000124 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100125
126 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100127 if (options->protocol == SSH_PROTO_UNKNOWN)
128 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
129 if (options->num_host_key_files == 0) {
130 /* fill default hostkeys for protocols */
131 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100132 options->host_key_files[options->num_host_key_files++] =
133 _PATH_HOST_KEY_FILE;
134 if (options->protocol & SSH_PROTO_2) {
135 options->host_key_files[options->num_host_key_files++] =
136 _PATH_HOST_RSA_KEY_FILE;
137 options->host_key_files[options->num_host_key_files++] =
138 _PATH_HOST_DSA_KEY_FILE;
139 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100140 }
Damien Miller34132e52000-01-14 15:45:46 +1100141 if (options->num_ports == 0)
142 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
143 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000144 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000145 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000146 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100147 if (options->server_key_bits == -1)
148 options->server_key_bits = 768;
149 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000150 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100151 if (options->key_regeneration_time == -1)
152 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000153 if (options->permit_root_login == PERMIT_NOT_SET)
154 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100155 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100156 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->ignore_user_known_hosts == -1)
158 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100159 if (options->print_motd == -1)
160 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000161 if (options->print_lastlog == -1)
162 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100163 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100164 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100166 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100167 if (options->x11_use_localhost == -1)
168 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000169 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000170 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->strict_modes == -1)
172 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100173 if (options->tcp_keep_alive == -1)
174 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100175 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100176 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100177 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000178 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100180 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000181 if (options->hostbased_authentication == -1)
182 options->hostbased_authentication = 0;
183 if (options->hostbased_uses_name_from_packet_only == -1)
184 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->rsa_authentication == -1)
186 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100187 if (options->pubkey_authentication == -1)
188 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100189 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000190 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->kerberos_or_local_passwd == -1)
192 options->kerberos_or_local_passwd = 1;
193 if (options->kerberos_ticket_cleanup == -1)
194 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100195 if (options->kerberos_get_afs_token == -1)
196 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000197 if (options->gss_authentication == -1)
198 options->gss_authentication = 0;
199 if (options->gss_cleanup_creds == -1)
200 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->password_authentication == -1)
202 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100203 if (options->kbd_interactive_authentication == -1)
204 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000205 if (options->challenge_response_authentication == -1)
206 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100208 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000209 if (options->permit_user_env == -1)
210 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100211 if (options->use_login == -1)
212 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000213 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000214 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100215 if (options->allow_tcp_forwarding == -1)
216 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000217 if (options->gateway_ports == -1)
218 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000219 if (options->max_startups == -1)
220 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000221 if (options->max_startups_rate == -1)
222 options->max_startups_rate = 100; /* 100% */
223 if (options->max_startups_begin == -1)
224 options->max_startups_begin = options->max_startups;
Darren Tucker89413db2004-05-24 10:36:23 +1000225 if (options->max_authtries == -1)
226 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000227 if (options->use_dns == -1)
228 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000229 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100230 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000231 if (options->client_alive_count_max == -1)
232 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100233 if (options->authorized_keys_file2 == NULL) {
234 /* authorized_keys_file2 falls back to authorized_keys_file */
235 if (options->authorized_keys_file != NULL)
236 options->authorized_keys_file2 = options->authorized_keys_file;
237 else
238 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
239 }
240 if (options->authorized_keys_file == NULL)
241 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Damien Millerd27b9472005-12-13 19:29:02 +1100242 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100243 options->permit_tun = SSH_TUNMODE_NO;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000244
Ben Lindstromfb62a692002-06-06 19:47:11 +0000245 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000246 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000247 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000248
Tim Rice40017b02002-07-14 13:36:49 -0700249#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000250 if (use_privsep && options->compression == 1) {
251 error("This platform does not support both privilege "
252 "separation and compression");
253 error("Compression disabled");
254 options->compression = 0;
255 }
256#endif
257
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000258}
259
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100261typedef enum {
262 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100263 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000264 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100265 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100266 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
267 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000268 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100269 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100270 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000271 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100272 sPasswordAuthentication, sKbdInteractiveAuthentication,
273 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000274 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100275 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100276 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000277 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100278 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000279 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000280 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
281 sMaxStartups, sMaxAuthTries,
Damien Miller3a961dc2003-06-03 10:25:48 +1000282 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100283 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000284 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Damien Millerd27b9472005-12-13 19:29:02 +1100285 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millere2754432006-07-24 14:06:47 +1000286 sMatch, sPermitOpen, sForceCommand,
Ben Lindstromc7431342002-03-22 03:11:49 +0000287 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000288 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000289} ServerOpCodes;
290
Darren Tucker45150472006-07-12 22:34:17 +1000291#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
292#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
293#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
294
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000295/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100296static struct {
297 const char *name;
298 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000299 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100300} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100301 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000302#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000303 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000304#else
Darren Tucker45150472006-07-12 22:34:17 +1000305 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000306#endif
Darren Tucker45150472006-07-12 22:34:17 +1000307 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100308 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000309 { "port", sPort, SSHCFG_GLOBAL },
310 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
311 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
312 { "pidfile", sPidFile, SSHCFG_GLOBAL },
313 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
314 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
315 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
316 { "permitrootlogin", sPermitRootLogin, SSHCFG_GLOBAL },
317 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
318 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
319 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
320 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_GLOBAL },
321 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_GLOBAL },
322 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
323 { "rsaauthentication", sRSAAuthentication, SSHCFG_GLOBAL },
324 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL },
325 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000326#ifdef KRB5
Darren Tucker45150472006-07-12 22:34:17 +1000327 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_GLOBAL },
328 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
329 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100330#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000331 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000332#else
Darren Tucker45150472006-07-12 22:34:17 +1000333 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100334#endif
335#else
Darren Tucker45150472006-07-12 22:34:17 +1000336 { "kerberosauthentication", sUnsupported, SSHCFG_GLOBAL },
337 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
338 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
339 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000340#endif
Darren Tucker45150472006-07-12 22:34:17 +1000341 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
342 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000343#ifdef GSSAPI
Darren Tucker45150472006-07-12 22:34:17 +1000344 { "gssapiauthentication", sGssAuthentication, SSHCFG_GLOBAL },
345 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000346#else
Darren Tucker45150472006-07-12 22:34:17 +1000347 { "gssapiauthentication", sUnsupported, SSHCFG_GLOBAL },
348 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000349#endif
Darren Tucker45150472006-07-12 22:34:17 +1000350 { "passwordauthentication", sPasswordAuthentication, SSHCFG_GLOBAL },
351 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_GLOBAL },
352 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
353 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
354 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
355 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
356 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
357 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
358 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
359 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
360 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000361 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
362 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
363 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000364 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
365 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
366 { "permitemptypasswords", sEmptyPasswd, SSHCFG_GLOBAL },
367 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
368 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
369 { "compression", sCompression, SSHCFG_GLOBAL },
370 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
371 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
372 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
373 { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
374 { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
375 { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
376 { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
377 { "ciphers", sCiphers, SSHCFG_GLOBAL },
378 { "macs", sMacs, SSHCFG_GLOBAL },
379 { "protocol", sProtocol, SSHCFG_GLOBAL },
380 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
381 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
382 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
383 { "maxauthtries", sMaxAuthTries, SSHCFG_GLOBAL },
384 { "banner", sBanner, SSHCFG_GLOBAL },
385 { "usedns", sUseDNS, SSHCFG_GLOBAL },
386 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
387 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
388 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
389 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
390 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
391 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
392 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL },
393 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
394 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Damien Miller9b439df2006-07-24 14:04:00 +1000395 { "match", sMatch, SSHCFG_ALL },
396 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000397 { "forcecommand", sForceCommand, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000398 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000399};
400
Damien Miller5428f641999-11-25 11:54:57 +1100401/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000402 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100403 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000404
Damien Miller4af51302000-04-16 11:18:38 +1000405static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100406parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000407 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000408{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000409 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000410
Damien Miller95def091999-11-25 00:26:21 +1100411 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000412 if (strcasecmp(cp, keywords[i].name) == 0) {
413 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100414 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000415 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000416
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000417 error("%s: line %d: Bad configuration option: %s",
418 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100419 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000420}
421
Ben Lindstrombba81212001-06-25 05:01:22 +0000422static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000423add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100424{
Damien Millereccb9de2005-06-17 12:59:34 +1000425 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100426
427 if (options->num_ports == 0)
428 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100429 if (options->address_family == -1)
430 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000431 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000432 for (i = 0; i < options->num_ports; i++)
433 add_one_listen_addr(options, addr, options->ports[i]);
434 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000435 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000436}
437
Ben Lindstrombba81212001-06-25 05:01:22 +0000438static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000439add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
440{
441 struct addrinfo hints, *ai, *aitop;
442 char strport[NI_MAXSERV];
443 int gaierr;
444
445 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100446 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000447 hints.ai_socktype = SOCK_STREAM;
448 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000449 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000450 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
451 fatal("bad addr or host: %s (%s)",
452 addr ? addr : "<NULL>",
453 gai_strerror(gaierr));
454 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
455 ;
456 ai->ai_next = options->listen_addrs;
457 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100458}
459
Darren Tucker45150472006-07-12 22:34:17 +1000460/*
461 * The strategy for the Match blocks is that the config file is parsed twice.
462 *
463 * The first time is at startup. activep is initialized to 1 and the
464 * directives in the global context are processed and acted on. Hitting a
465 * Match directive unsets activep and the directives inside the block are
466 * checked for syntax only.
467 *
468 * The second time is after a connection has been established but before
469 * authentication. activep is initialized to 2 and global config directives
470 * are ignored since they have already been processed. If the criteria in a
471 * Match block is met, activep is set and the subsequent directives
472 * processed and actioned until EOF or another Match block unsets it. Any
473 * options set are copied into the main server config.
474 *
475 * Potential additions/improvements:
476 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
477 *
478 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
479 * Match Address 192.168.0.*
480 * Tag trusted
481 * Match Group wheel
482 * Tag trusted
483 * Match Tag trusted
484 * AllowTcpForwarding yes
485 * GatewayPorts clientspecified
486 * [...]
487 *
488 * - Add a PermittedChannelRequests directive
489 * Match Group shell
490 * PermittedChannelRequests session,forwarded-tcpip
491 */
492
493static int
494match_cfg_line(char **condition, int line, const char *user, const char *host,
495 const char *address)
496{
497 int result = 1;
498 char *arg, *attrib, *cp = *condition;
499 size_t len;
500
501 if (user == NULL)
502 debug3("checking syntax for 'Match %s'", cp);
503 else
504 debug3("checking match for '%s' user %s host %s addr %s", cp,
505 user ? user : "(null)", host ? host : "(null)",
506 address ? address : "(null)");
507
508 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
509 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
510 error("Missing Match criteria for %s", attrib);
511 return -1;
512 }
513 len = strlen(arg);
514 if (strcasecmp(attrib, "user") == 0) {
515 if (!user) {
516 result = 0;
517 continue;
518 }
519 if (match_pattern_list(user, arg, len, 0) != 1)
520 result = 0;
521 else
522 debug("user %.100s matched 'User %.100s' at "
523 "line %d", user, arg, line);
524 } else if (strcasecmp(attrib, "host") == 0) {
525 if (!host) {
526 result = 0;
527 continue;
528 }
529 if (match_hostname(host, arg, len) != 1)
530 result = 0;
531 else
532 debug("connection from %.100s matched 'Host "
533 "%.100s' at line %d", host, arg, line);
534 } else if (strcasecmp(attrib, "address") == 0) {
535 debug("address '%s' arg '%s'", address, arg);
536 if (!address) {
537 result = 0;
538 continue;
539 }
540 if (match_hostname(address, arg, len) != 1)
541 result = 0;
542 else
543 debug("connection from %.100s matched 'Address "
544 "%.100s' at line %d", address, arg, line);
545 } else {
546 error("Unsupported Match attribute %s", attrib);
547 return -1;
548 }
549 }
550 if (user != NULL)
551 debug3("match %sfound", result ? "" : "not ");
552 *condition = cp;
553 return result;
554}
555
Damien Millere2754432006-07-24 14:06:47 +1000556#define WHITESPACE " \t\r\n"
557
Ben Lindstromade03f62001-12-06 18:22:17 +0000558int
559process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000560 const char *filename, int linenum, int *activep, const char *user,
561 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000562{
563 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000564 int cmdline = 0, *intptr, value, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000565 ServerOpCodes opcode;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100566 u_short port;
Darren Tucker45150472006-07-12 22:34:17 +1000567 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000568 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000569
570 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100571 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100572 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000573 /* Ignore leading whitespace */
574 if (*arg == '\0')
575 arg = strdelim(&cp);
576 if (!arg || !*arg || *arg == '#')
577 return 0;
578 intptr = NULL;
579 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000580 opcode = parse_token(arg, filename, linenum, &flags);
581
582 if (activep == NULL) { /* We are processing a command line directive */
583 cmdline = 1;
584 activep = &cmdline;
585 }
586 if (*activep && opcode != sMatch)
587 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
588 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
589 if (user == NULL) {
590 fatal("%s line %d: Directive '%s' is not allowed "
591 "within a Match block", filename, linenum, arg);
592 } else { /* this is a directive we have already processed */
593 while (arg)
594 arg = strdelim(&cp);
595 return 0;
596 }
597 }
598
Ben Lindstromade03f62001-12-06 18:22:17 +0000599 switch (opcode) {
600 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000601 case sUsePAM:
602 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000603 goto parse_flag;
604
605 /* Standard Options */
606 case sBadOption:
607 return -1;
608 case sPort:
609 /* ignore ports from configfile if cmdline specifies ports */
610 if (options->ports_from_cmdline)
611 return 0;
612 if (options->listen_addrs != NULL)
613 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100614 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000615 if (options->num_ports >= MAX_PORTS)
616 fatal("%s line %d: too many ports.",
617 filename, linenum);
618 arg = strdelim(&cp);
619 if (!arg || *arg == '\0')
620 fatal("%s line %d: missing port number.",
621 filename, linenum);
622 options->ports[options->num_ports++] = a2port(arg);
623 if (options->ports[options->num_ports-1] == 0)
624 fatal("%s line %d: Badly formatted port number.",
625 filename, linenum);
626 break;
627
628 case sServerKeyBits:
629 intptr = &options->server_key_bits;
630parse_int:
631 arg = strdelim(&cp);
632 if (!arg || *arg == '\0')
633 fatal("%s line %d: missing integer value.",
634 filename, linenum);
635 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000636 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000637 *intptr = value;
638 break;
639
640 case sLoginGraceTime:
641 intptr = &options->login_grace_time;
642parse_time:
643 arg = strdelim(&cp);
644 if (!arg || *arg == '\0')
645 fatal("%s line %d: missing time value.",
646 filename, linenum);
647 if ((value = convtime(arg)) == -1)
648 fatal("%s line %d: invalid time value.",
649 filename, linenum);
650 if (*intptr == -1)
651 *intptr = value;
652 break;
653
654 case sKeyRegenerationTime:
655 intptr = &options->key_regeneration_time;
656 goto parse_time;
657
658 case sListenAddress:
659 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100660 if (arg == NULL || *arg == '\0')
661 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000662 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000663 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
664 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
665 && strchr(p+1, ':') != NULL) {
666 add_listen_addr(options, arg, 0);
667 break;
668 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100669 p = hpdelim(&arg);
670 if (p == NULL)
671 fatal("%s line %d: bad address:port usage",
672 filename, linenum);
673 p = cleanhostname(p);
674 if (arg == NULL)
675 port = 0;
676 else if ((port = a2port(arg)) == 0)
677 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000678
Damien Millerf91ee4c2005-03-01 21:24:33 +1100679 add_listen_addr(options, p, port);
680
Ben Lindstromade03f62001-12-06 18:22:17 +0000681 break;
682
Darren Tucker0f383232005-01-20 10:57:56 +1100683 case sAddressFamily:
684 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000685 if (!arg || *arg == '\0')
686 fatal("%s line %d: missing address family.",
687 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100688 intptr = &options->address_family;
689 if (options->listen_addrs != NULL)
690 fatal("%s line %d: address family must be specified before "
691 "ListenAddress.", filename, linenum);
692 if (strcasecmp(arg, "inet") == 0)
693 value = AF_INET;
694 else if (strcasecmp(arg, "inet6") == 0)
695 value = AF_INET6;
696 else if (strcasecmp(arg, "any") == 0)
697 value = AF_UNSPEC;
698 else
699 fatal("%s line %d: unsupported address family \"%s\".",
700 filename, linenum, arg);
701 if (*intptr == -1)
702 *intptr = value;
703 break;
704
Ben Lindstromade03f62001-12-06 18:22:17 +0000705 case sHostKeyFile:
706 intptr = &options->num_host_key_files;
707 if (*intptr >= MAX_HOSTKEYS)
708 fatal("%s line %d: too many host keys specified (max %d).",
709 filename, linenum, MAX_HOSTKEYS);
710 charptr = &options->host_key_files[*intptr];
711parse_filename:
712 arg = strdelim(&cp);
713 if (!arg || *arg == '\0')
714 fatal("%s line %d: missing file name.",
715 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000716 if (*activep && *charptr == NULL) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000717 *charptr = tilde_expand_filename(arg, getuid());
718 /* increase optional counter */
719 if (intptr != NULL)
720 *intptr = *intptr + 1;
721 }
722 break;
723
724 case sPidFile:
725 charptr = &options->pid_file;
726 goto parse_filename;
727
728 case sPermitRootLogin:
729 intptr = &options->permit_root_login;
730 arg = strdelim(&cp);
731 if (!arg || *arg == '\0')
732 fatal("%s line %d: missing yes/"
733 "without-password/forced-commands-only/no "
734 "argument.", filename, linenum);
735 value = 0; /* silence compiler */
736 if (strcmp(arg, "without-password") == 0)
737 value = PERMIT_NO_PASSWD;
738 else if (strcmp(arg, "forced-commands-only") == 0)
739 value = PERMIT_FORCED_ONLY;
740 else if (strcmp(arg, "yes") == 0)
741 value = PERMIT_YES;
742 else if (strcmp(arg, "no") == 0)
743 value = PERMIT_NO;
744 else
745 fatal("%s line %d: Bad yes/"
746 "without-password/forced-commands-only/no "
747 "argument: %s", filename, linenum, arg);
748 if (*intptr == -1)
749 *intptr = value;
750 break;
751
752 case sIgnoreRhosts:
753 intptr = &options->ignore_rhosts;
754parse_flag:
755 arg = strdelim(&cp);
756 if (!arg || *arg == '\0')
757 fatal("%s line %d: missing yes/no argument.",
758 filename, linenum);
759 value = 0; /* silence compiler */
760 if (strcmp(arg, "yes") == 0)
761 value = 1;
762 else if (strcmp(arg, "no") == 0)
763 value = 0;
764 else
765 fatal("%s line %d: Bad yes/no argument: %s",
766 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000767 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000768 *intptr = value;
769 break;
770
771 case sIgnoreUserKnownHosts:
772 intptr = &options->ignore_user_known_hosts;
773 goto parse_flag;
774
Ben Lindstromade03f62001-12-06 18:22:17 +0000775 case sRhostsRSAAuthentication:
776 intptr = &options->rhosts_rsa_authentication;
777 goto parse_flag;
778
779 case sHostbasedAuthentication:
780 intptr = &options->hostbased_authentication;
781 goto parse_flag;
782
783 case sHostbasedUsesNameFromPacketOnly:
784 intptr = &options->hostbased_uses_name_from_packet_only;
785 goto parse_flag;
786
787 case sRSAAuthentication:
788 intptr = &options->rsa_authentication;
789 goto parse_flag;
790
791 case sPubkeyAuthentication:
792 intptr = &options->pubkey_authentication;
793 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000794
Ben Lindstromade03f62001-12-06 18:22:17 +0000795 case sKerberosAuthentication:
796 intptr = &options->kerberos_authentication;
797 goto parse_flag;
798
799 case sKerberosOrLocalPasswd:
800 intptr = &options->kerberos_or_local_passwd;
801 goto parse_flag;
802
803 case sKerberosTicketCleanup:
804 intptr = &options->kerberos_ticket_cleanup;
805 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000806
Darren Tucker22ef5082003-12-31 11:37:34 +1100807 case sKerberosGetAFSToken:
808 intptr = &options->kerberos_get_afs_token;
809 goto parse_flag;
810
Darren Tucker0efd1552003-08-26 11:49:55 +1000811 case sGssAuthentication:
812 intptr = &options->gss_authentication;
813 goto parse_flag;
814
815 case sGssCleanupCreds:
816 intptr = &options->gss_cleanup_creds;
817 goto parse_flag;
818
Ben Lindstromade03f62001-12-06 18:22:17 +0000819 case sPasswordAuthentication:
820 intptr = &options->password_authentication;
821 goto parse_flag;
822
823 case sKbdInteractiveAuthentication:
824 intptr = &options->kbd_interactive_authentication;
825 goto parse_flag;
826
827 case sChallengeResponseAuthentication:
828 intptr = &options->challenge_response_authentication;
829 goto parse_flag;
830
831 case sPrintMotd:
832 intptr = &options->print_motd;
833 goto parse_flag;
834
835 case sPrintLastLog:
836 intptr = &options->print_lastlog;
837 goto parse_flag;
838
839 case sX11Forwarding:
840 intptr = &options->x11_forwarding;
841 goto parse_flag;
842
843 case sX11DisplayOffset:
844 intptr = &options->x11_display_offset;
845 goto parse_int;
846
Damien Miller95c249f2002-02-05 12:11:34 +1100847 case sX11UseLocalhost:
848 intptr = &options->x11_use_localhost;
849 goto parse_flag;
850
Ben Lindstromade03f62001-12-06 18:22:17 +0000851 case sXAuthLocation:
852 charptr = &options->xauth_location;
853 goto parse_filename;
854
855 case sStrictModes:
856 intptr = &options->strict_modes;
857 goto parse_flag;
858
Damien Miller12c150e2003-12-17 16:31:10 +1100859 case sTCPKeepAlive:
860 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000861 goto parse_flag;
862
863 case sEmptyPasswd:
864 intptr = &options->permit_empty_passwd;
865 goto parse_flag;
866
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000867 case sPermitUserEnvironment:
868 intptr = &options->permit_user_env;
869 goto parse_flag;
870
Ben Lindstromade03f62001-12-06 18:22:17 +0000871 case sUseLogin:
872 intptr = &options->use_login;
873 goto parse_flag;
874
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000875 case sCompression:
876 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000877 arg = strdelim(&cp);
878 if (!arg || *arg == '\0')
879 fatal("%s line %d: missing yes/no/delayed "
880 "argument.", filename, linenum);
881 value = 0; /* silence compiler */
882 if (strcmp(arg, "delayed") == 0)
883 value = COMP_DELAYED;
884 else if (strcmp(arg, "yes") == 0)
885 value = COMP_ZLIB;
886 else if (strcmp(arg, "no") == 0)
887 value = COMP_NONE;
888 else
889 fatal("%s line %d: Bad yes/no/delayed "
890 "argument: %s", filename, linenum, arg);
891 if (*intptr == -1)
892 *intptr = value;
893 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000894
Ben Lindstromade03f62001-12-06 18:22:17 +0000895 case sGatewayPorts:
896 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100897 arg = strdelim(&cp);
898 if (!arg || *arg == '\0')
899 fatal("%s line %d: missing yes/no/clientspecified "
900 "argument.", filename, linenum);
901 value = 0; /* silence compiler */
902 if (strcmp(arg, "clientspecified") == 0)
903 value = 2;
904 else if (strcmp(arg, "yes") == 0)
905 value = 1;
906 else if (strcmp(arg, "no") == 0)
907 value = 0;
908 else
909 fatal("%s line %d: Bad yes/no/clientspecified "
910 "argument: %s", filename, linenum, arg);
911 if (*intptr == -1)
912 *intptr = value;
913 break;
Ben Lindstromade03f62001-12-06 18:22:17 +0000914
Damien Miller3a961dc2003-06-03 10:25:48 +1000915 case sUseDNS:
916 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000917 goto parse_flag;
918
919 case sLogFacility:
920 intptr = (int *) &options->log_facility;
921 arg = strdelim(&cp);
922 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100923 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000924 fatal("%.200s line %d: unsupported log facility '%s'",
925 filename, linenum, arg ? arg : "<NONE>");
926 if (*intptr == -1)
927 *intptr = (SyslogFacility) value;
928 break;
929
930 case sLogLevel:
931 intptr = (int *) &options->log_level;
932 arg = strdelim(&cp);
933 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100934 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000935 fatal("%.200s line %d: unsupported log level '%s'",
936 filename, linenum, arg ? arg : "<NONE>");
937 if (*intptr == -1)
938 *intptr = (LogLevel) value;
939 break;
940
941 case sAllowTcpForwarding:
942 intptr = &options->allow_tcp_forwarding;
943 goto parse_flag;
944
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000945 case sUsePrivilegeSeparation:
946 intptr = &use_privsep;
947 goto parse_flag;
948
Ben Lindstromade03f62001-12-06 18:22:17 +0000949 case sAllowUsers:
950 while ((arg = strdelim(&cp)) && *arg != '\0') {
951 if (options->num_allow_users >= MAX_ALLOW_USERS)
952 fatal("%s line %d: too many allow users.",
953 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000954 options->allow_users[options->num_allow_users++] =
955 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000956 }
957 break;
958
959 case sDenyUsers:
960 while ((arg = strdelim(&cp)) && *arg != '\0') {
961 if (options->num_deny_users >= MAX_DENY_USERS)
962 fatal( "%s line %d: too many deny users.",
963 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000964 options->deny_users[options->num_deny_users++] =
965 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000966 }
967 break;
968
969 case sAllowGroups:
970 while ((arg = strdelim(&cp)) && *arg != '\0') {
971 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
972 fatal("%s line %d: too many allow groups.",
973 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000974 options->allow_groups[options->num_allow_groups++] =
975 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000976 }
977 break;
978
979 case sDenyGroups:
980 while ((arg = strdelim(&cp)) && *arg != '\0') {
981 if (options->num_deny_groups >= MAX_DENY_GROUPS)
982 fatal("%s line %d: too many deny groups.",
983 filename, linenum);
984 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
985 }
986 break;
987
988 case sCiphers:
989 arg = strdelim(&cp);
990 if (!arg || *arg == '\0')
991 fatal("%s line %d: Missing argument.", filename, linenum);
992 if (!ciphers_valid(arg))
993 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
994 filename, linenum, arg ? arg : "<NONE>");
995 if (options->ciphers == NULL)
996 options->ciphers = xstrdup(arg);
997 break;
998
999 case sMacs:
1000 arg = strdelim(&cp);
1001 if (!arg || *arg == '\0')
1002 fatal("%s line %d: Missing argument.", filename, linenum);
1003 if (!mac_valid(arg))
1004 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1005 filename, linenum, arg ? arg : "<NONE>");
1006 if (options->macs == NULL)
1007 options->macs = xstrdup(arg);
1008 break;
1009
1010 case sProtocol:
1011 intptr = &options->protocol;
1012 arg = strdelim(&cp);
1013 if (!arg || *arg == '\0')
1014 fatal("%s line %d: Missing argument.", filename, linenum);
1015 value = proto_spec(arg);
1016 if (value == SSH_PROTO_UNKNOWN)
1017 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001018 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001019 if (*intptr == SSH_PROTO_UNKNOWN)
1020 *intptr = value;
1021 break;
1022
1023 case sSubsystem:
1024 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1025 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001026 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001027 }
1028 arg = strdelim(&cp);
1029 if (!arg || *arg == '\0')
1030 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001031 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001032 if (!*activep) {
1033 arg = strdelim(&cp);
1034 break;
1035 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001036 for (i = 0; i < options->num_subsystems; i++)
1037 if (strcmp(arg, options->subsystem_name[i]) == 0)
1038 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001039 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001040 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1041 arg = strdelim(&cp);
1042 if (!arg || *arg == '\0')
1043 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001044 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001045 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001046
1047 /* Collect arguments (separate to executable) */
1048 p = xstrdup(arg);
1049 len = strlen(p) + 1;
1050 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1051 len += 1 + strlen(arg);
1052 p = xrealloc(p, 1, len);
1053 strlcat(p, " ", len);
1054 strlcat(p, arg, len);
1055 }
1056 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001057 options->num_subsystems++;
1058 break;
1059
1060 case sMaxStartups:
1061 arg = strdelim(&cp);
1062 if (!arg || *arg == '\0')
1063 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001064 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001065 if ((n = sscanf(arg, "%d:%d:%d",
1066 &options->max_startups_begin,
1067 &options->max_startups_rate,
1068 &options->max_startups)) == 3) {
1069 if (options->max_startups_begin >
1070 options->max_startups ||
1071 options->max_startups_rate > 100 ||
1072 options->max_startups_rate < 1)
1073 fatal("%s line %d: Illegal MaxStartups spec.",
1074 filename, linenum);
1075 } else if (n != 1)
1076 fatal("%s line %d: Illegal MaxStartups spec.",
1077 filename, linenum);
1078 else
1079 options->max_startups = options->max_startups_begin;
1080 break;
1081
Darren Tucker89413db2004-05-24 10:36:23 +10001082 case sMaxAuthTries:
1083 intptr = &options->max_authtries;
1084 goto parse_int;
1085
Ben Lindstromade03f62001-12-06 18:22:17 +00001086 case sBanner:
1087 charptr = &options->banner;
1088 goto parse_filename;
1089 /*
1090 * These options can contain %X options expanded at
1091 * connect time, so that you can specify paths like:
1092 *
1093 * AuthorizedKeysFile /etc/ssh_keys/%u
1094 */
1095 case sAuthorizedKeysFile:
1096 case sAuthorizedKeysFile2:
1097 charptr = (opcode == sAuthorizedKeysFile ) ?
1098 &options->authorized_keys_file :
1099 &options->authorized_keys_file2;
1100 goto parse_filename;
1101
1102 case sClientAliveInterval:
1103 intptr = &options->client_alive_interval;
1104 goto parse_time;
1105
1106 case sClientAliveCountMax:
1107 intptr = &options->client_alive_count_max;
1108 goto parse_int;
1109
Darren Tucker46bc0752004-05-02 22:11:30 +10001110 case sAcceptEnv:
1111 while ((arg = strdelim(&cp)) && *arg != '\0') {
1112 if (strchr(arg, '=') != NULL)
1113 fatal("%s line %d: Invalid environment name.",
1114 filename, linenum);
1115 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1116 fatal("%s line %d: too many allow env.",
1117 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001118 if (!*activep)
1119 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001120 options->accept_env[options->num_accept_env++] =
1121 xstrdup(arg);
1122 }
1123 break;
1124
Damien Millerd27b9472005-12-13 19:29:02 +11001125 case sPermitTunnel:
1126 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001127 arg = strdelim(&cp);
1128 if (!arg || *arg == '\0')
1129 fatal("%s line %d: Missing yes/point-to-point/"
1130 "ethernet/no argument.", filename, linenum);
1131 value = 0; /* silence compiler */
1132 if (strcasecmp(arg, "ethernet") == 0)
1133 value = SSH_TUNMODE_ETHERNET;
1134 else if (strcasecmp(arg, "point-to-point") == 0)
1135 value = SSH_TUNMODE_POINTOPOINT;
1136 else if (strcasecmp(arg, "yes") == 0)
1137 value = SSH_TUNMODE_YES;
1138 else if (strcasecmp(arg, "no") == 0)
1139 value = SSH_TUNMODE_NO;
1140 else
1141 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1142 "no argument: %s", filename, linenum, arg);
1143 if (*intptr == -1)
1144 *intptr = value;
1145 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001146
Darren Tucker45150472006-07-12 22:34:17 +10001147 case sMatch:
1148 if (cmdline)
1149 fatal("Match directive not supported as a command-line "
1150 "option");
1151 value = match_cfg_line(&cp, linenum, user, host, address);
1152 if (value < 0)
1153 fatal("%s line %d: Bad Match condition", filename,
1154 linenum);
1155 *activep = value;
1156 break;
1157
Damien Miller9b439df2006-07-24 14:04:00 +10001158 case sPermitOpen:
1159 arg = strdelim(&cp);
1160 if (!arg || *arg == '\0')
1161 fatal("%s line %d: missing PermitOpen specification",
1162 filename, linenum);
1163 if (strcmp(arg, "any") == 0) {
Damien Millera765cf42006-07-24 14:08:13 +10001164 if (*activep) {
Damien Miller9b439df2006-07-24 14:04:00 +10001165 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001166 options->num_permitted_opens = 0;
1167 }
Damien Miller9b439df2006-07-24 14:04:00 +10001168 break;
1169 }
Damien Millera765cf42006-07-24 14:08:13 +10001170 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1171 p = hpdelim(&arg);
1172 if (p == NULL)
1173 fatal("%s line %d: missing host in PermitOpen",
1174 filename, linenum);
1175 p = cleanhostname(p);
1176 if (arg == NULL || (port = a2port(arg)) == 0)
1177 fatal("%s line %d: bad port number in "
1178 "PermitOpen", filename, linenum);
1179 if (*activep && options->num_permitted_opens == -1) {
1180 channel_clear_adm_permitted_opens();
1181 options->num_permitted_opens =
1182 channel_add_adm_permitted_opens(p, port);
1183 }
1184 }
Damien Miller9b439df2006-07-24 14:04:00 +10001185 break;
1186
Damien Millere2754432006-07-24 14:06:47 +10001187 case sForceCommand:
1188 if (cp == NULL)
1189 fatal("%.200s line %d: Missing argument.", filename,
1190 linenum);
1191 len = strspn(cp, WHITESPACE);
1192 if (*activep && options->adm_forced_command == NULL)
1193 options->adm_forced_command = xstrdup(cp + len);
1194 return 0;
1195
Ben Lindstromade03f62001-12-06 18:22:17 +00001196 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001197 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001198 filename, linenum, arg);
1199 while (arg)
1200 arg = strdelim(&cp);
1201 break;
1202
Damien Millerf9b3feb2003-05-16 11:38:32 +10001203 case sUnsupported:
1204 logit("%s line %d: Unsupported option %s",
1205 filename, linenum, arg);
1206 while (arg)
1207 arg = strdelim(&cp);
1208 break;
1209
Ben Lindstromade03f62001-12-06 18:22:17 +00001210 default:
1211 fatal("%s line %d: Missing handler for opcode %s (%d)",
1212 filename, linenum, arg, opcode);
1213 }
1214 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1215 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1216 filename, linenum, arg);
1217 return 0;
1218}
1219
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001220/* Reads the server configuration file. */
1221
Damien Miller4af51302000-04-16 11:18:38 +10001222void
Darren Tucker645ab752004-06-25 13:33:20 +10001223load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001224{
Darren Tucker645ab752004-06-25 13:33:20 +10001225 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001226 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001227
Darren Tucker645ab752004-06-25 13:33:20 +10001228 debug2("%s: filename %s", __func__, filename);
1229 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001230 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001231 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001232 }
Darren Tucker645ab752004-06-25 13:33:20 +10001233 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001234 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001235 /*
1236 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001237 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001238 * line numbers later for error messages
1239 */
1240 if ((cp = strchr(line, '#')) != NULL)
1241 memcpy(cp, "\n", 2);
1242 cp = line + strspn(line, " \t\r");
1243
1244 buffer_append(conf, cp, strlen(cp));
1245 }
1246 buffer_append(conf, "\0", 1);
1247 fclose(f);
1248 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1249}
1250
1251void
Darren Tucker45150472006-07-12 22:34:17 +10001252parse_server_match_config(ServerOptions *options, const char *user,
1253 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001254{
Darren Tucker45150472006-07-12 22:34:17 +10001255 ServerOptions mo;
1256
1257 initialize_server_options(&mo);
1258 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
1259 copy_set_server_options(options, &mo);
1260}
1261
1262/* Copy any (supported) values that are set */
1263void
1264copy_set_server_options(ServerOptions *dst, ServerOptions *src)
1265{
1266 if (src->allow_tcp_forwarding != -1)
1267 dst->allow_tcp_forwarding = src->allow_tcp_forwarding;
1268 if (src->gateway_ports != -1)
1269 dst->gateway_ports = src->gateway_ports;
Damien Millere2754432006-07-24 14:06:47 +10001270 if (src->adm_forced_command != NULL) {
1271 if (dst->adm_forced_command != NULL)
1272 xfree(dst->adm_forced_command);
1273 dst->adm_forced_command = src->adm_forced_command;
1274 }
Damien Millerd1de9952006-07-24 14:05:48 +10001275 if (src->x11_display_offset != -1)
1276 dst->x11_display_offset = src->x11_display_offset;
1277 if (src->x11_forwarding != -1)
1278 dst->x11_forwarding = src->x11_forwarding;
1279 if (src->x11_use_localhost != -1)
1280 dst->x11_use_localhost = src->x11_use_localhost;
Darren Tucker45150472006-07-12 22:34:17 +10001281}
1282
1283void
1284parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1285 const char *user, const char *host, const char *address)
1286{
1287 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001288 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001289
1290 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1291
Darren Tucker9fbac712004-08-12 22:41:44 +10001292 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001293 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001294 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001295 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001296 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001297 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001298 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001299 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001300 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001301 if (bad_options > 0)
1302 fatal("%s: terminating, %d bad configuration options",
1303 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001304}