blob: ae380f5227d32c03bedddb3f88ccec4dc2877e57 [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 Tucker46bc0752004-05-02 22:11:30 +100013RCSID("$OpenBSD: servconf.c,v 1.131 2004/04/27 09:46:37 djm 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 Tucker22ef5082003-12-31 11:37:34 +110075 options->kerberos_get_afs_token = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +100076 options->gss_authentication=-1;
77 options->gss_cleanup_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +110078 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110079 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000080 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110081 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +000082 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +110083 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +000084 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110085 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110086 options->num_allow_users = 0;
87 options->num_deny_users = 0;
88 options->num_allow_groups = 0;
89 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100090 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000091 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +100092 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100093 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100094 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100095 options->max_startups_begin = -1;
96 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100097 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +000098 options->banner = NULL;
Damien Miller3a961dc2003-06-03 10:25:48 +100099 options->use_dns = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000100 options->client_alive_interval = -1;
101 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000102 options->authorized_keys_file = NULL;
103 options->authorized_keys_file2 = NULL;
Darren Tucker46bc0752004-05-02 22:11:30 +1000104 options->num_accept_env = 0;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000105
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000106 /* Needs to be accessable in many places */
107 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000108}
109
Damien Miller4af51302000-04-16 11:18:38 +1000110void
Damien Miller95def091999-11-25 00:26:21 +1100111fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000112{
Damien Miller726273e2001-11-12 11:40:11 +1100113 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000114 if (options->use_pam == -1)
Damien Miller5c3a5582003-09-23 22:12:38 +1000115 options->use_pam = 0;
Damien Miller726273e2001-11-12 11:40:11 +1100116
117 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100118 if (options->protocol == SSH_PROTO_UNKNOWN)
119 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
120 if (options->num_host_key_files == 0) {
121 /* fill default hostkeys for protocols */
122 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100123 options->host_key_files[options->num_host_key_files++] =
124 _PATH_HOST_KEY_FILE;
125 if (options->protocol & SSH_PROTO_2) {
126 options->host_key_files[options->num_host_key_files++] =
127 _PATH_HOST_RSA_KEY_FILE;
128 options->host_key_files[options->num_host_key_files++] =
129 _PATH_HOST_DSA_KEY_FILE;
130 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100131 }
Damien Miller34132e52000-01-14 15:45:46 +1100132 if (options->num_ports == 0)
133 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
134 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000135 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000136 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000137 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100138 if (options->server_key_bits == -1)
139 options->server_key_bits = 768;
140 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000141 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100142 if (options->key_regeneration_time == -1)
143 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000144 if (options->permit_root_login == PERMIT_NOT_SET)
145 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100146 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100147 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100148 if (options->ignore_user_known_hosts == -1)
149 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100150 if (options->print_motd == -1)
151 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000152 if (options->print_lastlog == -1)
153 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100154 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100155 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100156 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100157 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100158 if (options->x11_use_localhost == -1)
159 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000160 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000161 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100162 if (options->strict_modes == -1)
163 options->strict_modes = 1;
Damien Miller12c150e2003-12-17 16:31:10 +1100164 if (options->tcp_keep_alive == -1)
165 options->tcp_keep_alive = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100166 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100167 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100168 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000169 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100170 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;
Darren Tucker22ef5082003-12-31 11:37:34 +1100186 if (options->kerberos_get_afs_token == -1)
187 options->kerberos_get_afs_token = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +1000188 if (options->gss_authentication == -1)
189 options->gss_authentication = 0;
190 if (options->gss_cleanup_creds == -1)
191 options->gss_cleanup_creds = 1;
Damien Miller95def091999-11-25 00:26:21 +1100192 if (options->password_authentication == -1)
193 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100194 if (options->kbd_interactive_authentication == -1)
195 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000196 if (options->challenge_response_authentication == -1)
197 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100198 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100199 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000200 if (options->permit_user_env == -1)
201 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->use_login == -1)
203 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000204 if (options->compression == -1)
205 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100206 if (options->allow_tcp_forwarding == -1)
207 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000208 if (options->gateway_ports == -1)
209 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000210 if (options->max_startups == -1)
211 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000212 if (options->max_startups_rate == -1)
213 options->max_startups_rate = 100; /* 100% */
214 if (options->max_startups_begin == -1)
215 options->max_startups_begin = options->max_startups;
Damien Miller3a961dc2003-06-03 10:25:48 +1000216 if (options->use_dns == -1)
217 options->use_dns = 1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000218 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100219 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000220 if (options->client_alive_count_max == -1)
221 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100222 if (options->authorized_keys_file2 == NULL) {
223 /* authorized_keys_file2 falls back to authorized_keys_file */
224 if (options->authorized_keys_file != NULL)
225 options->authorized_keys_file2 = options->authorized_keys_file;
226 else
227 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
228 }
229 if (options->authorized_keys_file == NULL)
230 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000231
Ben Lindstromfb62a692002-06-06 19:47:11 +0000232 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000233 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000234 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000235
Tim Rice40017b02002-07-14 13:36:49 -0700236#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000237 if (use_privsep && options->compression == 1) {
238 error("This platform does not support both privilege "
239 "separation and compression");
240 error("Compression disabled");
241 options->compression = 0;
242 }
243#endif
244
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000245}
246
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000247/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100248typedef enum {
249 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100250 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000251 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100252 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100253 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
254 sPermitRootLogin, sLogFacility, sLogLevel,
Darren Tuckerec960f22003-08-13 20:37:05 +1000255 sRhostsRSAAuthentication, sRSAAuthentication,
Damien Miller95def091999-11-25 00:26:21 +1100256 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Darren Tucker22ef5082003-12-31 11:37:34 +1100257 sKerberosGetAFSToken,
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000258 sKerberosTgtPassing, sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100259 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000260 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100261 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Damien Miller12c150e2003-12-17 16:31:10 +1100262 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000263 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100264 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000265 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100266 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Miller3a961dc2003-06-03 10:25:48 +1000267 sBanner, sUseDNS, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100268 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000269 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Darren Tucker46bc0752004-05-02 22:11:30 +1000270 sGssAuthentication, sGssCleanupCreds, sAcceptEnv,
Ben Lindstromc7431342002-03-22 03:11:49 +0000271 sUsePrivilegeSeparation,
Damien Millerf9b3feb2003-05-16 11:38:32 +1000272 sDeprecated, sUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000273} ServerOpCodes;
274
275/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100276static struct {
277 const char *name;
278 ServerOpCodes opcode;
279} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100280 /* Portable-specific options */
Damien Miller6ac2c482003-05-16 11:42:35 +1000281#ifdef USE_PAM
Damien Miller30912f72003-08-26 10:48:14 +1000282 { "usepam", sUsePAM },
Damien Miller6ac2c482003-05-16 11:42:35 +1000283#else
Damien Miller30912f72003-08-26 10:48:14 +1000284 { "usepam", sUnsupported },
Damien Miller6ac2c482003-05-16 11:42:35 +1000285#endif
Damien Miller30912f72003-08-26 10:48:14 +1000286 { "pamauthenticationviakbdint", sDeprecated },
Damien Miller726273e2001-11-12 11:40:11 +1100287 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100288 { "port", sPort },
289 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100290 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000291 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100292 { "serverkeybits", sServerKeyBits },
293 { "logingracetime", sLoginGraceTime },
294 { "keyregenerationinterval", sKeyRegenerationTime },
295 { "permitrootlogin", sPermitRootLogin },
296 { "syslogfacility", sLogFacility },
297 { "loglevel", sLogLevel },
Darren Tuckerec960f22003-08-13 20:37:05 +1000298 { "rhostsauthentication", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100299 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000300 { "hostbasedauthentication", sHostbasedAuthentication },
301 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100302 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100303 { "pubkeyauthentication", sPubkeyAuthentication },
304 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Darren Tucker6aaa58c2003-08-02 22:24:49 +1000305#ifdef KRB5
Damien Miller95def091999-11-25 00:26:21 +1100306 { "kerberosauthentication", sKerberosAuthentication },
307 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
308 { "kerberosticketcleanup", sKerberosTicketCleanup },
Darren Tucker3c78c5e2004-01-23 22:03:10 +1100309#ifdef USE_AFS
Darren Tucker22ef5082003-12-31 11:37:34 +1100310 { "kerberosgetafstoken", sKerberosGetAFSToken },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000311#else
Darren Tucker409cb322004-01-05 22:36:51 +1100312 { "kerberosgetafstoken", sUnsupported },
313#endif
314#else
Damien Millerf9b3feb2003-05-16 11:38:32 +1000315 { "kerberosauthentication", sUnsupported },
316 { "kerberosorlocalpasswd", sUnsupported },
317 { "kerberosticketcleanup", sUnsupported },
Darren Tucker22ef5082003-12-31 11:37:34 +1100318 { "kerberosgetafstoken", sUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000319#endif
Damien Miller1a0c0b92003-09-02 22:51:17 +1000320 { "kerberostgtpassing", sUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000321 { "afstokenpassing", sUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000322#ifdef GSSAPI
323 { "gssapiauthentication", sGssAuthentication },
Darren Tuckera49d36e2003-10-02 16:20:54 +1000324 { "gssapicleanupcredentials", sGssCleanupCreds },
Darren Tucker0efd1552003-08-26 11:49:55 +1000325#else
326 { "gssapiauthentication", sUnsupported },
Darren Tuckera49d36e2003-10-02 16:20:54 +1000327 { "gssapicleanupcredentials", sUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000328#endif
Damien Miller95def091999-11-25 00:26:21 +1100329 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100330 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000331 { "challengeresponseauthentication", sChallengeResponseAuthentication },
332 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000333 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100334 { "listenaddress", sListenAddress },
335 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000336 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100337 { "ignorerhosts", sIgnoreRhosts },
338 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
339 { "x11forwarding", sX11Forwarding },
340 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100341 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000342 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100343 { "strictmodes", sStrictModes },
344 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000345 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100346 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000347 { "compression", sCompression },
Damien Miller12c150e2003-12-17 16:31:10 +1100348 { "tcpkeepalive", sTCPKeepAlive },
349 { "keepalive", sTCPKeepAlive }, /* obsolete alias */
Damien Miller50a41ed2000-10-16 12:14:42 +1100350 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100351 { "allowusers", sAllowUsers },
352 { "denyusers", sDenyUsers },
353 { "allowgroups", sAllowGroups },
354 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000355 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000356 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000357 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000358 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000359 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000360 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000361 { "banner", sBanner },
Damien Miller3a961dc2003-06-03 10:25:48 +1000362 { "usedns", sUseDNS },
363 { "verifyreversemapping", sDeprecated },
364 { "reversemappingcheck", sDeprecated },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000365 { "clientaliveinterval", sClientAliveInterval },
366 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000367 { "authorizedkeysfile", sAuthorizedKeysFile },
368 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000369 { "useprivilegeseparation", sUsePrivilegeSeparation},
Darren Tucker46bc0752004-05-02 22:11:30 +1000370 { "acceptenv", sAcceptEnv },
Ben Lindstrom65366a82001-12-06 16:32:47 +0000371 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000372};
373
Damien Miller5428f641999-11-25 11:54:57 +1100374/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000375 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100376 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000377
Damien Miller4af51302000-04-16 11:18:38 +1000378static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100379parse_token(const char *cp, const char *filename,
380 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000382 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383
Damien Miller95def091999-11-25 00:26:21 +1100384 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100385 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100386 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000387
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000388 error("%s: line %d: Bad configuration option: %s",
389 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100390 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000391}
392
Ben Lindstrombba81212001-06-25 05:01:22 +0000393static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000394add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100395{
Damien Miller34132e52000-01-14 15:45:46 +1100396 int i;
397
398 if (options->num_ports == 0)
399 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000400 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000401 for (i = 0; i < options->num_ports; i++)
402 add_one_listen_addr(options, addr, options->ports[i]);
403 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000404 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000405}
406
Ben Lindstrombba81212001-06-25 05:01:22 +0000407static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000408add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
409{
410 struct addrinfo hints, *ai, *aitop;
411 char strport[NI_MAXSERV];
412 int gaierr;
413
414 memset(&hints, 0, sizeof(hints));
415 hints.ai_family = IPv4or6;
416 hints.ai_socktype = SOCK_STREAM;
417 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000418 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000419 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
420 fatal("bad addr or host: %s (%s)",
421 addr ? addr : "<NULL>",
422 gai_strerror(gaierr));
423 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
424 ;
425 ai->ai_next = options->listen_addrs;
426 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100427}
428
Ben Lindstromade03f62001-12-06 18:22:17 +0000429int
430process_server_config_line(ServerOptions *options, char *line,
431 const char *filename, int linenum)
432{
433 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000434 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000435 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000436
437 cp = line;
438 arg = strdelim(&cp);
439 /* Ignore leading whitespace */
440 if (*arg == '\0')
441 arg = strdelim(&cp);
442 if (!arg || !*arg || *arg == '#')
443 return 0;
444 intptr = NULL;
445 charptr = NULL;
446 opcode = parse_token(arg, filename, linenum);
447 switch (opcode) {
448 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000449 case sUsePAM:
450 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000451 goto parse_flag;
452
453 /* Standard Options */
454 case sBadOption:
455 return -1;
456 case sPort:
457 /* ignore ports from configfile if cmdline specifies ports */
458 if (options->ports_from_cmdline)
459 return 0;
460 if (options->listen_addrs != NULL)
461 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100462 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000463 if (options->num_ports >= MAX_PORTS)
464 fatal("%s line %d: too many ports.",
465 filename, linenum);
466 arg = strdelim(&cp);
467 if (!arg || *arg == '\0')
468 fatal("%s line %d: missing port number.",
469 filename, linenum);
470 options->ports[options->num_ports++] = a2port(arg);
471 if (options->ports[options->num_ports-1] == 0)
472 fatal("%s line %d: Badly formatted port number.",
473 filename, linenum);
474 break;
475
476 case sServerKeyBits:
477 intptr = &options->server_key_bits;
478parse_int:
479 arg = strdelim(&cp);
480 if (!arg || *arg == '\0')
481 fatal("%s line %d: missing integer value.",
482 filename, linenum);
483 value = atoi(arg);
484 if (*intptr == -1)
485 *intptr = value;
486 break;
487
488 case sLoginGraceTime:
489 intptr = &options->login_grace_time;
490parse_time:
491 arg = strdelim(&cp);
492 if (!arg || *arg == '\0')
493 fatal("%s line %d: missing time value.",
494 filename, linenum);
495 if ((value = convtime(arg)) == -1)
496 fatal("%s line %d: invalid time value.",
497 filename, linenum);
498 if (*intptr == -1)
499 *intptr = value;
500 break;
501
502 case sKeyRegenerationTime:
503 intptr = &options->key_regeneration_time;
504 goto parse_time;
505
506 case sListenAddress:
507 arg = strdelim(&cp);
508 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
509 fatal("%s line %d: missing inet addr.",
510 filename, linenum);
511 if (*arg == '[') {
512 if ((p = strchr(arg, ']')) == NULL)
513 fatal("%s line %d: bad ipv6 inet addr usage.",
514 filename, linenum);
515 arg++;
516 memmove(p, p+1, strlen(p+1)+1);
517 } else if (((p = strchr(arg, ':')) == NULL) ||
518 (strchr(p+1, ':') != NULL)) {
519 add_listen_addr(options, arg, 0);
520 break;
521 }
522 if (*p == ':') {
523 u_short port;
524
525 p++;
526 if (*p == '\0')
527 fatal("%s line %d: bad inet addr:port usage.",
528 filename, linenum);
529 else {
530 *(p-1) = '\0';
531 if ((port = a2port(p)) == 0)
532 fatal("%s line %d: bad port number.",
533 filename, linenum);
534 add_listen_addr(options, arg, port);
535 }
536 } else if (*p == '\0')
537 add_listen_addr(options, arg, 0);
538 else
539 fatal("%s line %d: bad inet addr usage.",
540 filename, linenum);
541 break;
542
543 case sHostKeyFile:
544 intptr = &options->num_host_key_files;
545 if (*intptr >= MAX_HOSTKEYS)
546 fatal("%s line %d: too many host keys specified (max %d).",
547 filename, linenum, MAX_HOSTKEYS);
548 charptr = &options->host_key_files[*intptr];
549parse_filename:
550 arg = strdelim(&cp);
551 if (!arg || *arg == '\0')
552 fatal("%s line %d: missing file name.",
553 filename, linenum);
554 if (*charptr == NULL) {
555 *charptr = tilde_expand_filename(arg, getuid());
556 /* increase optional counter */
557 if (intptr != NULL)
558 *intptr = *intptr + 1;
559 }
560 break;
561
562 case sPidFile:
563 charptr = &options->pid_file;
564 goto parse_filename;
565
566 case sPermitRootLogin:
567 intptr = &options->permit_root_login;
568 arg = strdelim(&cp);
569 if (!arg || *arg == '\0')
570 fatal("%s line %d: missing yes/"
571 "without-password/forced-commands-only/no "
572 "argument.", filename, linenum);
573 value = 0; /* silence compiler */
574 if (strcmp(arg, "without-password") == 0)
575 value = PERMIT_NO_PASSWD;
576 else if (strcmp(arg, "forced-commands-only") == 0)
577 value = PERMIT_FORCED_ONLY;
578 else if (strcmp(arg, "yes") == 0)
579 value = PERMIT_YES;
580 else if (strcmp(arg, "no") == 0)
581 value = PERMIT_NO;
582 else
583 fatal("%s line %d: Bad yes/"
584 "without-password/forced-commands-only/no "
585 "argument: %s", filename, linenum, arg);
586 if (*intptr == -1)
587 *intptr = value;
588 break;
589
590 case sIgnoreRhosts:
591 intptr = &options->ignore_rhosts;
592parse_flag:
593 arg = strdelim(&cp);
594 if (!arg || *arg == '\0')
595 fatal("%s line %d: missing yes/no argument.",
596 filename, linenum);
597 value = 0; /* silence compiler */
598 if (strcmp(arg, "yes") == 0)
599 value = 1;
600 else if (strcmp(arg, "no") == 0)
601 value = 0;
602 else
603 fatal("%s line %d: Bad yes/no argument: %s",
604 filename, linenum, arg);
605 if (*intptr == -1)
606 *intptr = value;
607 break;
608
609 case sIgnoreUserKnownHosts:
610 intptr = &options->ignore_user_known_hosts;
611 goto parse_flag;
612
Ben Lindstromade03f62001-12-06 18:22:17 +0000613 case sRhostsRSAAuthentication:
614 intptr = &options->rhosts_rsa_authentication;
615 goto parse_flag;
616
617 case sHostbasedAuthentication:
618 intptr = &options->hostbased_authentication;
619 goto parse_flag;
620
621 case sHostbasedUsesNameFromPacketOnly:
622 intptr = &options->hostbased_uses_name_from_packet_only;
623 goto parse_flag;
624
625 case sRSAAuthentication:
626 intptr = &options->rsa_authentication;
627 goto parse_flag;
628
629 case sPubkeyAuthentication:
630 intptr = &options->pubkey_authentication;
631 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000632
Ben Lindstromade03f62001-12-06 18:22:17 +0000633 case sKerberosAuthentication:
634 intptr = &options->kerberos_authentication;
635 goto parse_flag;
636
637 case sKerberosOrLocalPasswd:
638 intptr = &options->kerberos_or_local_passwd;
639 goto parse_flag;
640
641 case sKerberosTicketCleanup:
642 intptr = &options->kerberos_ticket_cleanup;
643 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000644
Darren Tucker22ef5082003-12-31 11:37:34 +1100645 case sKerberosGetAFSToken:
646 intptr = &options->kerberos_get_afs_token;
647 goto parse_flag;
648
Darren Tucker0efd1552003-08-26 11:49:55 +1000649 case sGssAuthentication:
650 intptr = &options->gss_authentication;
651 goto parse_flag;
652
653 case sGssCleanupCreds:
654 intptr = &options->gss_cleanup_creds;
655 goto parse_flag;
656
Ben Lindstromade03f62001-12-06 18:22:17 +0000657 case sPasswordAuthentication:
658 intptr = &options->password_authentication;
659 goto parse_flag;
660
661 case sKbdInteractiveAuthentication:
662 intptr = &options->kbd_interactive_authentication;
663 goto parse_flag;
664
665 case sChallengeResponseAuthentication:
666 intptr = &options->challenge_response_authentication;
667 goto parse_flag;
668
669 case sPrintMotd:
670 intptr = &options->print_motd;
671 goto parse_flag;
672
673 case sPrintLastLog:
674 intptr = &options->print_lastlog;
675 goto parse_flag;
676
677 case sX11Forwarding:
678 intptr = &options->x11_forwarding;
679 goto parse_flag;
680
681 case sX11DisplayOffset:
682 intptr = &options->x11_display_offset;
683 goto parse_int;
684
Damien Miller95c249f2002-02-05 12:11:34 +1100685 case sX11UseLocalhost:
686 intptr = &options->x11_use_localhost;
687 goto parse_flag;
688
Ben Lindstromade03f62001-12-06 18:22:17 +0000689 case sXAuthLocation:
690 charptr = &options->xauth_location;
691 goto parse_filename;
692
693 case sStrictModes:
694 intptr = &options->strict_modes;
695 goto parse_flag;
696
Damien Miller12c150e2003-12-17 16:31:10 +1100697 case sTCPKeepAlive:
698 intptr = &options->tcp_keep_alive;
Ben Lindstromade03f62001-12-06 18:22:17 +0000699 goto parse_flag;
700
701 case sEmptyPasswd:
702 intptr = &options->permit_empty_passwd;
703 goto parse_flag;
704
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000705 case sPermitUserEnvironment:
706 intptr = &options->permit_user_env;
707 goto parse_flag;
708
Ben Lindstromade03f62001-12-06 18:22:17 +0000709 case sUseLogin:
710 intptr = &options->use_login;
711 goto parse_flag;
712
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000713 case sCompression:
714 intptr = &options->compression;
715 goto parse_flag;
716
Ben Lindstromade03f62001-12-06 18:22:17 +0000717 case sGatewayPorts:
718 intptr = &options->gateway_ports;
719 goto parse_flag;
720
Damien Miller3a961dc2003-06-03 10:25:48 +1000721 case sUseDNS:
722 intptr = &options->use_dns;
Ben Lindstromade03f62001-12-06 18:22:17 +0000723 goto parse_flag;
724
725 case sLogFacility:
726 intptr = (int *) &options->log_facility;
727 arg = strdelim(&cp);
728 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100729 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000730 fatal("%.200s line %d: unsupported log facility '%s'",
731 filename, linenum, arg ? arg : "<NONE>");
732 if (*intptr == -1)
733 *intptr = (SyslogFacility) value;
734 break;
735
736 case sLogLevel:
737 intptr = (int *) &options->log_level;
738 arg = strdelim(&cp);
739 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100740 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000741 fatal("%.200s line %d: unsupported log level '%s'",
742 filename, linenum, arg ? arg : "<NONE>");
743 if (*intptr == -1)
744 *intptr = (LogLevel) value;
745 break;
746
747 case sAllowTcpForwarding:
748 intptr = &options->allow_tcp_forwarding;
749 goto parse_flag;
750
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000751 case sUsePrivilegeSeparation:
752 intptr = &use_privsep;
753 goto parse_flag;
754
Ben Lindstromade03f62001-12-06 18:22:17 +0000755 case sAllowUsers:
756 while ((arg = strdelim(&cp)) && *arg != '\0') {
757 if (options->num_allow_users >= MAX_ALLOW_USERS)
758 fatal("%s line %d: too many allow users.",
759 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000760 options->allow_users[options->num_allow_users++] =
761 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000762 }
763 break;
764
765 case sDenyUsers:
766 while ((arg = strdelim(&cp)) && *arg != '\0') {
767 if (options->num_deny_users >= MAX_DENY_USERS)
768 fatal( "%s line %d: too many deny users.",
769 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000770 options->deny_users[options->num_deny_users++] =
771 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000772 }
773 break;
774
775 case sAllowGroups:
776 while ((arg = strdelim(&cp)) && *arg != '\0') {
777 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
778 fatal("%s line %d: too many allow groups.",
779 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000780 options->allow_groups[options->num_allow_groups++] =
781 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000782 }
783 break;
784
785 case sDenyGroups:
786 while ((arg = strdelim(&cp)) && *arg != '\0') {
787 if (options->num_deny_groups >= MAX_DENY_GROUPS)
788 fatal("%s line %d: too many deny groups.",
789 filename, linenum);
790 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
791 }
792 break;
793
794 case sCiphers:
795 arg = strdelim(&cp);
796 if (!arg || *arg == '\0')
797 fatal("%s line %d: Missing argument.", filename, linenum);
798 if (!ciphers_valid(arg))
799 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
800 filename, linenum, arg ? arg : "<NONE>");
801 if (options->ciphers == NULL)
802 options->ciphers = xstrdup(arg);
803 break;
804
805 case sMacs:
806 arg = strdelim(&cp);
807 if (!arg || *arg == '\0')
808 fatal("%s line %d: Missing argument.", filename, linenum);
809 if (!mac_valid(arg))
810 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
811 filename, linenum, arg ? arg : "<NONE>");
812 if (options->macs == NULL)
813 options->macs = xstrdup(arg);
814 break;
815
816 case sProtocol:
817 intptr = &options->protocol;
818 arg = strdelim(&cp);
819 if (!arg || *arg == '\0')
820 fatal("%s line %d: Missing argument.", filename, linenum);
821 value = proto_spec(arg);
822 if (value == SSH_PROTO_UNKNOWN)
823 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100824 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000825 if (*intptr == SSH_PROTO_UNKNOWN)
826 *intptr = value;
827 break;
828
829 case sSubsystem:
830 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
831 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100832 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000833 }
834 arg = strdelim(&cp);
835 if (!arg || *arg == '\0')
836 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100837 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000838 for (i = 0; i < options->num_subsystems; i++)
839 if (strcmp(arg, options->subsystem_name[i]) == 0)
840 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100841 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000842 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
843 arg = strdelim(&cp);
844 if (!arg || *arg == '\0')
845 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100846 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000847 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
848 options->num_subsystems++;
849 break;
850
851 case sMaxStartups:
852 arg = strdelim(&cp);
853 if (!arg || *arg == '\0')
854 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100855 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000856 if ((n = sscanf(arg, "%d:%d:%d",
857 &options->max_startups_begin,
858 &options->max_startups_rate,
859 &options->max_startups)) == 3) {
860 if (options->max_startups_begin >
861 options->max_startups ||
862 options->max_startups_rate > 100 ||
863 options->max_startups_rate < 1)
864 fatal("%s line %d: Illegal MaxStartups spec.",
865 filename, linenum);
866 } else if (n != 1)
867 fatal("%s line %d: Illegal MaxStartups spec.",
868 filename, linenum);
869 else
870 options->max_startups = options->max_startups_begin;
871 break;
872
873 case sBanner:
874 charptr = &options->banner;
875 goto parse_filename;
876 /*
877 * These options can contain %X options expanded at
878 * connect time, so that you can specify paths like:
879 *
880 * AuthorizedKeysFile /etc/ssh_keys/%u
881 */
882 case sAuthorizedKeysFile:
883 case sAuthorizedKeysFile2:
884 charptr = (opcode == sAuthorizedKeysFile ) ?
885 &options->authorized_keys_file :
886 &options->authorized_keys_file2;
887 goto parse_filename;
888
889 case sClientAliveInterval:
890 intptr = &options->client_alive_interval;
891 goto parse_time;
892
893 case sClientAliveCountMax:
894 intptr = &options->client_alive_count_max;
895 goto parse_int;
896
Darren Tucker46bc0752004-05-02 22:11:30 +1000897 case sAcceptEnv:
898 while ((arg = strdelim(&cp)) && *arg != '\0') {
899 if (strchr(arg, '=') != NULL)
900 fatal("%s line %d: Invalid environment name.",
901 filename, linenum);
902 if (options->num_accept_env >= MAX_ACCEPT_ENV)
903 fatal("%s line %d: too many allow env.",
904 filename, linenum);
905 options->accept_env[options->num_accept_env++] =
906 xstrdup(arg);
907 }
908 break;
909
Ben Lindstromade03f62001-12-06 18:22:17 +0000910 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000911 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000912 filename, linenum, arg);
913 while (arg)
914 arg = strdelim(&cp);
915 break;
916
Damien Millerf9b3feb2003-05-16 11:38:32 +1000917 case sUnsupported:
918 logit("%s line %d: Unsupported option %s",
919 filename, linenum, arg);
920 while (arg)
921 arg = strdelim(&cp);
922 break;
923
Ben Lindstromade03f62001-12-06 18:22:17 +0000924 default:
925 fatal("%s line %d: Missing handler for opcode %s (%d)",
926 filename, linenum, arg, opcode);
927 }
928 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
929 fatal("%s line %d: garbage at end of line; \"%.200s\".",
930 filename, linenum, arg);
931 return 0;
932}
933
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000934/* Reads the server configuration file. */
935
Damien Miller4af51302000-04-16 11:18:38 +1000936void
Damien Miller95def091999-11-25 00:26:21 +1100937read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000938{
Ben Lindstrome1353632002-06-23 21:29:23 +0000939 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100940 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000941 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000942
Damien Miller9f82c8f2003-02-24 12:04:33 +1100943 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100944 f = fopen(filename, "r");
945 if (!f) {
946 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000947 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100948 }
949 linenum = 0;
950 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000951 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100952 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000953 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100954 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000955 }
Damien Miller95def091999-11-25 00:26:21 +1100956 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000957 if (bad_options > 0)
958 fatal("%s: terminating, %d bad configuration options",
959 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000960}