blob: 5840961e3870dab529b781d811985c580109a21a [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 Millerd248b5b2003-05-15 14:15:23 +100013RCSID("$OpenBSD: servconf.c,v 1.120 2003/05/15 04:08:44 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 Miller156cbe82003-05-15 14:16:41 +1000134#ifdef USE_PAM
135 options->use_pam = 1;
136#else
Damien Miller2aa0ab42003-05-15 12:05:28 +1000137 options->use_pam = 0;
Damien Miller156cbe82003-05-15 14:16:41 +1000138#endif
Damien Miller726273e2001-11-12 11:40:11 +1100139
140 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100141 if (options->protocol == SSH_PROTO_UNKNOWN)
142 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
143 if (options->num_host_key_files == 0) {
144 /* fill default hostkeys for protocols */
145 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100146 options->host_key_files[options->num_host_key_files++] =
147 _PATH_HOST_KEY_FILE;
148 if (options->protocol & SSH_PROTO_2) {
149 options->host_key_files[options->num_host_key_files++] =
150 _PATH_HOST_RSA_KEY_FILE;
151 options->host_key_files[options->num_host_key_files++] =
152 _PATH_HOST_DSA_KEY_FILE;
153 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100154 }
Damien Miller34132e52000-01-14 15:45:46 +1100155 if (options->num_ports == 0)
156 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
157 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000158 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000159 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000160 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100161 if (options->server_key_bits == -1)
162 options->server_key_bits = 768;
163 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000164 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->key_regeneration_time == -1)
166 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000167 if (options->permit_root_login == PERMIT_NOT_SET)
168 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100169 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100170 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->ignore_user_known_hosts == -1)
172 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->print_motd == -1)
174 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000175 if (options->print_lastlog == -1)
176 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100177 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100178 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100180 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100181 if (options->x11_use_localhost == -1)
182 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000183 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000184 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->strict_modes == -1)
186 options->strict_modes = 1;
187 if (options->keepalives == -1)
188 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100189 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100190 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100191 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000192 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100193 if (options->rhosts_authentication == -1)
194 options->rhosts_authentication = 0;
195 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100196 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000197 if (options->hostbased_authentication == -1)
198 options->hostbased_authentication = 0;
199 if (options->hostbased_uses_name_from_packet_only == -1)
200 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->rsa_authentication == -1)
202 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100203 if (options->pubkey_authentication == -1)
204 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000206 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->kerberos_or_local_passwd == -1)
208 options->kerberos_or_local_passwd = 1;
209 if (options->kerberos_ticket_cleanup == -1)
Damien Millerd248b5b2003-05-15 14:15:23 +1000210#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100211 options->kerberos_ticket_cleanup = 1;
Damien Millerd248b5b2003-05-15 14:15:23 +1000212#else
213 options->kerberos_ticket_cleanup = 0;
214#endif
Damien Miller95def091999-11-25 00:26:21 +1100215 if (options->kerberos_tgt_passing == -1)
216 options->kerberos_tgt_passing = 0;
217 if (options->afs_token_passing == -1)
Damien Millere4ccf102002-04-23 20:40:28 +1000218 options->afs_token_passing = 0;
Damien Miller95def091999-11-25 00:26:21 +1100219 if (options->password_authentication == -1)
220 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100221 if (options->kbd_interactive_authentication == -1)
222 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000223 if (options->challenge_response_authentication == -1)
224 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100225 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100226 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000227 if (options->permit_user_env == -1)
228 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->use_login == -1)
230 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000231 if (options->compression == -1)
232 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100233 if (options->allow_tcp_forwarding == -1)
234 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000235 if (options->gateway_ports == -1)
236 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000237 if (options->max_startups == -1)
238 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000239 if (options->max_startups_rate == -1)
240 options->max_startups_rate = 100; /* 100% */
241 if (options->max_startups_begin == -1)
242 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100243 if (options->verify_reverse_mapping == -1)
244 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000245 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100246 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000247 if (options->client_alive_count_max == -1)
248 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100249 if (options->authorized_keys_file2 == NULL) {
250 /* authorized_keys_file2 falls back to authorized_keys_file */
251 if (options->authorized_keys_file != NULL)
252 options->authorized_keys_file2 = options->authorized_keys_file;
253 else
254 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
255 }
256 if (options->authorized_keys_file == NULL)
257 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000258
Ben Lindstromfb62a692002-06-06 19:47:11 +0000259 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000260 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000261 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000262
Tim Rice40017b02002-07-14 13:36:49 -0700263#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000264 if (use_privsep && options->compression == 1) {
265 error("This platform does not support both privilege "
266 "separation and compression");
267 error("Compression disabled");
268 options->compression = 0;
269 }
270#endif
271
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000272}
273
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000274/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100275typedef enum {
276 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100277 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000278 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100279 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100280 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
281 sPermitRootLogin, sLogFacility, sLogLevel,
282 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100283 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Miller2aa0ab42003-05-15 12:05:28 +1000284 sKerberosTgtPassing, sAFSTokenPassing, sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100285 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000286 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100287 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000288 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000289 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100290 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000291 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100292 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100293 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100294 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000295 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000296 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000297 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000298} ServerOpCodes;
299
300/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100301static struct {
302 const char *name;
303 ServerOpCodes opcode;
304} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100305 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000306 { "UsePAM", sUsePAM },
Damien Miller726273e2001-11-12 11:40:11 +1100307 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100308 { "port", sPort },
309 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100310 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000311 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100312 { "serverkeybits", sServerKeyBits },
313 { "logingracetime", sLoginGraceTime },
314 { "keyregenerationinterval", sKeyRegenerationTime },
315 { "permitrootlogin", sPermitRootLogin },
316 { "syslogfacility", sLogFacility },
317 { "loglevel", sLogLevel },
318 { "rhostsauthentication", sRhostsAuthentication },
319 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000320 { "hostbasedauthentication", sHostbasedAuthentication },
321 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100322 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100323 { "pubkeyauthentication", sPubkeyAuthentication },
324 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100325 { "kerberosauthentication", sKerberosAuthentication },
326 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
327 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Miller95def091999-11-25 00:26:21 +1100328 { "kerberostgtpassing", sKerberosTgtPassing },
329 { "afstokenpassing", sAFSTokenPassing },
Damien Miller95def091999-11-25 00:26:21 +1100330 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100331 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000332 { "challengeresponseauthentication", sChallengeResponseAuthentication },
333 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000334 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100335 { "listenaddress", sListenAddress },
336 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000337 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100338 { "ignorerhosts", sIgnoreRhosts },
339 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
340 { "x11forwarding", sX11Forwarding },
341 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100342 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000343 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100344 { "strictmodes", sStrictModes },
345 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000346 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100347 { "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;
Ben Lindstrome1353632002-06-23 21:29:23 +0000416 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000417 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;
Ben Lindstrome1353632002-06-23 21:29:23 +0000432 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000433 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000434
435 cp = line;
436 arg = strdelim(&cp);
437 /* Ignore leading whitespace */
438 if (*arg == '\0')
439 arg = strdelim(&cp);
440 if (!arg || !*arg || *arg == '#')
441 return 0;
442 intptr = NULL;
443 charptr = NULL;
444 opcode = parse_token(arg, filename, linenum);
445 switch (opcode) {
446 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000447 case sUsePAM:
448 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000449 goto parse_flag;
450
451 /* Standard Options */
452 case sBadOption:
453 return -1;
454 case sPort:
455 /* ignore ports from configfile if cmdline specifies ports */
456 if (options->ports_from_cmdline)
457 return 0;
458 if (options->listen_addrs != NULL)
459 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100460 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000461 if (options->num_ports >= MAX_PORTS)
462 fatal("%s line %d: too many ports.",
463 filename, linenum);
464 arg = strdelim(&cp);
465 if (!arg || *arg == '\0')
466 fatal("%s line %d: missing port number.",
467 filename, linenum);
468 options->ports[options->num_ports++] = a2port(arg);
469 if (options->ports[options->num_ports-1] == 0)
470 fatal("%s line %d: Badly formatted port number.",
471 filename, linenum);
472 break;
473
474 case sServerKeyBits:
475 intptr = &options->server_key_bits;
476parse_int:
477 arg = strdelim(&cp);
478 if (!arg || *arg == '\0')
479 fatal("%s line %d: missing integer value.",
480 filename, linenum);
481 value = atoi(arg);
482 if (*intptr == -1)
483 *intptr = value;
484 break;
485
486 case sLoginGraceTime:
487 intptr = &options->login_grace_time;
488parse_time:
489 arg = strdelim(&cp);
490 if (!arg || *arg == '\0')
491 fatal("%s line %d: missing time value.",
492 filename, linenum);
493 if ((value = convtime(arg)) == -1)
494 fatal("%s line %d: invalid time value.",
495 filename, linenum);
496 if (*intptr == -1)
497 *intptr = value;
498 break;
499
500 case sKeyRegenerationTime:
501 intptr = &options->key_regeneration_time;
502 goto parse_time;
503
504 case sListenAddress:
505 arg = strdelim(&cp);
506 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
507 fatal("%s line %d: missing inet addr.",
508 filename, linenum);
509 if (*arg == '[') {
510 if ((p = strchr(arg, ']')) == NULL)
511 fatal("%s line %d: bad ipv6 inet addr usage.",
512 filename, linenum);
513 arg++;
514 memmove(p, p+1, strlen(p+1)+1);
515 } else if (((p = strchr(arg, ':')) == NULL) ||
516 (strchr(p+1, ':') != NULL)) {
517 add_listen_addr(options, arg, 0);
518 break;
519 }
520 if (*p == ':') {
521 u_short port;
522
523 p++;
524 if (*p == '\0')
525 fatal("%s line %d: bad inet addr:port usage.",
526 filename, linenum);
527 else {
528 *(p-1) = '\0';
529 if ((port = a2port(p)) == 0)
530 fatal("%s line %d: bad port number.",
531 filename, linenum);
532 add_listen_addr(options, arg, port);
533 }
534 } else if (*p == '\0')
535 add_listen_addr(options, arg, 0);
536 else
537 fatal("%s line %d: bad inet addr usage.",
538 filename, linenum);
539 break;
540
541 case sHostKeyFile:
542 intptr = &options->num_host_key_files;
543 if (*intptr >= MAX_HOSTKEYS)
544 fatal("%s line %d: too many host keys specified (max %d).",
545 filename, linenum, MAX_HOSTKEYS);
546 charptr = &options->host_key_files[*intptr];
547parse_filename:
548 arg = strdelim(&cp);
549 if (!arg || *arg == '\0')
550 fatal("%s line %d: missing file name.",
551 filename, linenum);
552 if (*charptr == NULL) {
553 *charptr = tilde_expand_filename(arg, getuid());
554 /* increase optional counter */
555 if (intptr != NULL)
556 *intptr = *intptr + 1;
557 }
558 break;
559
560 case sPidFile:
561 charptr = &options->pid_file;
562 goto parse_filename;
563
564 case sPermitRootLogin:
565 intptr = &options->permit_root_login;
566 arg = strdelim(&cp);
567 if (!arg || *arg == '\0')
568 fatal("%s line %d: missing yes/"
569 "without-password/forced-commands-only/no "
570 "argument.", filename, linenum);
571 value = 0; /* silence compiler */
572 if (strcmp(arg, "without-password") == 0)
573 value = PERMIT_NO_PASSWD;
574 else if (strcmp(arg, "forced-commands-only") == 0)
575 value = PERMIT_FORCED_ONLY;
576 else if (strcmp(arg, "yes") == 0)
577 value = PERMIT_YES;
578 else if (strcmp(arg, "no") == 0)
579 value = PERMIT_NO;
580 else
581 fatal("%s line %d: Bad yes/"
582 "without-password/forced-commands-only/no "
583 "argument: %s", filename, linenum, arg);
584 if (*intptr == -1)
585 *intptr = value;
586 break;
587
588 case sIgnoreRhosts:
589 intptr = &options->ignore_rhosts;
590parse_flag:
591 arg = strdelim(&cp);
592 if (!arg || *arg == '\0')
593 fatal("%s line %d: missing yes/no argument.",
594 filename, linenum);
595 value = 0; /* silence compiler */
596 if (strcmp(arg, "yes") == 0)
597 value = 1;
598 else if (strcmp(arg, "no") == 0)
599 value = 0;
600 else
601 fatal("%s line %d: Bad yes/no argument: %s",
602 filename, linenum, arg);
603 if (*intptr == -1)
604 *intptr = value;
605 break;
606
607 case sIgnoreUserKnownHosts:
608 intptr = &options->ignore_user_known_hosts;
609 goto parse_flag;
610
611 case sRhostsAuthentication:
612 intptr = &options->rhosts_authentication;
613 goto parse_flag;
614
615 case sRhostsRSAAuthentication:
616 intptr = &options->rhosts_rsa_authentication;
617 goto parse_flag;
618
619 case sHostbasedAuthentication:
620 intptr = &options->hostbased_authentication;
621 goto parse_flag;
622
623 case sHostbasedUsesNameFromPacketOnly:
624 intptr = &options->hostbased_uses_name_from_packet_only;
625 goto parse_flag;
626
627 case sRSAAuthentication:
628 intptr = &options->rsa_authentication;
629 goto parse_flag;
630
631 case sPubkeyAuthentication:
632 intptr = &options->pubkey_authentication;
633 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000634
Ben Lindstromade03f62001-12-06 18:22:17 +0000635 case sKerberosAuthentication:
636 intptr = &options->kerberos_authentication;
637 goto parse_flag;
638
639 case sKerberosOrLocalPasswd:
640 intptr = &options->kerberos_or_local_passwd;
641 goto parse_flag;
642
643 case sKerberosTicketCleanup:
644 intptr = &options->kerberos_ticket_cleanup;
645 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000646
Ben Lindstromade03f62001-12-06 18:22:17 +0000647 case sKerberosTgtPassing:
648 intptr = &options->kerberos_tgt_passing;
649 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000650
Ben Lindstromade03f62001-12-06 18:22:17 +0000651 case sAFSTokenPassing:
652 intptr = &options->afs_token_passing;
653 goto parse_flag;
Ben Lindstromade03f62001-12-06 18:22:17 +0000654
655 case sPasswordAuthentication:
656 intptr = &options->password_authentication;
657 goto parse_flag;
658
659 case sKbdInteractiveAuthentication:
660 intptr = &options->kbd_interactive_authentication;
661 goto parse_flag;
662
663 case sChallengeResponseAuthentication:
664 intptr = &options->challenge_response_authentication;
665 goto parse_flag;
666
667 case sPrintMotd:
668 intptr = &options->print_motd;
669 goto parse_flag;
670
671 case sPrintLastLog:
672 intptr = &options->print_lastlog;
673 goto parse_flag;
674
675 case sX11Forwarding:
676 intptr = &options->x11_forwarding;
677 goto parse_flag;
678
679 case sX11DisplayOffset:
680 intptr = &options->x11_display_offset;
681 goto parse_int;
682
Damien Miller95c249f2002-02-05 12:11:34 +1100683 case sX11UseLocalhost:
684 intptr = &options->x11_use_localhost;
685 goto parse_flag;
686
Ben Lindstromade03f62001-12-06 18:22:17 +0000687 case sXAuthLocation:
688 charptr = &options->xauth_location;
689 goto parse_filename;
690
691 case sStrictModes:
692 intptr = &options->strict_modes;
693 goto parse_flag;
694
695 case sKeepAlives:
696 intptr = &options->keepalives;
697 goto parse_flag;
698
699 case sEmptyPasswd:
700 intptr = &options->permit_empty_passwd;
701 goto parse_flag;
702
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000703 case sPermitUserEnvironment:
704 intptr = &options->permit_user_env;
705 goto parse_flag;
706
Ben Lindstromade03f62001-12-06 18:22:17 +0000707 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);
Ben Lindstrome1353632002-06-23 21:29:23 +0000758 options->allow_users[options->num_allow_users++] =
759 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000760 }
761 break;
762
763 case sDenyUsers:
764 while ((arg = strdelim(&cp)) && *arg != '\0') {
765 if (options->num_deny_users >= MAX_DENY_USERS)
766 fatal( "%s line %d: too many deny users.",
767 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000768 options->deny_users[options->num_deny_users++] =
769 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000770 }
771 break;
772
773 case sAllowGroups:
774 while ((arg = strdelim(&cp)) && *arg != '\0') {
775 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
776 fatal("%s line %d: too many allow groups.",
777 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000778 options->allow_groups[options->num_allow_groups++] =
779 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000780 }
781 break;
782
783 case sDenyGroups:
784 while ((arg = strdelim(&cp)) && *arg != '\0') {
785 if (options->num_deny_groups >= MAX_DENY_GROUPS)
786 fatal("%s line %d: too many deny groups.",
787 filename, linenum);
788 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
789 }
790 break;
791
792 case sCiphers:
793 arg = strdelim(&cp);
794 if (!arg || *arg == '\0')
795 fatal("%s line %d: Missing argument.", filename, linenum);
796 if (!ciphers_valid(arg))
797 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
798 filename, linenum, arg ? arg : "<NONE>");
799 if (options->ciphers == NULL)
800 options->ciphers = xstrdup(arg);
801 break;
802
803 case sMacs:
804 arg = strdelim(&cp);
805 if (!arg || *arg == '\0')
806 fatal("%s line %d: Missing argument.", filename, linenum);
807 if (!mac_valid(arg))
808 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
809 filename, linenum, arg ? arg : "<NONE>");
810 if (options->macs == NULL)
811 options->macs = xstrdup(arg);
812 break;
813
814 case sProtocol:
815 intptr = &options->protocol;
816 arg = strdelim(&cp);
817 if (!arg || *arg == '\0')
818 fatal("%s line %d: Missing argument.", filename, linenum);
819 value = proto_spec(arg);
820 if (value == SSH_PROTO_UNKNOWN)
821 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100822 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000823 if (*intptr == SSH_PROTO_UNKNOWN)
824 *intptr = value;
825 break;
826
827 case sSubsystem:
828 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
829 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100830 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000831 }
832 arg = strdelim(&cp);
833 if (!arg || *arg == '\0')
834 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100835 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000836 for (i = 0; i < options->num_subsystems; i++)
837 if (strcmp(arg, options->subsystem_name[i]) == 0)
838 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100839 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000840 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
841 arg = strdelim(&cp);
842 if (!arg || *arg == '\0')
843 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100844 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000845 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
846 options->num_subsystems++;
847 break;
848
849 case sMaxStartups:
850 arg = strdelim(&cp);
851 if (!arg || *arg == '\0')
852 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100853 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000854 if ((n = sscanf(arg, "%d:%d:%d",
855 &options->max_startups_begin,
856 &options->max_startups_rate,
857 &options->max_startups)) == 3) {
858 if (options->max_startups_begin >
859 options->max_startups ||
860 options->max_startups_rate > 100 ||
861 options->max_startups_rate < 1)
862 fatal("%s line %d: Illegal MaxStartups spec.",
863 filename, linenum);
864 } else if (n != 1)
865 fatal("%s line %d: Illegal MaxStartups spec.",
866 filename, linenum);
867 else
868 options->max_startups = options->max_startups_begin;
869 break;
870
871 case sBanner:
872 charptr = &options->banner;
873 goto parse_filename;
874 /*
875 * These options can contain %X options expanded at
876 * connect time, so that you can specify paths like:
877 *
878 * AuthorizedKeysFile /etc/ssh_keys/%u
879 */
880 case sAuthorizedKeysFile:
881 case sAuthorizedKeysFile2:
882 charptr = (opcode == sAuthorizedKeysFile ) ?
883 &options->authorized_keys_file :
884 &options->authorized_keys_file2;
885 goto parse_filename;
886
887 case sClientAliveInterval:
888 intptr = &options->client_alive_interval;
889 goto parse_time;
890
891 case sClientAliveCountMax:
892 intptr = &options->client_alive_count_max;
893 goto parse_int;
894
895 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000896 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000897 filename, linenum, arg);
898 while (arg)
899 arg = strdelim(&cp);
900 break;
901
902 default:
903 fatal("%s line %d: Missing handler for opcode %s (%d)",
904 filename, linenum, arg, opcode);
905 }
906 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
907 fatal("%s line %d: garbage at end of line; \"%.200s\".",
908 filename, linenum, arg);
909 return 0;
910}
911
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000912/* Reads the server configuration file. */
913
Damien Miller4af51302000-04-16 11:18:38 +1000914void
Damien Miller95def091999-11-25 00:26:21 +1100915read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000916{
Ben Lindstrome1353632002-06-23 21:29:23 +0000917 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100918 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000919 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000920
Damien Miller9f82c8f2003-02-24 12:04:33 +1100921 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100922 f = fopen(filename, "r");
923 if (!f) {
924 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000925 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100926 }
927 linenum = 0;
928 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000929 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100930 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000931 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100932 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000933 }
Damien Miller95def091999-11-25 00:26:21 +1100934 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000935 if (bad_options > 0)
936 fatal("%s: terminating, %d bad configuration options",
937 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000938}