blob: 5076c5df6d4cc79384eda1bdcbb76e2ede3c3091 [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"
Damien Miller2aa0ab42003-05-15 12:05:28 +100013RCSID("$OpenBSD: servconf.c,v 1.119 2003/05/15 01:48:10 jakob 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 Millerd5580922003-05-14 13:40:06 +100018
Damien Millerfd4c9ee2002-04-13 11:04:40 +100019#if defined(KRB5)
Damien Millerd5580922003-05-14 13:40:06 +100020# ifdef HEIMDAL
21# include <krb.h>
22# else
23/*
24 * XXX: Bodge - but then, so is using the kerberos IV KEYFILE to get a
25 * Kerberos V keytab
26 */
27# define KEYFILE "/etc/krb5.keytab"
28# endif
Damien Millerfd4c9ee2002-04-13 11:04:40 +100029#endif
Damien Millerd5580922003-05-14 13:40:06 +100030
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000031#ifdef AFS
32#include <kafs.h>
33#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100034
35#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100037#include "servconf.h"
38#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100039#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "pathnames.h"
41#include "tildexpand.h"
42#include "misc.h"
43#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000044#include "kex.h"
45#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046
Ben Lindstrombba81212001-06-25 05:01:22 +000047static void add_listen_addr(ServerOptions *, char *, u_short);
48static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110049
Ben Lindstrom226cfa02001-01-22 05:34:40 +000050/* AF_UNSPEC or AF_INET or AF_INET6 */
51extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000052/* Use of privilege separation or not */
53extern int use_privsep;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000054
Damien Millerd4a8b7e1999-10-27 13:42:43 +100055/* Initializes the server options to their default values. */
56
Damien Miller4af51302000-04-16 11:18:38 +100057void
Damien Miller95def091999-11-25 00:26:21 +110058initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100059{
Damien Miller95def091999-11-25 00:26:21 +110060 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110061
62 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100063 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110064
65 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110066 options->num_ports = 0;
67 options->ports_from_cmdline = 0;
68 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110069 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100070 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110071 options->server_key_bits = -1;
72 options->login_grace_time = -1;
73 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000074 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110075 options->ignore_rhosts = -1;
76 options->ignore_user_known_hosts = -1;
77 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000078 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110079 options->x11_forwarding = -1;
80 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110081 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100082 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110083 options->strict_modes = -1;
84 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110085 options->log_facility = SYSLOG_FACILITY_NOT_SET;
86 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110087 options->rhosts_authentication = -1;
88 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000089 options->hostbased_authentication = -1;
90 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110091 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110092 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110093 options->kerberos_authentication = -1;
94 options->kerberos_or_local_passwd = -1;
95 options->kerberos_ticket_cleanup = -1;
Damien Miller95def091999-11-25 00:26:21 +110096 options->kerberos_tgt_passing = -1;
97 options->afs_token_passing = -1;
Damien Miller95def091999-11-25 00:26:21 +110098 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110099 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000100 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100101 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000102 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000104 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100105 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->num_allow_users = 0;
107 options->num_deny_users = 0;
108 options->num_allow_groups = 0;
109 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000110 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000111 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000112 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000113 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000114 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000115 options->max_startups_begin = -1;
116 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000117 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000118 options->banner = NULL;
Damien Millerc5d86352002-02-05 12:13:41 +1100119 options->verify_reverse_mapping = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000120 options->client_alive_interval = -1;
121 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000122 options->authorized_keys_file = NULL;
123 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000124
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000125 /* Needs to be accessable in many places */
126 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000127}
128
Damien Miller4af51302000-04-16 11:18:38 +1000129void
Damien Miller95def091999-11-25 00:26:21 +1100130fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000131{
Damien Miller726273e2001-11-12 11:40:11 +1100132 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000133 if (options->use_pam == -1)
Damien Miller2aa0ab42003-05-15 12:05:28 +1000134 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100135
136 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100137 if (options->protocol == SSH_PROTO_UNKNOWN)
138 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
139 if (options->num_host_key_files == 0) {
140 /* fill default hostkeys for protocols */
141 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100142 options->host_key_files[options->num_host_key_files++] =
143 _PATH_HOST_KEY_FILE;
144 if (options->protocol & SSH_PROTO_2) {
145 options->host_key_files[options->num_host_key_files++] =
146 _PATH_HOST_RSA_KEY_FILE;
147 options->host_key_files[options->num_host_key_files++] =
148 _PATH_HOST_DSA_KEY_FILE;
149 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100150 }
Damien Miller34132e52000-01-14 15:45:46 +1100151 if (options->num_ports == 0)
152 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
153 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000154 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000155 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000156 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->server_key_bits == -1)
158 options->server_key_bits = 768;
159 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000160 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100161 if (options->key_regeneration_time == -1)
162 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000163 if (options->permit_root_login == PERMIT_NOT_SET)
164 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100166 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->ignore_user_known_hosts == -1)
168 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100169 if (options->print_motd == -1)
170 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000171 if (options->print_lastlog == -1)
172 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100174 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100175 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100176 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100177 if (options->x11_use_localhost == -1)
178 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000179 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000180 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100181 if (options->strict_modes == -1)
182 options->strict_modes = 1;
183 if (options->keepalives == -1)
184 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100185 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100186 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100187 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000188 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100189 if (options->rhosts_authentication == -1)
190 options->rhosts_authentication = 0;
191 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100192 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000193 if (options->hostbased_authentication == -1)
194 options->hostbased_authentication = 0;
195 if (options->hostbased_uses_name_from_packet_only == -1)
196 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->rsa_authentication == -1)
198 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100199 if (options->pubkey_authentication == -1)
200 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000202 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->kerberos_or_local_passwd == -1)
204 options->kerberos_or_local_passwd = 1;
205 if (options->kerberos_ticket_cleanup == -1)
206 options->kerberos_ticket_cleanup = 1;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->kerberos_tgt_passing == -1)
208 options->kerberos_tgt_passing = 0;
209 if (options->afs_token_passing == -1)
Damien Millere4ccf102002-04-23 20:40:28 +1000210 options->afs_token_passing = 0;
Damien Miller95def091999-11-25 00:26:21 +1100211 if (options->password_authentication == -1)
212 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100213 if (options->kbd_interactive_authentication == -1)
214 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000215 if (options->challenge_response_authentication == -1)
216 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100217 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100218 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000219 if (options->permit_user_env == -1)
220 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100221 if (options->use_login == -1)
222 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000223 if (options->compression == -1)
224 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100225 if (options->allow_tcp_forwarding == -1)
226 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000227 if (options->gateway_ports == -1)
228 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000229 if (options->max_startups == -1)
230 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000231 if (options->max_startups_rate == -1)
232 options->max_startups_rate = 100; /* 100% */
233 if (options->max_startups_begin == -1)
234 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100235 if (options->verify_reverse_mapping == -1)
236 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000237 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100238 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000239 if (options->client_alive_count_max == -1)
240 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100241 if (options->authorized_keys_file2 == NULL) {
242 /* authorized_keys_file2 falls back to authorized_keys_file */
243 if (options->authorized_keys_file != NULL)
244 options->authorized_keys_file2 = options->authorized_keys_file;
245 else
246 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
247 }
248 if (options->authorized_keys_file == NULL)
249 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000250
Ben Lindstromfb62a692002-06-06 19:47:11 +0000251 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000252 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000253 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000254
Tim Rice40017b02002-07-14 13:36:49 -0700255#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000256 if (use_privsep && options->compression == 1) {
257 error("This platform does not support both privilege "
258 "separation and compression");
259 error("Compression disabled");
260 options->compression = 0;
261 }
262#endif
263
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000264}
265
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100267typedef enum {
268 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100269 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000270 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100271 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100272 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
273 sPermitRootLogin, sLogFacility, sLogLevel,
274 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100275 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Miller2aa0ab42003-05-15 12:05:28 +1000276 sKerberosTgtPassing, sAFSTokenPassing, sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100277 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000278 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100279 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000280 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000281 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100282 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000283 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100284 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100285 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100286 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000287 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000288 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000289 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000290} ServerOpCodes;
291
292/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100293static struct {
294 const char *name;
295 ServerOpCodes opcode;
296} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100297 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000298 { "UsePAM", sUsePAM },
Damien Miller726273e2001-11-12 11:40:11 +1100299 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100300 { "port", sPort },
301 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100302 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000303 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100304 { "serverkeybits", sServerKeyBits },
305 { "logingracetime", sLoginGraceTime },
306 { "keyregenerationinterval", sKeyRegenerationTime },
307 { "permitrootlogin", sPermitRootLogin },
308 { "syslogfacility", sLogFacility },
309 { "loglevel", sLogLevel },
310 { "rhostsauthentication", sRhostsAuthentication },
311 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000312 { "hostbasedauthentication", sHostbasedAuthentication },
313 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100314 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100315 { "pubkeyauthentication", sPubkeyAuthentication },
316 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100317 { "kerberosauthentication", sKerberosAuthentication },
318 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
319 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Miller95def091999-11-25 00:26:21 +1100320 { "kerberostgtpassing", sKerberosTgtPassing },
321 { "afstokenpassing", sAFSTokenPassing },
Damien Miller95def091999-11-25 00:26:21 +1100322 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100323 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000324 { "challengeresponseauthentication", sChallengeResponseAuthentication },
325 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000326 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100327 { "listenaddress", sListenAddress },
328 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000329 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100330 { "ignorerhosts", sIgnoreRhosts },
331 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
332 { "x11forwarding", sX11Forwarding },
333 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100334 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000335 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100336 { "strictmodes", sStrictModes },
337 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000338 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100339 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000340 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100341 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100342 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100343 { "allowusers", sAllowUsers },
344 { "denyusers", sDenyUsers },
345 { "allowgroups", sAllowGroups },
346 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000347 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000348 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000349 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000350 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000351 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000352 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000353 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100354 { "verifyreversemapping", sVerifyReverseMapping },
355 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000356 { "clientaliveinterval", sClientAliveInterval },
357 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000358 { "authorizedkeysfile", sAuthorizedKeysFile },
359 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000360 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000361 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000362};
363
Damien Miller5428f641999-11-25 11:54:57 +1100364/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000365 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100366 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000367
Damien Miller4af51302000-04-16 11:18:38 +1000368static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100369parse_token(const char *cp, const char *filename,
370 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000371{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000372 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000373
Damien Miller95def091999-11-25 00:26:21 +1100374 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100375 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100376 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000377
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000378 error("%s: line %d: Bad configuration option: %s",
379 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100380 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381}
382
Ben Lindstrombba81212001-06-25 05:01:22 +0000383static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000384add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100385{
Damien Miller34132e52000-01-14 15:45:46 +1100386 int i;
387
388 if (options->num_ports == 0)
389 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000390 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000391 for (i = 0; i < options->num_ports; i++)
392 add_one_listen_addr(options, addr, options->ports[i]);
393 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000394 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000395}
396
Ben Lindstrombba81212001-06-25 05:01:22 +0000397static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000398add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
399{
400 struct addrinfo hints, *ai, *aitop;
401 char strport[NI_MAXSERV];
402 int gaierr;
403
404 memset(&hints, 0, sizeof(hints));
405 hints.ai_family = IPv4or6;
406 hints.ai_socktype = SOCK_STREAM;
407 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000408 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000409 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
410 fatal("bad addr or host: %s (%s)",
411 addr ? addr : "<NULL>",
412 gai_strerror(gaierr));
413 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
414 ;
415 ai->ai_next = options->listen_addrs;
416 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100417}
418
Ben Lindstromade03f62001-12-06 18:22:17 +0000419int
420process_server_config_line(ServerOptions *options, char *line,
421 const char *filename, int linenum)
422{
423 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000424 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000425 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000426
427 cp = line;
428 arg = strdelim(&cp);
429 /* Ignore leading whitespace */
430 if (*arg == '\0')
431 arg = strdelim(&cp);
432 if (!arg || !*arg || *arg == '#')
433 return 0;
434 intptr = NULL;
435 charptr = NULL;
436 opcode = parse_token(arg, filename, linenum);
437 switch (opcode) {
438 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000439 case sUsePAM:
440 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000441 goto parse_flag;
442
443 /* Standard Options */
444 case sBadOption:
445 return -1;
446 case sPort:
447 /* ignore ports from configfile if cmdline specifies ports */
448 if (options->ports_from_cmdline)
449 return 0;
450 if (options->listen_addrs != NULL)
451 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100452 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000453 if (options->num_ports >= MAX_PORTS)
454 fatal("%s line %d: too many ports.",
455 filename, linenum);
456 arg = strdelim(&cp);
457 if (!arg || *arg == '\0')
458 fatal("%s line %d: missing port number.",
459 filename, linenum);
460 options->ports[options->num_ports++] = a2port(arg);
461 if (options->ports[options->num_ports-1] == 0)
462 fatal("%s line %d: Badly formatted port number.",
463 filename, linenum);
464 break;
465
466 case sServerKeyBits:
467 intptr = &options->server_key_bits;
468parse_int:
469 arg = strdelim(&cp);
470 if (!arg || *arg == '\0')
471 fatal("%s line %d: missing integer value.",
472 filename, linenum);
473 value = atoi(arg);
474 if (*intptr == -1)
475 *intptr = value;
476 break;
477
478 case sLoginGraceTime:
479 intptr = &options->login_grace_time;
480parse_time:
481 arg = strdelim(&cp);
482 if (!arg || *arg == '\0')
483 fatal("%s line %d: missing time value.",
484 filename, linenum);
485 if ((value = convtime(arg)) == -1)
486 fatal("%s line %d: invalid time value.",
487 filename, linenum);
488 if (*intptr == -1)
489 *intptr = value;
490 break;
491
492 case sKeyRegenerationTime:
493 intptr = &options->key_regeneration_time;
494 goto parse_time;
495
496 case sListenAddress:
497 arg = strdelim(&cp);
498 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
499 fatal("%s line %d: missing inet addr.",
500 filename, linenum);
501 if (*arg == '[') {
502 if ((p = strchr(arg, ']')) == NULL)
503 fatal("%s line %d: bad ipv6 inet addr usage.",
504 filename, linenum);
505 arg++;
506 memmove(p, p+1, strlen(p+1)+1);
507 } else if (((p = strchr(arg, ':')) == NULL) ||
508 (strchr(p+1, ':') != NULL)) {
509 add_listen_addr(options, arg, 0);
510 break;
511 }
512 if (*p == ':') {
513 u_short port;
514
515 p++;
516 if (*p == '\0')
517 fatal("%s line %d: bad inet addr:port usage.",
518 filename, linenum);
519 else {
520 *(p-1) = '\0';
521 if ((port = a2port(p)) == 0)
522 fatal("%s line %d: bad port number.",
523 filename, linenum);
524 add_listen_addr(options, arg, port);
525 }
526 } else if (*p == '\0')
527 add_listen_addr(options, arg, 0);
528 else
529 fatal("%s line %d: bad inet addr usage.",
530 filename, linenum);
531 break;
532
533 case sHostKeyFile:
534 intptr = &options->num_host_key_files;
535 if (*intptr >= MAX_HOSTKEYS)
536 fatal("%s line %d: too many host keys specified (max %d).",
537 filename, linenum, MAX_HOSTKEYS);
538 charptr = &options->host_key_files[*intptr];
539parse_filename:
540 arg = strdelim(&cp);
541 if (!arg || *arg == '\0')
542 fatal("%s line %d: missing file name.",
543 filename, linenum);
544 if (*charptr == NULL) {
545 *charptr = tilde_expand_filename(arg, getuid());
546 /* increase optional counter */
547 if (intptr != NULL)
548 *intptr = *intptr + 1;
549 }
550 break;
551
552 case sPidFile:
553 charptr = &options->pid_file;
554 goto parse_filename;
555
556 case sPermitRootLogin:
557 intptr = &options->permit_root_login;
558 arg = strdelim(&cp);
559 if (!arg || *arg == '\0')
560 fatal("%s line %d: missing yes/"
561 "without-password/forced-commands-only/no "
562 "argument.", filename, linenum);
563 value = 0; /* silence compiler */
564 if (strcmp(arg, "without-password") == 0)
565 value = PERMIT_NO_PASSWD;
566 else if (strcmp(arg, "forced-commands-only") == 0)
567 value = PERMIT_FORCED_ONLY;
568 else if (strcmp(arg, "yes") == 0)
569 value = PERMIT_YES;
570 else if (strcmp(arg, "no") == 0)
571 value = PERMIT_NO;
572 else
573 fatal("%s line %d: Bad yes/"
574 "without-password/forced-commands-only/no "
575 "argument: %s", filename, linenum, arg);
576 if (*intptr == -1)
577 *intptr = value;
578 break;
579
580 case sIgnoreRhosts:
581 intptr = &options->ignore_rhosts;
582parse_flag:
583 arg = strdelim(&cp);
584 if (!arg || *arg == '\0')
585 fatal("%s line %d: missing yes/no argument.",
586 filename, linenum);
587 value = 0; /* silence compiler */
588 if (strcmp(arg, "yes") == 0)
589 value = 1;
590 else if (strcmp(arg, "no") == 0)
591 value = 0;
592 else
593 fatal("%s line %d: Bad yes/no argument: %s",
594 filename, linenum, arg);
595 if (*intptr == -1)
596 *intptr = value;
597 break;
598
599 case sIgnoreUserKnownHosts:
600 intptr = &options->ignore_user_known_hosts;
601 goto parse_flag;
602
603 case sRhostsAuthentication:
604 intptr = &options->rhosts_authentication;
605 goto parse_flag;
606
607 case sRhostsRSAAuthentication:
608 intptr = &options->rhosts_rsa_authentication;
609 goto parse_flag;
610
611 case sHostbasedAuthentication:
612 intptr = &options->hostbased_authentication;
613 goto parse_flag;
614
615 case sHostbasedUsesNameFromPacketOnly:
616 intptr = &options->hostbased_uses_name_from_packet_only;
617 goto parse_flag;
618
619 case sRSAAuthentication:
620 intptr = &options->rsa_authentication;
621 goto parse_flag;
622
623 case sPubkeyAuthentication:
624 intptr = &options->pubkey_authentication;
625 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000626
Ben Lindstromade03f62001-12-06 18:22:17 +0000627 case sKerberosAuthentication:
628 intptr = &options->kerberos_authentication;
629 goto parse_flag;
630
631 case sKerberosOrLocalPasswd:
632 intptr = &options->kerberos_or_local_passwd;
633 goto parse_flag;
634
635 case sKerberosTicketCleanup:
636 intptr = &options->kerberos_ticket_cleanup;
637 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000638
Ben Lindstromade03f62001-12-06 18:22:17 +0000639 case sKerberosTgtPassing:
640 intptr = &options->kerberos_tgt_passing;
641 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000642
Ben Lindstromade03f62001-12-06 18:22:17 +0000643 case sAFSTokenPassing:
644 intptr = &options->afs_token_passing;
645 goto parse_flag;
Ben Lindstromade03f62001-12-06 18:22:17 +0000646
647 case sPasswordAuthentication:
648 intptr = &options->password_authentication;
649 goto parse_flag;
650
651 case sKbdInteractiveAuthentication:
652 intptr = &options->kbd_interactive_authentication;
653 goto parse_flag;
654
655 case sChallengeResponseAuthentication:
656 intptr = &options->challenge_response_authentication;
657 goto parse_flag;
658
659 case sPrintMotd:
660 intptr = &options->print_motd;
661 goto parse_flag;
662
663 case sPrintLastLog:
664 intptr = &options->print_lastlog;
665 goto parse_flag;
666
667 case sX11Forwarding:
668 intptr = &options->x11_forwarding;
669 goto parse_flag;
670
671 case sX11DisplayOffset:
672 intptr = &options->x11_display_offset;
673 goto parse_int;
674
Damien Miller95c249f2002-02-05 12:11:34 +1100675 case sX11UseLocalhost:
676 intptr = &options->x11_use_localhost;
677 goto parse_flag;
678
Ben Lindstromade03f62001-12-06 18:22:17 +0000679 case sXAuthLocation:
680 charptr = &options->xauth_location;
681 goto parse_filename;
682
683 case sStrictModes:
684 intptr = &options->strict_modes;
685 goto parse_flag;
686
687 case sKeepAlives:
688 intptr = &options->keepalives;
689 goto parse_flag;
690
691 case sEmptyPasswd:
692 intptr = &options->permit_empty_passwd;
693 goto parse_flag;
694
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000695 case sPermitUserEnvironment:
696 intptr = &options->permit_user_env;
697 goto parse_flag;
698
Ben Lindstromade03f62001-12-06 18:22:17 +0000699 case sUseLogin:
700 intptr = &options->use_login;
701 goto parse_flag;
702
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000703 case sCompression:
704 intptr = &options->compression;
705 goto parse_flag;
706
Ben Lindstromade03f62001-12-06 18:22:17 +0000707 case sGatewayPorts:
708 intptr = &options->gateway_ports;
709 goto parse_flag;
710
Damien Millerc5d86352002-02-05 12:13:41 +1100711 case sVerifyReverseMapping:
712 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000713 goto parse_flag;
714
715 case sLogFacility:
716 intptr = (int *) &options->log_facility;
717 arg = strdelim(&cp);
718 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100719 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000720 fatal("%.200s line %d: unsupported log facility '%s'",
721 filename, linenum, arg ? arg : "<NONE>");
722 if (*intptr == -1)
723 *intptr = (SyslogFacility) value;
724 break;
725
726 case sLogLevel:
727 intptr = (int *) &options->log_level;
728 arg = strdelim(&cp);
729 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100730 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000731 fatal("%.200s line %d: unsupported log level '%s'",
732 filename, linenum, arg ? arg : "<NONE>");
733 if (*intptr == -1)
734 *intptr = (LogLevel) value;
735 break;
736
737 case sAllowTcpForwarding:
738 intptr = &options->allow_tcp_forwarding;
739 goto parse_flag;
740
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000741 case sUsePrivilegeSeparation:
742 intptr = &use_privsep;
743 goto parse_flag;
744
Ben Lindstromade03f62001-12-06 18:22:17 +0000745 case sAllowUsers:
746 while ((arg = strdelim(&cp)) && *arg != '\0') {
747 if (options->num_allow_users >= MAX_ALLOW_USERS)
748 fatal("%s line %d: too many allow users.",
749 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000750 options->allow_users[options->num_allow_users++] =
751 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000752 }
753 break;
754
755 case sDenyUsers:
756 while ((arg = strdelim(&cp)) && *arg != '\0') {
757 if (options->num_deny_users >= MAX_DENY_USERS)
758 fatal( "%s line %d: too many deny users.",
759 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000760 options->deny_users[options->num_deny_users++] =
761 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000762 }
763 break;
764
765 case sAllowGroups:
766 while ((arg = strdelim(&cp)) && *arg != '\0') {
767 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
768 fatal("%s line %d: too many allow groups.",
769 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000770 options->allow_groups[options->num_allow_groups++] =
771 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000772 }
773 break;
774
775 case sDenyGroups:
776 while ((arg = strdelim(&cp)) && *arg != '\0') {
777 if (options->num_deny_groups >= MAX_DENY_GROUPS)
778 fatal("%s line %d: too many deny groups.",
779 filename, linenum);
780 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
781 }
782 break;
783
784 case sCiphers:
785 arg = strdelim(&cp);
786 if (!arg || *arg == '\0')
787 fatal("%s line %d: Missing argument.", filename, linenum);
788 if (!ciphers_valid(arg))
789 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
790 filename, linenum, arg ? arg : "<NONE>");
791 if (options->ciphers == NULL)
792 options->ciphers = xstrdup(arg);
793 break;
794
795 case sMacs:
796 arg = strdelim(&cp);
797 if (!arg || *arg == '\0')
798 fatal("%s line %d: Missing argument.", filename, linenum);
799 if (!mac_valid(arg))
800 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
801 filename, linenum, arg ? arg : "<NONE>");
802 if (options->macs == NULL)
803 options->macs = xstrdup(arg);
804 break;
805
806 case sProtocol:
807 intptr = &options->protocol;
808 arg = strdelim(&cp);
809 if (!arg || *arg == '\0')
810 fatal("%s line %d: Missing argument.", filename, linenum);
811 value = proto_spec(arg);
812 if (value == SSH_PROTO_UNKNOWN)
813 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100814 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000815 if (*intptr == SSH_PROTO_UNKNOWN)
816 *intptr = value;
817 break;
818
819 case sSubsystem:
820 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
821 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100822 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000823 }
824 arg = strdelim(&cp);
825 if (!arg || *arg == '\0')
826 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100827 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000828 for (i = 0; i < options->num_subsystems; i++)
829 if (strcmp(arg, options->subsystem_name[i]) == 0)
830 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100831 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000832 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
833 arg = strdelim(&cp);
834 if (!arg || *arg == '\0')
835 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100836 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000837 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
838 options->num_subsystems++;
839 break;
840
841 case sMaxStartups:
842 arg = strdelim(&cp);
843 if (!arg || *arg == '\0')
844 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100845 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000846 if ((n = sscanf(arg, "%d:%d:%d",
847 &options->max_startups_begin,
848 &options->max_startups_rate,
849 &options->max_startups)) == 3) {
850 if (options->max_startups_begin >
851 options->max_startups ||
852 options->max_startups_rate > 100 ||
853 options->max_startups_rate < 1)
854 fatal("%s line %d: Illegal MaxStartups spec.",
855 filename, linenum);
856 } else if (n != 1)
857 fatal("%s line %d: Illegal MaxStartups spec.",
858 filename, linenum);
859 else
860 options->max_startups = options->max_startups_begin;
861 break;
862
863 case sBanner:
864 charptr = &options->banner;
865 goto parse_filename;
866 /*
867 * These options can contain %X options expanded at
868 * connect time, so that you can specify paths like:
869 *
870 * AuthorizedKeysFile /etc/ssh_keys/%u
871 */
872 case sAuthorizedKeysFile:
873 case sAuthorizedKeysFile2:
874 charptr = (opcode == sAuthorizedKeysFile ) ?
875 &options->authorized_keys_file :
876 &options->authorized_keys_file2;
877 goto parse_filename;
878
879 case sClientAliveInterval:
880 intptr = &options->client_alive_interval;
881 goto parse_time;
882
883 case sClientAliveCountMax:
884 intptr = &options->client_alive_count_max;
885 goto parse_int;
886
887 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000888 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000889 filename, linenum, arg);
890 while (arg)
891 arg = strdelim(&cp);
892 break;
893
894 default:
895 fatal("%s line %d: Missing handler for opcode %s (%d)",
896 filename, linenum, arg, opcode);
897 }
898 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
899 fatal("%s line %d: garbage at end of line; \"%.200s\".",
900 filename, linenum, arg);
901 return 0;
902}
903
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000904/* Reads the server configuration file. */
905
Damien Miller4af51302000-04-16 11:18:38 +1000906void
Damien Miller95def091999-11-25 00:26:21 +1100907read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000908{
Ben Lindstrome1353632002-06-23 21:29:23 +0000909 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100910 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000911 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000912
Damien Miller9f82c8f2003-02-24 12:04:33 +1100913 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100914 f = fopen(filename, "r");
915 if (!f) {
916 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000917 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100918 }
919 linenum = 0;
920 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000921 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100922 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000923 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100924 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000925 }
Damien Miller95def091999-11-25 00:26:21 +1100926 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000927 if (bad_options > 0)
928 fatal("%s: terminating, %d bad configuration options",
929 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000930}