blob: fbdc4d8faba7d7b5a3b4ccea81230e6311f672eb [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 Millerd5580922003-05-14 13:40:06 +100013RCSID("$OpenBSD: servconf.c,v 1.118 2003/04/09 08:23:52 hin Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
Damien Millerfd4c9ee2002-04-13 11:04:40 +100015#if defined(KRB4)
Ben Lindstrom226cfa02001-01-22 05:34:40 +000016#include <krb.h>
17#endif
Damien Millerd5580922003-05-14 13:40:06 +100018
Damien Millerfd4c9ee2002-04-13 11:04:40 +100019#if defined(KRB5)
Damien Millerd5580922003-05-14 13:40:06 +100020# ifdef HEIMDAL
21# include <krb.h>
22# else
23/*
24 * XXX: Bodge - but then, so is using the kerberos IV KEYFILE to get a
25 * Kerberos V keytab
26 */
27# define KEYFILE "/etc/krb5.keytab"
28# endif
Damien Millerfd4c9ee2002-04-13 11:04:40 +100029#endif
Damien Millerd5580922003-05-14 13:40:06 +100030
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000031#ifdef AFS
32#include <kafs.h>
33#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100034
35#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100037#include "servconf.h"
38#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100039#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "pathnames.h"
41#include "tildexpand.h"
42#include "misc.h"
43#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000044#include "kex.h"
45#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046
Ben Lindstrombba81212001-06-25 05:01:22 +000047static void add_listen_addr(ServerOptions *, char *, u_short);
48static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110049
Ben Lindstrom226cfa02001-01-22 05:34:40 +000050/* AF_UNSPEC or AF_INET or AF_INET6 */
51extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000052/* Use of privilege separation or not */
53extern int use_privsep;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000054
Damien Millerd4a8b7e1999-10-27 13:42:43 +100055/* Initializes the server options to their default values. */
56
Damien Miller4af51302000-04-16 11:18:38 +100057void
Damien Miller95def091999-11-25 00:26:21 +110058initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100059{
Damien Miller95def091999-11-25 00:26:21 +110060 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110061
Damien Miller4e448a32003-05-14 15:11:48 +100062#ifdef USE_PAM
Damien Miller726273e2001-11-12 11:40:11 +110063 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +100064 options->use_pam = -1;
65#endif
Damien Miller726273e2001-11-12 11:40:11 +110066
67 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110068 options->num_ports = 0;
69 options->ports_from_cmdline = 0;
70 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110071 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100072 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110073 options->server_key_bits = -1;
74 options->login_grace_time = -1;
75 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000076 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110077 options->ignore_rhosts = -1;
78 options->ignore_user_known_hosts = -1;
79 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000080 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110081 options->x11_forwarding = -1;
82 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110083 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100084 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110085 options->strict_modes = -1;
86 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110087 options->log_facility = SYSLOG_FACILITY_NOT_SET;
88 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110089 options->rhosts_authentication = -1;
90 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000091 options->hostbased_authentication = -1;
92 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110093 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110094 options->pubkey_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000095#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110096 options->kerberos_authentication = -1;
97 options->kerberos_or_local_passwd = -1;
98 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100099#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000100#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100101 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000102#endif
103#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100104 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105#endif
Damien Miller95def091999-11-25 00:26:21 +1100106 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100107 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000108 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100109 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000110 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100111 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000112 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100113 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100114 options->num_allow_users = 0;
115 options->num_deny_users = 0;
116 options->num_allow_groups = 0;
117 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000118 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000119 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000120 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000121 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000122 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000123 options->max_startups_begin = -1;
124 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000125 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000126 options->banner = NULL;
Damien Millerc5d86352002-02-05 12:13:41 +1100127 options->verify_reverse_mapping = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000128 options->client_alive_interval = -1;
129 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000130 options->authorized_keys_file = NULL;
131 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000132
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000133 /* Needs to be accessable in many places */
134 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000135}
136
Damien Miller4af51302000-04-16 11:18:38 +1000137void
Damien Miller95def091999-11-25 00:26:21 +1100138fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000139{
Damien Miller726273e2001-11-12 11:40:11 +1100140 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000141#ifdef USE_PAM
142 if (options->use_pam == -1)
143 options->use_pam = 1;
144#endif
Damien Miller726273e2001-11-12 11:40:11 +1100145
146 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100147 if (options->protocol == SSH_PROTO_UNKNOWN)
148 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
149 if (options->num_host_key_files == 0) {
150 /* fill default hostkeys for protocols */
151 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100152 options->host_key_files[options->num_host_key_files++] =
153 _PATH_HOST_KEY_FILE;
154 if (options->protocol & SSH_PROTO_2) {
155 options->host_key_files[options->num_host_key_files++] =
156 _PATH_HOST_RSA_KEY_FILE;
157 options->host_key_files[options->num_host_key_files++] =
158 _PATH_HOST_DSA_KEY_FILE;
159 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100160 }
Damien Miller34132e52000-01-14 15:45:46 +1100161 if (options->num_ports == 0)
162 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
163 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000164 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000165 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000166 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->server_key_bits == -1)
168 options->server_key_bits = 768;
169 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000170 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->key_regeneration_time == -1)
172 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000173 if (options->permit_root_login == PERMIT_NOT_SET)
174 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100175 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100176 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100177 if (options->ignore_user_known_hosts == -1)
178 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->print_motd == -1)
180 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000181 if (options->print_lastlog == -1)
182 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100183 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100184 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100186 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100187 if (options->x11_use_localhost == -1)
188 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000189 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000190 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100191 if (options->strict_modes == -1)
192 options->strict_modes = 1;
193 if (options->keepalives == -1)
194 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100195 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100196 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100197 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000198 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100199 if (options->rhosts_authentication == -1)
200 options->rhosts_authentication = 0;
201 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100202 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000203 if (options->hostbased_authentication == -1)
204 options->hostbased_authentication = 0;
205 if (options->hostbased_uses_name_from_packet_only == -1)
206 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100207 if (options->rsa_authentication == -1)
208 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100209 if (options->pubkey_authentication == -1)
210 options->pubkey_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000211#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100212 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000213 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100214 if (options->kerberos_or_local_passwd == -1)
215 options->kerberos_or_local_passwd = 1;
216 if (options->kerberos_ticket_cleanup == -1)
217 options->kerberos_ticket_cleanup = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000218#endif
219#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->kerberos_tgt_passing == -1)
221 options->kerberos_tgt_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000222#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100223#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100224 if (options->afs_token_passing == -1)
Damien Millere4ccf102002-04-23 20:40:28 +1000225 options->afs_token_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000226#endif
Damien Miller95def091999-11-25 00:26:21 +1100227 if (options->password_authentication == -1)
228 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100229 if (options->kbd_interactive_authentication == -1)
230 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000231 if (options->challenge_response_authentication == -1)
232 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100233 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100234 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000235 if (options->permit_user_env == -1)
236 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100237 if (options->use_login == -1)
238 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000239 if (options->compression == -1)
240 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100241 if (options->allow_tcp_forwarding == -1)
242 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000243 if (options->gateway_ports == -1)
244 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000245 if (options->max_startups == -1)
246 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000247 if (options->max_startups_rate == -1)
248 options->max_startups_rate = 100; /* 100% */
249 if (options->max_startups_begin == -1)
250 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100251 if (options->verify_reverse_mapping == -1)
252 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000253 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100254 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000255 if (options->client_alive_count_max == -1)
256 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100257 if (options->authorized_keys_file2 == NULL) {
258 /* authorized_keys_file2 falls back to authorized_keys_file */
259 if (options->authorized_keys_file != NULL)
260 options->authorized_keys_file2 = options->authorized_keys_file;
261 else
262 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
263 }
264 if (options->authorized_keys_file == NULL)
265 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000266
Ben Lindstromfb62a692002-06-06 19:47:11 +0000267 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000268 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000269 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000270
Tim Rice40017b02002-07-14 13:36:49 -0700271#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000272 if (use_privsep && options->compression == 1) {
273 error("This platform does not support both privilege "
274 "separation and compression");
275 error("Compression disabled");
276 options->compression = 0;
277 }
278#endif
279
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000280}
281
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000282/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100283typedef enum {
284 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100285 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000286 sUsePAM,
Damien Miller726273e2001-11-12 11:40:11 +1100287 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100288 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
289 sPermitRootLogin, sLogFacility, sLogLevel,
290 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000291#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100292 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000293#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000294#if defined(AFS) || defined(KRB5)
295 sKerberosTgtPassing,
296#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000297#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000298 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000299#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000300 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100301 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000302 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100303 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000304 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000305 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100306 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000307 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100308 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100309 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100310 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000311 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000312 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000313 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000314} ServerOpCodes;
315
316/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100317static struct {
318 const char *name;
319 ServerOpCodes opcode;
320} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100321 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000322 { "UsePAM", sUsePAM },
Damien Miller726273e2001-11-12 11:40:11 +1100323 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100324 { "port", sPort },
325 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100326 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000327 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100328 { "serverkeybits", sServerKeyBits },
329 { "logingracetime", sLoginGraceTime },
330 { "keyregenerationinterval", sKeyRegenerationTime },
331 { "permitrootlogin", sPermitRootLogin },
332 { "syslogfacility", sLogFacility },
333 { "loglevel", sLogLevel },
334 { "rhostsauthentication", sRhostsAuthentication },
335 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000336 { "hostbasedauthentication", sHostbasedAuthentication },
337 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100338 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100339 { "pubkeyauthentication", sPubkeyAuthentication },
340 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000341#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100342 { "kerberosauthentication", sKerberosAuthentication },
343 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
344 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000345#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000346#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100347 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000348#endif
349#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100350 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000351#endif
Damien Miller95def091999-11-25 00:26:21 +1100352 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100353 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000354 { "challengeresponseauthentication", sChallengeResponseAuthentication },
355 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000356 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100357 { "listenaddress", sListenAddress },
358 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000359 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100360 { "ignorerhosts", sIgnoreRhosts },
361 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
362 { "x11forwarding", sX11Forwarding },
363 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100364 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000365 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100366 { "strictmodes", sStrictModes },
367 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000368 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100369 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000370 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100371 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100372 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100373 { "allowusers", sAllowUsers },
374 { "denyusers", sDenyUsers },
375 { "allowgroups", sAllowGroups },
376 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000377 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000378 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000379 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000380 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000381 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000382 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000383 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100384 { "verifyreversemapping", sVerifyReverseMapping },
385 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000386 { "clientaliveinterval", sClientAliveInterval },
387 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000388 { "authorizedkeysfile", sAuthorizedKeysFile },
389 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000390 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000391 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000392};
393
Damien Miller5428f641999-11-25 11:54:57 +1100394/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000395 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100396 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000397
Damien Miller4af51302000-04-16 11:18:38 +1000398static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100399parse_token(const char *cp, const char *filename,
400 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000402 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000403
Damien Miller95def091999-11-25 00:26:21 +1100404 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100405 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100406 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000407
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000408 error("%s: line %d: Bad configuration option: %s",
409 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100410 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000411}
412
Ben Lindstrombba81212001-06-25 05:01:22 +0000413static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000414add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100415{
Damien Miller34132e52000-01-14 15:45:46 +1100416 int i;
417
418 if (options->num_ports == 0)
419 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000420 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000421 for (i = 0; i < options->num_ports; i++)
422 add_one_listen_addr(options, addr, options->ports[i]);
423 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000424 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000425}
426
Ben Lindstrombba81212001-06-25 05:01:22 +0000427static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000428add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
429{
430 struct addrinfo hints, *ai, *aitop;
431 char strport[NI_MAXSERV];
432 int gaierr;
433
434 memset(&hints, 0, sizeof(hints));
435 hints.ai_family = IPv4or6;
436 hints.ai_socktype = SOCK_STREAM;
437 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000438 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000439 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
440 fatal("bad addr or host: %s (%s)",
441 addr ? addr : "<NULL>",
442 gai_strerror(gaierr));
443 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
444 ;
445 ai->ai_next = options->listen_addrs;
446 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100447}
448
Ben Lindstromade03f62001-12-06 18:22:17 +0000449int
450process_server_config_line(ServerOptions *options, char *line,
451 const char *filename, int linenum)
452{
453 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000454 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000455 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000456
457 cp = line;
458 arg = strdelim(&cp);
459 /* Ignore leading whitespace */
460 if (*arg == '\0')
461 arg = strdelim(&cp);
462 if (!arg || !*arg || *arg == '#')
463 return 0;
464 intptr = NULL;
465 charptr = NULL;
466 opcode = parse_token(arg, filename, linenum);
467 switch (opcode) {
468 /* Portable-specific options */
Damien Miller4e448a32003-05-14 15:11:48 +1000469 case sUsePAM:
470 intptr = &options->use_pam;
Ben Lindstromade03f62001-12-06 18:22:17 +0000471 goto parse_flag;
472
473 /* Standard Options */
474 case sBadOption:
475 return -1;
476 case sPort:
477 /* ignore ports from configfile if cmdline specifies ports */
478 if (options->ports_from_cmdline)
479 return 0;
480 if (options->listen_addrs != NULL)
481 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100482 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000483 if (options->num_ports >= MAX_PORTS)
484 fatal("%s line %d: too many ports.",
485 filename, linenum);
486 arg = strdelim(&cp);
487 if (!arg || *arg == '\0')
488 fatal("%s line %d: missing port number.",
489 filename, linenum);
490 options->ports[options->num_ports++] = a2port(arg);
491 if (options->ports[options->num_ports-1] == 0)
492 fatal("%s line %d: Badly formatted port number.",
493 filename, linenum);
494 break;
495
496 case sServerKeyBits:
497 intptr = &options->server_key_bits;
498parse_int:
499 arg = strdelim(&cp);
500 if (!arg || *arg == '\0')
501 fatal("%s line %d: missing integer value.",
502 filename, linenum);
503 value = atoi(arg);
504 if (*intptr == -1)
505 *intptr = value;
506 break;
507
508 case sLoginGraceTime:
509 intptr = &options->login_grace_time;
510parse_time:
511 arg = strdelim(&cp);
512 if (!arg || *arg == '\0')
513 fatal("%s line %d: missing time value.",
514 filename, linenum);
515 if ((value = convtime(arg)) == -1)
516 fatal("%s line %d: invalid time value.",
517 filename, linenum);
518 if (*intptr == -1)
519 *intptr = value;
520 break;
521
522 case sKeyRegenerationTime:
523 intptr = &options->key_regeneration_time;
524 goto parse_time;
525
526 case sListenAddress:
527 arg = strdelim(&cp);
528 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
529 fatal("%s line %d: missing inet addr.",
530 filename, linenum);
531 if (*arg == '[') {
532 if ((p = strchr(arg, ']')) == NULL)
533 fatal("%s line %d: bad ipv6 inet addr usage.",
534 filename, linenum);
535 arg++;
536 memmove(p, p+1, strlen(p+1)+1);
537 } else if (((p = strchr(arg, ':')) == NULL) ||
538 (strchr(p+1, ':') != NULL)) {
539 add_listen_addr(options, arg, 0);
540 break;
541 }
542 if (*p == ':') {
543 u_short port;
544
545 p++;
546 if (*p == '\0')
547 fatal("%s line %d: bad inet addr:port usage.",
548 filename, linenum);
549 else {
550 *(p-1) = '\0';
551 if ((port = a2port(p)) == 0)
552 fatal("%s line %d: bad port number.",
553 filename, linenum);
554 add_listen_addr(options, arg, port);
555 }
556 } else if (*p == '\0')
557 add_listen_addr(options, arg, 0);
558 else
559 fatal("%s line %d: bad inet addr usage.",
560 filename, linenum);
561 break;
562
563 case sHostKeyFile:
564 intptr = &options->num_host_key_files;
565 if (*intptr >= MAX_HOSTKEYS)
566 fatal("%s line %d: too many host keys specified (max %d).",
567 filename, linenum, MAX_HOSTKEYS);
568 charptr = &options->host_key_files[*intptr];
569parse_filename:
570 arg = strdelim(&cp);
571 if (!arg || *arg == '\0')
572 fatal("%s line %d: missing file name.",
573 filename, linenum);
574 if (*charptr == NULL) {
575 *charptr = tilde_expand_filename(arg, getuid());
576 /* increase optional counter */
577 if (intptr != NULL)
578 *intptr = *intptr + 1;
579 }
580 break;
581
582 case sPidFile:
583 charptr = &options->pid_file;
584 goto parse_filename;
585
586 case sPermitRootLogin:
587 intptr = &options->permit_root_login;
588 arg = strdelim(&cp);
589 if (!arg || *arg == '\0')
590 fatal("%s line %d: missing yes/"
591 "without-password/forced-commands-only/no "
592 "argument.", filename, linenum);
593 value = 0; /* silence compiler */
594 if (strcmp(arg, "without-password") == 0)
595 value = PERMIT_NO_PASSWD;
596 else if (strcmp(arg, "forced-commands-only") == 0)
597 value = PERMIT_FORCED_ONLY;
598 else if (strcmp(arg, "yes") == 0)
599 value = PERMIT_YES;
600 else if (strcmp(arg, "no") == 0)
601 value = PERMIT_NO;
602 else
603 fatal("%s line %d: Bad yes/"
604 "without-password/forced-commands-only/no "
605 "argument: %s", filename, linenum, arg);
606 if (*intptr == -1)
607 *intptr = value;
608 break;
609
610 case sIgnoreRhosts:
611 intptr = &options->ignore_rhosts;
612parse_flag:
613 arg = strdelim(&cp);
614 if (!arg || *arg == '\0')
615 fatal("%s line %d: missing yes/no argument.",
616 filename, linenum);
617 value = 0; /* silence compiler */
618 if (strcmp(arg, "yes") == 0)
619 value = 1;
620 else if (strcmp(arg, "no") == 0)
621 value = 0;
622 else
623 fatal("%s line %d: Bad yes/no argument: %s",
624 filename, linenum, arg);
625 if (*intptr == -1)
626 *intptr = value;
627 break;
628
629 case sIgnoreUserKnownHosts:
630 intptr = &options->ignore_user_known_hosts;
631 goto parse_flag;
632
633 case sRhostsAuthentication:
634 intptr = &options->rhosts_authentication;
635 goto parse_flag;
636
637 case sRhostsRSAAuthentication:
638 intptr = &options->rhosts_rsa_authentication;
639 goto parse_flag;
640
641 case sHostbasedAuthentication:
642 intptr = &options->hostbased_authentication;
643 goto parse_flag;
644
645 case sHostbasedUsesNameFromPacketOnly:
646 intptr = &options->hostbased_uses_name_from_packet_only;
647 goto parse_flag;
648
649 case sRSAAuthentication:
650 intptr = &options->rsa_authentication;
651 goto parse_flag;
652
653 case sPubkeyAuthentication:
654 intptr = &options->pubkey_authentication;
655 goto parse_flag;
656#if defined(KRB4) || defined(KRB5)
657 case sKerberosAuthentication:
658 intptr = &options->kerberos_authentication;
659 goto parse_flag;
660
661 case sKerberosOrLocalPasswd:
662 intptr = &options->kerberos_or_local_passwd;
663 goto parse_flag;
664
665 case sKerberosTicketCleanup:
666 intptr = &options->kerberos_ticket_cleanup;
667 goto parse_flag;
668#endif
669#if defined(AFS) || defined(KRB5)
670 case sKerberosTgtPassing:
671 intptr = &options->kerberos_tgt_passing;
672 goto parse_flag;
673#endif
674#ifdef AFS
675 case sAFSTokenPassing:
676 intptr = &options->afs_token_passing;
677 goto parse_flag;
678#endif
679
680 case sPasswordAuthentication:
681 intptr = &options->password_authentication;
682 goto parse_flag;
683
684 case sKbdInteractiveAuthentication:
685 intptr = &options->kbd_interactive_authentication;
686 goto parse_flag;
687
688 case sChallengeResponseAuthentication:
689 intptr = &options->challenge_response_authentication;
690 goto parse_flag;
691
692 case sPrintMotd:
693 intptr = &options->print_motd;
694 goto parse_flag;
695
696 case sPrintLastLog:
697 intptr = &options->print_lastlog;
698 goto parse_flag;
699
700 case sX11Forwarding:
701 intptr = &options->x11_forwarding;
702 goto parse_flag;
703
704 case sX11DisplayOffset:
705 intptr = &options->x11_display_offset;
706 goto parse_int;
707
Damien Miller95c249f2002-02-05 12:11:34 +1100708 case sX11UseLocalhost:
709 intptr = &options->x11_use_localhost;
710 goto parse_flag;
711
Ben Lindstromade03f62001-12-06 18:22:17 +0000712 case sXAuthLocation:
713 charptr = &options->xauth_location;
714 goto parse_filename;
715
716 case sStrictModes:
717 intptr = &options->strict_modes;
718 goto parse_flag;
719
720 case sKeepAlives:
721 intptr = &options->keepalives;
722 goto parse_flag;
723
724 case sEmptyPasswd:
725 intptr = &options->permit_empty_passwd;
726 goto parse_flag;
727
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000728 case sPermitUserEnvironment:
729 intptr = &options->permit_user_env;
730 goto parse_flag;
731
Ben Lindstromade03f62001-12-06 18:22:17 +0000732 case sUseLogin:
733 intptr = &options->use_login;
734 goto parse_flag;
735
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000736 case sCompression:
737 intptr = &options->compression;
738 goto parse_flag;
739
Ben Lindstromade03f62001-12-06 18:22:17 +0000740 case sGatewayPorts:
741 intptr = &options->gateway_ports;
742 goto parse_flag;
743
Damien Millerc5d86352002-02-05 12:13:41 +1100744 case sVerifyReverseMapping:
745 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000746 goto parse_flag;
747
748 case sLogFacility:
749 intptr = (int *) &options->log_facility;
750 arg = strdelim(&cp);
751 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100752 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000753 fatal("%.200s line %d: unsupported log facility '%s'",
754 filename, linenum, arg ? arg : "<NONE>");
755 if (*intptr == -1)
756 *intptr = (SyslogFacility) value;
757 break;
758
759 case sLogLevel:
760 intptr = (int *) &options->log_level;
761 arg = strdelim(&cp);
762 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100763 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000764 fatal("%.200s line %d: unsupported log level '%s'",
765 filename, linenum, arg ? arg : "<NONE>");
766 if (*intptr == -1)
767 *intptr = (LogLevel) value;
768 break;
769
770 case sAllowTcpForwarding:
771 intptr = &options->allow_tcp_forwarding;
772 goto parse_flag;
773
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000774 case sUsePrivilegeSeparation:
775 intptr = &use_privsep;
776 goto parse_flag;
777
Ben Lindstromade03f62001-12-06 18:22:17 +0000778 case sAllowUsers:
779 while ((arg = strdelim(&cp)) && *arg != '\0') {
780 if (options->num_allow_users >= MAX_ALLOW_USERS)
781 fatal("%s line %d: too many allow users.",
782 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000783 options->allow_users[options->num_allow_users++] =
784 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000785 }
786 break;
787
788 case sDenyUsers:
789 while ((arg = strdelim(&cp)) && *arg != '\0') {
790 if (options->num_deny_users >= MAX_DENY_USERS)
791 fatal( "%s line %d: too many deny users.",
792 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000793 options->deny_users[options->num_deny_users++] =
794 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000795 }
796 break;
797
798 case sAllowGroups:
799 while ((arg = strdelim(&cp)) && *arg != '\0') {
800 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
801 fatal("%s line %d: too many allow groups.",
802 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000803 options->allow_groups[options->num_allow_groups++] =
804 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000805 }
806 break;
807
808 case sDenyGroups:
809 while ((arg = strdelim(&cp)) && *arg != '\0') {
810 if (options->num_deny_groups >= MAX_DENY_GROUPS)
811 fatal("%s line %d: too many deny groups.",
812 filename, linenum);
813 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
814 }
815 break;
816
817 case sCiphers:
818 arg = strdelim(&cp);
819 if (!arg || *arg == '\0')
820 fatal("%s line %d: Missing argument.", filename, linenum);
821 if (!ciphers_valid(arg))
822 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
823 filename, linenum, arg ? arg : "<NONE>");
824 if (options->ciphers == NULL)
825 options->ciphers = xstrdup(arg);
826 break;
827
828 case sMacs:
829 arg = strdelim(&cp);
830 if (!arg || *arg == '\0')
831 fatal("%s line %d: Missing argument.", filename, linenum);
832 if (!mac_valid(arg))
833 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
834 filename, linenum, arg ? arg : "<NONE>");
835 if (options->macs == NULL)
836 options->macs = xstrdup(arg);
837 break;
838
839 case sProtocol:
840 intptr = &options->protocol;
841 arg = strdelim(&cp);
842 if (!arg || *arg == '\0')
843 fatal("%s line %d: Missing argument.", filename, linenum);
844 value = proto_spec(arg);
845 if (value == SSH_PROTO_UNKNOWN)
846 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100847 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000848 if (*intptr == SSH_PROTO_UNKNOWN)
849 *intptr = value;
850 break;
851
852 case sSubsystem:
853 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
854 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100855 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000856 }
857 arg = strdelim(&cp);
858 if (!arg || *arg == '\0')
859 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100860 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000861 for (i = 0; i < options->num_subsystems; i++)
862 if (strcmp(arg, options->subsystem_name[i]) == 0)
863 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100864 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000865 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
866 arg = strdelim(&cp);
867 if (!arg || *arg == '\0')
868 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100869 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000870 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
871 options->num_subsystems++;
872 break;
873
874 case sMaxStartups:
875 arg = strdelim(&cp);
876 if (!arg || *arg == '\0')
877 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100878 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000879 if ((n = sscanf(arg, "%d:%d:%d",
880 &options->max_startups_begin,
881 &options->max_startups_rate,
882 &options->max_startups)) == 3) {
883 if (options->max_startups_begin >
884 options->max_startups ||
885 options->max_startups_rate > 100 ||
886 options->max_startups_rate < 1)
887 fatal("%s line %d: Illegal MaxStartups spec.",
888 filename, linenum);
889 } else if (n != 1)
890 fatal("%s line %d: Illegal MaxStartups spec.",
891 filename, linenum);
892 else
893 options->max_startups = options->max_startups_begin;
894 break;
895
896 case sBanner:
897 charptr = &options->banner;
898 goto parse_filename;
899 /*
900 * These options can contain %X options expanded at
901 * connect time, so that you can specify paths like:
902 *
903 * AuthorizedKeysFile /etc/ssh_keys/%u
904 */
905 case sAuthorizedKeysFile:
906 case sAuthorizedKeysFile2:
907 charptr = (opcode == sAuthorizedKeysFile ) ?
908 &options->authorized_keys_file :
909 &options->authorized_keys_file2;
910 goto parse_filename;
911
912 case sClientAliveInterval:
913 intptr = &options->client_alive_interval;
914 goto parse_time;
915
916 case sClientAliveCountMax:
917 intptr = &options->client_alive_count_max;
918 goto parse_int;
919
920 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000921 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000922 filename, linenum, arg);
923 while (arg)
924 arg = strdelim(&cp);
925 break;
926
927 default:
928 fatal("%s line %d: Missing handler for opcode %s (%d)",
929 filename, linenum, arg, opcode);
930 }
931 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
932 fatal("%s line %d: garbage at end of line; \"%.200s\".",
933 filename, linenum, arg);
934 return 0;
935}
936
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000937/* Reads the server configuration file. */
938
Damien Miller4af51302000-04-16 11:18:38 +1000939void
Damien Miller95def091999-11-25 00:26:21 +1100940read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000941{
Ben Lindstrome1353632002-06-23 21:29:23 +0000942 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100943 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000944 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000945
Damien Miller9f82c8f2003-02-24 12:04:33 +1100946 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100947 f = fopen(filename, "r");
948 if (!f) {
949 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000950 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100951 }
952 linenum = 0;
953 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000954 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100955 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000956 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100957 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000958 }
Damien Miller95def091999-11-25 00:26:21 +1100959 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000960 if (bad_options > 0)
961 fatal("%s: terminating, %d bad configuration options",
962 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000963}