blob: c4b2bb28453474de40529b1ef2a3e30015f95a22 [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 Tucker6aaa58c2003-08-02 22:24:49 +100013RCSID("$OpenBSD: servconf.c,v 1.123 2003/07/22 13:35:22 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_authentication = -1;
68 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000069 options->hostbased_authentication = -1;
70 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110071 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110072 options->pubkey_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110073 options->kerberos_authentication = -1;
74 options->kerberos_or_local_passwd = -1;
75 options->kerberos_ticket_cleanup = -1;
Damien Miller95def091999-11-25 00:26:21 +110076 options->kerberos_tgt_passing = -1;
Damien Miller95def091999-11-25 00:26:21 +110077 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110078 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000079 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110080 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +000081 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +110082 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +000083 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110084 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110085 options->num_allow_users = 0;
86 options->num_deny_users = 0;
87 options->num_allow_groups = 0;
88 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100089 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000090 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +100091 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100092 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100093 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100094 options->max_startups_begin = -1;
95 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100096 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +000097 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +100098 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +000099 options->client_alive_interval = -1;
100 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000101 options->authorized_keys_file = NULL;
102 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000103
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000104 /* Needs to be accessable in many places */
105 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000106}
107
Damien Miller4af51302000-04-16 11:18:38 +1000108void
Damien Miller95def091999-11-25 00:26:21 +1100109fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000110{
Damien Miller726273e2001-11-12 11:40:11 +1100111 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000112 if (options->use_pam == -1)
Damien Miller156cbe82003-05-15 14:16:41 +1000113 options->use_pam = 1;
Damien Miller726273e2001-11-12 11:40:11 +1100114
115 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100116 if (options->protocol == SSH_PROTO_UNKNOWN)
117 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
118 if (options->num_host_key_files == 0) {
119 /* fill default hostkeys for protocols */
120 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100121 options->host_key_files[options->num_host_key_files++] =
122 _PATH_HOST_KEY_FILE;
123 if (options->protocol & SSH_PROTO_2) {
124 options->host_key_files[options->num_host_key_files++] =
125 _PATH_HOST_RSA_KEY_FILE;
126 options->host_key_files[options->num_host_key_files++] =
127 _PATH_HOST_DSA_KEY_FILE;
128 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100129 }
Damien Miller34132e52000-01-14 15:45:46 +1100130 if (options->num_ports == 0)
131 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
132 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000133 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000134 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000135 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100136 if (options->server_key_bits == -1)
137 options->server_key_bits = 768;
138 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000139 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100140 if (options->key_regeneration_time == -1)
141 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000142 if (options->permit_root_login == PERMIT_NOT_SET)
143 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100144 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100145 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100146 if (options->ignore_user_known_hosts == -1)
147 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100148 if (options->print_motd == -1)
149 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000150 if (options->print_lastlog == -1)
151 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100152 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100153 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100154 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100155 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100156 if (options->x11_use_localhost == -1)
157 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000158 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000159 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100160 if (options->strict_modes == -1)
161 options->strict_modes = 1;
162 if (options->keepalives == -1)
163 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100164 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100165 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100166 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000167 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100168 if (options->rhosts_authentication == -1)
169 options->rhosts_authentication = 0;
170 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100171 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000172 if (options->hostbased_authentication == -1)
173 options->hostbased_authentication = 0;
174 if (options->hostbased_uses_name_from_packet_only == -1)
175 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100176 if (options->rsa_authentication == -1)
177 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100178 if (options->pubkey_authentication == -1)
179 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100180 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000181 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100182 if (options->kerberos_or_local_passwd == -1)
183 options->kerberos_or_local_passwd = 1;
184 if (options->kerberos_ticket_cleanup == -1)
185 options->kerberos_ticket_cleanup = 1;
Damien Miller95def091999-11-25 00:26:21 +1100186 if (options->kerberos_tgt_passing == -1)
187 options->kerberos_tgt_passing = 0;
Damien Miller95def091999-11-25 00:26:21 +1100188 if (options->password_authentication == -1)
189 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100190 if (options->kbd_interactive_authentication == -1)
191 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000192 if (options->challenge_response_authentication == -1)
193 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100194 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100195 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000196 if (options->permit_user_env == -1)
197 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->use_login == -1)
199 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000200 if (options->compression == -1)
201 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100202 if (options->allow_tcp_forwarding == -1)
203 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000204 if (options->gateway_ports == -1)
205 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000206 if (options->max_startups == -1)
207 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000208 if (options->max_startups_rate == -1)
209 options->max_startups_rate = 100; /* 100% */
210 if (options->max_startups_begin == -1)
211 options->max_startups_begin = options->max_startups;
Damien Miller3a961dc2003-06-03 10:25:48 +1000212 if (options->use_dns == -1)
213 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000214 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100215 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000216 if (options->client_alive_count_max == -1)
217 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100218 if (options->authorized_keys_file2 == NULL) {
219 /* authorized_keys_file2 falls back to authorized_keys_file */
220 if (options->authorized_keys_file != NULL)
221 options->authorized_keys_file2 = options->authorized_keys_file;
222 else
223 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
224 }
225 if (options->authorized_keys_file == NULL)
226 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000227
Ben Lindstromfb62a692002-06-06 19:47:11 +0000228 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000229 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000230 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000231
Tim Rice40017b02002-07-14 13:36:49 -0700232#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000233 if (use_privsep && options->compression == 1) {
234 error("This platform does not support both privilege "
235 "separation and compression");
236 error("Compression disabled");
237 options->compression = 0;
238 }
239#endif
240
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000241}
242
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000243/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100244typedef enum {
245 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100246 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000247 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100248 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100249 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
250 sPermitRootLogin, sLogFacility, sLogLevel,
251 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100252 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000253 sKerberosTgtPassing, sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100254 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000255 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100256 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000257 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000258 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100259 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000260 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100261 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Miller3a961dc2003-06-03 10:25:48 +1000262 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100263 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000264 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000265 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000266 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000267} ServerOpCodes;
268
269/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100270static struct {
271 const char *name;
272 ServerOpCodes opcode;
273} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100274 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000275#ifdef USE_PAM
Damien Miller4e448a32003-05-14 15:11:48 +1000276 { "UsePAM", sUsePAM },
Damien Miller6ac2c482003-05-16 11:42:35 +1000277#else
278 { "UsePAM", sUnsupported },
279#endif
Damien Miller726273e2001-11-12 11:40:11 +1100280 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100281 { "port", sPort },
282 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100283 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000284 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100285 { "serverkeybits", sServerKeyBits },
286 { "logingracetime", sLoginGraceTime },
287 { "keyregenerationinterval", sKeyRegenerationTime },
288 { "permitrootlogin", sPermitRootLogin },
289 { "syslogfacility", sLogFacility },
290 { "loglevel", sLogLevel },
291 { "rhostsauthentication", sRhostsAuthentication },
292 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000293 { "hostbasedauthentication", sHostbasedAuthentication },
294 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100295 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100296 { "pubkeyauthentication", sPubkeyAuthentication },
297 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000298#ifdef KRB5
Damien Miller95def091999-11-25 00:26:21 +1100299 { "kerberosauthentication", sKerberosAuthentication },
300 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
301 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Miller95def091999-11-25 00:26:21 +1100302 { "kerberostgtpassing", sKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000303#else
304 { "kerberosauthentication", sUnsupported },
305 { "kerberosorlocalpasswd", sUnsupported },
306 { "kerberosticketcleanup", sUnsupported },
307 { "kerberostgtpassing", sUnsupported },
308#endif
Damien Millerf9b3feb2003-05-16 11:38:32 +1000309 { "afstokenpassing", sUnsupported },
Damien Miller95def091999-11-25 00:26:21 +1100310 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100311 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000312 { "challengeresponseauthentication", sChallengeResponseAuthentication },
313 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000314 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100315 { "listenaddress", sListenAddress },
316 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000317 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100318 { "ignorerhosts", sIgnoreRhosts },
319 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
320 { "x11forwarding", sX11Forwarding },
321 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100322 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000323 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100324 { "strictmodes", sStrictModes },
325 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000326 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100327 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000328 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100329 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100330 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100331 { "allowusers", sAllowUsers },
332 { "denyusers", sDenyUsers },
333 { "allowgroups", sAllowGroups },
334 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000335 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000336 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000337 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000338 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000339 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000340 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000341 { "banner", sBanner },
Damien Miller3a961dc2003-06-03 10:25:48 +1000342 { "usedns", sUseDNS },
343 { "verifyreversemapping", sDeprecated },
344 { "reversemappingcheck", sDeprecated },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000345 { "clientaliveinterval", sClientAliveInterval },
346 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000347 { "authorizedkeysfile", sAuthorizedKeysFile },
348 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000349 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000350 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000351};
352
Damien Miller5428f641999-11-25 11:54:57 +1100353/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000354 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100355 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000356
Damien Miller4af51302000-04-16 11:18:38 +1000357static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100358parse_token(const char *cp, const char *filename,
359 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000360{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000361 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000362
Damien Miller95def091999-11-25 00:26:21 +1100363 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100364 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100365 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000366
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000367 error("%s: line %d: Bad configuration option: %s",
368 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100369 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000370}
371
Ben Lindstrombba81212001-06-25 05:01:22 +0000372static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000373add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100374{
Damien Miller34132e52000-01-14 15:45:46 +1100375 int i;
376
377 if (options->num_ports == 0)
378 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000379 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000380 for (i = 0; i < options->num_ports; i++)
381 add_one_listen_addr(options, addr, options->ports[i]);
382 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000383 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000384}
385
Ben Lindstrombba81212001-06-25 05:01:22 +0000386static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000387add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
388{
389 struct addrinfo hints, *ai, *aitop;
390 char strport[NI_MAXSERV];
391 int gaierr;
392
393 memset(&hints, 0, sizeof(hints));
394 hints.ai_family = IPv4or6;
395 hints.ai_socktype = SOCK_STREAM;
396 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000397 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000398 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
399 fatal("bad addr or host: %s (%s)",
400 addr ? addr : "<NULL>",
401 gai_strerror(gaierr));
402 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
403 ;
404 ai->ai_next = options->listen_addrs;
405 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100406}
407
Ben Lindstromade03f62001-12-06 18:22:17 +0000408int
409process_server_config_line(ServerOptions *options, char *line,
410 const char *filename, int linenum)
411{
412 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000413 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000414 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000415
416 cp = line;
417 arg = strdelim(&cp);
418 /* Ignore leading whitespace */
419 if (*arg == '\0')
420 arg = strdelim(&cp);
421 if (!arg || !*arg || *arg == '#')
422 return 0;
423 intptr = NULL;
424 charptr = NULL;
425 opcode = parse_token(arg, filename, linenum);
426 switch (opcode) {
427 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000428 case sUsePAM:
429 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000430 goto parse_flag;
431
432 /* Standard Options */
433 case sBadOption:
434 return -1;
435 case sPort:
436 /* ignore ports from configfile if cmdline specifies ports */
437 if (options->ports_from_cmdline)
438 return 0;
439 if (options->listen_addrs != NULL)
440 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100441 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000442 if (options->num_ports >= MAX_PORTS)
443 fatal("%s line %d: too many ports.",
444 filename, linenum);
445 arg = strdelim(&cp);
446 if (!arg || *arg == '\0')
447 fatal("%s line %d: missing port number.",
448 filename, linenum);
449 options->ports[options->num_ports++] = a2port(arg);
450 if (options->ports[options->num_ports-1] == 0)
451 fatal("%s line %d: Badly formatted port number.",
452 filename, linenum);
453 break;
454
455 case sServerKeyBits:
456 intptr = &options->server_key_bits;
457parse_int:
458 arg = strdelim(&cp);
459 if (!arg || *arg == '\0')
460 fatal("%s line %d: missing integer value.",
461 filename, linenum);
462 value = atoi(arg);
463 if (*intptr == -1)
464 *intptr = value;
465 break;
466
467 case sLoginGraceTime:
468 intptr = &options->login_grace_time;
469parse_time:
470 arg = strdelim(&cp);
471 if (!arg || *arg == '\0')
472 fatal("%s line %d: missing time value.",
473 filename, linenum);
474 if ((value = convtime(arg)) == -1)
475 fatal("%s line %d: invalid time value.",
476 filename, linenum);
477 if (*intptr == -1)
478 *intptr = value;
479 break;
480
481 case sKeyRegenerationTime:
482 intptr = &options->key_regeneration_time;
483 goto parse_time;
484
485 case sListenAddress:
486 arg = strdelim(&cp);
487 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
488 fatal("%s line %d: missing inet addr.",
489 filename, linenum);
490 if (*arg == '[') {
491 if ((p = strchr(arg, ']')) == NULL)
492 fatal("%s line %d: bad ipv6 inet addr usage.",
493 filename, linenum);
494 arg++;
495 memmove(p, p+1, strlen(p+1)+1);
496 } else if (((p = strchr(arg, ':')) == NULL) ||
497 (strchr(p+1, ':') != NULL)) {
498 add_listen_addr(options, arg, 0);
499 break;
500 }
501 if (*p == ':') {
502 u_short port;
503
504 p++;
505 if (*p == '\0')
506 fatal("%s line %d: bad inet addr:port usage.",
507 filename, linenum);
508 else {
509 *(p-1) = '\0';
510 if ((port = a2port(p)) == 0)
511 fatal("%s line %d: bad port number.",
512 filename, linenum);
513 add_listen_addr(options, arg, port);
514 }
515 } else if (*p == '\0')
516 add_listen_addr(options, arg, 0);
517 else
518 fatal("%s line %d: bad inet addr usage.",
519 filename, linenum);
520 break;
521
522 case sHostKeyFile:
523 intptr = &options->num_host_key_files;
524 if (*intptr >= MAX_HOSTKEYS)
525 fatal("%s line %d: too many host keys specified (max %d).",
526 filename, linenum, MAX_HOSTKEYS);
527 charptr = &options->host_key_files[*intptr];
528parse_filename:
529 arg = strdelim(&cp);
530 if (!arg || *arg == '\0')
531 fatal("%s line %d: missing file name.",
532 filename, linenum);
533 if (*charptr == NULL) {
534 *charptr = tilde_expand_filename(arg, getuid());
535 /* increase optional counter */
536 if (intptr != NULL)
537 *intptr = *intptr + 1;
538 }
539 break;
540
541 case sPidFile:
542 charptr = &options->pid_file;
543 goto parse_filename;
544
545 case sPermitRootLogin:
546 intptr = &options->permit_root_login;
547 arg = strdelim(&cp);
548 if (!arg || *arg == '\0')
549 fatal("%s line %d: missing yes/"
550 "without-password/forced-commands-only/no "
551 "argument.", filename, linenum);
552 value = 0; /* silence compiler */
553 if (strcmp(arg, "without-password") == 0)
554 value = PERMIT_NO_PASSWD;
555 else if (strcmp(arg, "forced-commands-only") == 0)
556 value = PERMIT_FORCED_ONLY;
557 else if (strcmp(arg, "yes") == 0)
558 value = PERMIT_YES;
559 else if (strcmp(arg, "no") == 0)
560 value = PERMIT_NO;
561 else
562 fatal("%s line %d: Bad yes/"
563 "without-password/forced-commands-only/no "
564 "argument: %s", filename, linenum, arg);
565 if (*intptr == -1)
566 *intptr = value;
567 break;
568
569 case sIgnoreRhosts:
570 intptr = &options->ignore_rhosts;
571parse_flag:
572 arg = strdelim(&cp);
573 if (!arg || *arg == '\0')
574 fatal("%s line %d: missing yes/no argument.",
575 filename, linenum);
576 value = 0; /* silence compiler */
577 if (strcmp(arg, "yes") == 0)
578 value = 1;
579 else if (strcmp(arg, "no") == 0)
580 value = 0;
581 else
582 fatal("%s line %d: Bad yes/no argument: %s",
583 filename, linenum, arg);
584 if (*intptr == -1)
585 *intptr = value;
586 break;
587
588 case sIgnoreUserKnownHosts:
589 intptr = &options->ignore_user_known_hosts;
590 goto parse_flag;
591
592 case sRhostsAuthentication:
593 intptr = &options->rhosts_authentication;
594 goto parse_flag;
595
596 case sRhostsRSAAuthentication:
597 intptr = &options->rhosts_rsa_authentication;
598 goto parse_flag;
599
600 case sHostbasedAuthentication:
601 intptr = &options->hostbased_authentication;
602 goto parse_flag;
603
604 case sHostbasedUsesNameFromPacketOnly:
605 intptr = &options->hostbased_uses_name_from_packet_only;
606 goto parse_flag;
607
608 case sRSAAuthentication:
609 intptr = &options->rsa_authentication;
610 goto parse_flag;
611
612 case sPubkeyAuthentication:
613 intptr = &options->pubkey_authentication;
614 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000615
Ben Lindstromade03f62001-12-06 18:22:17 +0000616 case sKerberosAuthentication:
617 intptr = &options->kerberos_authentication;
618 goto parse_flag;
619
620 case sKerberosOrLocalPasswd:
621 intptr = &options->kerberos_or_local_passwd;
622 goto parse_flag;
623
624 case sKerberosTicketCleanup:
625 intptr = &options->kerberos_ticket_cleanup;
626 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000627
Ben Lindstromade03f62001-12-06 18:22:17 +0000628 case sKerberosTgtPassing:
629 intptr = &options->kerberos_tgt_passing;
630 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000631
Ben Lindstromade03f62001-12-06 18:22:17 +0000632 case sPasswordAuthentication:
633 intptr = &options->password_authentication;
634 goto parse_flag;
635
636 case sKbdInteractiveAuthentication:
637 intptr = &options->kbd_interactive_authentication;
638 goto parse_flag;
639
640 case sChallengeResponseAuthentication:
641 intptr = &options->challenge_response_authentication;
642 goto parse_flag;
643
644 case sPrintMotd:
645 intptr = &options->print_motd;
646 goto parse_flag;
647
648 case sPrintLastLog:
649 intptr = &options->print_lastlog;
650 goto parse_flag;
651
652 case sX11Forwarding:
653 intptr = &options->x11_forwarding;
654 goto parse_flag;
655
656 case sX11DisplayOffset:
657 intptr = &options->x11_display_offset;
658 goto parse_int;
659
Damien Miller95c249f2002-02-05 12:11:34 +1100660 case sX11UseLocalhost:
661 intptr = &options->x11_use_localhost;
662 goto parse_flag;
663
Ben Lindstromade03f62001-12-06 18:22:17 +0000664 case sXAuthLocation:
665 charptr = &options->xauth_location;
666 goto parse_filename;
667
668 case sStrictModes:
669 intptr = &options->strict_modes;
670 goto parse_flag;
671
672 case sKeepAlives:
673 intptr = &options->keepalives;
674 goto parse_flag;
675
676 case sEmptyPasswd:
677 intptr = &options->permit_empty_passwd;
678 goto parse_flag;
679
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000680 case sPermitUserEnvironment:
681 intptr = &options->permit_user_env;
682 goto parse_flag;
683
Ben Lindstromade03f62001-12-06 18:22:17 +0000684 case sUseLogin:
685 intptr = &options->use_login;
686 goto parse_flag;
687
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000688 case sCompression:
689 intptr = &options->compression;
690 goto parse_flag;
691
Ben Lindstromade03f62001-12-06 18:22:17 +0000692 case sGatewayPorts:
693 intptr = &options->gateway_ports;
694 goto parse_flag;
695
Damien Miller3a961dc2003-06-03 10:25:48 +1000696 case sUseDNS:
697 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000698 goto parse_flag;
699
700 case sLogFacility:
701 intptr = (int *) &options->log_facility;
702 arg = strdelim(&cp);
703 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100704 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000705 fatal("%.200s line %d: unsupported log facility '%s'",
706 filename, linenum, arg ? arg : "<NONE>");
707 if (*intptr == -1)
708 *intptr = (SyslogFacility) value;
709 break;
710
711 case sLogLevel:
712 intptr = (int *) &options->log_level;
713 arg = strdelim(&cp);
714 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100715 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000716 fatal("%.200s line %d: unsupported log level '%s'",
717 filename, linenum, arg ? arg : "<NONE>");
718 if (*intptr == -1)
719 *intptr = (LogLevel) value;
720 break;
721
722 case sAllowTcpForwarding:
723 intptr = &options->allow_tcp_forwarding;
724 goto parse_flag;
725
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000726 case sUsePrivilegeSeparation:
727 intptr = &use_privsep;
728 goto parse_flag;
729
Ben Lindstromade03f62001-12-06 18:22:17 +0000730 case sAllowUsers:
731 while ((arg = strdelim(&cp)) && *arg != '\0') {
732 if (options->num_allow_users >= MAX_ALLOW_USERS)
733 fatal("%s line %d: too many allow users.",
734 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000735 options->allow_users[options->num_allow_users++] =
736 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000737 }
738 break;
739
740 case sDenyUsers:
741 while ((arg = strdelim(&cp)) && *arg != '\0') {
742 if (options->num_deny_users >= MAX_DENY_USERS)
743 fatal( "%s line %d: too many deny users.",
744 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000745 options->deny_users[options->num_deny_users++] =
746 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000747 }
748 break;
749
750 case sAllowGroups:
751 while ((arg = strdelim(&cp)) && *arg != '\0') {
752 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
753 fatal("%s line %d: too many allow groups.",
754 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000755 options->allow_groups[options->num_allow_groups++] =
756 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000757 }
758 break;
759
760 case sDenyGroups:
761 while ((arg = strdelim(&cp)) && *arg != '\0') {
762 if (options->num_deny_groups >= MAX_DENY_GROUPS)
763 fatal("%s line %d: too many deny groups.",
764 filename, linenum);
765 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
766 }
767 break;
768
769 case sCiphers:
770 arg = strdelim(&cp);
771 if (!arg || *arg == '\0')
772 fatal("%s line %d: Missing argument.", filename, linenum);
773 if (!ciphers_valid(arg))
774 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
775 filename, linenum, arg ? arg : "<NONE>");
776 if (options->ciphers == NULL)
777 options->ciphers = xstrdup(arg);
778 break;
779
780 case sMacs:
781 arg = strdelim(&cp);
782 if (!arg || *arg == '\0')
783 fatal("%s line %d: Missing argument.", filename, linenum);
784 if (!mac_valid(arg))
785 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
786 filename, linenum, arg ? arg : "<NONE>");
787 if (options->macs == NULL)
788 options->macs = xstrdup(arg);
789 break;
790
791 case sProtocol:
792 intptr = &options->protocol;
793 arg = strdelim(&cp);
794 if (!arg || *arg == '\0')
795 fatal("%s line %d: Missing argument.", filename, linenum);
796 value = proto_spec(arg);
797 if (value == SSH_PROTO_UNKNOWN)
798 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100799 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000800 if (*intptr == SSH_PROTO_UNKNOWN)
801 *intptr = value;
802 break;
803
804 case sSubsystem:
805 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
806 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100807 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000808 }
809 arg = strdelim(&cp);
810 if (!arg || *arg == '\0')
811 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100812 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000813 for (i = 0; i < options->num_subsystems; i++)
814 if (strcmp(arg, options->subsystem_name[i]) == 0)
815 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100816 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000817 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
818 arg = strdelim(&cp);
819 if (!arg || *arg == '\0')
820 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100821 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000822 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
823 options->num_subsystems++;
824 break;
825
826 case sMaxStartups:
827 arg = strdelim(&cp);
828 if (!arg || *arg == '\0')
829 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100830 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000831 if ((n = sscanf(arg, "%d:%d:%d",
832 &options->max_startups_begin,
833 &options->max_startups_rate,
834 &options->max_startups)) == 3) {
835 if (options->max_startups_begin >
836 options->max_startups ||
837 options->max_startups_rate > 100 ||
838 options->max_startups_rate < 1)
839 fatal("%s line %d: Illegal MaxStartups spec.",
840 filename, linenum);
841 } else if (n != 1)
842 fatal("%s line %d: Illegal MaxStartups spec.",
843 filename, linenum);
844 else
845 options->max_startups = options->max_startups_begin;
846 break;
847
848 case sBanner:
849 charptr = &options->banner;
850 goto parse_filename;
851 /*
852 * These options can contain %X options expanded at
853 * connect time, so that you can specify paths like:
854 *
855 * AuthorizedKeysFile /etc/ssh_keys/%u
856 */
857 case sAuthorizedKeysFile:
858 case sAuthorizedKeysFile2:
859 charptr = (opcode == sAuthorizedKeysFile ) ?
860 &options->authorized_keys_file :
861 &options->authorized_keys_file2;
862 goto parse_filename;
863
864 case sClientAliveInterval:
865 intptr = &options->client_alive_interval;
866 goto parse_time;
867
868 case sClientAliveCountMax:
869 intptr = &options->client_alive_count_max;
870 goto parse_int;
871
872 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000873 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000874 filename, linenum, arg);
875 while (arg)
876 arg = strdelim(&cp);
877 break;
878
Damien Millerf9b3feb2003-05-16 11:38:32 +1000879 case sUnsupported:
880 logit("%s line %d: Unsupported option %s",
881 filename, linenum, arg);
882 while (arg)
883 arg = strdelim(&cp);
884 break;
885
Ben Lindstromade03f62001-12-06 18:22:17 +0000886 default:
887 fatal("%s line %d: Missing handler for opcode %s (%d)",
888 filename, linenum, arg, opcode);
889 }
890 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
891 fatal("%s line %d: garbage at end of line; \"%.200s\".",
892 filename, linenum, arg);
893 return 0;
894}
895
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000896/* Reads the server configuration file. */
897
Damien Miller4af51302000-04-16 11:18:38 +1000898void
Damien Miller95def091999-11-25 00:26:21 +1100899read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000900{
Ben Lindstrome1353632002-06-23 21:29:23 +0000901 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100902 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000903 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000904
Damien Miller9f82c8f2003-02-24 12:04:33 +1100905 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100906 f = fopen(filename, "r");
907 if (!f) {
908 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000909 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100910 }
911 linenum = 0;
912 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000913 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100914 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000915 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100916 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000917 }
Damien Miller95def091999-11-25 00:26:21 +1100918 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000919 if (bad_options > 0)
920 fatal("%s: terminating, %d bad configuration options",
921 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000922}