blob: c501d7b64050e116822dd8c7d65c909e8ff734c7 [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 Miller3a961dc2003-06-03 10:25:48 +100013RCSID("$OpenBSD: servconf.c,v 1.122 2003/06/02 09:17:34 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 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 Miller3a961dc2003-06-03 10:25:48 +1000119 options->use_dns = -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 options->use_pam = 1;
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 Miller3a961dc2003-06-03 10:25:48 +1000235 if (options->use_dns == -1)
236 options->use_dns = 1;
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 Miller3a961dc2003-06-03 10:25:48 +1000285 sBanner, sUseDNS, 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,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000289 sDeprecated, sUnsupported
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 Miller6ac2c482003-05-16 11:42:35 +1000298#ifdef USE_PAM
Damien Miller4e448a32003-05-14 15:11:48 +1000299 { "UsePAM", sUsePAM },
Damien Miller6ac2c482003-05-16 11:42:35 +1000300#else
301 { "UsePAM", sUnsupported },
302#endif
Damien Miller726273e2001-11-12 11:40:11 +1100303 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100304 { "port", sPort },
305 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100306 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000307 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100308 { "serverkeybits", sServerKeyBits },
309 { "logingracetime", sLoginGraceTime },
310 { "keyregenerationinterval", sKeyRegenerationTime },
311 { "permitrootlogin", sPermitRootLogin },
312 { "syslogfacility", sLogFacility },
313 { "loglevel", sLogLevel },
314 { "rhostsauthentication", sRhostsAuthentication },
315 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000316 { "hostbasedauthentication", sHostbasedAuthentication },
317 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100318 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100319 { "pubkeyauthentication", sPubkeyAuthentication },
320 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000321#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100322 { "kerberosauthentication", sKerberosAuthentication },
323 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
324 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Miller95def091999-11-25 00:26:21 +1100325 { "kerberostgtpassing", sKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000326#else
327 { "kerberosauthentication", sUnsupported },
328 { "kerberosorlocalpasswd", sUnsupported },
329 { "kerberosticketcleanup", sUnsupported },
330 { "kerberostgtpassing", sUnsupported },
331#endif
332#if defined(AFS)
Damien Miller95def091999-11-25 00:26:21 +1100333 { "afstokenpassing", sAFSTokenPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000334#else
335 { "afstokenpassing", sUnsupported },
336#endif
Damien Miller95def091999-11-25 00:26:21 +1100337 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100338 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000339 { "challengeresponseauthentication", sChallengeResponseAuthentication },
340 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000341 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100342 { "listenaddress", sListenAddress },
343 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000344 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100345 { "ignorerhosts", sIgnoreRhosts },
346 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
347 { "x11forwarding", sX11Forwarding },
348 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100349 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000350 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100351 { "strictmodes", sStrictModes },
352 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000353 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100354 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000355 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100356 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100357 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100358 { "allowusers", sAllowUsers },
359 { "denyusers", sDenyUsers },
360 { "allowgroups", sAllowGroups },
361 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000362 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000363 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000364 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000365 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000366 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000367 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000368 { "banner", sBanner },
Damien Miller3a961dc2003-06-03 10:25:48 +1000369 { "usedns", sUseDNS },
370 { "verifyreversemapping", sDeprecated },
371 { "reversemappingcheck", sDeprecated },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000372 { "clientaliveinterval", sClientAliveInterval },
373 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000374 { "authorizedkeysfile", sAuthorizedKeysFile },
375 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000376 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000377 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000378};
379
Damien Miller5428f641999-11-25 11:54:57 +1100380/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000381 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100382 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383
Damien Miller4af51302000-04-16 11:18:38 +1000384static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100385parse_token(const char *cp, const char *filename,
386 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000387{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000388 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000389
Damien Miller95def091999-11-25 00:26:21 +1100390 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100391 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100392 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000393
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000394 error("%s: line %d: Bad configuration option: %s",
395 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100396 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000397}
398
Ben Lindstrombba81212001-06-25 05:01:22 +0000399static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000400add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100401{
Damien Miller34132e52000-01-14 15:45:46 +1100402 int i;
403
404 if (options->num_ports == 0)
405 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000406 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000407 for (i = 0; i < options->num_ports; i++)
408 add_one_listen_addr(options, addr, options->ports[i]);
409 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000410 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000411}
412
Ben Lindstrombba81212001-06-25 05:01:22 +0000413static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000414add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
415{
416 struct addrinfo hints, *ai, *aitop;
417 char strport[NI_MAXSERV];
418 int gaierr;
419
420 memset(&hints, 0, sizeof(hints));
421 hints.ai_family = IPv4or6;
422 hints.ai_socktype = SOCK_STREAM;
423 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000424 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000425 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
426 fatal("bad addr or host: %s (%s)",
427 addr ? addr : "<NULL>",
428 gai_strerror(gaierr));
429 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
430 ;
431 ai->ai_next = options->listen_addrs;
432 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100433}
434
Ben Lindstromade03f62001-12-06 18:22:17 +0000435int
436process_server_config_line(ServerOptions *options, char *line,
437 const char *filename, int linenum)
438{
439 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000440 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000441 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000442
443 cp = line;
444 arg = strdelim(&cp);
445 /* Ignore leading whitespace */
446 if (*arg == '\0')
447 arg = strdelim(&cp);
448 if (!arg || !*arg || *arg == '#')
449 return 0;
450 intptr = NULL;
451 charptr = NULL;
452 opcode = parse_token(arg, filename, linenum);
453 switch (opcode) {
454 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000455 case sUsePAM:
456 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000457 goto parse_flag;
458
459 /* Standard Options */
460 case sBadOption:
461 return -1;
462 case sPort:
463 /* ignore ports from configfile if cmdline specifies ports */
464 if (options->ports_from_cmdline)
465 return 0;
466 if (options->listen_addrs != NULL)
467 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100468 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000469 if (options->num_ports >= MAX_PORTS)
470 fatal("%s line %d: too many ports.",
471 filename, linenum);
472 arg = strdelim(&cp);
473 if (!arg || *arg == '\0')
474 fatal("%s line %d: missing port number.",
475 filename, linenum);
476 options->ports[options->num_ports++] = a2port(arg);
477 if (options->ports[options->num_ports-1] == 0)
478 fatal("%s line %d: Badly formatted port number.",
479 filename, linenum);
480 break;
481
482 case sServerKeyBits:
483 intptr = &options->server_key_bits;
484parse_int:
485 arg = strdelim(&cp);
486 if (!arg || *arg == '\0')
487 fatal("%s line %d: missing integer value.",
488 filename, linenum);
489 value = atoi(arg);
490 if (*intptr == -1)
491 *intptr = value;
492 break;
493
494 case sLoginGraceTime:
495 intptr = &options->login_grace_time;
496parse_time:
497 arg = strdelim(&cp);
498 if (!arg || *arg == '\0')
499 fatal("%s line %d: missing time value.",
500 filename, linenum);
501 if ((value = convtime(arg)) == -1)
502 fatal("%s line %d: invalid time value.",
503 filename, linenum);
504 if (*intptr == -1)
505 *intptr = value;
506 break;
507
508 case sKeyRegenerationTime:
509 intptr = &options->key_regeneration_time;
510 goto parse_time;
511
512 case sListenAddress:
513 arg = strdelim(&cp);
514 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
515 fatal("%s line %d: missing inet addr.",
516 filename, linenum);
517 if (*arg == '[') {
518 if ((p = strchr(arg, ']')) == NULL)
519 fatal("%s line %d: bad ipv6 inet addr usage.",
520 filename, linenum);
521 arg++;
522 memmove(p, p+1, strlen(p+1)+1);
523 } else if (((p = strchr(arg, ':')) == NULL) ||
524 (strchr(p+1, ':') != NULL)) {
525 add_listen_addr(options, arg, 0);
526 break;
527 }
528 if (*p == ':') {
529 u_short port;
530
531 p++;
532 if (*p == '\0')
533 fatal("%s line %d: bad inet addr:port usage.",
534 filename, linenum);
535 else {
536 *(p-1) = '\0';
537 if ((port = a2port(p)) == 0)
538 fatal("%s line %d: bad port number.",
539 filename, linenum);
540 add_listen_addr(options, arg, port);
541 }
542 } else if (*p == '\0')
543 add_listen_addr(options, arg, 0);
544 else
545 fatal("%s line %d: bad inet addr usage.",
546 filename, linenum);
547 break;
548
549 case sHostKeyFile:
550 intptr = &options->num_host_key_files;
551 if (*intptr >= MAX_HOSTKEYS)
552 fatal("%s line %d: too many host keys specified (max %d).",
553 filename, linenum, MAX_HOSTKEYS);
554 charptr = &options->host_key_files[*intptr];
555parse_filename:
556 arg = strdelim(&cp);
557 if (!arg || *arg == '\0')
558 fatal("%s line %d: missing file name.",
559 filename, linenum);
560 if (*charptr == NULL) {
561 *charptr = tilde_expand_filename(arg, getuid());
562 /* increase optional counter */
563 if (intptr != NULL)
564 *intptr = *intptr + 1;
565 }
566 break;
567
568 case sPidFile:
569 charptr = &options->pid_file;
570 goto parse_filename;
571
572 case sPermitRootLogin:
573 intptr = &options->permit_root_login;
574 arg = strdelim(&cp);
575 if (!arg || *arg == '\0')
576 fatal("%s line %d: missing yes/"
577 "without-password/forced-commands-only/no "
578 "argument.", filename, linenum);
579 value = 0; /* silence compiler */
580 if (strcmp(arg, "without-password") == 0)
581 value = PERMIT_NO_PASSWD;
582 else if (strcmp(arg, "forced-commands-only") == 0)
583 value = PERMIT_FORCED_ONLY;
584 else if (strcmp(arg, "yes") == 0)
585 value = PERMIT_YES;
586 else if (strcmp(arg, "no") == 0)
587 value = PERMIT_NO;
588 else
589 fatal("%s line %d: Bad yes/"
590 "without-password/forced-commands-only/no "
591 "argument: %s", filename, linenum, arg);
592 if (*intptr == -1)
593 *intptr = value;
594 break;
595
596 case sIgnoreRhosts:
597 intptr = &options->ignore_rhosts;
598parse_flag:
599 arg = strdelim(&cp);
600 if (!arg || *arg == '\0')
601 fatal("%s line %d: missing yes/no argument.",
602 filename, linenum);
603 value = 0; /* silence compiler */
604 if (strcmp(arg, "yes") == 0)
605 value = 1;
606 else if (strcmp(arg, "no") == 0)
607 value = 0;
608 else
609 fatal("%s line %d: Bad yes/no argument: %s",
610 filename, linenum, arg);
611 if (*intptr == -1)
612 *intptr = value;
613 break;
614
615 case sIgnoreUserKnownHosts:
616 intptr = &options->ignore_user_known_hosts;
617 goto parse_flag;
618
619 case sRhostsAuthentication:
620 intptr = &options->rhosts_authentication;
621 goto parse_flag;
622
623 case sRhostsRSAAuthentication:
624 intptr = &options->rhosts_rsa_authentication;
625 goto parse_flag;
626
627 case sHostbasedAuthentication:
628 intptr = &options->hostbased_authentication;
629 goto parse_flag;
630
631 case sHostbasedUsesNameFromPacketOnly:
632 intptr = &options->hostbased_uses_name_from_packet_only;
633 goto parse_flag;
634
635 case sRSAAuthentication:
636 intptr = &options->rsa_authentication;
637 goto parse_flag;
638
639 case sPubkeyAuthentication:
640 intptr = &options->pubkey_authentication;
641 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000642
Ben Lindstromade03f62001-12-06 18:22:17 +0000643 case sKerberosAuthentication:
644 intptr = &options->kerberos_authentication;
645 goto parse_flag;
646
647 case sKerberosOrLocalPasswd:
648 intptr = &options->kerberos_or_local_passwd;
649 goto parse_flag;
650
651 case sKerberosTicketCleanup:
652 intptr = &options->kerberos_ticket_cleanup;
653 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000654
Ben Lindstromade03f62001-12-06 18:22:17 +0000655 case sKerberosTgtPassing:
656 intptr = &options->kerberos_tgt_passing;
657 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000658
Ben Lindstromade03f62001-12-06 18:22:17 +0000659 case sAFSTokenPassing:
660 intptr = &options->afs_token_passing;
661 goto parse_flag;
Ben Lindstromade03f62001-12-06 18:22:17 +0000662
663 case sPasswordAuthentication:
664 intptr = &options->password_authentication;
665 goto parse_flag;
666
667 case sKbdInteractiveAuthentication:
668 intptr = &options->kbd_interactive_authentication;
669 goto parse_flag;
670
671 case sChallengeResponseAuthentication:
672 intptr = &options->challenge_response_authentication;
673 goto parse_flag;
674
675 case sPrintMotd:
676 intptr = &options->print_motd;
677 goto parse_flag;
678
679 case sPrintLastLog:
680 intptr = &options->print_lastlog;
681 goto parse_flag;
682
683 case sX11Forwarding:
684 intptr = &options->x11_forwarding;
685 goto parse_flag;
686
687 case sX11DisplayOffset:
688 intptr = &options->x11_display_offset;
689 goto parse_int;
690
Damien Miller95c249f2002-02-05 12:11:34 +1100691 case sX11UseLocalhost:
692 intptr = &options->x11_use_localhost;
693 goto parse_flag;
694
Ben Lindstromade03f62001-12-06 18:22:17 +0000695 case sXAuthLocation:
696 charptr = &options->xauth_location;
697 goto parse_filename;
698
699 case sStrictModes:
700 intptr = &options->strict_modes;
701 goto parse_flag;
702
703 case sKeepAlives:
704 intptr = &options->keepalives;
705 goto parse_flag;
706
707 case sEmptyPasswd:
708 intptr = &options->permit_empty_passwd;
709 goto parse_flag;
710
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000711 case sPermitUserEnvironment:
712 intptr = &options->permit_user_env;
713 goto parse_flag;
714
Ben Lindstromade03f62001-12-06 18:22:17 +0000715 case sUseLogin:
716 intptr = &options->use_login;
717 goto parse_flag;
718
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000719 case sCompression:
720 intptr = &options->compression;
721 goto parse_flag;
722
Ben Lindstromade03f62001-12-06 18:22:17 +0000723 case sGatewayPorts:
724 intptr = &options->gateway_ports;
725 goto parse_flag;
726
Damien Miller3a961dc2003-06-03 10:25:48 +1000727 case sUseDNS:
728 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000729 goto parse_flag;
730
731 case sLogFacility:
732 intptr = (int *) &options->log_facility;
733 arg = strdelim(&cp);
734 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100735 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000736 fatal("%.200s line %d: unsupported log facility '%s'",
737 filename, linenum, arg ? arg : "<NONE>");
738 if (*intptr == -1)
739 *intptr = (SyslogFacility) value;
740 break;
741
742 case sLogLevel:
743 intptr = (int *) &options->log_level;
744 arg = strdelim(&cp);
745 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100746 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000747 fatal("%.200s line %d: unsupported log level '%s'",
748 filename, linenum, arg ? arg : "<NONE>");
749 if (*intptr == -1)
750 *intptr = (LogLevel) value;
751 break;
752
753 case sAllowTcpForwarding:
754 intptr = &options->allow_tcp_forwarding;
755 goto parse_flag;
756
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000757 case sUsePrivilegeSeparation:
758 intptr = &use_privsep;
759 goto parse_flag;
760
Ben Lindstromade03f62001-12-06 18:22:17 +0000761 case sAllowUsers:
762 while ((arg = strdelim(&cp)) && *arg != '\0') {
763 if (options->num_allow_users >= MAX_ALLOW_USERS)
764 fatal("%s line %d: too many allow users.",
765 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000766 options->allow_users[options->num_allow_users++] =
767 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000768 }
769 break;
770
771 case sDenyUsers:
772 while ((arg = strdelim(&cp)) && *arg != '\0') {
773 if (options->num_deny_users >= MAX_DENY_USERS)
774 fatal( "%s line %d: too many deny users.",
775 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000776 options->deny_users[options->num_deny_users++] =
777 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000778 }
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);
Ben Lindstrome1353632002-06-23 21:29:23 +0000786 options->allow_groups[options->num_allow_groups++] =
787 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000788 }
789 break;
790
791 case sDenyGroups:
792 while ((arg = strdelim(&cp)) && *arg != '\0') {
793 if (options->num_deny_groups >= MAX_DENY_GROUPS)
794 fatal("%s line %d: too many deny groups.",
795 filename, linenum);
796 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
797 }
798 break;
799
800 case sCiphers:
801 arg = strdelim(&cp);
802 if (!arg || *arg == '\0')
803 fatal("%s line %d: Missing argument.", filename, linenum);
804 if (!ciphers_valid(arg))
805 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
806 filename, linenum, arg ? arg : "<NONE>");
807 if (options->ciphers == NULL)
808 options->ciphers = xstrdup(arg);
809 break;
810
811 case sMacs:
812 arg = strdelim(&cp);
813 if (!arg || *arg == '\0')
814 fatal("%s line %d: Missing argument.", filename, linenum);
815 if (!mac_valid(arg))
816 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
817 filename, linenum, arg ? arg : "<NONE>");
818 if (options->macs == NULL)
819 options->macs = xstrdup(arg);
820 break;
821
822 case sProtocol:
823 intptr = &options->protocol;
824 arg = strdelim(&cp);
825 if (!arg || *arg == '\0')
826 fatal("%s line %d: Missing argument.", filename, linenum);
827 value = proto_spec(arg);
828 if (value == SSH_PROTO_UNKNOWN)
829 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100830 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000831 if (*intptr == SSH_PROTO_UNKNOWN)
832 *intptr = value;
833 break;
834
835 case sSubsystem:
836 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
837 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100838 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000839 }
840 arg = strdelim(&cp);
841 if (!arg || *arg == '\0')
842 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100843 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000844 for (i = 0; i < options->num_subsystems; i++)
845 if (strcmp(arg, options->subsystem_name[i]) == 0)
846 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100847 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000848 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
849 arg = strdelim(&cp);
850 if (!arg || *arg == '\0')
851 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100852 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000853 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
854 options->num_subsystems++;
855 break;
856
857 case sMaxStartups:
858 arg = strdelim(&cp);
859 if (!arg || *arg == '\0')
860 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100861 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000862 if ((n = sscanf(arg, "%d:%d:%d",
863 &options->max_startups_begin,
864 &options->max_startups_rate,
865 &options->max_startups)) == 3) {
866 if (options->max_startups_begin >
867 options->max_startups ||
868 options->max_startups_rate > 100 ||
869 options->max_startups_rate < 1)
870 fatal("%s line %d: Illegal MaxStartups spec.",
871 filename, linenum);
872 } else if (n != 1)
873 fatal("%s line %d: Illegal MaxStartups spec.",
874 filename, linenum);
875 else
876 options->max_startups = options->max_startups_begin;
877 break;
878
879 case sBanner:
880 charptr = &options->banner;
881 goto parse_filename;
882 /*
883 * These options can contain %X options expanded at
884 * connect time, so that you can specify paths like:
885 *
886 * AuthorizedKeysFile /etc/ssh_keys/%u
887 */
888 case sAuthorizedKeysFile:
889 case sAuthorizedKeysFile2:
890 charptr = (opcode == sAuthorizedKeysFile ) ?
891 &options->authorized_keys_file :
892 &options->authorized_keys_file2;
893 goto parse_filename;
894
895 case sClientAliveInterval:
896 intptr = &options->client_alive_interval;
897 goto parse_time;
898
899 case sClientAliveCountMax:
900 intptr = &options->client_alive_count_max;
901 goto parse_int;
902
903 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000904 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000905 filename, linenum, arg);
906 while (arg)
907 arg = strdelim(&cp);
908 break;
909
Damien Millerf9b3feb2003-05-16 11:38:32 +1000910 case sUnsupported:
911 logit("%s line %d: Unsupported option %s",
912 filename, linenum, arg);
913 while (arg)
914 arg = strdelim(&cp);
915 break;
916
Ben Lindstromade03f62001-12-06 18:22:17 +0000917 default:
918 fatal("%s line %d: Missing handler for opcode %s (%d)",
919 filename, linenum, arg, opcode);
920 }
921 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
922 fatal("%s line %d: garbage at end of line; \"%.200s\".",
923 filename, linenum, arg);
924 return 0;
925}
926
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000927/* Reads the server configuration file. */
928
Damien Miller4af51302000-04-16 11:18:38 +1000929void
Damien Miller95def091999-11-25 00:26:21 +1100930read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000931{
Ben Lindstrome1353632002-06-23 21:29:23 +0000932 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100933 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000934 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000935
Damien Miller9f82c8f2003-02-24 12:04:33 +1100936 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100937 f = fopen(filename, "r");
938 if (!f) {
939 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000940 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100941 }
942 linenum = 0;
943 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000944 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100945 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000946 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100947 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000948 }
Damien Miller95def091999-11-25 00:26:21 +1100949 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000950 if (bad_options > 0)
951 fatal("%s: terminating, %d bad configuration options",
952 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000953}