blob: 3b6b55e93f154dec8d58de4237fb07a43a8567d5 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Millere4340be2000-09-16 13:29:08 +11005 * As far as I am concerned, the code I have written for this software
6 * can be used freely for any purpose. Any derived versions of this
7 * software must be clearly marked as such, and if the derived work is
8 * incompatible with the protocol description in the RFC file, it must be
9 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110010 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100011
12#include "includes.h"
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000013RCSID("$OpenBSD: servconf.c,v 1.102 2002/03/18 17:50:31 provos Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
Damien Millerc4b7fea2001-07-14 12:20:32 +100015#if defined(KRB4) || defined(KRB5)
Ben Lindstrom226cfa02001-01-22 05:34:40 +000016#include <krb.h>
17#endif
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000018#ifdef AFS
19#include <kafs.h>
20#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021
22#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"
28#include "tildexpand.h"
29#include "misc.h"
30#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000031#include "kex.h"
32#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000033
Ben Lindstrombba81212001-06-25 05:01:22 +000034static void add_listen_addr(ServerOptions *, char *, u_short);
35static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110036
Ben Lindstrom226cfa02001-01-22 05:34:40 +000037/* AF_UNSPEC or AF_INET or AF_INET6 */
38extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000039/* Use of privilege separation or not */
40extern int use_privsep;
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 */
50 options->pam_authentication_via_kbd_int = -1;
51
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;
Damien Miller0bc1bd82000-11-13 22:57:25 +110056 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100057 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110058 options->server_key_bits = -1;
59 options->login_grace_time = -1;
60 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000061 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110062 options->ignore_rhosts = -1;
63 options->ignore_user_known_hosts = -1;
64 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000065 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110066 options->x11_forwarding = -1;
67 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110068 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100069 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110070 options->strict_modes = -1;
71 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110072 options->log_facility = SYSLOG_FACILITY_NOT_SET;
73 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110074 options->rhosts_authentication = -1;
75 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;
Ben Lindstromec95ed92001-07-04 04:21:14 +000080#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110081 options->kerberos_authentication = -1;
82 options->kerberos_or_local_passwd = -1;
83 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100084#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +000085#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110086 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000087#endif
88#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110089 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100090#endif
Damien Miller95def091999-11-25 00:26:21 +110091 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110092 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000093 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110094 options->permit_empty_passwd = -1;
95 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110096 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110097 options->num_allow_users = 0;
98 options->num_deny_users = 0;
99 options->num_allow_groups = 0;
100 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000101 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000102 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000103 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000104 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000105 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000106 options->max_startups_begin = -1;
107 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000108 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000109 options->banner = NULL;
Damien Millerc5d86352002-02-05 12:13:41 +1100110 options->verify_reverse_mapping = -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;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000115
116 options->unprivileged_user = -1;
117 options->unprivileged_group = -1;
118 options->unprivileged_dir = NULL;
119
120 /* Needs to be accessable in many places */
121 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000122}
123
Damien Miller4af51302000-04-16 11:18:38 +1000124void
Damien Miller95def091999-11-25 00:26:21 +1100125fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000126{
Damien Miller726273e2001-11-12 11:40:11 +1100127 /* Portable-specific options */
128 if (options->pam_authentication_via_kbd_int == -1)
129 options->pam_authentication_via_kbd_int = 0;
130
131 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100132 if (options->protocol == SSH_PROTO_UNKNOWN)
133 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
134 if (options->num_host_key_files == 0) {
135 /* fill default hostkeys for protocols */
136 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100137 options->host_key_files[options->num_host_key_files++] =
138 _PATH_HOST_KEY_FILE;
139 if (options->protocol & SSH_PROTO_2) {
140 options->host_key_files[options->num_host_key_files++] =
141 _PATH_HOST_RSA_KEY_FILE;
142 options->host_key_files[options->num_host_key_files++] =
143 _PATH_HOST_DSA_KEY_FILE;
144 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100145 }
Damien Miller34132e52000-01-14 15:45:46 +1100146 if (options->num_ports == 0)
147 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
148 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000149 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000150 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000151 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100152 if (options->server_key_bits == -1)
153 options->server_key_bits = 768;
154 if (options->login_grace_time == -1)
155 options->login_grace_time = 600;
156 if (options->key_regeneration_time == -1)
157 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000158 if (options->permit_root_login == PERMIT_NOT_SET)
159 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100160 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100161 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100162 if (options->ignore_user_known_hosts == -1)
163 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100164 if (options->print_motd == -1)
165 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000166 if (options->print_lastlog == -1)
167 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100168 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100169 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100170 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100171 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100172 if (options->x11_use_localhost == -1)
173 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000174 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000175 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100176 if (options->strict_modes == -1)
177 options->strict_modes = 1;
178 if (options->keepalives == -1)
179 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100180 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100181 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100182 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000183 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100184 if (options->rhosts_authentication == -1)
185 options->rhosts_authentication = 0;
186 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100187 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000188 if (options->hostbased_authentication == -1)
189 options->hostbased_authentication = 0;
190 if (options->hostbased_uses_name_from_packet_only == -1)
191 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->rsa_authentication == -1)
193 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100194 if (options->pubkey_authentication == -1)
195 options->pubkey_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000196#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->kerberos_authentication == -1)
198 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
199 if (options->kerberos_or_local_passwd == -1)
200 options->kerberos_or_local_passwd = 1;
201 if (options->kerberos_ticket_cleanup == -1)
202 options->kerberos_ticket_cleanup = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000203#endif
204#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->kerberos_tgt_passing == -1)
206 options->kerberos_tgt_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000207#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100208#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->afs_token_passing == -1)
210 options->afs_token_passing = k_hasafs();
Ben Lindstromec95ed92001-07-04 04:21:14 +0000211#endif
Damien Miller95def091999-11-25 00:26:21 +1100212 if (options->password_authentication == -1)
213 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100214 if (options->kbd_interactive_authentication == -1)
215 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000216 if (options->challenge_response_authentication == -1)
217 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100218 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100219 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->use_login == -1)
221 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100222 if (options->allow_tcp_forwarding == -1)
223 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000224 if (options->gateway_ports == -1)
225 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000226 if (options->max_startups == -1)
227 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000228 if (options->max_startups_rate == -1)
229 options->max_startups_rate = 100; /* 100% */
230 if (options->max_startups_begin == -1)
231 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100232 if (options->verify_reverse_mapping == -1)
233 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000234 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100235 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000236 if (options->client_alive_count_max == -1)
237 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100238 if (options->authorized_keys_file2 == NULL) {
239 /* authorized_keys_file2 falls back to authorized_keys_file */
240 if (options->authorized_keys_file != NULL)
241 options->authorized_keys_file2 = options->authorized_keys_file;
242 else
243 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
244 }
245 if (options->authorized_keys_file == NULL)
246 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000247
248 /* Turn privilege separation _off_ by default */
249 if (use_privsep == -1)
250 use_privsep = 0;
251 if (options->unprivileged_user == -1)
252 options->unprivileged_user = 32767;
253 if (options->unprivileged_group == -1)
254 options->unprivileged_group = 32767;
255 if (options->unprivileged_dir == NULL)
256 options->unprivileged_dir = "/var/empty";
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000257}
258
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000259/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100260typedef enum {
261 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100262 /* Portable-specific options */
263 sPAMAuthenticationViaKbdInt,
264 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100265 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
266 sPermitRootLogin, sLogFacility, sLogLevel,
267 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000268#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100269 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000270#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000271#if defined(AFS) || defined(KRB5)
272 sKerberosTgtPassing,
273#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000274#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000275 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000276#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000277 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100278 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000279 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100280 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000281 sStrictModes, sEmptyPasswd, sKeepAlives,
Damien Miller50a41ed2000-10-16 12:14:42 +1100282 sUseLogin, sAllowTcpForwarding,
283 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000284 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100285 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100286 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100287 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000288 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000289 sUsePrivilegeSeparation, sUnprivUser, sUnprivGroup, sUnprivDir,
Ben Lindstromade03f62001-12-06 18:22:17 +0000290 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000291} ServerOpCodes;
292
293/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100294static struct {
295 const char *name;
296 ServerOpCodes opcode;
297} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100298 /* Portable-specific options */
299 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
300 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100301 { "port", sPort },
302 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100303 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000304 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100305 { "serverkeybits", sServerKeyBits },
306 { "logingracetime", sLoginGraceTime },
307 { "keyregenerationinterval", sKeyRegenerationTime },
308 { "permitrootlogin", sPermitRootLogin },
309 { "syslogfacility", sLogFacility },
310 { "loglevel", sLogLevel },
311 { "rhostsauthentication", sRhostsAuthentication },
312 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000313 { "hostbasedauthentication", sHostbasedAuthentication },
314 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100315 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100316 { "pubkeyauthentication", sPubkeyAuthentication },
317 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000318#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100319 { "kerberosauthentication", sKerberosAuthentication },
320 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
321 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000322#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000323#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100324 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000325#endif
326#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100327 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000328#endif
Damien Miller95def091999-11-25 00:26:21 +1100329 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100330 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000331 { "challengeresponseauthentication", sChallengeResponseAuthentication },
332 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000333 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100334 { "listenaddress", sListenAddress },
335 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000336 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100337 { "ignorerhosts", sIgnoreRhosts },
338 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
339 { "x11forwarding", sX11Forwarding },
340 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100341 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000342 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100343 { "strictmodes", sStrictModes },
344 { "permitemptypasswords", sEmptyPasswd },
345 { "uselogin", sUseLogin },
Damien Miller95def091999-11-25 00:26:21 +1100346 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100347 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100348 { "allowusers", sAllowUsers },
349 { "denyusers", sDenyUsers },
350 { "allowgroups", sAllowGroups },
351 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000352 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000353 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000354 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000355 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000356 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000357 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000358 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100359 { "verifyreversemapping", sVerifyReverseMapping },
360 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000361 { "clientaliveinterval", sClientAliveInterval },
362 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000363 { "authorizedkeysfile", sAuthorizedKeysFile },
364 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000365 { "useprivilegeseparation", sUsePrivilegeSeparation},
366 { "unprivuser", sUnprivUser},
367 { "unprivgroup", sUnprivGroup},
368 { "unprivdir", sUnprivDir},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000369 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000370};
371
Damien Miller5428f641999-11-25 11:54:57 +1100372/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000373 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100374 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000375
Damien Miller4af51302000-04-16 11:18:38 +1000376static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100377parse_token(const char *cp, const char *filename,
378 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000380 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381
Damien Miller95def091999-11-25 00:26:21 +1100382 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100383 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100384 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000385
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000386 error("%s: line %d: Bad configuration option: %s",
387 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100388 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000389}
390
Ben Lindstrombba81212001-06-25 05:01:22 +0000391static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000392add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100393{
Damien Miller34132e52000-01-14 15:45:46 +1100394 int i;
395
396 if (options->num_ports == 0)
397 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000398 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000399 for (i = 0; i < options->num_ports; i++)
400 add_one_listen_addr(options, addr, options->ports[i]);
401 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000402 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000403}
404
Ben Lindstrombba81212001-06-25 05:01:22 +0000405static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000406add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
407{
408 struct addrinfo hints, *ai, *aitop;
409 char strport[NI_MAXSERV];
410 int gaierr;
411
412 memset(&hints, 0, sizeof(hints));
413 hints.ai_family = IPv4or6;
414 hints.ai_socktype = SOCK_STREAM;
415 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
416 snprintf(strport, sizeof strport, "%d", port);
417 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
418 fatal("bad addr or host: %s (%s)",
419 addr ? addr : "<NULL>",
420 gai_strerror(gaierr));
421 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
422 ;
423 ai->ai_next = options->listen_addrs;
424 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100425}
426
Ben Lindstromade03f62001-12-06 18:22:17 +0000427int
428process_server_config_line(ServerOptions *options, char *line,
429 const char *filename, int linenum)
430{
431 char *cp, **charptr, *arg, *p;
432 int *intptr, value;
433 ServerOpCodes opcode;
434 int i, n;
435
436 cp = line;
437 arg = strdelim(&cp);
438 /* Ignore leading whitespace */
439 if (*arg == '\0')
440 arg = strdelim(&cp);
441 if (!arg || !*arg || *arg == '#')
442 return 0;
443 intptr = NULL;
444 charptr = NULL;
445 opcode = parse_token(arg, filename, linenum);
446 switch (opcode) {
447 /* Portable-specific options */
448 case sPAMAuthenticationViaKbdInt:
449 intptr = &options->pam_authentication_via_kbd_int;
450 goto parse_flag;
451
452 /* Standard Options */
453 case sBadOption:
454 return -1;
455 case sPort:
456 /* ignore ports from configfile if cmdline specifies ports */
457 if (options->ports_from_cmdline)
458 return 0;
459 if (options->listen_addrs != NULL)
460 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100461 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000462 if (options->num_ports >= MAX_PORTS)
463 fatal("%s line %d: too many ports.",
464 filename, linenum);
465 arg = strdelim(&cp);
466 if (!arg || *arg == '\0')
467 fatal("%s line %d: missing port number.",
468 filename, linenum);
469 options->ports[options->num_ports++] = a2port(arg);
470 if (options->ports[options->num_ports-1] == 0)
471 fatal("%s line %d: Badly formatted port number.",
472 filename, linenum);
473 break;
474
475 case sServerKeyBits:
476 intptr = &options->server_key_bits;
477parse_int:
478 arg = strdelim(&cp);
479 if (!arg || *arg == '\0')
480 fatal("%s line %d: missing integer value.",
481 filename, linenum);
482 value = atoi(arg);
483 if (*intptr == -1)
484 *intptr = value;
485 break;
486
487 case sLoginGraceTime:
488 intptr = &options->login_grace_time;
489parse_time:
490 arg = strdelim(&cp);
491 if (!arg || *arg == '\0')
492 fatal("%s line %d: missing time value.",
493 filename, linenum);
494 if ((value = convtime(arg)) == -1)
495 fatal("%s line %d: invalid time value.",
496 filename, linenum);
497 if (*intptr == -1)
498 *intptr = value;
499 break;
500
501 case sKeyRegenerationTime:
502 intptr = &options->key_regeneration_time;
503 goto parse_time;
504
505 case sListenAddress:
506 arg = strdelim(&cp);
507 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
508 fatal("%s line %d: missing inet addr.",
509 filename, linenum);
510 if (*arg == '[') {
511 if ((p = strchr(arg, ']')) == NULL)
512 fatal("%s line %d: bad ipv6 inet addr usage.",
513 filename, linenum);
514 arg++;
515 memmove(p, p+1, strlen(p+1)+1);
516 } else if (((p = strchr(arg, ':')) == NULL) ||
517 (strchr(p+1, ':') != NULL)) {
518 add_listen_addr(options, arg, 0);
519 break;
520 }
521 if (*p == ':') {
522 u_short port;
523
524 p++;
525 if (*p == '\0')
526 fatal("%s line %d: bad inet addr:port usage.",
527 filename, linenum);
528 else {
529 *(p-1) = '\0';
530 if ((port = a2port(p)) == 0)
531 fatal("%s line %d: bad port number.",
532 filename, linenum);
533 add_listen_addr(options, arg, port);
534 }
535 } else if (*p == '\0')
536 add_listen_addr(options, arg, 0);
537 else
538 fatal("%s line %d: bad inet addr usage.",
539 filename, linenum);
540 break;
541
542 case sHostKeyFile:
543 intptr = &options->num_host_key_files;
544 if (*intptr >= MAX_HOSTKEYS)
545 fatal("%s line %d: too many host keys specified (max %d).",
546 filename, linenum, MAX_HOSTKEYS);
547 charptr = &options->host_key_files[*intptr];
548parse_filename:
549 arg = strdelim(&cp);
550 if (!arg || *arg == '\0')
551 fatal("%s line %d: missing file name.",
552 filename, linenum);
553 if (*charptr == NULL) {
554 *charptr = tilde_expand_filename(arg, getuid());
555 /* increase optional counter */
556 if (intptr != NULL)
557 *intptr = *intptr + 1;
558 }
559 break;
560
561 case sPidFile:
562 charptr = &options->pid_file;
563 goto parse_filename;
564
565 case sPermitRootLogin:
566 intptr = &options->permit_root_login;
567 arg = strdelim(&cp);
568 if (!arg || *arg == '\0')
569 fatal("%s line %d: missing yes/"
570 "without-password/forced-commands-only/no "
571 "argument.", filename, linenum);
572 value = 0; /* silence compiler */
573 if (strcmp(arg, "without-password") == 0)
574 value = PERMIT_NO_PASSWD;
575 else if (strcmp(arg, "forced-commands-only") == 0)
576 value = PERMIT_FORCED_ONLY;
577 else if (strcmp(arg, "yes") == 0)
578 value = PERMIT_YES;
579 else if (strcmp(arg, "no") == 0)
580 value = PERMIT_NO;
581 else
582 fatal("%s line %d: Bad yes/"
583 "without-password/forced-commands-only/no "
584 "argument: %s", filename, linenum, arg);
585 if (*intptr == -1)
586 *intptr = value;
587 break;
588
589 case sIgnoreRhosts:
590 intptr = &options->ignore_rhosts;
591parse_flag:
592 arg = strdelim(&cp);
593 if (!arg || *arg == '\0')
594 fatal("%s line %d: missing yes/no argument.",
595 filename, linenum);
596 value = 0; /* silence compiler */
597 if (strcmp(arg, "yes") == 0)
598 value = 1;
599 else if (strcmp(arg, "no") == 0)
600 value = 0;
601 else
602 fatal("%s line %d: Bad yes/no argument: %s",
603 filename, linenum, arg);
604 if (*intptr == -1)
605 *intptr = value;
606 break;
607
608 case sIgnoreUserKnownHosts:
609 intptr = &options->ignore_user_known_hosts;
610 goto parse_flag;
611
612 case sRhostsAuthentication:
613 intptr = &options->rhosts_authentication;
614 goto parse_flag;
615
616 case sRhostsRSAAuthentication:
617 intptr = &options->rhosts_rsa_authentication;
618 goto parse_flag;
619
620 case sHostbasedAuthentication:
621 intptr = &options->hostbased_authentication;
622 goto parse_flag;
623
624 case sHostbasedUsesNameFromPacketOnly:
625 intptr = &options->hostbased_uses_name_from_packet_only;
626 goto parse_flag;
627
628 case sRSAAuthentication:
629 intptr = &options->rsa_authentication;
630 goto parse_flag;
631
632 case sPubkeyAuthentication:
633 intptr = &options->pubkey_authentication;
634 goto parse_flag;
635#if defined(KRB4) || defined(KRB5)
636 case sKerberosAuthentication:
637 intptr = &options->kerberos_authentication;
638 goto parse_flag;
639
640 case sKerberosOrLocalPasswd:
641 intptr = &options->kerberos_or_local_passwd;
642 goto parse_flag;
643
644 case sKerberosTicketCleanup:
645 intptr = &options->kerberos_ticket_cleanup;
646 goto parse_flag;
647#endif
648#if defined(AFS) || defined(KRB5)
649 case sKerberosTgtPassing:
650 intptr = &options->kerberos_tgt_passing;
651 goto parse_flag;
652#endif
653#ifdef AFS
654 case sAFSTokenPassing:
655 intptr = &options->afs_token_passing;
656 goto parse_flag;
657#endif
658
659 case sPasswordAuthentication:
660 intptr = &options->password_authentication;
661 goto parse_flag;
662
663 case sKbdInteractiveAuthentication:
664 intptr = &options->kbd_interactive_authentication;
665 goto parse_flag;
666
667 case sChallengeResponseAuthentication:
668 intptr = &options->challenge_response_authentication;
669 goto parse_flag;
670
671 case sPrintMotd:
672 intptr = &options->print_motd;
673 goto parse_flag;
674
675 case sPrintLastLog:
676 intptr = &options->print_lastlog;
677 goto parse_flag;
678
679 case sX11Forwarding:
680 intptr = &options->x11_forwarding;
681 goto parse_flag;
682
683 case sX11DisplayOffset:
684 intptr = &options->x11_display_offset;
685 goto parse_int;
686
Damien Miller95c249f2002-02-05 12:11:34 +1100687 case sX11UseLocalhost:
688 intptr = &options->x11_use_localhost;
689 goto parse_flag;
690
Ben Lindstromade03f62001-12-06 18:22:17 +0000691 case sXAuthLocation:
692 charptr = &options->xauth_location;
693 goto parse_filename;
694
695 case sStrictModes:
696 intptr = &options->strict_modes;
697 goto parse_flag;
698
699 case sKeepAlives:
700 intptr = &options->keepalives;
701 goto parse_flag;
702
703 case sEmptyPasswd:
704 intptr = &options->permit_empty_passwd;
705 goto parse_flag;
706
707 case sUseLogin:
708 intptr = &options->use_login;
709 goto parse_flag;
710
711 case sGatewayPorts:
712 intptr = &options->gateway_ports;
713 goto parse_flag;
714
Damien Millerc5d86352002-02-05 12:13:41 +1100715 case sVerifyReverseMapping:
716 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000717 goto parse_flag;
718
719 case sLogFacility:
720 intptr = (int *) &options->log_facility;
721 arg = strdelim(&cp);
722 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100723 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000724 fatal("%.200s line %d: unsupported log facility '%s'",
725 filename, linenum, arg ? arg : "<NONE>");
726 if (*intptr == -1)
727 *intptr = (SyslogFacility) value;
728 break;
729
730 case sLogLevel:
731 intptr = (int *) &options->log_level;
732 arg = strdelim(&cp);
733 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100734 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000735 fatal("%.200s line %d: unsupported log level '%s'",
736 filename, linenum, arg ? arg : "<NONE>");
737 if (*intptr == -1)
738 *intptr = (LogLevel) value;
739 break;
740
741 case sAllowTcpForwarding:
742 intptr = &options->allow_tcp_forwarding;
743 goto parse_flag;
744
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000745 case sUsePrivilegeSeparation:
746 intptr = &use_privsep;
747 goto parse_flag;
748
749 case sUnprivUser:
750 intptr = &options->unprivileged_user;
751 goto parse_flag;
752
753 case sUnprivGroup:
754 intptr = &options->unprivileged_group;
755 goto parse_flag;
756
757 case sUnprivDir:
758 charptr = &options->unprivileged_dir;
759 goto parse_filename;
760
Ben Lindstromade03f62001-12-06 18:22:17 +0000761 case sAllowUsers:
762 while ((arg = strdelim(&cp)) && *arg != '\0') {
763 if (options->num_allow_users >= MAX_ALLOW_USERS)
764 fatal("%s line %d: too many allow users.",
765 filename, linenum);
766 options->allow_users[options->num_allow_users++] = xstrdup(arg);
767 }
768 break;
769
770 case sDenyUsers:
771 while ((arg = strdelim(&cp)) && *arg != '\0') {
772 if (options->num_deny_users >= MAX_DENY_USERS)
773 fatal( "%s line %d: too many deny users.",
774 filename, linenum);
775 options->deny_users[options->num_deny_users++] = xstrdup(arg);
776 }
777 break;
778
779 case sAllowGroups:
780 while ((arg = strdelim(&cp)) && *arg != '\0') {
781 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
782 fatal("%s line %d: too many allow groups.",
783 filename, linenum);
784 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
785 }
786 break;
787
788 case sDenyGroups:
789 while ((arg = strdelim(&cp)) && *arg != '\0') {
790 if (options->num_deny_groups >= MAX_DENY_GROUPS)
791 fatal("%s line %d: too many deny groups.",
792 filename, linenum);
793 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
794 }
795 break;
796
797 case sCiphers:
798 arg = strdelim(&cp);
799 if (!arg || *arg == '\0')
800 fatal("%s line %d: Missing argument.", filename, linenum);
801 if (!ciphers_valid(arg))
802 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
803 filename, linenum, arg ? arg : "<NONE>");
804 if (options->ciphers == NULL)
805 options->ciphers = xstrdup(arg);
806 break;
807
808 case sMacs:
809 arg = strdelim(&cp);
810 if (!arg || *arg == '\0')
811 fatal("%s line %d: Missing argument.", filename, linenum);
812 if (!mac_valid(arg))
813 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
814 filename, linenum, arg ? arg : "<NONE>");
815 if (options->macs == NULL)
816 options->macs = xstrdup(arg);
817 break;
818
819 case sProtocol:
820 intptr = &options->protocol;
821 arg = strdelim(&cp);
822 if (!arg || *arg == '\0')
823 fatal("%s line %d: Missing argument.", filename, linenum);
824 value = proto_spec(arg);
825 if (value == SSH_PROTO_UNKNOWN)
826 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100827 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000828 if (*intptr == SSH_PROTO_UNKNOWN)
829 *intptr = value;
830 break;
831
832 case sSubsystem:
833 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
834 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100835 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000836 }
837 arg = strdelim(&cp);
838 if (!arg || *arg == '\0')
839 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100840 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000841 for (i = 0; i < options->num_subsystems; i++)
842 if (strcmp(arg, options->subsystem_name[i]) == 0)
843 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100844 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000845 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
846 arg = strdelim(&cp);
847 if (!arg || *arg == '\0')
848 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100849 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000850 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
851 options->num_subsystems++;
852 break;
853
854 case sMaxStartups:
855 arg = strdelim(&cp);
856 if (!arg || *arg == '\0')
857 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100858 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000859 if ((n = sscanf(arg, "%d:%d:%d",
860 &options->max_startups_begin,
861 &options->max_startups_rate,
862 &options->max_startups)) == 3) {
863 if (options->max_startups_begin >
864 options->max_startups ||
865 options->max_startups_rate > 100 ||
866 options->max_startups_rate < 1)
867 fatal("%s line %d: Illegal MaxStartups spec.",
868 filename, linenum);
869 } else if (n != 1)
870 fatal("%s line %d: Illegal MaxStartups spec.",
871 filename, linenum);
872 else
873 options->max_startups = options->max_startups_begin;
874 break;
875
876 case sBanner:
877 charptr = &options->banner;
878 goto parse_filename;
879 /*
880 * These options can contain %X options expanded at
881 * connect time, so that you can specify paths like:
882 *
883 * AuthorizedKeysFile /etc/ssh_keys/%u
884 */
885 case sAuthorizedKeysFile:
886 case sAuthorizedKeysFile2:
887 charptr = (opcode == sAuthorizedKeysFile ) ?
888 &options->authorized_keys_file :
889 &options->authorized_keys_file2;
890 goto parse_filename;
891
892 case sClientAliveInterval:
893 intptr = &options->client_alive_interval;
894 goto parse_time;
895
896 case sClientAliveCountMax:
897 intptr = &options->client_alive_count_max;
898 goto parse_int;
899
900 case sDeprecated:
901 log("%s line %d: Deprecated option %s",
902 filename, linenum, arg);
903 while (arg)
904 arg = strdelim(&cp);
905 break;
906
907 default:
908 fatal("%s line %d: Missing handler for opcode %s (%d)",
909 filename, linenum, arg, opcode);
910 }
911 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
912 fatal("%s line %d: garbage at end of line; \"%.200s\".",
913 filename, linenum, arg);
914 return 0;
915}
916
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000917/* Reads the server configuration file. */
918
Damien Miller4af51302000-04-16 11:18:38 +1000919void
Damien Miller95def091999-11-25 00:26:21 +1100920read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000921{
Damien Miller95def091999-11-25 00:26:21 +1100922 FILE *f;
923 char line[1024];
Ben Lindstromade03f62001-12-06 18:22:17 +0000924 int linenum;
Damien Miller95def091999-11-25 00:26:21 +1100925 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000926
Damien Miller95def091999-11-25 00:26:21 +1100927 f = fopen(filename, "r");
928 if (!f) {
929 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000930 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100931 }
932 linenum = 0;
933 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000934 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100935 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000936 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100937 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000938 }
Damien Miller95def091999-11-25 00:26:21 +1100939 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000940 if (bad_options > 0)
941 fatal("%s: terminating, %d bad configuration options",
942 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000943}