blob: e13309388957d8d06c9f8c07e2a25addf29d39f5 [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"
Darren Tucker0efd1552003-08-26 11:49:55 +100013RCSID("$OpenBSD: servconf.c,v 1.125 2003/08/22 10:56:09 markus Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
15#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000016#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100017#include "servconf.h"
18#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100019#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000020#include "pathnames.h"
21#include "tildexpand.h"
22#include "misc.h"
23#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000024#include "kex.h"
25#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000026
Ben Lindstrombba81212001-06-25 05:01:22 +000027static void add_listen_addr(ServerOptions *, char *, u_short);
28static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110029
Ben Lindstrom226cfa02001-01-22 05:34:40 +000030/* AF_UNSPEC or AF_INET or AF_INET6 */
31extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000032/* Use of privilege separation or not */
33extern int use_privsep;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000034
Damien Millerd4a8b7e1999-10-27 13:42:43 +100035/* Initializes the server options to their default values. */
36
Damien Miller4af51302000-04-16 11:18:38 +100037void
Damien Miller95def091999-11-25 00:26:21 +110038initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039{
Damien Miller95def091999-11-25 00:26:21 +110040 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110041
42 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100043 options->use_pam = -1;
Damien Miller726273e2001-11-12 11:40:11 +110044
45 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110046 options->num_ports = 0;
47 options->ports_from_cmdline = 0;
48 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110049 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100050 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110051 options->server_key_bits = -1;
52 options->login_grace_time = -1;
53 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000054 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110055 options->ignore_rhosts = -1;
56 options->ignore_user_known_hosts = -1;
57 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000058 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110059 options->x11_forwarding = -1;
60 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110061 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100062 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110063 options->strict_modes = -1;
64 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110065 options->log_facility = SYSLOG_FACILITY_NOT_SET;
66 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110067 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000068 options->hostbased_authentication = -1;
69 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110070 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110071 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110072 options->kerberos_authentication = -1;
73 options->kerberos_or_local_passwd = -1;
74 options->kerberos_ticket_cleanup = -1;
Damien Miller95def091999-11-25 00:26:21 +110075 options->kerberos_tgt_passing = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +100076 options->gss_authentication=-1;
77 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +110078 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110079 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000080 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110081 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +000082 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +110083 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +000084 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110085 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110086 options->num_allow_users = 0;
87 options->num_deny_users = 0;
88 options->num_allow_groups = 0;
89 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100090 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000091 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +100092 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100093 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100094 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100095 options->max_startups_begin = -1;
96 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100097 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +000098 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +100099 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000100 options->client_alive_interval = -1;
101 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000102 options->authorized_keys_file = NULL;
103 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000104
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000105 /* Needs to be accessable in many places */
106 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000107}
108
Damien Miller4af51302000-04-16 11:18:38 +1000109void
Damien Miller95def091999-11-25 00:26:21 +1100110fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000111{
Damien Miller726273e2001-11-12 11:40:11 +1100112 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000113 if (options->use_pam == -1)
Damien Miller156cbe82003-05-15 14:16:41 +1000114 options->use_pam = 1;
Damien Miller726273e2001-11-12 11:40:11 +1100115
116 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100117 if (options->protocol == SSH_PROTO_UNKNOWN)
118 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
119 if (options->num_host_key_files == 0) {
120 /* fill default hostkeys for protocols */
121 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100122 options->host_key_files[options->num_host_key_files++] =
123 _PATH_HOST_KEY_FILE;
124 if (options->protocol & SSH_PROTO_2) {
125 options->host_key_files[options->num_host_key_files++] =
126 _PATH_HOST_RSA_KEY_FILE;
127 options->host_key_files[options->num_host_key_files++] =
128 _PATH_HOST_DSA_KEY_FILE;
129 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100130 }
Damien Miller34132e52000-01-14 15:45:46 +1100131 if (options->num_ports == 0)
132 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
133 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000134 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000135 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000136 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100137 if (options->server_key_bits == -1)
138 options->server_key_bits = 768;
139 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000140 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100141 if (options->key_regeneration_time == -1)
142 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000143 if (options->permit_root_login == PERMIT_NOT_SET)
144 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100145 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100146 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100147 if (options->ignore_user_known_hosts == -1)
148 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100149 if (options->print_motd == -1)
150 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000151 if (options->print_lastlog == -1)
152 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100153 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100154 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100155 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100156 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100157 if (options->x11_use_localhost == -1)
158 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000159 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000160 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100161 if (options->strict_modes == -1)
162 options->strict_modes = 1;
163 if (options->keepalives == -1)
164 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100165 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100166 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100167 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000168 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100169 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100170 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000171 if (options->hostbased_authentication == -1)
172 options->hostbased_authentication = 0;
173 if (options->hostbased_uses_name_from_packet_only == -1)
174 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100175 if (options->rsa_authentication == -1)
176 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100177 if (options->pubkey_authentication == -1)
178 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000180 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100181 if (options->kerberos_or_local_passwd == -1)
182 options->kerberos_or_local_passwd = 1;
183 if (options->kerberos_ticket_cleanup == -1)
184 options->kerberos_ticket_cleanup = 1;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->kerberos_tgt_passing == -1)
186 options->kerberos_tgt_passing = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000187 if (options->gss_authentication == -1)
188 options->gss_authentication = 0;
189 if (options->gss_cleanup_creds == -1)
190 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->password_authentication == -1)
192 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100193 if (options->kbd_interactive_authentication == -1)
194 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000195 if (options->challenge_response_authentication == -1)
196 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100198 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000199 if (options->permit_user_env == -1)
200 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->use_login == -1)
202 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000203 if (options->compression == -1)
204 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100205 if (options->allow_tcp_forwarding == -1)
206 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000207 if (options->gateway_ports == -1)
208 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000209 if (options->max_startups == -1)
210 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000211 if (options->max_startups_rate == -1)
212 options->max_startups_rate = 100; /* 100% */
213 if (options->max_startups_begin == -1)
214 options->max_startups_begin = options->max_startups;
Damien Miller3a961dc2003-06-03 10:25:48 +1000215 if (options->use_dns == -1)
216 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000217 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100218 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000219 if (options->client_alive_count_max == -1)
220 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100221 if (options->authorized_keys_file2 == NULL) {
222 /* authorized_keys_file2 falls back to authorized_keys_file */
223 if (options->authorized_keys_file != NULL)
224 options->authorized_keys_file2 = options->authorized_keys_file;
225 else
226 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
227 }
228 if (options->authorized_keys_file == NULL)
229 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000230
Ben Lindstromfb62a692002-06-06 19:47:11 +0000231 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000232 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000233 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000234
Tim Rice40017b02002-07-14 13:36:49 -0700235#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000236 if (use_privsep && options->compression == 1) {
237 error("This platform does not support both privilege "
238 "separation and compression");
239 error("Compression disabled");
240 options->compression = 0;
241 }
242#endif
243
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000244}
245
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000246/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100247typedef enum {
248 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100249 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000250 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100251 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100252 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
253 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000254 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100255 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000256 sKerberosTgtPassing, sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100257 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000258 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100259 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000260 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000261 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100262 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000263 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100264 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Miller3a961dc2003-06-03 10:25:48 +1000265 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100266 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000267 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Darren Tucker0efd1552003-08-26 11:49:55 +1000268 sGssAuthentication, sGssCleanupCreds,
Ben Lindstromc7431342002-03-22 03:11:49 +0000269 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000270 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000271} ServerOpCodes;
272
273/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100274static struct {
275 const char *name;
276 ServerOpCodes opcode;
277} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100278 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000279#ifdef USE_PAM
Damien Miller30912f72003-08-26 10:48:14 +1000280 { "usepam", sUsePAM },
Damien Miller6ac2c482003-05-16 11:42:35 +1000281#else
Damien Miller30912f72003-08-26 10:48:14 +1000282 { "usepam", sUnsupported },
Damien Miller6ac2c482003-05-16 11:42:35 +1000283#endif
Damien Miller30912f72003-08-26 10:48:14 +1000284 { "pamauthenticationviakbdint", sDeprecated },
Damien Miller726273e2001-11-12 11:40:11 +1100285 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100286 { "port", sPort },
287 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100288 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000289 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100290 { "serverkeybits", sServerKeyBits },
291 { "logingracetime", sLoginGraceTime },
292 { "keyregenerationinterval", sKeyRegenerationTime },
293 { "permitrootlogin", sPermitRootLogin },
294 { "syslogfacility", sLogFacility },
295 { "loglevel", sLogLevel },
Darren Tuckerec960f22003-08-13 20:37:05 +1000296 { "rhostsauthentication", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100297 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000298 { "hostbasedauthentication", sHostbasedAuthentication },
299 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100300 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100301 { "pubkeyauthentication", sPubkeyAuthentication },
302 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000303#ifdef KRB5
Damien Miller95def091999-11-25 00:26:21 +1100304 { "kerberosauthentication", sKerberosAuthentication },
305 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
306 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Miller95def091999-11-25 00:26:21 +1100307 { "kerberostgtpassing", sKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000308#else
309 { "kerberosauthentication", sUnsupported },
310 { "kerberosorlocalpasswd", sUnsupported },
311 { "kerberosticketcleanup", sUnsupported },
312 { "kerberostgtpassing", sUnsupported },
313#endif
Damien Millerf9b3feb2003-05-16 11:38:32 +1000314 { "afstokenpassing", sUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000315#ifdef GSSAPI
316 { "gssapiauthentication", sGssAuthentication },
317 { "gssapicleanupcreds", sGssCleanupCreds },
318#else
319 { "gssapiauthentication", sUnsupported },
320 { "gssapicleanupcreds", sUnsupported },
321#endif
Damien Miller95def091999-11-25 00:26:21 +1100322 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100323 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000324 { "challengeresponseauthentication", sChallengeResponseAuthentication },
325 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000326 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100327 { "listenaddress", sListenAddress },
328 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000329 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100330 { "ignorerhosts", sIgnoreRhosts },
331 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
332 { "x11forwarding", sX11Forwarding },
333 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100334 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000335 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100336 { "strictmodes", sStrictModes },
337 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000338 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100339 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000340 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100341 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100342 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100343 { "allowusers", sAllowUsers },
344 { "denyusers", sDenyUsers },
345 { "allowgroups", sAllowGroups },
346 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000347 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000348 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000349 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000350 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000351 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000352 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000353 { "banner", sBanner },
Damien Miller3a961dc2003-06-03 10:25:48 +1000354 { "usedns", sUseDNS },
355 { "verifyreversemapping", sDeprecated },
356 { "reversemappingcheck", sDeprecated },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000357 { "clientaliveinterval", sClientAliveInterval },
358 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000359 { "authorizedkeysfile", sAuthorizedKeysFile },
360 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000361 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000362 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000363};
364
Damien Miller5428f641999-11-25 11:54:57 +1100365/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000366 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100367 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000368
Damien Miller4af51302000-04-16 11:18:38 +1000369static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100370parse_token(const char *cp, const char *filename,
371 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000372{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000373 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000374
Damien Miller95def091999-11-25 00:26:21 +1100375 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100376 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100377 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000378
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000379 error("%s: line %d: Bad configuration option: %s",
380 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100381 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000382}
383
Ben Lindstrombba81212001-06-25 05:01:22 +0000384static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000385add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100386{
Damien Miller34132e52000-01-14 15:45:46 +1100387 int i;
388
389 if (options->num_ports == 0)
390 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000391 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000392 for (i = 0; i < options->num_ports; i++)
393 add_one_listen_addr(options, addr, options->ports[i]);
394 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000395 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000396}
397
Ben Lindstrombba81212001-06-25 05:01:22 +0000398static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000399add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
400{
401 struct addrinfo hints, *ai, *aitop;
402 char strport[NI_MAXSERV];
403 int gaierr;
404
405 memset(&hints, 0, sizeof(hints));
406 hints.ai_family = IPv4or6;
407 hints.ai_socktype = SOCK_STREAM;
408 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000409 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000410 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
411 fatal("bad addr or host: %s (%s)",
412 addr ? addr : "<NULL>",
413 gai_strerror(gaierr));
414 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
415 ;
416 ai->ai_next = options->listen_addrs;
417 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100418}
419
Ben Lindstromade03f62001-12-06 18:22:17 +0000420int
421process_server_config_line(ServerOptions *options, char *line,
422 const char *filename, int linenum)
423{
424 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000425 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000426 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000427
428 cp = line;
429 arg = strdelim(&cp);
430 /* Ignore leading whitespace */
431 if (*arg == '\0')
432 arg = strdelim(&cp);
433 if (!arg || !*arg || *arg == '#')
434 return 0;
435 intptr = NULL;
436 charptr = NULL;
437 opcode = parse_token(arg, filename, linenum);
438 switch (opcode) {
439 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000440 case sUsePAM:
441 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000442 goto parse_flag;
443
444 /* Standard Options */
445 case sBadOption:
446 return -1;
447 case sPort:
448 /* ignore ports from configfile if cmdline specifies ports */
449 if (options->ports_from_cmdline)
450 return 0;
451 if (options->listen_addrs != NULL)
452 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100453 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000454 if (options->num_ports >= MAX_PORTS)
455 fatal("%s line %d: too many ports.",
456 filename, linenum);
457 arg = strdelim(&cp);
458 if (!arg || *arg == '\0')
459 fatal("%s line %d: missing port number.",
460 filename, linenum);
461 options->ports[options->num_ports++] = a2port(arg);
462 if (options->ports[options->num_ports-1] == 0)
463 fatal("%s line %d: Badly formatted port number.",
464 filename, linenum);
465 break;
466
467 case sServerKeyBits:
468 intptr = &options->server_key_bits;
469parse_int:
470 arg = strdelim(&cp);
471 if (!arg || *arg == '\0')
472 fatal("%s line %d: missing integer value.",
473 filename, linenum);
474 value = atoi(arg);
475 if (*intptr == -1)
476 *intptr = value;
477 break;
478
479 case sLoginGraceTime:
480 intptr = &options->login_grace_time;
481parse_time:
482 arg = strdelim(&cp);
483 if (!arg || *arg == '\0')
484 fatal("%s line %d: missing time value.",
485 filename, linenum);
486 if ((value = convtime(arg)) == -1)
487 fatal("%s line %d: invalid time value.",
488 filename, linenum);
489 if (*intptr == -1)
490 *intptr = value;
491 break;
492
493 case sKeyRegenerationTime:
494 intptr = &options->key_regeneration_time;
495 goto parse_time;
496
497 case sListenAddress:
498 arg = strdelim(&cp);
499 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
500 fatal("%s line %d: missing inet addr.",
501 filename, linenum);
502 if (*arg == '[') {
503 if ((p = strchr(arg, ']')) == NULL)
504 fatal("%s line %d: bad ipv6 inet addr usage.",
505 filename, linenum);
506 arg++;
507 memmove(p, p+1, strlen(p+1)+1);
508 } else if (((p = strchr(arg, ':')) == NULL) ||
509 (strchr(p+1, ':') != NULL)) {
510 add_listen_addr(options, arg, 0);
511 break;
512 }
513 if (*p == ':') {
514 u_short port;
515
516 p++;
517 if (*p == '\0')
518 fatal("%s line %d: bad inet addr:port usage.",
519 filename, linenum);
520 else {
521 *(p-1) = '\0';
522 if ((port = a2port(p)) == 0)
523 fatal("%s line %d: bad port number.",
524 filename, linenum);
525 add_listen_addr(options, arg, port);
526 }
527 } else if (*p == '\0')
528 add_listen_addr(options, arg, 0);
529 else
530 fatal("%s line %d: bad inet addr usage.",
531 filename, linenum);
532 break;
533
534 case sHostKeyFile:
535 intptr = &options->num_host_key_files;
536 if (*intptr >= MAX_HOSTKEYS)
537 fatal("%s line %d: too many host keys specified (max %d).",
538 filename, linenum, MAX_HOSTKEYS);
539 charptr = &options->host_key_files[*intptr];
540parse_filename:
541 arg = strdelim(&cp);
542 if (!arg || *arg == '\0')
543 fatal("%s line %d: missing file name.",
544 filename, linenum);
545 if (*charptr == NULL) {
546 *charptr = tilde_expand_filename(arg, getuid());
547 /* increase optional counter */
548 if (intptr != NULL)
549 *intptr = *intptr + 1;
550 }
551 break;
552
553 case sPidFile:
554 charptr = &options->pid_file;
555 goto parse_filename;
556
557 case sPermitRootLogin:
558 intptr = &options->permit_root_login;
559 arg = strdelim(&cp);
560 if (!arg || *arg == '\0')
561 fatal("%s line %d: missing yes/"
562 "without-password/forced-commands-only/no "
563 "argument.", filename, linenum);
564 value = 0; /* silence compiler */
565 if (strcmp(arg, "without-password") == 0)
566 value = PERMIT_NO_PASSWD;
567 else if (strcmp(arg, "forced-commands-only") == 0)
568 value = PERMIT_FORCED_ONLY;
569 else if (strcmp(arg, "yes") == 0)
570 value = PERMIT_YES;
571 else if (strcmp(arg, "no") == 0)
572 value = PERMIT_NO;
573 else
574 fatal("%s line %d: Bad yes/"
575 "without-password/forced-commands-only/no "
576 "argument: %s", filename, linenum, arg);
577 if (*intptr == -1)
578 *intptr = value;
579 break;
580
581 case sIgnoreRhosts:
582 intptr = &options->ignore_rhosts;
583parse_flag:
584 arg = strdelim(&cp);
585 if (!arg || *arg == '\0')
586 fatal("%s line %d: missing yes/no argument.",
587 filename, linenum);
588 value = 0; /* silence compiler */
589 if (strcmp(arg, "yes") == 0)
590 value = 1;
591 else if (strcmp(arg, "no") == 0)
592 value = 0;
593 else
594 fatal("%s line %d: Bad yes/no argument: %s",
595 filename, linenum, arg);
596 if (*intptr == -1)
597 *intptr = value;
598 break;
599
600 case sIgnoreUserKnownHosts:
601 intptr = &options->ignore_user_known_hosts;
602 goto parse_flag;
603
Ben Lindstromade03f62001-12-06 18:22:17 +0000604 case sRhostsRSAAuthentication:
605 intptr = &options->rhosts_rsa_authentication;
606 goto parse_flag;
607
608 case sHostbasedAuthentication:
609 intptr = &options->hostbased_authentication;
610 goto parse_flag;
611
612 case sHostbasedUsesNameFromPacketOnly:
613 intptr = &options->hostbased_uses_name_from_packet_only;
614 goto parse_flag;
615
616 case sRSAAuthentication:
617 intptr = &options->rsa_authentication;
618 goto parse_flag;
619
620 case sPubkeyAuthentication:
621 intptr = &options->pubkey_authentication;
622 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000623
Ben Lindstromade03f62001-12-06 18:22:17 +0000624 case sKerberosAuthentication:
625 intptr = &options->kerberos_authentication;
626 goto parse_flag;
627
628 case sKerberosOrLocalPasswd:
629 intptr = &options->kerberos_or_local_passwd;
630 goto parse_flag;
631
632 case sKerberosTicketCleanup:
633 intptr = &options->kerberos_ticket_cleanup;
634 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000635
Ben Lindstromade03f62001-12-06 18:22:17 +0000636 case sKerberosTgtPassing:
637 intptr = &options->kerberos_tgt_passing;
638 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000639
Darren Tucker0efd1552003-08-26 11:49:55 +1000640 case sGssAuthentication:
641 intptr = &options->gss_authentication;
642 goto parse_flag;
643
644 case sGssCleanupCreds:
645 intptr = &options->gss_cleanup_creds;
646 goto parse_flag;
647
Ben Lindstromade03f62001-12-06 18:22:17 +0000648 case sPasswordAuthentication:
649 intptr = &options->password_authentication;
650 goto parse_flag;
651
652 case sKbdInteractiveAuthentication:
653 intptr = &options->kbd_interactive_authentication;
654 goto parse_flag;
655
656 case sChallengeResponseAuthentication:
657 intptr = &options->challenge_response_authentication;
658 goto parse_flag;
659
660 case sPrintMotd:
661 intptr = &options->print_motd;
662 goto parse_flag;
663
664 case sPrintLastLog:
665 intptr = &options->print_lastlog;
666 goto parse_flag;
667
668 case sX11Forwarding:
669 intptr = &options->x11_forwarding;
670 goto parse_flag;
671
672 case sX11DisplayOffset:
673 intptr = &options->x11_display_offset;
674 goto parse_int;
675
Damien Miller95c249f2002-02-05 12:11:34 +1100676 case sX11UseLocalhost:
677 intptr = &options->x11_use_localhost;
678 goto parse_flag;
679
Ben Lindstromade03f62001-12-06 18:22:17 +0000680 case sXAuthLocation:
681 charptr = &options->xauth_location;
682 goto parse_filename;
683
684 case sStrictModes:
685 intptr = &options->strict_modes;
686 goto parse_flag;
687
688 case sKeepAlives:
689 intptr = &options->keepalives;
690 goto parse_flag;
691
692 case sEmptyPasswd:
693 intptr = &options->permit_empty_passwd;
694 goto parse_flag;
695
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000696 case sPermitUserEnvironment:
697 intptr = &options->permit_user_env;
698 goto parse_flag;
699
Ben Lindstromade03f62001-12-06 18:22:17 +0000700 case sUseLogin:
701 intptr = &options->use_login;
702 goto parse_flag;
703
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000704 case sCompression:
705 intptr = &options->compression;
706 goto parse_flag;
707
Ben Lindstromade03f62001-12-06 18:22:17 +0000708 case sGatewayPorts:
709 intptr = &options->gateway_ports;
710 goto parse_flag;
711
Damien Miller3a961dc2003-06-03 10:25:48 +1000712 case sUseDNS:
713 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000714 goto parse_flag;
715
716 case sLogFacility:
717 intptr = (int *) &options->log_facility;
718 arg = strdelim(&cp);
719 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100720 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000721 fatal("%.200s line %d: unsupported log facility '%s'",
722 filename, linenum, arg ? arg : "<NONE>");
723 if (*intptr == -1)
724 *intptr = (SyslogFacility) value;
725 break;
726
727 case sLogLevel:
728 intptr = (int *) &options->log_level;
729 arg = strdelim(&cp);
730 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100731 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000732 fatal("%.200s line %d: unsupported log level '%s'",
733 filename, linenum, arg ? arg : "<NONE>");
734 if (*intptr == -1)
735 *intptr = (LogLevel) value;
736 break;
737
738 case sAllowTcpForwarding:
739 intptr = &options->allow_tcp_forwarding;
740 goto parse_flag;
741
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000742 case sUsePrivilegeSeparation:
743 intptr = &use_privsep;
744 goto parse_flag;
745
Ben Lindstromade03f62001-12-06 18:22:17 +0000746 case sAllowUsers:
747 while ((arg = strdelim(&cp)) && *arg != '\0') {
748 if (options->num_allow_users >= MAX_ALLOW_USERS)
749 fatal("%s line %d: too many allow users.",
750 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000751 options->allow_users[options->num_allow_users++] =
752 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000753 }
754 break;
755
756 case sDenyUsers:
757 while ((arg = strdelim(&cp)) && *arg != '\0') {
758 if (options->num_deny_users >= MAX_DENY_USERS)
759 fatal( "%s line %d: too many deny users.",
760 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000761 options->deny_users[options->num_deny_users++] =
762 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000763 }
764 break;
765
766 case sAllowGroups:
767 while ((arg = strdelim(&cp)) && *arg != '\0') {
768 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
769 fatal("%s line %d: too many allow groups.",
770 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000771 options->allow_groups[options->num_allow_groups++] =
772 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000773 }
774 break;
775
776 case sDenyGroups:
777 while ((arg = strdelim(&cp)) && *arg != '\0') {
778 if (options->num_deny_groups >= MAX_DENY_GROUPS)
779 fatal("%s line %d: too many deny groups.",
780 filename, linenum);
781 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
782 }
783 break;
784
785 case sCiphers:
786 arg = strdelim(&cp);
787 if (!arg || *arg == '\0')
788 fatal("%s line %d: Missing argument.", filename, linenum);
789 if (!ciphers_valid(arg))
790 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
791 filename, linenum, arg ? arg : "<NONE>");
792 if (options->ciphers == NULL)
793 options->ciphers = xstrdup(arg);
794 break;
795
796 case sMacs:
797 arg = strdelim(&cp);
798 if (!arg || *arg == '\0')
799 fatal("%s line %d: Missing argument.", filename, linenum);
800 if (!mac_valid(arg))
801 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
802 filename, linenum, arg ? arg : "<NONE>");
803 if (options->macs == NULL)
804 options->macs = xstrdup(arg);
805 break;
806
807 case sProtocol:
808 intptr = &options->protocol;
809 arg = strdelim(&cp);
810 if (!arg || *arg == '\0')
811 fatal("%s line %d: Missing argument.", filename, linenum);
812 value = proto_spec(arg);
813 if (value == SSH_PROTO_UNKNOWN)
814 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100815 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000816 if (*intptr == SSH_PROTO_UNKNOWN)
817 *intptr = value;
818 break;
819
820 case sSubsystem:
821 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
822 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100823 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000824 }
825 arg = strdelim(&cp);
826 if (!arg || *arg == '\0')
827 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100828 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000829 for (i = 0; i < options->num_subsystems; i++)
830 if (strcmp(arg, options->subsystem_name[i]) == 0)
831 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100832 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000833 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
834 arg = strdelim(&cp);
835 if (!arg || *arg == '\0')
836 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100837 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000838 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
839 options->num_subsystems++;
840 break;
841
842 case sMaxStartups:
843 arg = strdelim(&cp);
844 if (!arg || *arg == '\0')
845 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100846 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000847 if ((n = sscanf(arg, "%d:%d:%d",
848 &options->max_startups_begin,
849 &options->max_startups_rate,
850 &options->max_startups)) == 3) {
851 if (options->max_startups_begin >
852 options->max_startups ||
853 options->max_startups_rate > 100 ||
854 options->max_startups_rate < 1)
855 fatal("%s line %d: Illegal MaxStartups spec.",
856 filename, linenum);
857 } else if (n != 1)
858 fatal("%s line %d: Illegal MaxStartups spec.",
859 filename, linenum);
860 else
861 options->max_startups = options->max_startups_begin;
862 break;
863
864 case sBanner:
865 charptr = &options->banner;
866 goto parse_filename;
867 /*
868 * These options can contain %X options expanded at
869 * connect time, so that you can specify paths like:
870 *
871 * AuthorizedKeysFile /etc/ssh_keys/%u
872 */
873 case sAuthorizedKeysFile:
874 case sAuthorizedKeysFile2:
875 charptr = (opcode == sAuthorizedKeysFile ) ?
876 &options->authorized_keys_file :
877 &options->authorized_keys_file2;
878 goto parse_filename;
879
880 case sClientAliveInterval:
881 intptr = &options->client_alive_interval;
882 goto parse_time;
883
884 case sClientAliveCountMax:
885 intptr = &options->client_alive_count_max;
886 goto parse_int;
887
888 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000889 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000890 filename, linenum, arg);
891 while (arg)
892 arg = strdelim(&cp);
893 break;
894
Damien Millerf9b3feb2003-05-16 11:38:32 +1000895 case sUnsupported:
896 logit("%s line %d: Unsupported option %s",
897 filename, linenum, arg);
898 while (arg)
899 arg = strdelim(&cp);
900 break;
901
Ben Lindstromade03f62001-12-06 18:22:17 +0000902 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}