blob: 6df2a255bd3e5afd197fdd430204f4d2c014abd8 [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
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000019#ifdef AFS
20#include <kafs.h>
21#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100022
23#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000024#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100025#include "servconf.h"
26#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100027#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000028#include "pathnames.h"
29#include "tildexpand.h"
30#include "misc.h"
31#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000032#include "kex.h"
33#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000034
Ben Lindstrombba81212001-06-25 05:01:22 +000035static void add_listen_addr(ServerOptions *, char *, u_short);
36static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110037
Ben Lindstrom226cfa02001-01-22 05:34:40 +000038/* AF_UNSPEC or AF_INET or AF_INET6 */
39extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000040/* Use of privilege separation or not */
41extern int use_privsep;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000042
Damien Millerd4a8b7e1999-10-27 13:42:43 +100043/* Initializes the server options to their default values. */
44
Damien Miller4af51302000-04-16 11:18:38 +100045void
Damien Miller95def091999-11-25 00:26:21 +110046initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100047{
Damien Miller95def091999-11-25 00:26:21 +110048 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110049
50 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100051 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110052
53 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110054 options->num_ports = 0;
55 options->ports_from_cmdline = 0;
56 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110057 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100058 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110059 options->server_key_bits = -1;
60 options->login_grace_time = -1;
61 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000062 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110063 options->ignore_rhosts = -1;
64 options->ignore_user_known_hosts = -1;
65 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000066 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110067 options->x11_forwarding = -1;
68 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110069 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100070 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110071 options->strict_modes = -1;
72 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110073 options->log_facility = SYSLOG_FACILITY_NOT_SET;
74 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110075 options->rhosts_authentication = -1;
76 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000077 options->hostbased_authentication = -1;
78 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110079 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110080 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110081 options->kerberos_authentication = -1;
82 options->kerberos_or_local_passwd = -1;
83 options->kerberos_ticket_cleanup = -1;
Damien Miller95def091999-11-25 00:26:21 +110084 options->kerberos_tgt_passing = -1;
85 options->afs_token_passing = -1;
Damien Miller95def091999-11-25 00:26:21 +110086 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110087 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000088 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110089 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +000090 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +110091 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +000092 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110093 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110094 options->num_allow_users = 0;
95 options->num_deny_users = 0;
96 options->num_allow_groups = 0;
97 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100098 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000099 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000100 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000101 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000102 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000103 options->max_startups_begin = -1;
104 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000105 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000106 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +1000107 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000108 options->client_alive_interval = -1;
109 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000110 options->authorized_keys_file = NULL;
111 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000112
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000113 /* Needs to be accessable in many places */
114 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000115}
116
Damien Miller4af51302000-04-16 11:18:38 +1000117void
Damien Miller95def091999-11-25 00:26:21 +1100118fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119{
Damien Miller726273e2001-11-12 11:40:11 +1100120 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000121 if (options->use_pam == -1)
Damien Miller156cbe82003-05-15 14:16:41 +1000122 options->use_pam = 1;
Damien Miller726273e2001-11-12 11:40:11 +1100123
124 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100125 if (options->protocol == SSH_PROTO_UNKNOWN)
126 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
127 if (options->num_host_key_files == 0) {
128 /* fill default hostkeys for protocols */
129 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100130 options->host_key_files[options->num_host_key_files++] =
131 _PATH_HOST_KEY_FILE;
132 if (options->protocol & SSH_PROTO_2) {
133 options->host_key_files[options->num_host_key_files++] =
134 _PATH_HOST_RSA_KEY_FILE;
135 options->host_key_files[options->num_host_key_files++] =
136 _PATH_HOST_DSA_KEY_FILE;
137 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100138 }
Damien Miller34132e52000-01-14 15:45:46 +1100139 if (options->num_ports == 0)
140 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
141 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000142 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000143 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000144 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100145 if (options->server_key_bits == -1)
146 options->server_key_bits = 768;
147 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000148 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100149 if (options->key_regeneration_time == -1)
150 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000151 if (options->permit_root_login == PERMIT_NOT_SET)
152 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100153 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100154 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100155 if (options->ignore_user_known_hosts == -1)
156 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->print_motd == -1)
158 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000159 if (options->print_lastlog == -1)
160 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100161 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100162 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100163 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100164 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100165 if (options->x11_use_localhost == -1)
166 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000167 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000168 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100169 if (options->strict_modes == -1)
170 options->strict_modes = 1;
171 if (options->keepalives == -1)
172 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100173 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100174 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100175 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000176 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100177 if (options->rhosts_authentication == -1)
178 options->rhosts_authentication = 0;
179 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100180 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000181 if (options->hostbased_authentication == -1)
182 options->hostbased_authentication = 0;
183 if (options->hostbased_uses_name_from_packet_only == -1)
184 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->rsa_authentication == -1)
186 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100187 if (options->pubkey_authentication == -1)
188 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100189 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000190 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->kerberos_or_local_passwd == -1)
192 options->kerberos_or_local_passwd = 1;
193 if (options->kerberos_ticket_cleanup == -1)
194 options->kerberos_ticket_cleanup = 1;
Damien Miller95def091999-11-25 00:26:21 +1100195 if (options->kerberos_tgt_passing == -1)
196 options->kerberos_tgt_passing = 0;
197 if (options->afs_token_passing == -1)
Damien Millere4ccf102002-04-23 20:40:28 +1000198 options->afs_token_passing = 0;
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->password_authentication == -1)
200 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100201 if (options->kbd_interactive_authentication == -1)
202 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000203 if (options->challenge_response_authentication == -1)
204 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100206 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000207 if (options->permit_user_env == -1)
208 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100209 if (options->use_login == -1)
210 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000211 if (options->compression == -1)
212 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100213 if (options->allow_tcp_forwarding == -1)
214 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000215 if (options->gateway_ports == -1)
216 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000217 if (options->max_startups == -1)
218 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000219 if (options->max_startups_rate == -1)
220 options->max_startups_rate = 100; /* 100% */
221 if (options->max_startups_begin == -1)
222 options->max_startups_begin = options->max_startups;
Damien Miller3a961dc2003-06-03 10:25:48 +1000223 if (options->use_dns == -1)
224 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000225 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100226 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000227 if (options->client_alive_count_max == -1)
228 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100229 if (options->authorized_keys_file2 == NULL) {
230 /* authorized_keys_file2 falls back to authorized_keys_file */
231 if (options->authorized_keys_file != NULL)
232 options->authorized_keys_file2 = options->authorized_keys_file;
233 else
234 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
235 }
236 if (options->authorized_keys_file == NULL)
237 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000238
Ben Lindstromfb62a692002-06-06 19:47:11 +0000239 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000240 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000241 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000242
Tim Rice40017b02002-07-14 13:36:49 -0700243#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000244 if (use_privsep && options->compression == 1) {
245 error("This platform does not support both privilege "
246 "separation and compression");
247 error("Compression disabled");
248 options->compression = 0;
249 }
250#endif
251
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000252}
253
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000254/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100255typedef enum {
256 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100257 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000258 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100259 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100260 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
261 sPermitRootLogin, sLogFacility, sLogLevel,
262 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100263 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Miller2aa0ab42003-05-15 12:05:28 +1000264 sKerberosTgtPassing, sAFSTokenPassing, sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100265 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000266 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100267 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000268 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000269 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100270 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000271 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100272 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Miller3a961dc2003-06-03 10:25:48 +1000273 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100274 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000275 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000276 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000277 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278} ServerOpCodes;
279
280/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100281static struct {
282 const char *name;
283 ServerOpCodes opcode;
284} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100285 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000286#ifdef USE_PAM
Damien Miller4e448a32003-05-14 15:11:48 +1000287 { "UsePAM", sUsePAM },
Damien Miller6ac2c482003-05-16 11:42:35 +1000288#else
289 { "UsePAM", sUnsupported },
290#endif
Damien Miller726273e2001-11-12 11:40:11 +1100291 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100292 { "port", sPort },
293 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100294 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000295 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100296 { "serverkeybits", sServerKeyBits },
297 { "logingracetime", sLoginGraceTime },
298 { "keyregenerationinterval", sKeyRegenerationTime },
299 { "permitrootlogin", sPermitRootLogin },
300 { "syslogfacility", sLogFacility },
301 { "loglevel", sLogLevel },
302 { "rhostsauthentication", sRhostsAuthentication },
303 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000304 { "hostbasedauthentication", sHostbasedAuthentication },
305 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100306 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100307 { "pubkeyauthentication", sPubkeyAuthentication },
308 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000309#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100310 { "kerberosauthentication", sKerberosAuthentication },
311 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
312 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Miller95def091999-11-25 00:26:21 +1100313 { "kerberostgtpassing", sKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000314#else
315 { "kerberosauthentication", sUnsupported },
316 { "kerberosorlocalpasswd", sUnsupported },
317 { "kerberosticketcleanup", sUnsupported },
318 { "kerberostgtpassing", sUnsupported },
319#endif
320#if defined(AFS)
Damien Miller95def091999-11-25 00:26:21 +1100321 { "afstokenpassing", sAFSTokenPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000322#else
323 { "afstokenpassing", sUnsupported },
324#endif
Damien Miller95def091999-11-25 00:26:21 +1100325 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100326 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000327 { "challengeresponseauthentication", sChallengeResponseAuthentication },
328 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000329 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100330 { "listenaddress", sListenAddress },
331 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000332 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100333 { "ignorerhosts", sIgnoreRhosts },
334 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
335 { "x11forwarding", sX11Forwarding },
336 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100337 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000338 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100339 { "strictmodes", sStrictModes },
340 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000341 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100342 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000343 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100344 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100345 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100346 { "allowusers", sAllowUsers },
347 { "denyusers", sDenyUsers },
348 { "allowgroups", sAllowGroups },
349 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000350 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000351 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000352 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000353 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000354 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000355 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000356 { "banner", sBanner },
Damien Miller3a961dc2003-06-03 10:25:48 +1000357 { "usedns", sUseDNS },
358 { "verifyreversemapping", sDeprecated },
359 { "reversemappingcheck", sDeprecated },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000360 { "clientaliveinterval", sClientAliveInterval },
361 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000362 { "authorizedkeysfile", sAuthorizedKeysFile },
363 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000364 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000365 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000366};
367
Damien Miller5428f641999-11-25 11:54:57 +1100368/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000369 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100370 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000371
Damien Miller4af51302000-04-16 11:18:38 +1000372static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100373parse_token(const char *cp, const char *filename,
374 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000375{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000376 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000377
Damien Miller95def091999-11-25 00:26:21 +1100378 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100379 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100380 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000382 error("%s: line %d: Bad configuration option: %s",
383 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100384 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000385}
386
Ben Lindstrombba81212001-06-25 05:01:22 +0000387static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000388add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100389{
Damien Miller34132e52000-01-14 15:45:46 +1100390 int i;
391
392 if (options->num_ports == 0)
393 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000394 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000395 for (i = 0; i < options->num_ports; i++)
396 add_one_listen_addr(options, addr, options->ports[i]);
397 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000398 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000399}
400
Ben Lindstrombba81212001-06-25 05:01:22 +0000401static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000402add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
403{
404 struct addrinfo hints, *ai, *aitop;
405 char strport[NI_MAXSERV];
406 int gaierr;
407
408 memset(&hints, 0, sizeof(hints));
409 hints.ai_family = IPv4or6;
410 hints.ai_socktype = SOCK_STREAM;
411 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000412 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000413 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
414 fatal("bad addr or host: %s (%s)",
415 addr ? addr : "<NULL>",
416 gai_strerror(gaierr));
417 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
418 ;
419 ai->ai_next = options->listen_addrs;
420 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100421}
422
Ben Lindstromade03f62001-12-06 18:22:17 +0000423int
424process_server_config_line(ServerOptions *options, char *line,
425 const char *filename, int linenum)
426{
427 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000428 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000429 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000430
431 cp = line;
432 arg = strdelim(&cp);
433 /* Ignore leading whitespace */
434 if (*arg == '\0')
435 arg = strdelim(&cp);
436 if (!arg || !*arg || *arg == '#')
437 return 0;
438 intptr = NULL;
439 charptr = NULL;
440 opcode = parse_token(arg, filename, linenum);
441 switch (opcode) {
442 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000443 case sUsePAM:
444 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000445 goto parse_flag;
446
447 /* Standard Options */
448 case sBadOption:
449 return -1;
450 case sPort:
451 /* ignore ports from configfile if cmdline specifies ports */
452 if (options->ports_from_cmdline)
453 return 0;
454 if (options->listen_addrs != NULL)
455 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100456 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000457 if (options->num_ports >= MAX_PORTS)
458 fatal("%s line %d: too many ports.",
459 filename, linenum);
460 arg = strdelim(&cp);
461 if (!arg || *arg == '\0')
462 fatal("%s line %d: missing port number.",
463 filename, linenum);
464 options->ports[options->num_ports++] = a2port(arg);
465 if (options->ports[options->num_ports-1] == 0)
466 fatal("%s line %d: Badly formatted port number.",
467 filename, linenum);
468 break;
469
470 case sServerKeyBits:
471 intptr = &options->server_key_bits;
472parse_int:
473 arg = strdelim(&cp);
474 if (!arg || *arg == '\0')
475 fatal("%s line %d: missing integer value.",
476 filename, linenum);
477 value = atoi(arg);
478 if (*intptr == -1)
479 *intptr = value;
480 break;
481
482 case sLoginGraceTime:
483 intptr = &options->login_grace_time;
484parse_time:
485 arg = strdelim(&cp);
486 if (!arg || *arg == '\0')
487 fatal("%s line %d: missing time value.",
488 filename, linenum);
489 if ((value = convtime(arg)) == -1)
490 fatal("%s line %d: invalid time value.",
491 filename, linenum);
492 if (*intptr == -1)
493 *intptr = value;
494 break;
495
496 case sKeyRegenerationTime:
497 intptr = &options->key_regeneration_time;
498 goto parse_time;
499
500 case sListenAddress:
501 arg = strdelim(&cp);
502 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
503 fatal("%s line %d: missing inet addr.",
504 filename, linenum);
505 if (*arg == '[') {
506 if ((p = strchr(arg, ']')) == NULL)
507 fatal("%s line %d: bad ipv6 inet addr usage.",
508 filename, linenum);
509 arg++;
510 memmove(p, p+1, strlen(p+1)+1);
511 } else if (((p = strchr(arg, ':')) == NULL) ||
512 (strchr(p+1, ':') != NULL)) {
513 add_listen_addr(options, arg, 0);
514 break;
515 }
516 if (*p == ':') {
517 u_short port;
518
519 p++;
520 if (*p == '\0')
521 fatal("%s line %d: bad inet addr:port usage.",
522 filename, linenum);
523 else {
524 *(p-1) = '\0';
525 if ((port = a2port(p)) == 0)
526 fatal("%s line %d: bad port number.",
527 filename, linenum);
528 add_listen_addr(options, arg, port);
529 }
530 } else if (*p == '\0')
531 add_listen_addr(options, arg, 0);
532 else
533 fatal("%s line %d: bad inet addr usage.",
534 filename, linenum);
535 break;
536
537 case sHostKeyFile:
538 intptr = &options->num_host_key_files;
539 if (*intptr >= MAX_HOSTKEYS)
540 fatal("%s line %d: too many host keys specified (max %d).",
541 filename, linenum, MAX_HOSTKEYS);
542 charptr = &options->host_key_files[*intptr];
543parse_filename:
544 arg = strdelim(&cp);
545 if (!arg || *arg == '\0')
546 fatal("%s line %d: missing file name.",
547 filename, linenum);
548 if (*charptr == NULL) {
549 *charptr = tilde_expand_filename(arg, getuid());
550 /* increase optional counter */
551 if (intptr != NULL)
552 *intptr = *intptr + 1;
553 }
554 break;
555
556 case sPidFile:
557 charptr = &options->pid_file;
558 goto parse_filename;
559
560 case sPermitRootLogin:
561 intptr = &options->permit_root_login;
562 arg = strdelim(&cp);
563 if (!arg || *arg == '\0')
564 fatal("%s line %d: missing yes/"
565 "without-password/forced-commands-only/no "
566 "argument.", filename, linenum);
567 value = 0; /* silence compiler */
568 if (strcmp(arg, "without-password") == 0)
569 value = PERMIT_NO_PASSWD;
570 else if (strcmp(arg, "forced-commands-only") == 0)
571 value = PERMIT_FORCED_ONLY;
572 else if (strcmp(arg, "yes") == 0)
573 value = PERMIT_YES;
574 else if (strcmp(arg, "no") == 0)
575 value = PERMIT_NO;
576 else
577 fatal("%s line %d: Bad yes/"
578 "without-password/forced-commands-only/no "
579 "argument: %s", filename, linenum, arg);
580 if (*intptr == -1)
581 *intptr = value;
582 break;
583
584 case sIgnoreRhosts:
585 intptr = &options->ignore_rhosts;
586parse_flag:
587 arg = strdelim(&cp);
588 if (!arg || *arg == '\0')
589 fatal("%s line %d: missing yes/no argument.",
590 filename, linenum);
591 value = 0; /* silence compiler */
592 if (strcmp(arg, "yes") == 0)
593 value = 1;
594 else if (strcmp(arg, "no") == 0)
595 value = 0;
596 else
597 fatal("%s line %d: Bad yes/no argument: %s",
598 filename, linenum, arg);
599 if (*intptr == -1)
600 *intptr = value;
601 break;
602
603 case sIgnoreUserKnownHosts:
604 intptr = &options->ignore_user_known_hosts;
605 goto parse_flag;
606
607 case sRhostsAuthentication:
608 intptr = &options->rhosts_authentication;
609 goto parse_flag;
610
611 case sRhostsRSAAuthentication:
612 intptr = &options->rhosts_rsa_authentication;
613 goto parse_flag;
614
615 case sHostbasedAuthentication:
616 intptr = &options->hostbased_authentication;
617 goto parse_flag;
618
619 case sHostbasedUsesNameFromPacketOnly:
620 intptr = &options->hostbased_uses_name_from_packet_only;
621 goto parse_flag;
622
623 case sRSAAuthentication:
624 intptr = &options->rsa_authentication;
625 goto parse_flag;
626
627 case sPubkeyAuthentication:
628 intptr = &options->pubkey_authentication;
629 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000630
Ben Lindstromade03f62001-12-06 18:22:17 +0000631 case sKerberosAuthentication:
632 intptr = &options->kerberos_authentication;
633 goto parse_flag;
634
635 case sKerberosOrLocalPasswd:
636 intptr = &options->kerberos_or_local_passwd;
637 goto parse_flag;
638
639 case sKerberosTicketCleanup:
640 intptr = &options->kerberos_ticket_cleanup;
641 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000642
Ben Lindstromade03f62001-12-06 18:22:17 +0000643 case sKerberosTgtPassing:
644 intptr = &options->kerberos_tgt_passing;
645 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000646
Ben Lindstromade03f62001-12-06 18:22:17 +0000647 case sAFSTokenPassing:
648 intptr = &options->afs_token_passing;
649 goto parse_flag;
Ben Lindstromade03f62001-12-06 18:22:17 +0000650
651 case sPasswordAuthentication:
652 intptr = &options->password_authentication;
653 goto parse_flag;
654
655 case sKbdInteractiveAuthentication:
656 intptr = &options->kbd_interactive_authentication;
657 goto parse_flag;
658
659 case sChallengeResponseAuthentication:
660 intptr = &options->challenge_response_authentication;
661 goto parse_flag;
662
663 case sPrintMotd:
664 intptr = &options->print_motd;
665 goto parse_flag;
666
667 case sPrintLastLog:
668 intptr = &options->print_lastlog;
669 goto parse_flag;
670
671 case sX11Forwarding:
672 intptr = &options->x11_forwarding;
673 goto parse_flag;
674
675 case sX11DisplayOffset:
676 intptr = &options->x11_display_offset;
677 goto parse_int;
678
Damien Miller95c249f2002-02-05 12:11:34 +1100679 case sX11UseLocalhost:
680 intptr = &options->x11_use_localhost;
681 goto parse_flag;
682
Ben Lindstromade03f62001-12-06 18:22:17 +0000683 case sXAuthLocation:
684 charptr = &options->xauth_location;
685 goto parse_filename;
686
687 case sStrictModes:
688 intptr = &options->strict_modes;
689 goto parse_flag;
690
691 case sKeepAlives:
692 intptr = &options->keepalives;
693 goto parse_flag;
694
695 case sEmptyPasswd:
696 intptr = &options->permit_empty_passwd;
697 goto parse_flag;
698
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000699 case sPermitUserEnvironment:
700 intptr = &options->permit_user_env;
701 goto parse_flag;
702
Ben Lindstromade03f62001-12-06 18:22:17 +0000703 case sUseLogin:
704 intptr = &options->use_login;
705 goto parse_flag;
706
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000707 case sCompression:
708 intptr = &options->compression;
709 goto parse_flag;
710
Ben Lindstromade03f62001-12-06 18:22:17 +0000711 case sGatewayPorts:
712 intptr = &options->gateway_ports;
713 goto parse_flag;
714
Damien Miller3a961dc2003-06-03 10:25:48 +1000715 case sUseDNS:
716 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000717 goto parse_flag;
718
719 case sLogFacility:
720 intptr = (int *) &options->log_facility;
721 arg = strdelim(&cp);
722 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100723 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000724 fatal("%.200s line %d: unsupported log facility '%s'",
725 filename, linenum, arg ? arg : "<NONE>");
726 if (*intptr == -1)
727 *intptr = (SyslogFacility) value;
728 break;
729
730 case sLogLevel:
731 intptr = (int *) &options->log_level;
732 arg = strdelim(&cp);
733 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100734 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000735 fatal("%.200s line %d: unsupported log level '%s'",
736 filename, linenum, arg ? arg : "<NONE>");
737 if (*intptr == -1)
738 *intptr = (LogLevel) value;
739 break;
740
741 case sAllowTcpForwarding:
742 intptr = &options->allow_tcp_forwarding;
743 goto parse_flag;
744
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000745 case sUsePrivilegeSeparation:
746 intptr = &use_privsep;
747 goto parse_flag;
748
Ben Lindstromade03f62001-12-06 18:22:17 +0000749 case sAllowUsers:
750 while ((arg = strdelim(&cp)) && *arg != '\0') {
751 if (options->num_allow_users >= MAX_ALLOW_USERS)
752 fatal("%s line %d: too many allow users.",
753 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000754 options->allow_users[options->num_allow_users++] =
755 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000756 }
757 break;
758
759 case sDenyUsers:
760 while ((arg = strdelim(&cp)) && *arg != '\0') {
761 if (options->num_deny_users >= MAX_DENY_USERS)
762 fatal( "%s line %d: too many deny users.",
763 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000764 options->deny_users[options->num_deny_users++] =
765 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000766 }
767 break;
768
769 case sAllowGroups:
770 while ((arg = strdelim(&cp)) && *arg != '\0') {
771 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
772 fatal("%s line %d: too many allow groups.",
773 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000774 options->allow_groups[options->num_allow_groups++] =
775 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000776 }
777 break;
778
779 case sDenyGroups:
780 while ((arg = strdelim(&cp)) && *arg != '\0') {
781 if (options->num_deny_groups >= MAX_DENY_GROUPS)
782 fatal("%s line %d: too many deny groups.",
783 filename, linenum);
784 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
785 }
786 break;
787
788 case sCiphers:
789 arg = strdelim(&cp);
790 if (!arg || *arg == '\0')
791 fatal("%s line %d: Missing argument.", filename, linenum);
792 if (!ciphers_valid(arg))
793 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
794 filename, linenum, arg ? arg : "<NONE>");
795 if (options->ciphers == NULL)
796 options->ciphers = xstrdup(arg);
797 break;
798
799 case sMacs:
800 arg = strdelim(&cp);
801 if (!arg || *arg == '\0')
802 fatal("%s line %d: Missing argument.", filename, linenum);
803 if (!mac_valid(arg))
804 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
805 filename, linenum, arg ? arg : "<NONE>");
806 if (options->macs == NULL)
807 options->macs = xstrdup(arg);
808 break;
809
810 case sProtocol:
811 intptr = &options->protocol;
812 arg = strdelim(&cp);
813 if (!arg || *arg == '\0')
814 fatal("%s line %d: Missing argument.", filename, linenum);
815 value = proto_spec(arg);
816 if (value == SSH_PROTO_UNKNOWN)
817 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100818 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000819 if (*intptr == SSH_PROTO_UNKNOWN)
820 *intptr = value;
821 break;
822
823 case sSubsystem:
824 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
825 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100826 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000827 }
828 arg = strdelim(&cp);
829 if (!arg || *arg == '\0')
830 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100831 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000832 for (i = 0; i < options->num_subsystems; i++)
833 if (strcmp(arg, options->subsystem_name[i]) == 0)
834 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100835 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000836 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
837 arg = strdelim(&cp);
838 if (!arg || *arg == '\0')
839 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100840 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000841 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
842 options->num_subsystems++;
843 break;
844
845 case sMaxStartups:
846 arg = strdelim(&cp);
847 if (!arg || *arg == '\0')
848 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100849 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000850 if ((n = sscanf(arg, "%d:%d:%d",
851 &options->max_startups_begin,
852 &options->max_startups_rate,
853 &options->max_startups)) == 3) {
854 if (options->max_startups_begin >
855 options->max_startups ||
856 options->max_startups_rate > 100 ||
857 options->max_startups_rate < 1)
858 fatal("%s line %d: Illegal MaxStartups spec.",
859 filename, linenum);
860 } else if (n != 1)
861 fatal("%s line %d: Illegal MaxStartups spec.",
862 filename, linenum);
863 else
864 options->max_startups = options->max_startups_begin;
865 break;
866
867 case sBanner:
868 charptr = &options->banner;
869 goto parse_filename;
870 /*
871 * These options can contain %X options expanded at
872 * connect time, so that you can specify paths like:
873 *
874 * AuthorizedKeysFile /etc/ssh_keys/%u
875 */
876 case sAuthorizedKeysFile:
877 case sAuthorizedKeysFile2:
878 charptr = (opcode == sAuthorizedKeysFile ) ?
879 &options->authorized_keys_file :
880 &options->authorized_keys_file2;
881 goto parse_filename;
882
883 case sClientAliveInterval:
884 intptr = &options->client_alive_interval;
885 goto parse_time;
886
887 case sClientAliveCountMax:
888 intptr = &options->client_alive_count_max;
889 goto parse_int;
890
891 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000892 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000893 filename, linenum, arg);
894 while (arg)
895 arg = strdelim(&cp);
896 break;
897
Damien Millerf9b3feb2003-05-16 11:38:32 +1000898 case sUnsupported:
899 logit("%s line %d: Unsupported option %s",
900 filename, linenum, arg);
901 while (arg)
902 arg = strdelim(&cp);
903 break;
904
Ben Lindstromade03f62001-12-06 18:22:17 +0000905 default:
906 fatal("%s line %d: Missing handler for opcode %s (%d)",
907 filename, linenum, arg, opcode);
908 }
909 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
910 fatal("%s line %d: garbage at end of line; \"%.200s\".",
911 filename, linenum, arg);
912 return 0;
913}
914
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000915/* Reads the server configuration file. */
916
Damien Miller4af51302000-04-16 11:18:38 +1000917void
Damien Miller95def091999-11-25 00:26:21 +1100918read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000919{
Ben Lindstrome1353632002-06-23 21:29:23 +0000920 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100921 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000922 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000923
Damien Miller9f82c8f2003-02-24 12:04:33 +1100924 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100925 f = fopen(filename, "r");
926 if (!f) {
927 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000928 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100929 }
930 linenum = 0;
931 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000932 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100933 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000934 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100935 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000936 }
Damien Miller95def091999-11-25 00:26:21 +1100937 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000938 if (bad_options > 0)
939 fatal("%s: terminating, %d bad configuration options",
940 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000941}