blob: fb6332c31b6973f2779ec3f9cc8172dcb23d65e8 [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 Miller4903eb42002-06-21 16:20:44 +1000259
260#if !defined(HAVE_MMAP) || !defined(MAP_ANON)
261 if (use_privsep && options->compression == 1) {
262 error("This platform does not support both privilege "
263 "separation and compression");
264 error("Compression disabled");
265 options->compression = 0;
266 }
267#endif
268
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000269}
270
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000271/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100272typedef enum {
273 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100274 /* Portable-specific options */
275 sPAMAuthenticationViaKbdInt,
276 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100277 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
278 sPermitRootLogin, sLogFacility, sLogLevel,
279 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000280#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100281 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000282#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000283#if defined(AFS) || defined(KRB5)
284 sKerberosTgtPassing,
285#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000286#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000287 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000288#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000289 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100290 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000291 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100292 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000293 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000294 sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100295 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000296 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100297 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100298 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100299 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000300 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000301 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000302 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000303} ServerOpCodes;
304
305/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100306static struct {
307 const char *name;
308 ServerOpCodes opcode;
309} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100310 /* Portable-specific options */
311 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
312 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100313 { "port", sPort },
314 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100315 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000316 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100317 { "serverkeybits", sServerKeyBits },
318 { "logingracetime", sLoginGraceTime },
319 { "keyregenerationinterval", sKeyRegenerationTime },
320 { "permitrootlogin", sPermitRootLogin },
321 { "syslogfacility", sLogFacility },
322 { "loglevel", sLogLevel },
323 { "rhostsauthentication", sRhostsAuthentication },
324 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000325 { "hostbasedauthentication", sHostbasedAuthentication },
326 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100327 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100328 { "pubkeyauthentication", sPubkeyAuthentication },
329 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000330#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100331 { "kerberosauthentication", sKerberosAuthentication },
332 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
333 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000334#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000335#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100336 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000337#endif
338#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100339 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000340#endif
Damien Miller95def091999-11-25 00:26:21 +1100341 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100342 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000343 { "challengeresponseauthentication", sChallengeResponseAuthentication },
344 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000345 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100346 { "listenaddress", sListenAddress },
347 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000348 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100349 { "ignorerhosts", sIgnoreRhosts },
350 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
351 { "x11forwarding", sX11Forwarding },
352 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100353 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000354 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100355 { "strictmodes", sStrictModes },
356 { "permitemptypasswords", sEmptyPasswd },
357 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000358 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100359 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100360 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100361 { "allowusers", sAllowUsers },
362 { "denyusers", sDenyUsers },
363 { "allowgroups", sAllowGroups },
364 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000365 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000366 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000367 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000368 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000369 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000370 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000371 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100372 { "verifyreversemapping", sVerifyReverseMapping },
373 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000374 { "clientaliveinterval", sClientAliveInterval },
375 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000376 { "authorizedkeysfile", sAuthorizedKeysFile },
377 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000378 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000379 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000380};
381
Damien Miller5428f641999-11-25 11:54:57 +1100382/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000383 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100384 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000385
Damien Miller4af51302000-04-16 11:18:38 +1000386static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100387parse_token(const char *cp, const char *filename,
388 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000389{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000390 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000391
Damien Miller95def091999-11-25 00:26:21 +1100392 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100393 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100394 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000395
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000396 error("%s: line %d: Bad configuration option: %s",
397 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100398 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000399}
400
Ben Lindstrombba81212001-06-25 05:01:22 +0000401static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000402add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100403{
Damien Miller34132e52000-01-14 15:45:46 +1100404 int i;
405
406 if (options->num_ports == 0)
407 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000408 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000409 for (i = 0; i < options->num_ports; i++)
410 add_one_listen_addr(options, addr, options->ports[i]);
411 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000412 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000413}
414
Ben Lindstrombba81212001-06-25 05:01:22 +0000415static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000416add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
417{
418 struct addrinfo hints, *ai, *aitop;
419 char strport[NI_MAXSERV];
420 int gaierr;
421
422 memset(&hints, 0, sizeof(hints));
423 hints.ai_family = IPv4or6;
424 hints.ai_socktype = SOCK_STREAM;
425 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
426 snprintf(strport, sizeof strport, "%d", port);
427 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
428 fatal("bad addr or host: %s (%s)",
429 addr ? addr : "<NULL>",
430 gai_strerror(gaierr));
431 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
432 ;
433 ai->ai_next = options->listen_addrs;
434 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100435}
436
Ben Lindstromade03f62001-12-06 18:22:17 +0000437int
438process_server_config_line(ServerOptions *options, char *line,
439 const char *filename, int linenum)
440{
441 char *cp, **charptr, *arg, *p;
442 int *intptr, value;
443 ServerOpCodes opcode;
444 int i, n;
445
446 cp = line;
447 arg = strdelim(&cp);
448 /* Ignore leading whitespace */
449 if (*arg == '\0')
450 arg = strdelim(&cp);
451 if (!arg || !*arg || *arg == '#')
452 return 0;
453 intptr = NULL;
454 charptr = NULL;
455 opcode = parse_token(arg, filename, linenum);
456 switch (opcode) {
457 /* Portable-specific options */
458 case sPAMAuthenticationViaKbdInt:
459 intptr = &options->pam_authentication_via_kbd_int;
460 goto parse_flag;
461
462 /* Standard Options */
463 case sBadOption:
464 return -1;
465 case sPort:
466 /* ignore ports from configfile if cmdline specifies ports */
467 if (options->ports_from_cmdline)
468 return 0;
469 if (options->listen_addrs != NULL)
470 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100471 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000472 if (options->num_ports >= MAX_PORTS)
473 fatal("%s line %d: too many ports.",
474 filename, linenum);
475 arg = strdelim(&cp);
476 if (!arg || *arg == '\0')
477 fatal("%s line %d: missing port number.",
478 filename, linenum);
479 options->ports[options->num_ports++] = a2port(arg);
480 if (options->ports[options->num_ports-1] == 0)
481 fatal("%s line %d: Badly formatted port number.",
482 filename, linenum);
483 break;
484
485 case sServerKeyBits:
486 intptr = &options->server_key_bits;
487parse_int:
488 arg = strdelim(&cp);
489 if (!arg || *arg == '\0')
490 fatal("%s line %d: missing integer value.",
491 filename, linenum);
492 value = atoi(arg);
493 if (*intptr == -1)
494 *intptr = value;
495 break;
496
497 case sLoginGraceTime:
498 intptr = &options->login_grace_time;
499parse_time:
500 arg = strdelim(&cp);
501 if (!arg || *arg == '\0')
502 fatal("%s line %d: missing time value.",
503 filename, linenum);
504 if ((value = convtime(arg)) == -1)
505 fatal("%s line %d: invalid time value.",
506 filename, linenum);
507 if (*intptr == -1)
508 *intptr = value;
509 break;
510
511 case sKeyRegenerationTime:
512 intptr = &options->key_regeneration_time;
513 goto parse_time;
514
515 case sListenAddress:
516 arg = strdelim(&cp);
517 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
518 fatal("%s line %d: missing inet addr.",
519 filename, linenum);
520 if (*arg == '[') {
521 if ((p = strchr(arg, ']')) == NULL)
522 fatal("%s line %d: bad ipv6 inet addr usage.",
523 filename, linenum);
524 arg++;
525 memmove(p, p+1, strlen(p+1)+1);
526 } else if (((p = strchr(arg, ':')) == NULL) ||
527 (strchr(p+1, ':') != NULL)) {
528 add_listen_addr(options, arg, 0);
529 break;
530 }
531 if (*p == ':') {
532 u_short port;
533
534 p++;
535 if (*p == '\0')
536 fatal("%s line %d: bad inet addr:port usage.",
537 filename, linenum);
538 else {
539 *(p-1) = '\0';
540 if ((port = a2port(p)) == 0)
541 fatal("%s line %d: bad port number.",
542 filename, linenum);
543 add_listen_addr(options, arg, port);
544 }
545 } else if (*p == '\0')
546 add_listen_addr(options, arg, 0);
547 else
548 fatal("%s line %d: bad inet addr usage.",
549 filename, linenum);
550 break;
551
552 case sHostKeyFile:
553 intptr = &options->num_host_key_files;
554 if (*intptr >= MAX_HOSTKEYS)
555 fatal("%s line %d: too many host keys specified (max %d).",
556 filename, linenum, MAX_HOSTKEYS);
557 charptr = &options->host_key_files[*intptr];
558parse_filename:
559 arg = strdelim(&cp);
560 if (!arg || *arg == '\0')
561 fatal("%s line %d: missing file name.",
562 filename, linenum);
563 if (*charptr == NULL) {
564 *charptr = tilde_expand_filename(arg, getuid());
565 /* increase optional counter */
566 if (intptr != NULL)
567 *intptr = *intptr + 1;
568 }
569 break;
570
571 case sPidFile:
572 charptr = &options->pid_file;
573 goto parse_filename;
574
575 case sPermitRootLogin:
576 intptr = &options->permit_root_login;
577 arg = strdelim(&cp);
578 if (!arg || *arg == '\0')
579 fatal("%s line %d: missing yes/"
580 "without-password/forced-commands-only/no "
581 "argument.", filename, linenum);
582 value = 0; /* silence compiler */
583 if (strcmp(arg, "without-password") == 0)
584 value = PERMIT_NO_PASSWD;
585 else if (strcmp(arg, "forced-commands-only") == 0)
586 value = PERMIT_FORCED_ONLY;
587 else if (strcmp(arg, "yes") == 0)
588 value = PERMIT_YES;
589 else if (strcmp(arg, "no") == 0)
590 value = PERMIT_NO;
591 else
592 fatal("%s line %d: Bad yes/"
593 "without-password/forced-commands-only/no "
594 "argument: %s", filename, linenum, arg);
595 if (*intptr == -1)
596 *intptr = value;
597 break;
598
599 case sIgnoreRhosts:
600 intptr = &options->ignore_rhosts;
601parse_flag:
602 arg = strdelim(&cp);
603 if (!arg || *arg == '\0')
604 fatal("%s line %d: missing yes/no argument.",
605 filename, linenum);
606 value = 0; /* silence compiler */
607 if (strcmp(arg, "yes") == 0)
608 value = 1;
609 else if (strcmp(arg, "no") == 0)
610 value = 0;
611 else
612 fatal("%s line %d: Bad yes/no argument: %s",
613 filename, linenum, arg);
614 if (*intptr == -1)
615 *intptr = value;
616 break;
617
618 case sIgnoreUserKnownHosts:
619 intptr = &options->ignore_user_known_hosts;
620 goto parse_flag;
621
622 case sRhostsAuthentication:
623 intptr = &options->rhosts_authentication;
624 goto parse_flag;
625
626 case sRhostsRSAAuthentication:
627 intptr = &options->rhosts_rsa_authentication;
628 goto parse_flag;
629
630 case sHostbasedAuthentication:
631 intptr = &options->hostbased_authentication;
632 goto parse_flag;
633
634 case sHostbasedUsesNameFromPacketOnly:
635 intptr = &options->hostbased_uses_name_from_packet_only;
636 goto parse_flag;
637
638 case sRSAAuthentication:
639 intptr = &options->rsa_authentication;
640 goto parse_flag;
641
642 case sPubkeyAuthentication:
643 intptr = &options->pubkey_authentication;
644 goto parse_flag;
645#if defined(KRB4) || defined(KRB5)
646 case sKerberosAuthentication:
647 intptr = &options->kerberos_authentication;
648 goto parse_flag;
649
650 case sKerberosOrLocalPasswd:
651 intptr = &options->kerberos_or_local_passwd;
652 goto parse_flag;
653
654 case sKerberosTicketCleanup:
655 intptr = &options->kerberos_ticket_cleanup;
656 goto parse_flag;
657#endif
658#if defined(AFS) || defined(KRB5)
659 case sKerberosTgtPassing:
660 intptr = &options->kerberos_tgt_passing;
661 goto parse_flag;
662#endif
663#ifdef AFS
664 case sAFSTokenPassing:
665 intptr = &options->afs_token_passing;
666 goto parse_flag;
667#endif
668
669 case sPasswordAuthentication:
670 intptr = &options->password_authentication;
671 goto parse_flag;
672
673 case sKbdInteractiveAuthentication:
674 intptr = &options->kbd_interactive_authentication;
675 goto parse_flag;
676
677 case sChallengeResponseAuthentication:
678 intptr = &options->challenge_response_authentication;
679 goto parse_flag;
680
681 case sPrintMotd:
682 intptr = &options->print_motd;
683 goto parse_flag;
684
685 case sPrintLastLog:
686 intptr = &options->print_lastlog;
687 goto parse_flag;
688
689 case sX11Forwarding:
690 intptr = &options->x11_forwarding;
691 goto parse_flag;
692
693 case sX11DisplayOffset:
694 intptr = &options->x11_display_offset;
695 goto parse_int;
696
Damien Miller95c249f2002-02-05 12:11:34 +1100697 case sX11UseLocalhost:
698 intptr = &options->x11_use_localhost;
699 goto parse_flag;
700
Ben Lindstromade03f62001-12-06 18:22:17 +0000701 case sXAuthLocation:
702 charptr = &options->xauth_location;
703 goto parse_filename;
704
705 case sStrictModes:
706 intptr = &options->strict_modes;
707 goto parse_flag;
708
709 case sKeepAlives:
710 intptr = &options->keepalives;
711 goto parse_flag;
712
713 case sEmptyPasswd:
714 intptr = &options->permit_empty_passwd;
715 goto parse_flag;
716
717 case sUseLogin:
718 intptr = &options->use_login;
719 goto parse_flag;
720
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000721 case sCompression:
722 intptr = &options->compression;
723 goto parse_flag;
724
Ben Lindstromade03f62001-12-06 18:22:17 +0000725 case sGatewayPorts:
726 intptr = &options->gateway_ports;
727 goto parse_flag;
728
Damien Millerc5d86352002-02-05 12:13:41 +1100729 case sVerifyReverseMapping:
730 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000731 goto parse_flag;
732
733 case sLogFacility:
734 intptr = (int *) &options->log_facility;
735 arg = strdelim(&cp);
736 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100737 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000738 fatal("%.200s line %d: unsupported log facility '%s'",
739 filename, linenum, arg ? arg : "<NONE>");
740 if (*intptr == -1)
741 *intptr = (SyslogFacility) value;
742 break;
743
744 case sLogLevel:
745 intptr = (int *) &options->log_level;
746 arg = strdelim(&cp);
747 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100748 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000749 fatal("%.200s line %d: unsupported log level '%s'",
750 filename, linenum, arg ? arg : "<NONE>");
751 if (*intptr == -1)
752 *intptr = (LogLevel) value;
753 break;
754
755 case sAllowTcpForwarding:
756 intptr = &options->allow_tcp_forwarding;
757 goto parse_flag;
758
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000759 case sUsePrivilegeSeparation:
760 intptr = &use_privsep;
761 goto parse_flag;
762
Ben Lindstromade03f62001-12-06 18:22:17 +0000763 case sAllowUsers:
764 while ((arg = strdelim(&cp)) && *arg != '\0') {
765 if (options->num_allow_users >= MAX_ALLOW_USERS)
766 fatal("%s line %d: too many allow users.",
767 filename, linenum);
768 options->allow_users[options->num_allow_users++] = xstrdup(arg);
769 }
770 break;
771
772 case sDenyUsers:
773 while ((arg = strdelim(&cp)) && *arg != '\0') {
774 if (options->num_deny_users >= MAX_DENY_USERS)
775 fatal( "%s line %d: too many deny users.",
776 filename, linenum);
777 options->deny_users[options->num_deny_users++] = xstrdup(arg);
778 }
779 break;
780
781 case sAllowGroups:
782 while ((arg = strdelim(&cp)) && *arg != '\0') {
783 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
784 fatal("%s line %d: too many allow groups.",
785 filename, linenum);
786 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
787 }
788 break;
789
790 case sDenyGroups:
791 while ((arg = strdelim(&cp)) && *arg != '\0') {
792 if (options->num_deny_groups >= MAX_DENY_GROUPS)
793 fatal("%s line %d: too many deny groups.",
794 filename, linenum);
795 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
796 }
797 break;
798
799 case sCiphers:
800 arg = strdelim(&cp);
801 if (!arg || *arg == '\0')
802 fatal("%s line %d: Missing argument.", filename, linenum);
803 if (!ciphers_valid(arg))
804 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
805 filename, linenum, arg ? arg : "<NONE>");
806 if (options->ciphers == NULL)
807 options->ciphers = xstrdup(arg);
808 break;
809
810 case sMacs:
811 arg = strdelim(&cp);
812 if (!arg || *arg == '\0')
813 fatal("%s line %d: Missing argument.", filename, linenum);
814 if (!mac_valid(arg))
815 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
816 filename, linenum, arg ? arg : "<NONE>");
817 if (options->macs == NULL)
818 options->macs = xstrdup(arg);
819 break;
820
821 case sProtocol:
822 intptr = &options->protocol;
823 arg = strdelim(&cp);
824 if (!arg || *arg == '\0')
825 fatal("%s line %d: Missing argument.", filename, linenum);
826 value = proto_spec(arg);
827 if (value == SSH_PROTO_UNKNOWN)
828 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100829 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000830 if (*intptr == SSH_PROTO_UNKNOWN)
831 *intptr = value;
832 break;
833
834 case sSubsystem:
835 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
836 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100837 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000838 }
839 arg = strdelim(&cp);
840 if (!arg || *arg == '\0')
841 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100842 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000843 for (i = 0; i < options->num_subsystems; i++)
844 if (strcmp(arg, options->subsystem_name[i]) == 0)
845 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100846 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000847 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
848 arg = strdelim(&cp);
849 if (!arg || *arg == '\0')
850 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100851 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000852 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
853 options->num_subsystems++;
854 break;
855
856 case sMaxStartups:
857 arg = strdelim(&cp);
858 if (!arg || *arg == '\0')
859 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100860 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000861 if ((n = sscanf(arg, "%d:%d:%d",
862 &options->max_startups_begin,
863 &options->max_startups_rate,
864 &options->max_startups)) == 3) {
865 if (options->max_startups_begin >
866 options->max_startups ||
867 options->max_startups_rate > 100 ||
868 options->max_startups_rate < 1)
869 fatal("%s line %d: Illegal MaxStartups spec.",
870 filename, linenum);
871 } else if (n != 1)
872 fatal("%s line %d: Illegal MaxStartups spec.",
873 filename, linenum);
874 else
875 options->max_startups = options->max_startups_begin;
876 break;
877
878 case sBanner:
879 charptr = &options->banner;
880 goto parse_filename;
881 /*
882 * These options can contain %X options expanded at
883 * connect time, so that you can specify paths like:
884 *
885 * AuthorizedKeysFile /etc/ssh_keys/%u
886 */
887 case sAuthorizedKeysFile:
888 case sAuthorizedKeysFile2:
889 charptr = (opcode == sAuthorizedKeysFile ) ?
890 &options->authorized_keys_file :
891 &options->authorized_keys_file2;
892 goto parse_filename;
893
894 case sClientAliveInterval:
895 intptr = &options->client_alive_interval;
896 goto parse_time;
897
898 case sClientAliveCountMax:
899 intptr = &options->client_alive_count_max;
900 goto parse_int;
901
902 case sDeprecated:
903 log("%s line %d: Deprecated option %s",
904 filename, linenum, arg);
905 while (arg)
906 arg = strdelim(&cp);
907 break;
908
909 default:
910 fatal("%s line %d: Missing handler for opcode %s (%d)",
911 filename, linenum, arg, opcode);
912 }
913 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
914 fatal("%s line %d: garbage at end of line; \"%.200s\".",
915 filename, linenum, arg);
916 return 0;
917}
918
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000919/* Reads the server configuration file. */
920
Damien Miller4af51302000-04-16 11:18:38 +1000921void
Damien Miller95def091999-11-25 00:26:21 +1100922read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000923{
Damien Miller95def091999-11-25 00:26:21 +1100924 FILE *f;
925 char line[1024];
Ben Lindstromade03f62001-12-06 18:22:17 +0000926 int linenum;
Damien Miller95def091999-11-25 00:26:21 +1100927 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000928
Damien Miller95def091999-11-25 00:26:21 +1100929 f = fopen(filename, "r");
930 if (!f) {
931 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000932 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100933 }
934 linenum = 0;
935 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000936 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100937 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000938 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100939 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000940 }
Damien Miller95def091999-11-25 00:26:21 +1100941 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000942 if (bad_options > 0)
943 fatal("%s: terminating, %d bad configuration options",
944 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000945}