blob: b7f941ab5aed9801fa4d561efe45b8160d00a0e0 [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 Lindstrom23e0f662002-06-21 01:09:47 +000013RCSID("$OpenBSD: servconf.c,v 1.111 2002/06/20 23:05:55 markus Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
Damien Millerfd4c9ee2002-04-13 11:04:40 +100015#if defined(KRB4)
Ben Lindstrom226cfa02001-01-22 05:34:40 +000016#include <krb.h>
17#endif
Damien Millerfd4c9ee2002-04-13 11:04:40 +100018#if defined(KRB5)
19#ifdef HEIMDAL
20#include <krb.h>
21#else
22/* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V
23 * keytab */
24#define KEYFILE "/etc/krb5.keytab"
25#endif
26#endif
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000027#ifdef AFS
28#include <kafs.h>
29#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100030
31#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000032#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100033#include "servconf.h"
34#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100035#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036#include "pathnames.h"
37#include "tildexpand.h"
38#include "misc.h"
39#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000040#include "kex.h"
41#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000042
Ben Lindstrombba81212001-06-25 05:01:22 +000043static void add_listen_addr(ServerOptions *, char *, u_short);
44static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110045
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046/* AF_UNSPEC or AF_INET or AF_INET6 */
47extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000048/* Use of privilege separation or not */
49extern int use_privsep;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000050
Damien Millerd4a8b7e1999-10-27 13:42:43 +100051/* Initializes the server options to their default values. */
52
Damien Miller4af51302000-04-16 11:18:38 +100053void
Damien Miller95def091999-11-25 00:26:21 +110054initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100055{
Damien Miller95def091999-11-25 00:26:21 +110056 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110057
58 /* Portable-specific options */
59 options->pam_authentication_via_kbd_int = -1;
60
61 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110062 options->num_ports = 0;
63 options->ports_from_cmdline = 0;
64 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110065 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100066 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110067 options->server_key_bits = -1;
68 options->login_grace_time = -1;
69 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000070 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110071 options->ignore_rhosts = -1;
72 options->ignore_user_known_hosts = -1;
73 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000074 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110075 options->x11_forwarding = -1;
76 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110077 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100078 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110079 options->strict_modes = -1;
80 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110081 options->log_facility = SYSLOG_FACILITY_NOT_SET;
82 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110083 options->rhosts_authentication = -1;
84 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000085 options->hostbased_authentication = -1;
86 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110087 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110088 options->pubkey_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000089#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110090 options->kerberos_authentication = -1;
91 options->kerberos_or_local_passwd = -1;
92 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100093#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +000094#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110095 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000096#endif
97#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110098 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100099#endif
Damien Miller95def091999-11-25 00:26:21 +1100100 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100101 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000102 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->permit_empty_passwd = -1;
104 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000105 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100106 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->num_allow_users = 0;
108 options->num_deny_users = 0;
109 options->num_allow_groups = 0;
110 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000111 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000112 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000113 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000114 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000115 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000116 options->max_startups_begin = -1;
117 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000118 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000119 options->banner = NULL;
Damien Millerc5d86352002-02-05 12:13:41 +1100120 options->verify_reverse_mapping = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000121 options->client_alive_interval = -1;
122 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000123 options->authorized_keys_file = NULL;
124 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000125
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000126 /* Needs to be accessable in many places */
127 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000128}
129
Damien Miller4af51302000-04-16 11:18:38 +1000130void
Damien Miller95def091999-11-25 00:26:21 +1100131fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000132{
Damien Miller726273e2001-11-12 11:40:11 +1100133 /* Portable-specific options */
134 if (options->pam_authentication_via_kbd_int == -1)
135 options->pam_authentication_via_kbd_int = 0;
136
137 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100138 if (options->protocol == SSH_PROTO_UNKNOWN)
139 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
140 if (options->num_host_key_files == 0) {
141 /* fill default hostkeys for protocols */
142 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100143 options->host_key_files[options->num_host_key_files++] =
144 _PATH_HOST_KEY_FILE;
145 if (options->protocol & SSH_PROTO_2) {
146 options->host_key_files[options->num_host_key_files++] =
147 _PATH_HOST_RSA_KEY_FILE;
148 options->host_key_files[options->num_host_key_files++] =
149 _PATH_HOST_DSA_KEY_FILE;
150 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100151 }
Damien Miller34132e52000-01-14 15:45:46 +1100152 if (options->num_ports == 0)
153 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
154 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000155 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000156 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000157 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100158 if (options->server_key_bits == -1)
159 options->server_key_bits = 768;
160 if (options->login_grace_time == -1)
161 options->login_grace_time = 600;
162 if (options->key_regeneration_time == -1)
163 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000164 if (options->permit_root_login == PERMIT_NOT_SET)
165 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100166 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100167 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100168 if (options->ignore_user_known_hosts == -1)
169 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100170 if (options->print_motd == -1)
171 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000172 if (options->print_lastlog == -1)
173 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100174 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100175 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100176 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100177 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100178 if (options->x11_use_localhost == -1)
179 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000180 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000181 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100182 if (options->strict_modes == -1)
183 options->strict_modes = 1;
184 if (options->keepalives == -1)
185 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100186 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100187 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100188 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000189 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100190 if (options->rhosts_authentication == -1)
191 options->rhosts_authentication = 0;
192 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100193 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000194 if (options->hostbased_authentication == -1)
195 options->hostbased_authentication = 0;
196 if (options->hostbased_uses_name_from_packet_only == -1)
197 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->rsa_authentication == -1)
199 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100200 if (options->pubkey_authentication == -1)
201 options->pubkey_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000202#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000204 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->kerberos_or_local_passwd == -1)
206 options->kerberos_or_local_passwd = 1;
207 if (options->kerberos_ticket_cleanup == -1)
208 options->kerberos_ticket_cleanup = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000209#endif
210#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100211 if (options->kerberos_tgt_passing == -1)
212 options->kerberos_tgt_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000213#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100214#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100215 if (options->afs_token_passing == -1)
Damien Millere4ccf102002-04-23 20:40:28 +1000216 options->afs_token_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000217#endif
Damien Miller95def091999-11-25 00:26:21 +1100218 if (options->password_authentication == -1)
219 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100220 if (options->kbd_interactive_authentication == -1)
221 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000222 if (options->challenge_response_authentication == -1)
223 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100224 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100225 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100226 if (options->use_login == -1)
227 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000228 if (options->compression == -1)
229 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100230 if (options->allow_tcp_forwarding == -1)
231 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000232 if (options->gateway_ports == -1)
233 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000234 if (options->max_startups == -1)
235 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000236 if (options->max_startups_rate == -1)
237 options->max_startups_rate = 100; /* 100% */
238 if (options->max_startups_begin == -1)
239 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100240 if (options->verify_reverse_mapping == -1)
241 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000242 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100243 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000244 if (options->client_alive_count_max == -1)
245 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100246 if (options->authorized_keys_file2 == NULL) {
247 /* authorized_keys_file2 falls back to authorized_keys_file */
248 if (options->authorized_keys_file != NULL)
249 options->authorized_keys_file2 = options->authorized_keys_file;
250 else
251 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
252 }
253 if (options->authorized_keys_file == NULL)
254 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000255
Ben Lindstromfb62a692002-06-06 19:47:11 +0000256 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000257 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000258 use_privsep = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000259}
260
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000261/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100262typedef enum {
263 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100264 /* Portable-specific options */
265 sPAMAuthenticationViaKbdInt,
266 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100267 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
268 sPermitRootLogin, sLogFacility, sLogLevel,
269 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000270#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100271 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000272#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000273#if defined(AFS) || defined(KRB5)
274 sKerberosTgtPassing,
275#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000276#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000277 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000279 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100280 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000281 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100282 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000283 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000284 sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100285 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000286 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100287 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100288 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100289 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000290 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000291 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000292 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000293} ServerOpCodes;
294
295/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100296static struct {
297 const char *name;
298 ServerOpCodes opcode;
299} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100300 /* Portable-specific options */
301 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
302 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100303 { "port", sPort },
304 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100305 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000306 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100307 { "serverkeybits", sServerKeyBits },
308 { "logingracetime", sLoginGraceTime },
309 { "keyregenerationinterval", sKeyRegenerationTime },
310 { "permitrootlogin", sPermitRootLogin },
311 { "syslogfacility", sLogFacility },
312 { "loglevel", sLogLevel },
313 { "rhostsauthentication", sRhostsAuthentication },
314 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000315 { "hostbasedauthentication", sHostbasedAuthentication },
316 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100317 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100318 { "pubkeyauthentication", sPubkeyAuthentication },
319 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000320#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100321 { "kerberosauthentication", sKerberosAuthentication },
322 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
323 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000324#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000325#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100326 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000327#endif
328#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100329 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000330#endif
Damien Miller95def091999-11-25 00:26:21 +1100331 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100332 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000333 { "challengeresponseauthentication", sChallengeResponseAuthentication },
334 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000335 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100336 { "listenaddress", sListenAddress },
337 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000338 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100339 { "ignorerhosts", sIgnoreRhosts },
340 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
341 { "x11forwarding", sX11Forwarding },
342 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100343 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000344 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100345 { "strictmodes", sStrictModes },
346 { "permitemptypasswords", sEmptyPasswd },
347 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000348 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100349 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100350 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100351 { "allowusers", sAllowUsers },
352 { "denyusers", sDenyUsers },
353 { "allowgroups", sAllowGroups },
354 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000355 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000356 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000357 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000358 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000359 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000360 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000361 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100362 { "verifyreversemapping", sVerifyReverseMapping },
363 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000364 { "clientaliveinterval", sClientAliveInterval },
365 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000366 { "authorizedkeysfile", sAuthorizedKeysFile },
367 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000368 { "useprivilegeseparation", sUsePrivilegeSeparation},
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
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000711 case sCompression:
712 intptr = &options->compression;
713 goto parse_flag;
714
Ben Lindstromade03f62001-12-06 18:22:17 +0000715 case sGatewayPorts:
716 intptr = &options->gateway_ports;
717 goto parse_flag;
718
Damien Millerc5d86352002-02-05 12:13:41 +1100719 case sVerifyReverseMapping:
720 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000721 goto parse_flag;
722
723 case sLogFacility:
724 intptr = (int *) &options->log_facility;
725 arg = strdelim(&cp);
726 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100727 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000728 fatal("%.200s line %d: unsupported log facility '%s'",
729 filename, linenum, arg ? arg : "<NONE>");
730 if (*intptr == -1)
731 *intptr = (SyslogFacility) value;
732 break;
733
734 case sLogLevel:
735 intptr = (int *) &options->log_level;
736 arg = strdelim(&cp);
737 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100738 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000739 fatal("%.200s line %d: unsupported log level '%s'",
740 filename, linenum, arg ? arg : "<NONE>");
741 if (*intptr == -1)
742 *intptr = (LogLevel) value;
743 break;
744
745 case sAllowTcpForwarding:
746 intptr = &options->allow_tcp_forwarding;
747 goto parse_flag;
748
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000749 case sUsePrivilegeSeparation:
750 intptr = &use_privsep;
751 goto parse_flag;
752
Ben Lindstromade03f62001-12-06 18:22:17 +0000753 case sAllowUsers:
754 while ((arg = strdelim(&cp)) && *arg != '\0') {
755 if (options->num_allow_users >= MAX_ALLOW_USERS)
756 fatal("%s line %d: too many allow users.",
757 filename, linenum);
758 options->allow_users[options->num_allow_users++] = xstrdup(arg);
759 }
760 break;
761
762 case sDenyUsers:
763 while ((arg = strdelim(&cp)) && *arg != '\0') {
764 if (options->num_deny_users >= MAX_DENY_USERS)
765 fatal( "%s line %d: too many deny users.",
766 filename, linenum);
767 options->deny_users[options->num_deny_users++] = xstrdup(arg);
768 }
769 break;
770
771 case sAllowGroups:
772 while ((arg = strdelim(&cp)) && *arg != '\0') {
773 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
774 fatal("%s line %d: too many allow groups.",
775 filename, linenum);
776 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
777 }
778 break;
779
780 case sDenyGroups:
781 while ((arg = strdelim(&cp)) && *arg != '\0') {
782 if (options->num_deny_groups >= MAX_DENY_GROUPS)
783 fatal("%s line %d: too many deny groups.",
784 filename, linenum);
785 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
786 }
787 break;
788
789 case sCiphers:
790 arg = strdelim(&cp);
791 if (!arg || *arg == '\0')
792 fatal("%s line %d: Missing argument.", filename, linenum);
793 if (!ciphers_valid(arg))
794 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
795 filename, linenum, arg ? arg : "<NONE>");
796 if (options->ciphers == NULL)
797 options->ciphers = xstrdup(arg);
798 break;
799
800 case sMacs:
801 arg = strdelim(&cp);
802 if (!arg || *arg == '\0')
803 fatal("%s line %d: Missing argument.", filename, linenum);
804 if (!mac_valid(arg))
805 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
806 filename, linenum, arg ? arg : "<NONE>");
807 if (options->macs == NULL)
808 options->macs = xstrdup(arg);
809 break;
810
811 case sProtocol:
812 intptr = &options->protocol;
813 arg = strdelim(&cp);
814 if (!arg || *arg == '\0')
815 fatal("%s line %d: Missing argument.", filename, linenum);
816 value = proto_spec(arg);
817 if (value == SSH_PROTO_UNKNOWN)
818 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100819 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000820 if (*intptr == SSH_PROTO_UNKNOWN)
821 *intptr = value;
822 break;
823
824 case sSubsystem:
825 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
826 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100827 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000828 }
829 arg = strdelim(&cp);
830 if (!arg || *arg == '\0')
831 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100832 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000833 for (i = 0; i < options->num_subsystems; i++)
834 if (strcmp(arg, options->subsystem_name[i]) == 0)
835 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100836 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000837 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
838 arg = strdelim(&cp);
839 if (!arg || *arg == '\0')
840 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100841 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000842 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
843 options->num_subsystems++;
844 break;
845
846 case sMaxStartups:
847 arg = strdelim(&cp);
848 if (!arg || *arg == '\0')
849 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100850 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000851 if ((n = sscanf(arg, "%d:%d:%d",
852 &options->max_startups_begin,
853 &options->max_startups_rate,
854 &options->max_startups)) == 3) {
855 if (options->max_startups_begin >
856 options->max_startups ||
857 options->max_startups_rate > 100 ||
858 options->max_startups_rate < 1)
859 fatal("%s line %d: Illegal MaxStartups spec.",
860 filename, linenum);
861 } else if (n != 1)
862 fatal("%s line %d: Illegal MaxStartups spec.",
863 filename, linenum);
864 else
865 options->max_startups = options->max_startups_begin;
866 break;
867
868 case sBanner:
869 charptr = &options->banner;
870 goto parse_filename;
871 /*
872 * These options can contain %X options expanded at
873 * connect time, so that you can specify paths like:
874 *
875 * AuthorizedKeysFile /etc/ssh_keys/%u
876 */
877 case sAuthorizedKeysFile:
878 case sAuthorizedKeysFile2:
879 charptr = (opcode == sAuthorizedKeysFile ) ?
880 &options->authorized_keys_file :
881 &options->authorized_keys_file2;
882 goto parse_filename;
883
884 case sClientAliveInterval:
885 intptr = &options->client_alive_interval;
886 goto parse_time;
887
888 case sClientAliveCountMax:
889 intptr = &options->client_alive_count_max;
890 goto parse_int;
891
892 case sDeprecated:
893 log("%s line %d: Deprecated option %s",
894 filename, linenum, arg);
895 while (arg)
896 arg = strdelim(&cp);
897 break;
898
899 default:
900 fatal("%s line %d: Missing handler for opcode %s (%d)",
901 filename, linenum, arg, opcode);
902 }
903 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
904 fatal("%s line %d: garbage at end of line; \"%.200s\".",
905 filename, linenum, arg);
906 return 0;
907}
908
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000909/* Reads the server configuration file. */
910
Damien Miller4af51302000-04-16 11:18:38 +1000911void
Damien Miller95def091999-11-25 00:26:21 +1100912read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000913{
Damien Miller95def091999-11-25 00:26:21 +1100914 FILE *f;
915 char line[1024];
Ben Lindstromade03f62001-12-06 18:22:17 +0000916 int linenum;
Damien Miller95def091999-11-25 00:26:21 +1100917 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000918
Damien Miller95def091999-11-25 00:26:21 +1100919 f = fopen(filename, "r");
920 if (!f) {
921 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000922 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100923 }
924 linenum = 0;
925 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000926 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100927 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000928 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100929 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000930 }
Damien Miller95def091999-11-25 00:26:21 +1100931 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000932 if (bad_options > 0)
933 fatal("%s: terminating, %d bad configuration options",
934 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000935}