blob: ce44b5f60c5d09cf84527aaa5ff97ff87e134c26 [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 Millerbe43ebf2006-07-24 13:51:51 +100018#if defined(HAVE_NETDB_H)
19# include <netdb.h>
20#endif
Damien Millere3476ed2006-07-24 14:13:33 +100021#include <string.h>
Damien Millere6b3b612006-07-24 14:01:23 +100022#include <unistd.h>
Damien Millerbe43ebf2006-07-24 13:51:51 +100023
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000025#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100026#include "servconf.h"
27#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100028#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000029#include "pathnames.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000030#include "misc.h"
31#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000032#include "kex.h"
33#include "mac.h"
Darren Tucker45150472006-07-12 22:34:17 +100034#include "match.h"
Damien Miller9b439df2006-07-24 14:04:00 +100035#include "channels.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036
Ben Lindstrombba81212001-06-25 05:01:22 +000037static void add_listen_addr(ServerOptions *, char *, u_short);
38static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110039
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000040/* Use of privilege separation or not */
41extern int use_privsep;
Darren Tucker45150472006-07-12 22:34:17 +100042extern Buffer cfg;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000043
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044/* Initializes the server options to their default values. */
45
Damien Miller4af51302000-04-16 11:18:38 +100046void
Damien Miller95def091999-11-25 00:26:21 +110047initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100048{
Damien Miller95def091999-11-25 00:26:21 +110049 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110050
51 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100052 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110053
54 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110055 options->num_ports = 0;
56 options->ports_from_cmdline = 0;
57 options->listen_addrs = NULL;
Darren Tucker0f383232005-01-20 10:57:56 +110058 options->address_family = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110059 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100060 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110061 options->server_key_bits = -1;
62 options->login_grace_time = -1;
63 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000064 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110065 options->ignore_rhosts = -1;
66 options->ignore_user_known_hosts = -1;
67 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000068 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110069 options->x11_forwarding = -1;
70 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110071 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100072 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110073 options->strict_modes = -1;
Damien Miller12c150e2003-12-17 16:31:10 +110074 options->tcp_keep_alive = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110075 options->log_facility = SYSLOG_FACILITY_NOT_SET;
76 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110077 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000078 options->hostbased_authentication = -1;
79 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110080 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110081 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110082 options->kerberos_authentication = -1;
83 options->kerberos_or_local_passwd = -1;
84 options->kerberos_ticket_cleanup = -1;
Darren Tucker22ef5082003-12-31 11:37:34 +110085 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +100086 options->gss_authentication=-1;
87 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +110088 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110089 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000090 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110091 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +000092 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +110093 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +000094 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110095 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110096 options->num_allow_users = 0;
97 options->num_deny_users = 0;
98 options->num_allow_groups = 0;
99 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000100 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000101 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000102 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000103 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000104 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000105 options->max_startups_begin = -1;
106 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000107 options->max_startups = -1;
Darren Tucker89413db2004-05-24 10:36:23 +1000108 options->max_authtries = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000109 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000110 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000111 options->client_alive_interval = -1;
112 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000113 options->authorized_keys_file = NULL;
114 options->authorized_keys_file2 = NULL;
Darren Tucker46bc0752004-05-02 22:11:30 +1000115 options->num_accept_env = 0;
Damien Millerd27b9472005-12-13 19:29:02 +1100116 options->permit_tun = -1;
Damien Millera765cf42006-07-24 14:08:13 +1000117 options->num_permitted_opens = -1;
Damien Millere2754432006-07-24 14:06:47 +1000118 options->adm_forced_command = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119}
120
Damien Miller4af51302000-04-16 11:18:38 +1000121void
Damien Miller95def091999-11-25 00:26:21 +1100122fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000123{
Damien Miller726273e2001-11-12 11:40:11 +1100124 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000125 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000126 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100127
128 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100129 if (options->protocol == SSH_PROTO_UNKNOWN)
130 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
131 if (options->num_host_key_files == 0) {
132 /* fill default hostkeys for protocols */
133 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100134 options->host_key_files[options->num_host_key_files++] =
135 _PATH_HOST_KEY_FILE;
136 if (options->protocol & SSH_PROTO_2) {
137 options->host_key_files[options->num_host_key_files++] =
138 _PATH_HOST_RSA_KEY_FILE;
139 options->host_key_files[options->num_host_key_files++] =
140 _PATH_HOST_DSA_KEY_FILE;
141 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100142 }
Damien Miller34132e52000-01-14 15:45:46 +1100143 if (options->num_ports == 0)
144 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
145 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000146 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000147 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000148 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100149 if (options->server_key_bits == -1)
150 options->server_key_bits = 768;
151 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000152 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100153 if (options->key_regeneration_time == -1)
154 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000155 if (options->permit_root_login == PERMIT_NOT_SET)
156 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100158 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100159 if (options->ignore_user_known_hosts == -1)
160 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100161 if (options->print_motd == -1)
162 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000163 if (options->print_lastlog == -1)
164 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100166 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100168 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100169 if (options->x11_use_localhost == -1)
170 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000171 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000172 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->strict_modes == -1)
174 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100175 if (options->tcp_keep_alive == -1)
176 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100177 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100178 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100179 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000180 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100181 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100182 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000183 if (options->hostbased_authentication == -1)
184 options->hostbased_authentication = 0;
185 if (options->hostbased_uses_name_from_packet_only == -1)
186 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100187 if (options->rsa_authentication == -1)
188 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100189 if (options->pubkey_authentication == -1)
190 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000192 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100193 if (options->kerberos_or_local_passwd == -1)
194 options->kerberos_or_local_passwd = 1;
195 if (options->kerberos_ticket_cleanup == -1)
196 options->kerberos_ticket_cleanup = 1;
Darren Tucker22ef5082003-12-31 11:37:34 +1100197 if (options->kerberos_get_afs_token == -1)
198 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000199 if (options->gss_authentication == -1)
200 options->gss_authentication = 0;
201 if (options->gss_cleanup_creds == -1)
202 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->password_authentication == -1)
204 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100205 if (options->kbd_interactive_authentication == -1)
206 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000207 if (options->challenge_response_authentication == -1)
208 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100210 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000211 if (options->permit_user_env == -1)
212 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100213 if (options->use_login == -1)
214 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000215 if (options->compression == -1)
Damien Miller9786e6e2005-07-26 21:54:56 +1000216 options->compression = COMP_DELAYED;
Damien Miller50a41ed2000-10-16 12:14:42 +1100217 if (options->allow_tcp_forwarding == -1)
218 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000219 if (options->gateway_ports == -1)
220 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000221 if (options->max_startups == -1)
222 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000223 if (options->max_startups_rate == -1)
224 options->max_startups_rate = 100; /* 100% */
225 if (options->max_startups_begin == -1)
226 options->max_startups_begin = options->max_startups;
Darren Tucker89413db2004-05-24 10:36:23 +1000227 if (options->max_authtries == -1)
228 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
Damien Miller3a961dc2003-06-03 10:25:48 +1000229 if (options->use_dns == -1)
230 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000231 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100232 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000233 if (options->client_alive_count_max == -1)
234 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100235 if (options->authorized_keys_file2 == NULL) {
236 /* authorized_keys_file2 falls back to authorized_keys_file */
237 if (options->authorized_keys_file != NULL)
238 options->authorized_keys_file2 = options->authorized_keys_file;
239 else
240 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
241 }
242 if (options->authorized_keys_file == NULL)
243 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Damien Millerd27b9472005-12-13 19:29:02 +1100244 if (options->permit_tun == -1)
Damien Miller7b58e802005-12-13 19:33:19 +1100245 options->permit_tun = SSH_TUNMODE_NO;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000246
Ben Lindstromfb62a692002-06-06 19:47:11 +0000247 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000248 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000249 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000250
Tim Rice40017b02002-07-14 13:36:49 -0700251#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000252 if (use_privsep && options->compression == 1) {
253 error("This platform does not support both privilege "
254 "separation and compression");
255 error("Compression disabled");
256 options->compression = 0;
257 }
258#endif
259
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260}
261
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000262/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100263typedef enum {
264 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100265 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000266 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100267 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100268 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
269 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000270 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100271 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100272 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000273 sKerberosTgtPassing, sChallengeResponseAuthentication,
Darren Tucker0f383232005-01-20 10:57:56 +1100274 sPasswordAuthentication, sKbdInteractiveAuthentication,
275 sListenAddress, sAddressFamily,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000276 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100277 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100278 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000279 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100280 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000281 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Darren Tucker89413db2004-05-24 10:36:23 +1000282 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
283 sMaxStartups, sMaxAuthTries,
Damien Miller3a961dc2003-06-03 10:25:48 +1000284 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100285 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000286 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Damien Millerd27b9472005-12-13 19:29:02 +1100287 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Damien Millere2754432006-07-24 14:06:47 +1000288 sMatch, sPermitOpen, sForceCommand,
Ben Lindstromc7431342002-03-22 03:11:49 +0000289 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000290 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000291} ServerOpCodes;
292
Darren Tucker45150472006-07-12 22:34:17 +1000293#define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
294#define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
295#define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
296
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000297/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100298static struct {
299 const char *name;
300 ServerOpCodes opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000301 u_int flags;
Damien Miller95def091999-11-25 00:26:21 +1100302} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100303 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000304#ifdef USE_PAM
Darren Tucker45150472006-07-12 22:34:17 +1000305 { "usepam", sUsePAM, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000306#else
Darren Tucker45150472006-07-12 22:34:17 +1000307 { "usepam", sUnsupported, SSHCFG_GLOBAL },
Damien Miller6ac2c482003-05-16 11:42:35 +1000308#endif
Darren Tucker45150472006-07-12 22:34:17 +1000309 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
Damien Miller726273e2001-11-12 11:40:11 +1100310 /* Standard Options */
Darren Tucker45150472006-07-12 22:34:17 +1000311 { "port", sPort, SSHCFG_GLOBAL },
312 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
313 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
314 { "pidfile", sPidFile, SSHCFG_GLOBAL },
315 { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
316 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
317 { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
318 { "permitrootlogin", sPermitRootLogin, SSHCFG_GLOBAL },
319 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
320 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
321 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
322 { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_GLOBAL },
323 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_GLOBAL },
324 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
325 { "rsaauthentication", sRSAAuthentication, SSHCFG_GLOBAL },
326 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL },
327 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000328#ifdef KRB5
Darren Tucker45150472006-07-12 22:34:17 +1000329 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_GLOBAL },
330 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
331 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100332#ifdef USE_AFS
Darren Tucker45150472006-07-12 22:34:17 +1000333 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000334#else
Darren Tucker45150472006-07-12 22:34:17 +1000335 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker409cb322004-01-05 22:36:51 +1100336#endif
337#else
Darren Tucker45150472006-07-12 22:34:17 +1000338 { "kerberosauthentication", sUnsupported, SSHCFG_GLOBAL },
339 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
340 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
341 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000342#endif
Darren Tucker45150472006-07-12 22:34:17 +1000343 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
344 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000345#ifdef GSSAPI
Darren Tucker45150472006-07-12 22:34:17 +1000346 { "gssapiauthentication", sGssAuthentication, SSHCFG_GLOBAL },
347 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000348#else
Darren Tucker45150472006-07-12 22:34:17 +1000349 { "gssapiauthentication", sUnsupported, SSHCFG_GLOBAL },
350 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Darren Tucker0efd1552003-08-26 11:49:55 +1000351#endif
Darren Tucker45150472006-07-12 22:34:17 +1000352 { "passwordauthentication", sPasswordAuthentication, SSHCFG_GLOBAL },
353 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_GLOBAL },
354 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
355 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
356 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
357 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
358 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
359 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
360 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
361 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
362 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
Damien Millerd1de9952006-07-24 14:05:48 +1000363 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
364 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
365 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000366 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
367 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
368 { "permitemptypasswords", sEmptyPasswd, SSHCFG_GLOBAL },
369 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
370 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
371 { "compression", sCompression, SSHCFG_GLOBAL },
372 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
373 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
374 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
375 { "allowusers", sAllowUsers, SSHCFG_GLOBAL },
376 { "denyusers", sDenyUsers, SSHCFG_GLOBAL },
377 { "allowgroups", sAllowGroups, SSHCFG_GLOBAL },
378 { "denygroups", sDenyGroups, SSHCFG_GLOBAL },
379 { "ciphers", sCiphers, SSHCFG_GLOBAL },
380 { "macs", sMacs, SSHCFG_GLOBAL },
381 { "protocol", sProtocol, SSHCFG_GLOBAL },
382 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
383 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
384 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
385 { "maxauthtries", sMaxAuthTries, SSHCFG_GLOBAL },
386 { "banner", sBanner, SSHCFG_GLOBAL },
387 { "usedns", sUseDNS, SSHCFG_GLOBAL },
388 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
389 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
390 { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
391 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
392 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
393 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
394 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL },
395 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
396 { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
Damien Miller9b439df2006-07-24 14:04:00 +1000397 { "match", sMatch, SSHCFG_ALL },
398 { "permitopen", sPermitOpen, SSHCFG_ALL },
Damien Millere2754432006-07-24 14:06:47 +1000399 { "forcecommand", sForceCommand, SSHCFG_ALL },
Darren Tucker45150472006-07-12 22:34:17 +1000400 { NULL, sBadOption, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401};
402
Damien Miller5428f641999-11-25 11:54:57 +1100403/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000404 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100405 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000406
Damien Miller4af51302000-04-16 11:18:38 +1000407static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100408parse_token(const char *cp, const char *filename,
Darren Tucker45150472006-07-12 22:34:17 +1000409 int linenum, u_int *flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000410{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000411 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000412
Damien Miller95def091999-11-25 00:26:21 +1100413 for (i = 0; keywords[i].name; i++)
Darren Tucker45150472006-07-12 22:34:17 +1000414 if (strcasecmp(cp, keywords[i].name) == 0) {
415 *flags = keywords[i].flags;
Damien Miller95def091999-11-25 00:26:21 +1100416 return keywords[i].opcode;
Darren Tucker45150472006-07-12 22:34:17 +1000417 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000418
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000419 error("%s: line %d: Bad configuration option: %s",
420 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100421 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422}
423
Ben Lindstrombba81212001-06-25 05:01:22 +0000424static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000425add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100426{
Damien Millereccb9de2005-06-17 12:59:34 +1000427 u_int i;
Damien Miller34132e52000-01-14 15:45:46 +1100428
429 if (options->num_ports == 0)
430 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Darren Tucker0f383232005-01-20 10:57:56 +1100431 if (options->address_family == -1)
432 options->address_family = AF_UNSPEC;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000433 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000434 for (i = 0; i < options->num_ports; i++)
435 add_one_listen_addr(options, addr, options->ports[i]);
436 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000437 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000438}
439
Ben Lindstrombba81212001-06-25 05:01:22 +0000440static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000441add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
442{
443 struct addrinfo hints, *ai, *aitop;
444 char strport[NI_MAXSERV];
445 int gaierr;
446
447 memset(&hints, 0, sizeof(hints));
Darren Tucker0f383232005-01-20 10:57:56 +1100448 hints.ai_family = options->address_family;
Ben Lindstromc510af42001-04-07 17:25:48 +0000449 hints.ai_socktype = SOCK_STREAM;
450 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000451 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000452 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
453 fatal("bad addr or host: %s (%s)",
454 addr ? addr : "<NULL>",
455 gai_strerror(gaierr));
456 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
457 ;
458 ai->ai_next = options->listen_addrs;
459 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100460}
461
Darren Tucker45150472006-07-12 22:34:17 +1000462/*
463 * The strategy for the Match blocks is that the config file is parsed twice.
464 *
465 * The first time is at startup. activep is initialized to 1 and the
466 * directives in the global context are processed and acted on. Hitting a
467 * Match directive unsets activep and the directives inside the block are
468 * checked for syntax only.
469 *
470 * The second time is after a connection has been established but before
471 * authentication. activep is initialized to 2 and global config directives
472 * are ignored since they have already been processed. If the criteria in a
473 * Match block is met, activep is set and the subsequent directives
474 * processed and actioned until EOF or another Match block unsets it. Any
475 * options set are copied into the main server config.
476 *
477 * Potential additions/improvements:
478 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
479 *
480 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
481 * Match Address 192.168.0.*
482 * Tag trusted
483 * Match Group wheel
484 * Tag trusted
485 * Match Tag trusted
486 * AllowTcpForwarding yes
487 * GatewayPorts clientspecified
488 * [...]
489 *
490 * - Add a PermittedChannelRequests directive
491 * Match Group shell
492 * PermittedChannelRequests session,forwarded-tcpip
493 */
494
495static int
496match_cfg_line(char **condition, int line, const char *user, const char *host,
497 const char *address)
498{
499 int result = 1;
500 char *arg, *attrib, *cp = *condition;
501 size_t len;
502
503 if (user == NULL)
504 debug3("checking syntax for 'Match %s'", cp);
505 else
506 debug3("checking match for '%s' user %s host %s addr %s", cp,
507 user ? user : "(null)", host ? host : "(null)",
508 address ? address : "(null)");
509
510 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
511 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
512 error("Missing Match criteria for %s", attrib);
513 return -1;
514 }
515 len = strlen(arg);
516 if (strcasecmp(attrib, "user") == 0) {
517 if (!user) {
518 result = 0;
519 continue;
520 }
521 if (match_pattern_list(user, arg, len, 0) != 1)
522 result = 0;
523 else
524 debug("user %.100s matched 'User %.100s' at "
525 "line %d", user, arg, line);
526 } else if (strcasecmp(attrib, "host") == 0) {
527 if (!host) {
528 result = 0;
529 continue;
530 }
531 if (match_hostname(host, arg, len) != 1)
532 result = 0;
533 else
534 debug("connection from %.100s matched 'Host "
535 "%.100s' at line %d", host, arg, line);
536 } else if (strcasecmp(attrib, "address") == 0) {
537 debug("address '%s' arg '%s'", address, arg);
538 if (!address) {
539 result = 0;
540 continue;
541 }
542 if (match_hostname(address, arg, len) != 1)
543 result = 0;
544 else
545 debug("connection from %.100s matched 'Address "
546 "%.100s' at line %d", address, arg, line);
547 } else {
548 error("Unsupported Match attribute %s", attrib);
549 return -1;
550 }
551 }
552 if (user != NULL)
553 debug3("match %sfound", result ? "" : "not ");
554 *condition = cp;
555 return result;
556}
557
Damien Millere2754432006-07-24 14:06:47 +1000558#define WHITESPACE " \t\r\n"
559
Ben Lindstromade03f62001-12-06 18:22:17 +0000560int
561process_server_config_line(ServerOptions *options, char *line,
Darren Tucker45150472006-07-12 22:34:17 +1000562 const char *filename, int linenum, int *activep, const char *user,
563 const char *host, const char *address)
Ben Lindstromade03f62001-12-06 18:22:17 +0000564{
565 char *cp, **charptr, *arg, *p;
Darren Tucker45150472006-07-12 22:34:17 +1000566 int cmdline = 0, *intptr, value, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000567 ServerOpCodes opcode;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100568 u_short port;
Darren Tucker45150472006-07-12 22:34:17 +1000569 u_int i, flags = 0;
Damien Miller917f9b62006-07-10 20:36:47 +1000570 size_t len;
Ben Lindstromade03f62001-12-06 18:22:17 +0000571
572 cp = line;
Damien Miller78f16cb2006-03-26 13:54:37 +1100573 if ((arg = strdelim(&cp)) == NULL)
Damien Miller928b2362006-03-26 13:53:32 +1100574 return 0;
Ben Lindstromade03f62001-12-06 18:22:17 +0000575 /* Ignore leading whitespace */
576 if (*arg == '\0')
577 arg = strdelim(&cp);
578 if (!arg || !*arg || *arg == '#')
579 return 0;
580 intptr = NULL;
581 charptr = NULL;
Darren Tucker45150472006-07-12 22:34:17 +1000582 opcode = parse_token(arg, filename, linenum, &flags);
583
584 if (activep == NULL) { /* We are processing a command line directive */
585 cmdline = 1;
586 activep = &cmdline;
587 }
588 if (*activep && opcode != sMatch)
589 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
590 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
591 if (user == NULL) {
592 fatal("%s line %d: Directive '%s' is not allowed "
593 "within a Match block", filename, linenum, arg);
594 } else { /* this is a directive we have already processed */
595 while (arg)
596 arg = strdelim(&cp);
597 return 0;
598 }
599 }
600
Ben Lindstromade03f62001-12-06 18:22:17 +0000601 switch (opcode) {
602 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000603 case sUsePAM:
604 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000605 goto parse_flag;
606
607 /* Standard Options */
608 case sBadOption:
609 return -1;
610 case sPort:
611 /* ignore ports from configfile if cmdline specifies ports */
612 if (options->ports_from_cmdline)
613 return 0;
614 if (options->listen_addrs != NULL)
615 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100616 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000617 if (options->num_ports >= MAX_PORTS)
618 fatal("%s line %d: too many ports.",
619 filename, linenum);
620 arg = strdelim(&cp);
621 if (!arg || *arg == '\0')
622 fatal("%s line %d: missing port number.",
623 filename, linenum);
624 options->ports[options->num_ports++] = a2port(arg);
625 if (options->ports[options->num_ports-1] == 0)
626 fatal("%s line %d: Badly formatted port number.",
627 filename, linenum);
628 break;
629
630 case sServerKeyBits:
631 intptr = &options->server_key_bits;
632parse_int:
633 arg = strdelim(&cp);
634 if (!arg || *arg == '\0')
635 fatal("%s line %d: missing integer value.",
636 filename, linenum);
637 value = atoi(arg);
Darren Tucker45150472006-07-12 22:34:17 +1000638 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000639 *intptr = value;
640 break;
641
642 case sLoginGraceTime:
643 intptr = &options->login_grace_time;
644parse_time:
645 arg = strdelim(&cp);
646 if (!arg || *arg == '\0')
647 fatal("%s line %d: missing time value.",
648 filename, linenum);
649 if ((value = convtime(arg)) == -1)
650 fatal("%s line %d: invalid time value.",
651 filename, linenum);
652 if (*intptr == -1)
653 *intptr = value;
654 break;
655
656 case sKeyRegenerationTime:
657 intptr = &options->key_regeneration_time;
658 goto parse_time;
659
660 case sListenAddress:
661 arg = strdelim(&cp);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100662 if (arg == NULL || *arg == '\0')
663 fatal("%s line %d: missing address",
Ben Lindstromade03f62001-12-06 18:22:17 +0000664 filename, linenum);
Damien Miller203c7052005-08-12 22:11:37 +1000665 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
666 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
667 && strchr(p+1, ':') != NULL) {
668 add_listen_addr(options, arg, 0);
669 break;
670 }
Damien Millerf91ee4c2005-03-01 21:24:33 +1100671 p = hpdelim(&arg);
672 if (p == NULL)
673 fatal("%s line %d: bad address:port usage",
674 filename, linenum);
675 p = cleanhostname(p);
676 if (arg == NULL)
677 port = 0;
678 else if ((port = a2port(arg)) == 0)
679 fatal("%s line %d: bad port number", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000680
Damien Millerf91ee4c2005-03-01 21:24:33 +1100681 add_listen_addr(options, p, port);
682
Ben Lindstromade03f62001-12-06 18:22:17 +0000683 break;
684
Darren Tucker0f383232005-01-20 10:57:56 +1100685 case sAddressFamily:
686 arg = strdelim(&cp);
Damien Miller17b23d82005-05-26 12:11:56 +1000687 if (!arg || *arg == '\0')
688 fatal("%s line %d: missing address family.",
689 filename, linenum);
Darren Tucker0f383232005-01-20 10:57:56 +1100690 intptr = &options->address_family;
691 if (options->listen_addrs != NULL)
692 fatal("%s line %d: address family must be specified before "
693 "ListenAddress.", filename, linenum);
694 if (strcasecmp(arg, "inet") == 0)
695 value = AF_INET;
696 else if (strcasecmp(arg, "inet6") == 0)
697 value = AF_INET6;
698 else if (strcasecmp(arg, "any") == 0)
699 value = AF_UNSPEC;
700 else
701 fatal("%s line %d: unsupported address family \"%s\".",
702 filename, linenum, arg);
703 if (*intptr == -1)
704 *intptr = value;
705 break;
706
Ben Lindstromade03f62001-12-06 18:22:17 +0000707 case sHostKeyFile:
708 intptr = &options->num_host_key_files;
709 if (*intptr >= MAX_HOSTKEYS)
710 fatal("%s line %d: too many host keys specified (max %d).",
711 filename, linenum, MAX_HOSTKEYS);
712 charptr = &options->host_key_files[*intptr];
713parse_filename:
714 arg = strdelim(&cp);
715 if (!arg || *arg == '\0')
716 fatal("%s line %d: missing file name.",
717 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +1000718 if (*activep && *charptr == NULL) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000719 *charptr = tilde_expand_filename(arg, getuid());
720 /* increase optional counter */
721 if (intptr != NULL)
722 *intptr = *intptr + 1;
723 }
724 break;
725
726 case sPidFile:
727 charptr = &options->pid_file;
728 goto parse_filename;
729
730 case sPermitRootLogin:
731 intptr = &options->permit_root_login;
732 arg = strdelim(&cp);
733 if (!arg || *arg == '\0')
734 fatal("%s line %d: missing yes/"
735 "without-password/forced-commands-only/no "
736 "argument.", filename, linenum);
737 value = 0; /* silence compiler */
738 if (strcmp(arg, "without-password") == 0)
739 value = PERMIT_NO_PASSWD;
740 else if (strcmp(arg, "forced-commands-only") == 0)
741 value = PERMIT_FORCED_ONLY;
742 else if (strcmp(arg, "yes") == 0)
743 value = PERMIT_YES;
744 else if (strcmp(arg, "no") == 0)
745 value = PERMIT_NO;
746 else
747 fatal("%s line %d: Bad yes/"
748 "without-password/forced-commands-only/no "
749 "argument: %s", filename, linenum, arg);
750 if (*intptr == -1)
751 *intptr = value;
752 break;
753
754 case sIgnoreRhosts:
755 intptr = &options->ignore_rhosts;
756parse_flag:
757 arg = strdelim(&cp);
758 if (!arg || *arg == '\0')
759 fatal("%s line %d: missing yes/no argument.",
760 filename, linenum);
761 value = 0; /* silence compiler */
762 if (strcmp(arg, "yes") == 0)
763 value = 1;
764 else if (strcmp(arg, "no") == 0)
765 value = 0;
766 else
767 fatal("%s line %d: Bad yes/no argument: %s",
768 filename, linenum, arg);
Darren Tucker45150472006-07-12 22:34:17 +1000769 if (*activep && *intptr == -1)
Ben Lindstromade03f62001-12-06 18:22:17 +0000770 *intptr = value;
771 break;
772
773 case sIgnoreUserKnownHosts:
774 intptr = &options->ignore_user_known_hosts;
775 goto parse_flag;
776
Ben Lindstromade03f62001-12-06 18:22:17 +0000777 case sRhostsRSAAuthentication:
778 intptr = &options->rhosts_rsa_authentication;
779 goto parse_flag;
780
781 case sHostbasedAuthentication:
782 intptr = &options->hostbased_authentication;
783 goto parse_flag;
784
785 case sHostbasedUsesNameFromPacketOnly:
786 intptr = &options->hostbased_uses_name_from_packet_only;
787 goto parse_flag;
788
789 case sRSAAuthentication:
790 intptr = &options->rsa_authentication;
791 goto parse_flag;
792
793 case sPubkeyAuthentication:
794 intptr = &options->pubkey_authentication;
795 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000796
Ben Lindstromade03f62001-12-06 18:22:17 +0000797 case sKerberosAuthentication:
798 intptr = &options->kerberos_authentication;
799 goto parse_flag;
800
801 case sKerberosOrLocalPasswd:
802 intptr = &options->kerberos_or_local_passwd;
803 goto parse_flag;
804
805 case sKerberosTicketCleanup:
806 intptr = &options->kerberos_ticket_cleanup;
807 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000808
Darren Tucker22ef5082003-12-31 11:37:34 +1100809 case sKerberosGetAFSToken:
810 intptr = &options->kerberos_get_afs_token;
811 goto parse_flag;
812
Darren Tucker0efd1552003-08-26 11:49:55 +1000813 case sGssAuthentication:
814 intptr = &options->gss_authentication;
815 goto parse_flag;
816
817 case sGssCleanupCreds:
818 intptr = &options->gss_cleanup_creds;
819 goto parse_flag;
820
Ben Lindstromade03f62001-12-06 18:22:17 +0000821 case sPasswordAuthentication:
822 intptr = &options->password_authentication;
823 goto parse_flag;
824
825 case sKbdInteractiveAuthentication:
826 intptr = &options->kbd_interactive_authentication;
827 goto parse_flag;
828
829 case sChallengeResponseAuthentication:
830 intptr = &options->challenge_response_authentication;
831 goto parse_flag;
832
833 case sPrintMotd:
834 intptr = &options->print_motd;
835 goto parse_flag;
836
837 case sPrintLastLog:
838 intptr = &options->print_lastlog;
839 goto parse_flag;
840
841 case sX11Forwarding:
842 intptr = &options->x11_forwarding;
843 goto parse_flag;
844
845 case sX11DisplayOffset:
846 intptr = &options->x11_display_offset;
847 goto parse_int;
848
Damien Miller95c249f2002-02-05 12:11:34 +1100849 case sX11UseLocalhost:
850 intptr = &options->x11_use_localhost;
851 goto parse_flag;
852
Ben Lindstromade03f62001-12-06 18:22:17 +0000853 case sXAuthLocation:
854 charptr = &options->xauth_location;
855 goto parse_filename;
856
857 case sStrictModes:
858 intptr = &options->strict_modes;
859 goto parse_flag;
860
Damien Miller12c150e2003-12-17 16:31:10 +1100861 case sTCPKeepAlive:
862 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000863 goto parse_flag;
864
865 case sEmptyPasswd:
866 intptr = &options->permit_empty_passwd;
867 goto parse_flag;
868
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000869 case sPermitUserEnvironment:
870 intptr = &options->permit_user_env;
871 goto parse_flag;
872
Ben Lindstromade03f62001-12-06 18:22:17 +0000873 case sUseLogin:
874 intptr = &options->use_login;
875 goto parse_flag;
876
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000877 case sCompression:
878 intptr = &options->compression;
Damien Miller9786e6e2005-07-26 21:54:56 +1000879 arg = strdelim(&cp);
880 if (!arg || *arg == '\0')
881 fatal("%s line %d: missing yes/no/delayed "
882 "argument.", filename, linenum);
883 value = 0; /* silence compiler */
884 if (strcmp(arg, "delayed") == 0)
885 value = COMP_DELAYED;
886 else if (strcmp(arg, "yes") == 0)
887 value = COMP_ZLIB;
888 else if (strcmp(arg, "no") == 0)
889 value = COMP_NONE;
890 else
891 fatal("%s line %d: Bad yes/no/delayed "
892 "argument: %s", filename, linenum, arg);
893 if (*intptr == -1)
894 *intptr = value;
895 break;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000896
Ben Lindstromade03f62001-12-06 18:22:17 +0000897 case sGatewayPorts:
898 intptr = &options->gateway_ports;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100899 arg = strdelim(&cp);
900 if (!arg || *arg == '\0')
901 fatal("%s line %d: missing yes/no/clientspecified "
902 "argument.", filename, linenum);
903 value = 0; /* silence compiler */
904 if (strcmp(arg, "clientspecified") == 0)
905 value = 2;
906 else if (strcmp(arg, "yes") == 0)
907 value = 1;
908 else if (strcmp(arg, "no") == 0)
909 value = 0;
910 else
911 fatal("%s line %d: Bad yes/no/clientspecified "
912 "argument: %s", filename, linenum, arg);
913 if (*intptr == -1)
914 *intptr = value;
915 break;
Ben Lindstromade03f62001-12-06 18:22:17 +0000916
Damien Miller3a961dc2003-06-03 10:25:48 +1000917 case sUseDNS:
918 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000919 goto parse_flag;
920
921 case sLogFacility:
922 intptr = (int *) &options->log_facility;
923 arg = strdelim(&cp);
924 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100925 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000926 fatal("%.200s line %d: unsupported log facility '%s'",
927 filename, linenum, arg ? arg : "<NONE>");
928 if (*intptr == -1)
929 *intptr = (SyslogFacility) value;
930 break;
931
932 case sLogLevel:
933 intptr = (int *) &options->log_level;
934 arg = strdelim(&cp);
935 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100936 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000937 fatal("%.200s line %d: unsupported log level '%s'",
938 filename, linenum, arg ? arg : "<NONE>");
939 if (*intptr == -1)
940 *intptr = (LogLevel) value;
941 break;
942
943 case sAllowTcpForwarding:
944 intptr = &options->allow_tcp_forwarding;
945 goto parse_flag;
946
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000947 case sUsePrivilegeSeparation:
948 intptr = &use_privsep;
949 goto parse_flag;
950
Ben Lindstromade03f62001-12-06 18:22:17 +0000951 case sAllowUsers:
952 while ((arg = strdelim(&cp)) && *arg != '\0') {
953 if (options->num_allow_users >= MAX_ALLOW_USERS)
954 fatal("%s line %d: too many allow users.",
955 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000956 options->allow_users[options->num_allow_users++] =
957 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000958 }
959 break;
960
961 case sDenyUsers:
962 while ((arg = strdelim(&cp)) && *arg != '\0') {
963 if (options->num_deny_users >= MAX_DENY_USERS)
964 fatal( "%s line %d: too many deny users.",
965 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000966 options->deny_users[options->num_deny_users++] =
967 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000968 }
969 break;
970
971 case sAllowGroups:
972 while ((arg = strdelim(&cp)) && *arg != '\0') {
973 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
974 fatal("%s line %d: too many allow groups.",
975 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000976 options->allow_groups[options->num_allow_groups++] =
977 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000978 }
979 break;
980
981 case sDenyGroups:
982 while ((arg = strdelim(&cp)) && *arg != '\0') {
983 if (options->num_deny_groups >= MAX_DENY_GROUPS)
984 fatal("%s line %d: too many deny groups.",
985 filename, linenum);
986 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
987 }
988 break;
989
990 case sCiphers:
991 arg = strdelim(&cp);
992 if (!arg || *arg == '\0')
993 fatal("%s line %d: Missing argument.", filename, linenum);
994 if (!ciphers_valid(arg))
995 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
996 filename, linenum, arg ? arg : "<NONE>");
997 if (options->ciphers == NULL)
998 options->ciphers = xstrdup(arg);
999 break;
1000
1001 case sMacs:
1002 arg = strdelim(&cp);
1003 if (!arg || *arg == '\0')
1004 fatal("%s line %d: Missing argument.", filename, linenum);
1005 if (!mac_valid(arg))
1006 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1007 filename, linenum, arg ? arg : "<NONE>");
1008 if (options->macs == NULL)
1009 options->macs = xstrdup(arg);
1010 break;
1011
1012 case sProtocol:
1013 intptr = &options->protocol;
1014 arg = strdelim(&cp);
1015 if (!arg || *arg == '\0')
1016 fatal("%s line %d: Missing argument.", filename, linenum);
1017 value = proto_spec(arg);
1018 if (value == SSH_PROTO_UNKNOWN)
1019 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001020 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +00001021 if (*intptr == SSH_PROTO_UNKNOWN)
1022 *intptr = value;
1023 break;
1024
1025 case sSubsystem:
1026 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1027 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001028 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001029 }
1030 arg = strdelim(&cp);
1031 if (!arg || *arg == '\0')
1032 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001033 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001034 if (!*activep) {
1035 arg = strdelim(&cp);
1036 break;
1037 }
Ben Lindstromade03f62001-12-06 18:22:17 +00001038 for (i = 0; i < options->num_subsystems; i++)
1039 if (strcmp(arg, options->subsystem_name[i]) == 0)
1040 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001041 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +00001042 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1043 arg = strdelim(&cp);
1044 if (!arg || *arg == '\0')
1045 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001046 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001047 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Miller917f9b62006-07-10 20:36:47 +10001048
1049 /* Collect arguments (separate to executable) */
1050 p = xstrdup(arg);
1051 len = strlen(p) + 1;
1052 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1053 len += 1 + strlen(arg);
1054 p = xrealloc(p, 1, len);
1055 strlcat(p, " ", len);
1056 strlcat(p, arg, len);
1057 }
1058 options->subsystem_args[options->num_subsystems] = p;
Ben Lindstromade03f62001-12-06 18:22:17 +00001059 options->num_subsystems++;
1060 break;
1061
1062 case sMaxStartups:
1063 arg = strdelim(&cp);
1064 if (!arg || *arg == '\0')
1065 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001066 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +00001067 if ((n = sscanf(arg, "%d:%d:%d",
1068 &options->max_startups_begin,
1069 &options->max_startups_rate,
1070 &options->max_startups)) == 3) {
1071 if (options->max_startups_begin >
1072 options->max_startups ||
1073 options->max_startups_rate > 100 ||
1074 options->max_startups_rate < 1)
1075 fatal("%s line %d: Illegal MaxStartups spec.",
1076 filename, linenum);
1077 } else if (n != 1)
1078 fatal("%s line %d: Illegal MaxStartups spec.",
1079 filename, linenum);
1080 else
1081 options->max_startups = options->max_startups_begin;
1082 break;
1083
Darren Tucker89413db2004-05-24 10:36:23 +10001084 case sMaxAuthTries:
1085 intptr = &options->max_authtries;
1086 goto parse_int;
1087
Ben Lindstromade03f62001-12-06 18:22:17 +00001088 case sBanner:
1089 charptr = &options->banner;
1090 goto parse_filename;
1091 /*
1092 * These options can contain %X options expanded at
1093 * connect time, so that you can specify paths like:
1094 *
1095 * AuthorizedKeysFile /etc/ssh_keys/%u
1096 */
1097 case sAuthorizedKeysFile:
1098 case sAuthorizedKeysFile2:
1099 charptr = (opcode == sAuthorizedKeysFile ) ?
1100 &options->authorized_keys_file :
1101 &options->authorized_keys_file2;
1102 goto parse_filename;
1103
1104 case sClientAliveInterval:
1105 intptr = &options->client_alive_interval;
1106 goto parse_time;
1107
1108 case sClientAliveCountMax:
1109 intptr = &options->client_alive_count_max;
1110 goto parse_int;
1111
Darren Tucker46bc0752004-05-02 22:11:30 +10001112 case sAcceptEnv:
1113 while ((arg = strdelim(&cp)) && *arg != '\0') {
1114 if (strchr(arg, '=') != NULL)
1115 fatal("%s line %d: Invalid environment name.",
1116 filename, linenum);
1117 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1118 fatal("%s line %d: too many allow env.",
1119 filename, linenum);
Darren Tucker45150472006-07-12 22:34:17 +10001120 if (!*activep)
1121 break;
Darren Tucker46bc0752004-05-02 22:11:30 +10001122 options->accept_env[options->num_accept_env++] =
1123 xstrdup(arg);
1124 }
1125 break;
1126
Damien Millerd27b9472005-12-13 19:29:02 +11001127 case sPermitTunnel:
1128 intptr = &options->permit_tun;
Damien Miller7b58e802005-12-13 19:33:19 +11001129 arg = strdelim(&cp);
1130 if (!arg || *arg == '\0')
1131 fatal("%s line %d: Missing yes/point-to-point/"
1132 "ethernet/no argument.", filename, linenum);
1133 value = 0; /* silence compiler */
1134 if (strcasecmp(arg, "ethernet") == 0)
1135 value = SSH_TUNMODE_ETHERNET;
1136 else if (strcasecmp(arg, "point-to-point") == 0)
1137 value = SSH_TUNMODE_POINTOPOINT;
1138 else if (strcasecmp(arg, "yes") == 0)
1139 value = SSH_TUNMODE_YES;
1140 else if (strcasecmp(arg, "no") == 0)
1141 value = SSH_TUNMODE_NO;
1142 else
1143 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1144 "no argument: %s", filename, linenum, arg);
1145 if (*intptr == -1)
1146 *intptr = value;
1147 break;
Damien Millerd27b9472005-12-13 19:29:02 +11001148
Darren Tucker45150472006-07-12 22:34:17 +10001149 case sMatch:
1150 if (cmdline)
1151 fatal("Match directive not supported as a command-line "
1152 "option");
1153 value = match_cfg_line(&cp, linenum, user, host, address);
1154 if (value < 0)
1155 fatal("%s line %d: Bad Match condition", filename,
1156 linenum);
1157 *activep = value;
1158 break;
1159
Damien Miller9b439df2006-07-24 14:04:00 +10001160 case sPermitOpen:
1161 arg = strdelim(&cp);
1162 if (!arg || *arg == '\0')
1163 fatal("%s line %d: missing PermitOpen specification",
1164 filename, linenum);
1165 if (strcmp(arg, "any") == 0) {
Damien Millera765cf42006-07-24 14:08:13 +10001166 if (*activep) {
Damien Miller9b439df2006-07-24 14:04:00 +10001167 channel_clear_adm_permitted_opens();
Damien Millera765cf42006-07-24 14:08:13 +10001168 options->num_permitted_opens = 0;
1169 }
Damien Miller9b439df2006-07-24 14:04:00 +10001170 break;
1171 }
Damien Millera765cf42006-07-24 14:08:13 +10001172 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1173 p = hpdelim(&arg);
1174 if (p == NULL)
1175 fatal("%s line %d: missing host in PermitOpen",
1176 filename, linenum);
1177 p = cleanhostname(p);
1178 if (arg == NULL || (port = a2port(arg)) == 0)
1179 fatal("%s line %d: bad port number in "
1180 "PermitOpen", filename, linenum);
1181 if (*activep && options->num_permitted_opens == -1) {
1182 channel_clear_adm_permitted_opens();
1183 options->num_permitted_opens =
1184 channel_add_adm_permitted_opens(p, port);
1185 }
1186 }
Damien Miller9b439df2006-07-24 14:04:00 +10001187 break;
1188
Damien Millere2754432006-07-24 14:06:47 +10001189 case sForceCommand:
1190 if (cp == NULL)
1191 fatal("%.200s line %d: Missing argument.", filename,
1192 linenum);
1193 len = strspn(cp, WHITESPACE);
1194 if (*activep && options->adm_forced_command == NULL)
1195 options->adm_forced_command = xstrdup(cp + len);
1196 return 0;
1197
Ben Lindstromade03f62001-12-06 18:22:17 +00001198 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +10001199 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +00001200 filename, linenum, arg);
1201 while (arg)
1202 arg = strdelim(&cp);
1203 break;
1204
Damien Millerf9b3feb2003-05-16 11:38:32 +10001205 case sUnsupported:
1206 logit("%s line %d: Unsupported option %s",
1207 filename, linenum, arg);
1208 while (arg)
1209 arg = strdelim(&cp);
1210 break;
1211
Ben Lindstromade03f62001-12-06 18:22:17 +00001212 default:
1213 fatal("%s line %d: Missing handler for opcode %s (%d)",
1214 filename, linenum, arg, opcode);
1215 }
1216 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1217 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1218 filename, linenum, arg);
1219 return 0;
1220}
1221
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001222/* Reads the server configuration file. */
1223
Damien Miller4af51302000-04-16 11:18:38 +10001224void
Darren Tucker645ab752004-06-25 13:33:20 +10001225load_server_config(const char *filename, Buffer *conf)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001226{
Darren Tucker645ab752004-06-25 13:33:20 +10001227 char line[1024], *cp;
Ben Lindstrome1353632002-06-23 21:29:23 +00001228 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001229
Darren Tucker645ab752004-06-25 13:33:20 +10001230 debug2("%s: filename %s", __func__, filename);
1231 if ((f = fopen(filename, "r")) == NULL) {
Damien Miller95def091999-11-25 00:26:21 +11001232 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001233 exit(1);
Damien Miller95def091999-11-25 00:26:21 +11001234 }
Darren Tucker645ab752004-06-25 13:33:20 +10001235 buffer_clear(conf);
Damien Miller95def091999-11-25 00:26:21 +11001236 while (fgets(line, sizeof(line), f)) {
Darren Tucker645ab752004-06-25 13:33:20 +10001237 /*
1238 * Trim out comments and strip whitespace
Darren Tuckerfc959702004-07-17 16:12:08 +10001239 * NB - preserve newlines, they are needed to reproduce
Darren Tucker645ab752004-06-25 13:33:20 +10001240 * line numbers later for error messages
1241 */
1242 if ((cp = strchr(line, '#')) != NULL)
1243 memcpy(cp, "\n", 2);
1244 cp = line + strspn(line, " \t\r");
1245
1246 buffer_append(conf, cp, strlen(cp));
1247 }
1248 buffer_append(conf, "\0", 1);
1249 fclose(f);
1250 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1251}
1252
1253void
Darren Tucker45150472006-07-12 22:34:17 +10001254parse_server_match_config(ServerOptions *options, const char *user,
1255 const char *host, const char *address)
Darren Tucker645ab752004-06-25 13:33:20 +10001256{
Darren Tucker45150472006-07-12 22:34:17 +10001257 ServerOptions mo;
1258
1259 initialize_server_options(&mo);
1260 parse_server_config(&mo, "reprocess config", &cfg, user, host, address);
1261 copy_set_server_options(options, &mo);
1262}
1263
1264/* Copy any (supported) values that are set */
1265void
1266copy_set_server_options(ServerOptions *dst, ServerOptions *src)
1267{
1268 if (src->allow_tcp_forwarding != -1)
1269 dst->allow_tcp_forwarding = src->allow_tcp_forwarding;
1270 if (src->gateway_ports != -1)
1271 dst->gateway_ports = src->gateway_ports;
Damien Millere2754432006-07-24 14:06:47 +10001272 if (src->adm_forced_command != NULL) {
1273 if (dst->adm_forced_command != NULL)
1274 xfree(dst->adm_forced_command);
1275 dst->adm_forced_command = src->adm_forced_command;
1276 }
Damien Millerd1de9952006-07-24 14:05:48 +10001277 if (src->x11_display_offset != -1)
1278 dst->x11_display_offset = src->x11_display_offset;
1279 if (src->x11_forwarding != -1)
1280 dst->x11_forwarding = src->x11_forwarding;
1281 if (src->x11_use_localhost != -1)
1282 dst->x11_use_localhost = src->x11_use_localhost;
Darren Tucker45150472006-07-12 22:34:17 +10001283}
1284
1285void
1286parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1287 const char *user, const char *host, const char *address)
1288{
1289 int active, linenum, bad_options = 0;
Darren Tucker9fbac712004-08-12 22:41:44 +10001290 char *cp, *obuf, *cbuf;
Darren Tucker645ab752004-06-25 13:33:20 +10001291
1292 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1293
Darren Tucker9fbac712004-08-12 22:41:44 +10001294 obuf = cbuf = xstrdup(buffer_ptr(conf));
Darren Tucker45150472006-07-12 22:34:17 +10001295 active = user ? 0 : 1;
Darren Tucker137e9c92004-08-13 21:30:24 +10001296 linenum = 1;
Darren Tucker47eede72005-03-14 23:08:12 +11001297 while ((cp = strsep(&cbuf, "\n")) != NULL) {
Darren Tucker645ab752004-06-25 13:33:20 +10001298 if (process_server_config_line(options, cp, filename,
Darren Tucker45150472006-07-12 22:34:17 +10001299 linenum++, &active, user, host, address) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001300 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001301 }
Darren Tucker9fbac712004-08-12 22:41:44 +10001302 xfree(obuf);
Ben Lindstromb5cdc662001-04-16 02:13:26 +00001303 if (bad_options > 0)
1304 fatal("%s: terminating, %d bad configuration options",
1305 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001306}