blob: a6824a86363cd196ac153c3b4d06199ea6a5f0db [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Millere4340be2000-09-16 13:29:08 +11005 * As far as I am concerned, the code I have written for this software
6 * can be used freely for any purpose. Any derived versions of this
7 * software must be clearly marked as such, and if the derived work is
8 * incompatible with the protocol description in the RFC file, it must be
9 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110010 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100011
12#include "includes.h"
Damien Miller12c150e2003-12-17 16:31:10 +110013RCSID("$OpenBSD: servconf.c,v 1.129 2003/12/09 21:53:36 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;
Damien Miller12c150e2003-12-17 16:31:10 +110064 options->tcp_keep_alive = -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;
Darren Tucker0efd1552003-08-26 11:49:55 +100075 options->gss_authentication=-1;
76 options->gss_cleanup_creds = -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 Miller5c3a5582003-09-23 22:12:38 +1000113 options->use_pam = 0;
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;
Damien Miller12c150e2003-12-17 16:31:10 +1100162 if (options->tcp_keep_alive == -1)
163 options->tcp_keep_alive = 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_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100169 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000170 if (options->hostbased_authentication == -1)
171 options->hostbased_authentication = 0;
172 if (options->hostbased_uses_name_from_packet_only == -1)
173 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100174 if (options->rsa_authentication == -1)
175 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100176 if (options->pubkey_authentication == -1)
177 options->pubkey_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100178 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000179 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100180 if (options->kerberos_or_local_passwd == -1)
181 options->kerberos_or_local_passwd = 1;
182 if (options->kerberos_ticket_cleanup == -1)
183 options->kerberos_ticket_cleanup = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +1000184 if (options->gss_authentication == -1)
185 options->gss_authentication = 0;
186 if (options->gss_cleanup_creds == -1)
187 options->gss_cleanup_creds = 1;
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,
Darren Tuckerec960f22003-08-13 20:37:05 +1000251 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,
Damien Miller12c150e2003-12-17 16:31:10 +1100257 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
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,
Darren Tucker0efd1552003-08-26 11:49:55 +1000265 sGssAuthentication, sGssCleanupCreds,
Ben Lindstromc7431342002-03-22 03:11:49 +0000266 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000267 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000268} ServerOpCodes;
269
270/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100271static struct {
272 const char *name;
273 ServerOpCodes opcode;
274} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100275 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000276#ifdef USE_PAM
Damien Miller30912f72003-08-26 10:48:14 +1000277 { "usepam", sUsePAM },
Damien Miller6ac2c482003-05-16 11:42:35 +1000278#else
Damien Miller30912f72003-08-26 10:48:14 +1000279 { "usepam", sUnsupported },
Damien Miller6ac2c482003-05-16 11:42:35 +1000280#endif
Damien Miller30912f72003-08-26 10:48:14 +1000281 { "pamauthenticationviakbdint", sDeprecated },
Damien Miller726273e2001-11-12 11:40:11 +1100282 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100283 { "port", sPort },
284 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100285 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000286 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100287 { "serverkeybits", sServerKeyBits },
288 { "logingracetime", sLoginGraceTime },
289 { "keyregenerationinterval", sKeyRegenerationTime },
290 { "permitrootlogin", sPermitRootLogin },
291 { "syslogfacility", sLogFacility },
292 { "loglevel", sLogLevel },
Darren Tuckerec960f22003-08-13 20:37:05 +1000293 { "rhostsauthentication", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100294 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000295 { "hostbasedauthentication", sHostbasedAuthentication },
296 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100297 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100298 { "pubkeyauthentication", sPubkeyAuthentication },
299 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000300#ifdef KRB5
Damien Miller95def091999-11-25 00:26:21 +1100301 { "kerberosauthentication", sKerberosAuthentication },
302 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
303 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000304#else
305 { "kerberosauthentication", sUnsupported },
306 { "kerberosorlocalpasswd", sUnsupported },
307 { "kerberosticketcleanup", sUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000308#endif
Damien Miller1a0c0b92003-09-02 22:51:17 +1000309 { "kerberostgtpassing", sUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000310 { "afstokenpassing", sUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000311#ifdef GSSAPI
312 { "gssapiauthentication", sGssAuthentication },
Darren Tuckera49d36e2003-10-02 16:20:54 +1000313 { "gssapicleanupcredentials", sGssCleanupCreds },
Darren Tucker0efd1552003-08-26 11:49:55 +1000314#else
315 { "gssapiauthentication", sUnsupported },
Darren Tuckera49d36e2003-10-02 16:20:54 +1000316 { "gssapicleanupcredentials", sUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000317#endif
Damien Miller95def091999-11-25 00:26:21 +1100318 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100319 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000320 { "challengeresponseauthentication", sChallengeResponseAuthentication },
321 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000322 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100323 { "listenaddress", sListenAddress },
324 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000325 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100326 { "ignorerhosts", sIgnoreRhosts },
327 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
328 { "x11forwarding", sX11Forwarding },
329 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100330 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000331 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100332 { "strictmodes", sStrictModes },
333 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000334 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100335 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000336 { "compression", sCompression },
Damien Miller12c150e2003-12-17 16:31:10 +1100337 { "tcpkeepalive", sTCPKeepAlive },
338 { "keepalive", sTCPKeepAlive }, /* obsolete alias */
Damien Miller50a41ed2000-10-16 12:14:42 +1100339 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100340 { "allowusers", sAllowUsers },
341 { "denyusers", sDenyUsers },
342 { "allowgroups", sAllowGroups },
343 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000344 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000345 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000346 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000347 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000348 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000349 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000350 { "banner", sBanner },
Damien Miller3a961dc2003-06-03 10:25:48 +1000351 { "usedns", sUseDNS },
352 { "verifyreversemapping", sDeprecated },
353 { "reversemappingcheck", sDeprecated },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000354 { "clientaliveinterval", sClientAliveInterval },
355 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000356 { "authorizedkeysfile", sAuthorizedKeysFile },
357 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000358 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000359 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000360};
361
Damien Miller5428f641999-11-25 11:54:57 +1100362/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000363 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100364 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000365
Damien Miller4af51302000-04-16 11:18:38 +1000366static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100367parse_token(const char *cp, const char *filename,
368 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000369{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000370 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000371
Damien Miller95def091999-11-25 00:26:21 +1100372 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100373 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100374 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000375
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000376 error("%s: line %d: Bad configuration option: %s",
377 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100378 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379}
380
Ben Lindstrombba81212001-06-25 05:01:22 +0000381static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000382add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100383{
Damien Miller34132e52000-01-14 15:45:46 +1100384 int i;
385
386 if (options->num_ports == 0)
387 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000388 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000389 for (i = 0; i < options->num_ports; i++)
390 add_one_listen_addr(options, addr, options->ports[i]);
391 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000392 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000393}
394
Ben Lindstrombba81212001-06-25 05:01:22 +0000395static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000396add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
397{
398 struct addrinfo hints, *ai, *aitop;
399 char strport[NI_MAXSERV];
400 int gaierr;
401
402 memset(&hints, 0, sizeof(hints));
403 hints.ai_family = IPv4or6;
404 hints.ai_socktype = SOCK_STREAM;
405 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000406 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000407 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
408 fatal("bad addr or host: %s (%s)",
409 addr ? addr : "<NULL>",
410 gai_strerror(gaierr));
411 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
412 ;
413 ai->ai_next = options->listen_addrs;
414 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100415}
416
Ben Lindstromade03f62001-12-06 18:22:17 +0000417int
418process_server_config_line(ServerOptions *options, char *line,
419 const char *filename, int linenum)
420{
421 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000422 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000423 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000424
425 cp = line;
426 arg = strdelim(&cp);
427 /* Ignore leading whitespace */
428 if (*arg == '\0')
429 arg = strdelim(&cp);
430 if (!arg || !*arg || *arg == '#')
431 return 0;
432 intptr = NULL;
433 charptr = NULL;
434 opcode = parse_token(arg, filename, linenum);
435 switch (opcode) {
436 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000437 case sUsePAM:
438 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000439 goto parse_flag;
440
441 /* Standard Options */
442 case sBadOption:
443 return -1;
444 case sPort:
445 /* ignore ports from configfile if cmdline specifies ports */
446 if (options->ports_from_cmdline)
447 return 0;
448 if (options->listen_addrs != NULL)
449 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100450 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000451 if (options->num_ports >= MAX_PORTS)
452 fatal("%s line %d: too many ports.",
453 filename, linenum);
454 arg = strdelim(&cp);
455 if (!arg || *arg == '\0')
456 fatal("%s line %d: missing port number.",
457 filename, linenum);
458 options->ports[options->num_ports++] = a2port(arg);
459 if (options->ports[options->num_ports-1] == 0)
460 fatal("%s line %d: Badly formatted port number.",
461 filename, linenum);
462 break;
463
464 case sServerKeyBits:
465 intptr = &options->server_key_bits;
466parse_int:
467 arg = strdelim(&cp);
468 if (!arg || *arg == '\0')
469 fatal("%s line %d: missing integer value.",
470 filename, linenum);
471 value = atoi(arg);
472 if (*intptr == -1)
473 *intptr = value;
474 break;
475
476 case sLoginGraceTime:
477 intptr = &options->login_grace_time;
478parse_time:
479 arg = strdelim(&cp);
480 if (!arg || *arg == '\0')
481 fatal("%s line %d: missing time value.",
482 filename, linenum);
483 if ((value = convtime(arg)) == -1)
484 fatal("%s line %d: invalid time value.",
485 filename, linenum);
486 if (*intptr == -1)
487 *intptr = value;
488 break;
489
490 case sKeyRegenerationTime:
491 intptr = &options->key_regeneration_time;
492 goto parse_time;
493
494 case sListenAddress:
495 arg = strdelim(&cp);
496 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
497 fatal("%s line %d: missing inet addr.",
498 filename, linenum);
499 if (*arg == '[') {
500 if ((p = strchr(arg, ']')) == NULL)
501 fatal("%s line %d: bad ipv6 inet addr usage.",
502 filename, linenum);
503 arg++;
504 memmove(p, p+1, strlen(p+1)+1);
505 } else if (((p = strchr(arg, ':')) == NULL) ||
506 (strchr(p+1, ':') != NULL)) {
507 add_listen_addr(options, arg, 0);
508 break;
509 }
510 if (*p == ':') {
511 u_short port;
512
513 p++;
514 if (*p == '\0')
515 fatal("%s line %d: bad inet addr:port usage.",
516 filename, linenum);
517 else {
518 *(p-1) = '\0';
519 if ((port = a2port(p)) == 0)
520 fatal("%s line %d: bad port number.",
521 filename, linenum);
522 add_listen_addr(options, arg, port);
523 }
524 } else if (*p == '\0')
525 add_listen_addr(options, arg, 0);
526 else
527 fatal("%s line %d: bad inet addr usage.",
528 filename, linenum);
529 break;
530
531 case sHostKeyFile:
532 intptr = &options->num_host_key_files;
533 if (*intptr >= MAX_HOSTKEYS)
534 fatal("%s line %d: too many host keys specified (max %d).",
535 filename, linenum, MAX_HOSTKEYS);
536 charptr = &options->host_key_files[*intptr];
537parse_filename:
538 arg = strdelim(&cp);
539 if (!arg || *arg == '\0')
540 fatal("%s line %d: missing file name.",
541 filename, linenum);
542 if (*charptr == NULL) {
543 *charptr = tilde_expand_filename(arg, getuid());
544 /* increase optional counter */
545 if (intptr != NULL)
546 *intptr = *intptr + 1;
547 }
548 break;
549
550 case sPidFile:
551 charptr = &options->pid_file;
552 goto parse_filename;
553
554 case sPermitRootLogin:
555 intptr = &options->permit_root_login;
556 arg = strdelim(&cp);
557 if (!arg || *arg == '\0')
558 fatal("%s line %d: missing yes/"
559 "without-password/forced-commands-only/no "
560 "argument.", filename, linenum);
561 value = 0; /* silence compiler */
562 if (strcmp(arg, "without-password") == 0)
563 value = PERMIT_NO_PASSWD;
564 else if (strcmp(arg, "forced-commands-only") == 0)
565 value = PERMIT_FORCED_ONLY;
566 else if (strcmp(arg, "yes") == 0)
567 value = PERMIT_YES;
568 else if (strcmp(arg, "no") == 0)
569 value = PERMIT_NO;
570 else
571 fatal("%s line %d: Bad yes/"
572 "without-password/forced-commands-only/no "
573 "argument: %s", filename, linenum, arg);
574 if (*intptr == -1)
575 *intptr = value;
576 break;
577
578 case sIgnoreRhosts:
579 intptr = &options->ignore_rhosts;
580parse_flag:
581 arg = strdelim(&cp);
582 if (!arg || *arg == '\0')
583 fatal("%s line %d: missing yes/no argument.",
584 filename, linenum);
585 value = 0; /* silence compiler */
586 if (strcmp(arg, "yes") == 0)
587 value = 1;
588 else if (strcmp(arg, "no") == 0)
589 value = 0;
590 else
591 fatal("%s line %d: Bad yes/no argument: %s",
592 filename, linenum, arg);
593 if (*intptr == -1)
594 *intptr = value;
595 break;
596
597 case sIgnoreUserKnownHosts:
598 intptr = &options->ignore_user_known_hosts;
599 goto parse_flag;
600
Ben Lindstromade03f62001-12-06 18:22:17 +0000601 case sRhostsRSAAuthentication:
602 intptr = &options->rhosts_rsa_authentication;
603 goto parse_flag;
604
605 case sHostbasedAuthentication:
606 intptr = &options->hostbased_authentication;
607 goto parse_flag;
608
609 case sHostbasedUsesNameFromPacketOnly:
610 intptr = &options->hostbased_uses_name_from_packet_only;
611 goto parse_flag;
612
613 case sRSAAuthentication:
614 intptr = &options->rsa_authentication;
615 goto parse_flag;
616
617 case sPubkeyAuthentication:
618 intptr = &options->pubkey_authentication;
619 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000620
Ben Lindstromade03f62001-12-06 18:22:17 +0000621 case sKerberosAuthentication:
622 intptr = &options->kerberos_authentication;
623 goto parse_flag;
624
625 case sKerberosOrLocalPasswd:
626 intptr = &options->kerberos_or_local_passwd;
627 goto parse_flag;
628
629 case sKerberosTicketCleanup:
630 intptr = &options->kerberos_ticket_cleanup;
631 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000632
Darren Tucker0efd1552003-08-26 11:49:55 +1000633 case sGssAuthentication:
634 intptr = &options->gss_authentication;
635 goto parse_flag;
636
637 case sGssCleanupCreds:
638 intptr = &options->gss_cleanup_creds;
639 goto parse_flag;
640
Ben Lindstromade03f62001-12-06 18:22:17 +0000641 case sPasswordAuthentication:
642 intptr = &options->password_authentication;
643 goto parse_flag;
644
645 case sKbdInteractiveAuthentication:
646 intptr = &options->kbd_interactive_authentication;
647 goto parse_flag;
648
649 case sChallengeResponseAuthentication:
650 intptr = &options->challenge_response_authentication;
651 goto parse_flag;
652
653 case sPrintMotd:
654 intptr = &options->print_motd;
655 goto parse_flag;
656
657 case sPrintLastLog:
658 intptr = &options->print_lastlog;
659 goto parse_flag;
660
661 case sX11Forwarding:
662 intptr = &options->x11_forwarding;
663 goto parse_flag;
664
665 case sX11DisplayOffset:
666 intptr = &options->x11_display_offset;
667 goto parse_int;
668
Damien Miller95c249f2002-02-05 12:11:34 +1100669 case sX11UseLocalhost:
670 intptr = &options->x11_use_localhost;
671 goto parse_flag;
672
Ben Lindstromade03f62001-12-06 18:22:17 +0000673 case sXAuthLocation:
674 charptr = &options->xauth_location;
675 goto parse_filename;
676
677 case sStrictModes:
678 intptr = &options->strict_modes;
679 goto parse_flag;
680
Damien Miller12c150e2003-12-17 16:31:10 +1100681 case sTCPKeepAlive:
682 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000683 goto parse_flag;
684
685 case sEmptyPasswd:
686 intptr = &options->permit_empty_passwd;
687 goto parse_flag;
688
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000689 case sPermitUserEnvironment:
690 intptr = &options->permit_user_env;
691 goto parse_flag;
692
Ben Lindstromade03f62001-12-06 18:22:17 +0000693 case sUseLogin:
694 intptr = &options->use_login;
695 goto parse_flag;
696
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000697 case sCompression:
698 intptr = &options->compression;
699 goto parse_flag;
700
Ben Lindstromade03f62001-12-06 18:22:17 +0000701 case sGatewayPorts:
702 intptr = &options->gateway_ports;
703 goto parse_flag;
704
Damien Miller3a961dc2003-06-03 10:25:48 +1000705 case sUseDNS:
706 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000707 goto parse_flag;
708
709 case sLogFacility:
710 intptr = (int *) &options->log_facility;
711 arg = strdelim(&cp);
712 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100713 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000714 fatal("%.200s line %d: unsupported log facility '%s'",
715 filename, linenum, arg ? arg : "<NONE>");
716 if (*intptr == -1)
717 *intptr = (SyslogFacility) value;
718 break;
719
720 case sLogLevel:
721 intptr = (int *) &options->log_level;
722 arg = strdelim(&cp);
723 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100724 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000725 fatal("%.200s line %d: unsupported log level '%s'",
726 filename, linenum, arg ? arg : "<NONE>");
727 if (*intptr == -1)
728 *intptr = (LogLevel) value;
729 break;
730
731 case sAllowTcpForwarding:
732 intptr = &options->allow_tcp_forwarding;
733 goto parse_flag;
734
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000735 case sUsePrivilegeSeparation:
736 intptr = &use_privsep;
737 goto parse_flag;
738
Ben Lindstromade03f62001-12-06 18:22:17 +0000739 case sAllowUsers:
740 while ((arg = strdelim(&cp)) && *arg != '\0') {
741 if (options->num_allow_users >= MAX_ALLOW_USERS)
742 fatal("%s line %d: too many allow users.",
743 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000744 options->allow_users[options->num_allow_users++] =
745 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000746 }
747 break;
748
749 case sDenyUsers:
750 while ((arg = strdelim(&cp)) && *arg != '\0') {
751 if (options->num_deny_users >= MAX_DENY_USERS)
752 fatal( "%s line %d: too many deny users.",
753 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000754 options->deny_users[options->num_deny_users++] =
755 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000756 }
757 break;
758
759 case sAllowGroups:
760 while ((arg = strdelim(&cp)) && *arg != '\0') {
761 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
762 fatal("%s line %d: too many allow groups.",
763 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000764 options->allow_groups[options->num_allow_groups++] =
765 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000766 }
767 break;
768
769 case sDenyGroups:
770 while ((arg = strdelim(&cp)) && *arg != '\0') {
771 if (options->num_deny_groups >= MAX_DENY_GROUPS)
772 fatal("%s line %d: too many deny groups.",
773 filename, linenum);
774 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
775 }
776 break;
777
778 case sCiphers:
779 arg = strdelim(&cp);
780 if (!arg || *arg == '\0')
781 fatal("%s line %d: Missing argument.", filename, linenum);
782 if (!ciphers_valid(arg))
783 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
784 filename, linenum, arg ? arg : "<NONE>");
785 if (options->ciphers == NULL)
786 options->ciphers = xstrdup(arg);
787 break;
788
789 case sMacs:
790 arg = strdelim(&cp);
791 if (!arg || *arg == '\0')
792 fatal("%s line %d: Missing argument.", filename, linenum);
793 if (!mac_valid(arg))
794 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
795 filename, linenum, arg ? arg : "<NONE>");
796 if (options->macs == NULL)
797 options->macs = xstrdup(arg);
798 break;
799
800 case sProtocol:
801 intptr = &options->protocol;
802 arg = strdelim(&cp);
803 if (!arg || *arg == '\0')
804 fatal("%s line %d: Missing argument.", filename, linenum);
805 value = proto_spec(arg);
806 if (value == SSH_PROTO_UNKNOWN)
807 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100808 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000809 if (*intptr == SSH_PROTO_UNKNOWN)
810 *intptr = value;
811 break;
812
813 case sSubsystem:
814 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
815 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100816 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000817 }
818 arg = strdelim(&cp);
819 if (!arg || *arg == '\0')
820 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100821 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000822 for (i = 0; i < options->num_subsystems; i++)
823 if (strcmp(arg, options->subsystem_name[i]) == 0)
824 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100825 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000826 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
827 arg = strdelim(&cp);
828 if (!arg || *arg == '\0')
829 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100830 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000831 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
832 options->num_subsystems++;
833 break;
834
835 case sMaxStartups:
836 arg = strdelim(&cp);
837 if (!arg || *arg == '\0')
838 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100839 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000840 if ((n = sscanf(arg, "%d:%d:%d",
841 &options->max_startups_begin,
842 &options->max_startups_rate,
843 &options->max_startups)) == 3) {
844 if (options->max_startups_begin >
845 options->max_startups ||
846 options->max_startups_rate > 100 ||
847 options->max_startups_rate < 1)
848 fatal("%s line %d: Illegal MaxStartups spec.",
849 filename, linenum);
850 } else if (n != 1)
851 fatal("%s line %d: Illegal MaxStartups spec.",
852 filename, linenum);
853 else
854 options->max_startups = options->max_startups_begin;
855 break;
856
857 case sBanner:
858 charptr = &options->banner;
859 goto parse_filename;
860 /*
861 * These options can contain %X options expanded at
862 * connect time, so that you can specify paths like:
863 *
864 * AuthorizedKeysFile /etc/ssh_keys/%u
865 */
866 case sAuthorizedKeysFile:
867 case sAuthorizedKeysFile2:
868 charptr = (opcode == sAuthorizedKeysFile ) ?
869 &options->authorized_keys_file :
870 &options->authorized_keys_file2;
871 goto parse_filename;
872
873 case sClientAliveInterval:
874 intptr = &options->client_alive_interval;
875 goto parse_time;
876
877 case sClientAliveCountMax:
878 intptr = &options->client_alive_count_max;
879 goto parse_int;
880
881 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000882 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000883 filename, linenum, arg);
884 while (arg)
885 arg = strdelim(&cp);
886 break;
887
Damien Millerf9b3feb2003-05-16 11:38:32 +1000888 case sUnsupported:
889 logit("%s line %d: Unsupported option %s",
890 filename, linenum, arg);
891 while (arg)
892 arg = strdelim(&cp);
893 break;
894
Ben Lindstromade03f62001-12-06 18:22:17 +0000895 default:
896 fatal("%s line %d: Missing handler for opcode %s (%d)",
897 filename, linenum, arg, opcode);
898 }
899 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
900 fatal("%s line %d: garbage at end of line; \"%.200s\".",
901 filename, linenum, arg);
902 return 0;
903}
904
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000905/* Reads the server configuration file. */
906
Damien Miller4af51302000-04-16 11:18:38 +1000907void
Damien Miller95def091999-11-25 00:26:21 +1100908read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000909{
Ben Lindstrome1353632002-06-23 21:29:23 +0000910 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100911 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000912 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000913
Damien Miller9f82c8f2003-02-24 12:04:33 +1100914 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100915 f = fopen(filename, "r");
916 if (!f) {
917 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000918 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100919 }
920 linenum = 0;
921 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000922 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100923 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000924 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100925 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000926 }
Damien Miller95def091999-11-25 00:26:21 +1100927 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000928 if (bad_options > 0)
929 fatal("%s: terminating, %d bad configuration options",
930 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000931}