blob: e9c313bbbab78b0f06ce6a9320fee32a60c0f9a9 [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 Tuckerec960f22003-08-13 20:37:05 +100013RCSID("$OpenBSD: servconf.c,v 1.124 2003/08/13 08:46:30 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;
Damien Miller95def091999-11-25 00:26:21 +110076 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110077 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000078 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110079 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +000080 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +110081 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +000082 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110083 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110084 options->num_allow_users = 0;
85 options->num_deny_users = 0;
86 options->num_allow_groups = 0;
87 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100088 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000089 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +100090 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100091 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100092 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100093 options->max_startups_begin = -1;
94 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100095 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +000096 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +100097 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +000098 options->client_alive_interval = -1;
99 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000100 options->authorized_keys_file = NULL;
101 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000102
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000103 /* Needs to be accessable in many places */
104 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105}
106
Damien Miller4af51302000-04-16 11:18:38 +1000107void
Damien Miller95def091999-11-25 00:26:21 +1100108fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000109{
Damien Miller726273e2001-11-12 11:40:11 +1100110 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000111 if (options->use_pam == -1)
Damien Miller156cbe82003-05-15 14:16:41 +1000112 options->use_pam = 1;
Damien Miller726273e2001-11-12 11:40:11 +1100113
114 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100115 if (options->protocol == SSH_PROTO_UNKNOWN)
116 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
117 if (options->num_host_key_files == 0) {
118 /* fill default hostkeys for protocols */
119 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100120 options->host_key_files[options->num_host_key_files++] =
121 _PATH_HOST_KEY_FILE;
122 if (options->protocol & SSH_PROTO_2) {
123 options->host_key_files[options->num_host_key_files++] =
124 _PATH_HOST_RSA_KEY_FILE;
125 options->host_key_files[options->num_host_key_files++] =
126 _PATH_HOST_DSA_KEY_FILE;
127 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100128 }
Damien Miller34132e52000-01-14 15:45:46 +1100129 if (options->num_ports == 0)
130 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
131 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000132 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000133 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000134 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100135 if (options->server_key_bits == -1)
136 options->server_key_bits = 768;
137 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000138 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100139 if (options->key_regeneration_time == -1)
140 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000141 if (options->permit_root_login == PERMIT_NOT_SET)
142 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100143 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100144 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100145 if (options->ignore_user_known_hosts == -1)
146 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100147 if (options->print_motd == -1)
148 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000149 if (options->print_lastlog == -1)
150 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100151 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100152 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100153 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100154 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100155 if (options->x11_use_localhost == -1)
156 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000157 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000158 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100159 if (options->strict_modes == -1)
160 options->strict_modes = 1;
161 if (options->keepalives == -1)
162 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100163 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100164 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100165 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000166 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100168 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000169 if (options->hostbased_authentication == -1)
170 options->hostbased_authentication = 0;
171 if (options->hostbased_uses_name_from_packet_only == -1)
172 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->rsa_authentication == -1)
174 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100175 if (options->pubkey_authentication == -1)
176 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100177 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000178 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->kerberos_or_local_passwd == -1)
180 options->kerberos_or_local_passwd = 1;
181 if (options->kerberos_ticket_cleanup == -1)
182 options->kerberos_ticket_cleanup = 1;
Damien Miller95def091999-11-25 00:26:21 +1100183 if (options->kerberos_tgt_passing == -1)
184 options->kerberos_tgt_passing = 0;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->password_authentication == -1)
186 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100187 if (options->kbd_interactive_authentication == -1)
188 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000189 if (options->challenge_response_authentication == -1)
190 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100192 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000193 if (options->permit_user_env == -1)
194 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100195 if (options->use_login == -1)
196 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000197 if (options->compression == -1)
198 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100199 if (options->allow_tcp_forwarding == -1)
200 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000201 if (options->gateway_ports == -1)
202 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000203 if (options->max_startups == -1)
204 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000205 if (options->max_startups_rate == -1)
206 options->max_startups_rate = 100; /* 100% */
207 if (options->max_startups_begin == -1)
208 options->max_startups_begin = options->max_startups;
Damien Miller3a961dc2003-06-03 10:25:48 +1000209 if (options->use_dns == -1)
210 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000211 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100212 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000213 if (options->client_alive_count_max == -1)
214 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100215 if (options->authorized_keys_file2 == NULL) {
216 /* authorized_keys_file2 falls back to authorized_keys_file */
217 if (options->authorized_keys_file != NULL)
218 options->authorized_keys_file2 = options->authorized_keys_file;
219 else
220 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
221 }
222 if (options->authorized_keys_file == NULL)
223 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000224
Ben Lindstromfb62a692002-06-06 19:47:11 +0000225 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000226 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000227 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000228
Tim Rice40017b02002-07-14 13:36:49 -0700229#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000230 if (use_privsep && options->compression == 1) {
231 error("This platform does not support both privilege "
232 "separation and compression");
233 error("Compression disabled");
234 options->compression = 0;
235 }
236#endif
237
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000238}
239
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000240/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100241typedef enum {
242 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100243 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000244 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100245 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100246 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
247 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000248 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100249 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000250 sKerberosTgtPassing, sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100251 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000252 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100253 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000254 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000255 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100256 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000257 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100258 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Miller3a961dc2003-06-03 10:25:48 +1000259 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100260 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000261 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000262 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000263 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000264} ServerOpCodes;
265
266/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100267static struct {
268 const char *name;
269 ServerOpCodes opcode;
270} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100271 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000272#ifdef USE_PAM
Damien Miller4e448a32003-05-14 15:11:48 +1000273 { "UsePAM", sUsePAM },
Damien Miller6ac2c482003-05-16 11:42:35 +1000274#else
275 { "UsePAM", sUnsupported },
276#endif
Damien Miller726273e2001-11-12 11:40:11 +1100277 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100278 { "port", sPort },
279 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100280 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000281 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100282 { "serverkeybits", sServerKeyBits },
283 { "logingracetime", sLoginGraceTime },
284 { "keyregenerationinterval", sKeyRegenerationTime },
285 { "permitrootlogin", sPermitRootLogin },
286 { "syslogfacility", sLogFacility },
287 { "loglevel", sLogLevel },
Darren Tuckerec960f22003-08-13 20:37:05 +1000288 { "rhostsauthentication", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100289 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000290 { "hostbasedauthentication", sHostbasedAuthentication },
291 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100292 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100293 { "pubkeyauthentication", sPubkeyAuthentication },
294 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000295#ifdef KRB5
Damien Miller95def091999-11-25 00:26:21 +1100296 { "kerberosauthentication", sKerberosAuthentication },
297 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
298 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Miller95def091999-11-25 00:26:21 +1100299 { "kerberostgtpassing", sKerberosTgtPassing },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000300#else
301 { "kerberosauthentication", sUnsupported },
302 { "kerberosorlocalpasswd", sUnsupported },
303 { "kerberosticketcleanup", sUnsupported },
304 { "kerberostgtpassing", sUnsupported },
305#endif
Damien Millerf9b3feb2003-05-16 11:38:32 +1000306 { "afstokenpassing", sUnsupported },
Damien Miller95def091999-11-25 00:26:21 +1100307 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100308 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000309 { "challengeresponseauthentication", sChallengeResponseAuthentication },
310 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000311 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100312 { "listenaddress", sListenAddress },
313 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000314 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100315 { "ignorerhosts", sIgnoreRhosts },
316 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
317 { "x11forwarding", sX11Forwarding },
318 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100319 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000320 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100321 { "strictmodes", sStrictModes },
322 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000323 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100324 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000325 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100326 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100327 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100328 { "allowusers", sAllowUsers },
329 { "denyusers", sDenyUsers },
330 { "allowgroups", sAllowGroups },
331 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000332 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000333 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000334 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000335 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000336 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000337 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000338 { "banner", sBanner },
Damien Miller3a961dc2003-06-03 10:25:48 +1000339 { "usedns", sUseDNS },
340 { "verifyreversemapping", sDeprecated },
341 { "reversemappingcheck", sDeprecated },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000342 { "clientaliveinterval", sClientAliveInterval },
343 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000344 { "authorizedkeysfile", sAuthorizedKeysFile },
345 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000346 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000347 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000348};
349
Damien Miller5428f641999-11-25 11:54:57 +1100350/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000351 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100352 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000353
Damien Miller4af51302000-04-16 11:18:38 +1000354static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100355parse_token(const char *cp, const char *filename,
356 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000357{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000358 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000359
Damien Miller95def091999-11-25 00:26:21 +1100360 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100361 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100362 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000363
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000364 error("%s: line %d: Bad configuration option: %s",
365 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100366 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000367}
368
Ben Lindstrombba81212001-06-25 05:01:22 +0000369static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000370add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100371{
Damien Miller34132e52000-01-14 15:45:46 +1100372 int i;
373
374 if (options->num_ports == 0)
375 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000376 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000377 for (i = 0; i < options->num_ports; i++)
378 add_one_listen_addr(options, addr, options->ports[i]);
379 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000380 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000381}
382
Ben Lindstrombba81212001-06-25 05:01:22 +0000383static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000384add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
385{
386 struct addrinfo hints, *ai, *aitop;
387 char strport[NI_MAXSERV];
388 int gaierr;
389
390 memset(&hints, 0, sizeof(hints));
391 hints.ai_family = IPv4or6;
392 hints.ai_socktype = SOCK_STREAM;
393 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000394 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000395 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
396 fatal("bad addr or host: %s (%s)",
397 addr ? addr : "<NULL>",
398 gai_strerror(gaierr));
399 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
400 ;
401 ai->ai_next = options->listen_addrs;
402 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100403}
404
Ben Lindstromade03f62001-12-06 18:22:17 +0000405int
406process_server_config_line(ServerOptions *options, char *line,
407 const char *filename, int linenum)
408{
409 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000410 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000411 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000412
413 cp = line;
414 arg = strdelim(&cp);
415 /* Ignore leading whitespace */
416 if (*arg == '\0')
417 arg = strdelim(&cp);
418 if (!arg || !*arg || *arg == '#')
419 return 0;
420 intptr = NULL;
421 charptr = NULL;
422 opcode = parse_token(arg, filename, linenum);
423 switch (opcode) {
424 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000425 case sUsePAM:
426 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000427 goto parse_flag;
428
429 /* Standard Options */
430 case sBadOption:
431 return -1;
432 case sPort:
433 /* ignore ports from configfile if cmdline specifies ports */
434 if (options->ports_from_cmdline)
435 return 0;
436 if (options->listen_addrs != NULL)
437 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100438 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000439 if (options->num_ports >= MAX_PORTS)
440 fatal("%s line %d: too many ports.",
441 filename, linenum);
442 arg = strdelim(&cp);
443 if (!arg || *arg == '\0')
444 fatal("%s line %d: missing port number.",
445 filename, linenum);
446 options->ports[options->num_ports++] = a2port(arg);
447 if (options->ports[options->num_ports-1] == 0)
448 fatal("%s line %d: Badly formatted port number.",
449 filename, linenum);
450 break;
451
452 case sServerKeyBits:
453 intptr = &options->server_key_bits;
454parse_int:
455 arg = strdelim(&cp);
456 if (!arg || *arg == '\0')
457 fatal("%s line %d: missing integer value.",
458 filename, linenum);
459 value = atoi(arg);
460 if (*intptr == -1)
461 *intptr = value;
462 break;
463
464 case sLoginGraceTime:
465 intptr = &options->login_grace_time;
466parse_time:
467 arg = strdelim(&cp);
468 if (!arg || *arg == '\0')
469 fatal("%s line %d: missing time value.",
470 filename, linenum);
471 if ((value = convtime(arg)) == -1)
472 fatal("%s line %d: invalid time value.",
473 filename, linenum);
474 if (*intptr == -1)
475 *intptr = value;
476 break;
477
478 case sKeyRegenerationTime:
479 intptr = &options->key_regeneration_time;
480 goto parse_time;
481
482 case sListenAddress:
483 arg = strdelim(&cp);
484 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
485 fatal("%s line %d: missing inet addr.",
486 filename, linenum);
487 if (*arg == '[') {
488 if ((p = strchr(arg, ']')) == NULL)
489 fatal("%s line %d: bad ipv6 inet addr usage.",
490 filename, linenum);
491 arg++;
492 memmove(p, p+1, strlen(p+1)+1);
493 } else if (((p = strchr(arg, ':')) == NULL) ||
494 (strchr(p+1, ':') != NULL)) {
495 add_listen_addr(options, arg, 0);
496 break;
497 }
498 if (*p == ':') {
499 u_short port;
500
501 p++;
502 if (*p == '\0')
503 fatal("%s line %d: bad inet addr:port usage.",
504 filename, linenum);
505 else {
506 *(p-1) = '\0';
507 if ((port = a2port(p)) == 0)
508 fatal("%s line %d: bad port number.",
509 filename, linenum);
510 add_listen_addr(options, arg, port);
511 }
512 } else if (*p == '\0')
513 add_listen_addr(options, arg, 0);
514 else
515 fatal("%s line %d: bad inet addr usage.",
516 filename, linenum);
517 break;
518
519 case sHostKeyFile:
520 intptr = &options->num_host_key_files;
521 if (*intptr >= MAX_HOSTKEYS)
522 fatal("%s line %d: too many host keys specified (max %d).",
523 filename, linenum, MAX_HOSTKEYS);
524 charptr = &options->host_key_files[*intptr];
525parse_filename:
526 arg = strdelim(&cp);
527 if (!arg || *arg == '\0')
528 fatal("%s line %d: missing file name.",
529 filename, linenum);
530 if (*charptr == NULL) {
531 *charptr = tilde_expand_filename(arg, getuid());
532 /* increase optional counter */
533 if (intptr != NULL)
534 *intptr = *intptr + 1;
535 }
536 break;
537
538 case sPidFile:
539 charptr = &options->pid_file;
540 goto parse_filename;
541
542 case sPermitRootLogin:
543 intptr = &options->permit_root_login;
544 arg = strdelim(&cp);
545 if (!arg || *arg == '\0')
546 fatal("%s line %d: missing yes/"
547 "without-password/forced-commands-only/no "
548 "argument.", filename, linenum);
549 value = 0; /* silence compiler */
550 if (strcmp(arg, "without-password") == 0)
551 value = PERMIT_NO_PASSWD;
552 else if (strcmp(arg, "forced-commands-only") == 0)
553 value = PERMIT_FORCED_ONLY;
554 else if (strcmp(arg, "yes") == 0)
555 value = PERMIT_YES;
556 else if (strcmp(arg, "no") == 0)
557 value = PERMIT_NO;
558 else
559 fatal("%s line %d: Bad yes/"
560 "without-password/forced-commands-only/no "
561 "argument: %s", filename, linenum, arg);
562 if (*intptr == -1)
563 *intptr = value;
564 break;
565
566 case sIgnoreRhosts:
567 intptr = &options->ignore_rhosts;
568parse_flag:
569 arg = strdelim(&cp);
570 if (!arg || *arg == '\0')
571 fatal("%s line %d: missing yes/no argument.",
572 filename, linenum);
573 value = 0; /* silence compiler */
574 if (strcmp(arg, "yes") == 0)
575 value = 1;
576 else if (strcmp(arg, "no") == 0)
577 value = 0;
578 else
579 fatal("%s line %d: Bad yes/no argument: %s",
580 filename, linenum, arg);
581 if (*intptr == -1)
582 *intptr = value;
583 break;
584
585 case sIgnoreUserKnownHosts:
586 intptr = &options->ignore_user_known_hosts;
587 goto parse_flag;
588
Ben Lindstromade03f62001-12-06 18:22:17 +0000589 case sRhostsRSAAuthentication:
590 intptr = &options->rhosts_rsa_authentication;
591 goto parse_flag;
592
593 case sHostbasedAuthentication:
594 intptr = &options->hostbased_authentication;
595 goto parse_flag;
596
597 case sHostbasedUsesNameFromPacketOnly:
598 intptr = &options->hostbased_uses_name_from_packet_only;
599 goto parse_flag;
600
601 case sRSAAuthentication:
602 intptr = &options->rsa_authentication;
603 goto parse_flag;
604
605 case sPubkeyAuthentication:
606 intptr = &options->pubkey_authentication;
607 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000608
Ben Lindstromade03f62001-12-06 18:22:17 +0000609 case sKerberosAuthentication:
610 intptr = &options->kerberos_authentication;
611 goto parse_flag;
612
613 case sKerberosOrLocalPasswd:
614 intptr = &options->kerberos_or_local_passwd;
615 goto parse_flag;
616
617 case sKerberosTicketCleanup:
618 intptr = &options->kerberos_ticket_cleanup;
619 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000620
Ben Lindstromade03f62001-12-06 18:22:17 +0000621 case sKerberosTgtPassing:
622 intptr = &options->kerberos_tgt_passing;
623 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000624
Ben Lindstromade03f62001-12-06 18:22:17 +0000625 case sPasswordAuthentication:
626 intptr = &options->password_authentication;
627 goto parse_flag;
628
629 case sKbdInteractiveAuthentication:
630 intptr = &options->kbd_interactive_authentication;
631 goto parse_flag;
632
633 case sChallengeResponseAuthentication:
634 intptr = &options->challenge_response_authentication;
635 goto parse_flag;
636
637 case sPrintMotd:
638 intptr = &options->print_motd;
639 goto parse_flag;
640
641 case sPrintLastLog:
642 intptr = &options->print_lastlog;
643 goto parse_flag;
644
645 case sX11Forwarding:
646 intptr = &options->x11_forwarding;
647 goto parse_flag;
648
649 case sX11DisplayOffset:
650 intptr = &options->x11_display_offset;
651 goto parse_int;
652
Damien Miller95c249f2002-02-05 12:11:34 +1100653 case sX11UseLocalhost:
654 intptr = &options->x11_use_localhost;
655 goto parse_flag;
656
Ben Lindstromade03f62001-12-06 18:22:17 +0000657 case sXAuthLocation:
658 charptr = &options->xauth_location;
659 goto parse_filename;
660
661 case sStrictModes:
662 intptr = &options->strict_modes;
663 goto parse_flag;
664
665 case sKeepAlives:
666 intptr = &options->keepalives;
667 goto parse_flag;
668
669 case sEmptyPasswd:
670 intptr = &options->permit_empty_passwd;
671 goto parse_flag;
672
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000673 case sPermitUserEnvironment:
674 intptr = &options->permit_user_env;
675 goto parse_flag;
676
Ben Lindstromade03f62001-12-06 18:22:17 +0000677 case sUseLogin:
678 intptr = &options->use_login;
679 goto parse_flag;
680
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000681 case sCompression:
682 intptr = &options->compression;
683 goto parse_flag;
684
Ben Lindstromade03f62001-12-06 18:22:17 +0000685 case sGatewayPorts:
686 intptr = &options->gateway_ports;
687 goto parse_flag;
688
Damien Miller3a961dc2003-06-03 10:25:48 +1000689 case sUseDNS:
690 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000691 goto parse_flag;
692
693 case sLogFacility:
694 intptr = (int *) &options->log_facility;
695 arg = strdelim(&cp);
696 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100697 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000698 fatal("%.200s line %d: unsupported log facility '%s'",
699 filename, linenum, arg ? arg : "<NONE>");
700 if (*intptr == -1)
701 *intptr = (SyslogFacility) value;
702 break;
703
704 case sLogLevel:
705 intptr = (int *) &options->log_level;
706 arg = strdelim(&cp);
707 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100708 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000709 fatal("%.200s line %d: unsupported log level '%s'",
710 filename, linenum, arg ? arg : "<NONE>");
711 if (*intptr == -1)
712 *intptr = (LogLevel) value;
713 break;
714
715 case sAllowTcpForwarding:
716 intptr = &options->allow_tcp_forwarding;
717 goto parse_flag;
718
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000719 case sUsePrivilegeSeparation:
720 intptr = &use_privsep;
721 goto parse_flag;
722
Ben Lindstromade03f62001-12-06 18:22:17 +0000723 case sAllowUsers:
724 while ((arg = strdelim(&cp)) && *arg != '\0') {
725 if (options->num_allow_users >= MAX_ALLOW_USERS)
726 fatal("%s line %d: too many allow users.",
727 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000728 options->allow_users[options->num_allow_users++] =
729 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000730 }
731 break;
732
733 case sDenyUsers:
734 while ((arg = strdelim(&cp)) && *arg != '\0') {
735 if (options->num_deny_users >= MAX_DENY_USERS)
736 fatal( "%s line %d: too many deny users.",
737 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000738 options->deny_users[options->num_deny_users++] =
739 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000740 }
741 break;
742
743 case sAllowGroups:
744 while ((arg = strdelim(&cp)) && *arg != '\0') {
745 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
746 fatal("%s line %d: too many allow groups.",
747 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000748 options->allow_groups[options->num_allow_groups++] =
749 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000750 }
751 break;
752
753 case sDenyGroups:
754 while ((arg = strdelim(&cp)) && *arg != '\0') {
755 if (options->num_deny_groups >= MAX_DENY_GROUPS)
756 fatal("%s line %d: too many deny groups.",
757 filename, linenum);
758 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
759 }
760 break;
761
762 case sCiphers:
763 arg = strdelim(&cp);
764 if (!arg || *arg == '\0')
765 fatal("%s line %d: Missing argument.", filename, linenum);
766 if (!ciphers_valid(arg))
767 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
768 filename, linenum, arg ? arg : "<NONE>");
769 if (options->ciphers == NULL)
770 options->ciphers = xstrdup(arg);
771 break;
772
773 case sMacs:
774 arg = strdelim(&cp);
775 if (!arg || *arg == '\0')
776 fatal("%s line %d: Missing argument.", filename, linenum);
777 if (!mac_valid(arg))
778 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
779 filename, linenum, arg ? arg : "<NONE>");
780 if (options->macs == NULL)
781 options->macs = xstrdup(arg);
782 break;
783
784 case sProtocol:
785 intptr = &options->protocol;
786 arg = strdelim(&cp);
787 if (!arg || *arg == '\0')
788 fatal("%s line %d: Missing argument.", filename, linenum);
789 value = proto_spec(arg);
790 if (value == SSH_PROTO_UNKNOWN)
791 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100792 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000793 if (*intptr == SSH_PROTO_UNKNOWN)
794 *intptr = value;
795 break;
796
797 case sSubsystem:
798 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
799 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100800 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000801 }
802 arg = strdelim(&cp);
803 if (!arg || *arg == '\0')
804 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100805 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000806 for (i = 0; i < options->num_subsystems; i++)
807 if (strcmp(arg, options->subsystem_name[i]) == 0)
808 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100809 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000810 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
811 arg = strdelim(&cp);
812 if (!arg || *arg == '\0')
813 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100814 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000815 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
816 options->num_subsystems++;
817 break;
818
819 case sMaxStartups:
820 arg = strdelim(&cp);
821 if (!arg || *arg == '\0')
822 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100823 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000824 if ((n = sscanf(arg, "%d:%d:%d",
825 &options->max_startups_begin,
826 &options->max_startups_rate,
827 &options->max_startups)) == 3) {
828 if (options->max_startups_begin >
829 options->max_startups ||
830 options->max_startups_rate > 100 ||
831 options->max_startups_rate < 1)
832 fatal("%s line %d: Illegal MaxStartups spec.",
833 filename, linenum);
834 } else if (n != 1)
835 fatal("%s line %d: Illegal MaxStartups spec.",
836 filename, linenum);
837 else
838 options->max_startups = options->max_startups_begin;
839 break;
840
841 case sBanner:
842 charptr = &options->banner;
843 goto parse_filename;
844 /*
845 * These options can contain %X options expanded at
846 * connect time, so that you can specify paths like:
847 *
848 * AuthorizedKeysFile /etc/ssh_keys/%u
849 */
850 case sAuthorizedKeysFile:
851 case sAuthorizedKeysFile2:
852 charptr = (opcode == sAuthorizedKeysFile ) ?
853 &options->authorized_keys_file :
854 &options->authorized_keys_file2;
855 goto parse_filename;
856
857 case sClientAliveInterval:
858 intptr = &options->client_alive_interval;
859 goto parse_time;
860
861 case sClientAliveCountMax:
862 intptr = &options->client_alive_count_max;
863 goto parse_int;
864
865 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000866 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000867 filename, linenum, arg);
868 while (arg)
869 arg = strdelim(&cp);
870 break;
871
Damien Millerf9b3feb2003-05-16 11:38:32 +1000872 case sUnsupported:
873 logit("%s line %d: Unsupported option %s",
874 filename, linenum, arg);
875 while (arg)
876 arg = strdelim(&cp);
877 break;
878
Ben Lindstromade03f62001-12-06 18:22:17 +0000879 default:
880 fatal("%s line %d: Missing handler for opcode %s (%d)",
881 filename, linenum, arg, opcode);
882 }
883 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
884 fatal("%s line %d: garbage at end of line; \"%.200s\".",
885 filename, linenum, arg);
886 return 0;
887}
888
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000889/* Reads the server configuration file. */
890
Damien Miller4af51302000-04-16 11:18:38 +1000891void
Damien Miller95def091999-11-25 00:26:21 +1100892read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000893{
Ben Lindstrome1353632002-06-23 21:29:23 +0000894 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100895 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000896 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000897
Damien Miller9f82c8f2003-02-24 12:04:33 +1100898 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100899 f = fopen(filename, "r");
900 if (!f) {
901 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000902 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100903 }
904 linenum = 0;
905 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000906 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100907 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000908 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100909 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000910 }
Damien Miller95def091999-11-25 00:26:21 +1100911 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000912 if (bad_options > 0)
913 fatal("%s: terminating, %d bad configuration options",
914 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000915}