blob: 8e2839085b08a4be114a0cfbe19711b289014be5 [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
62 /* Portable-specific options */
63 options->pam_authentication_via_kbd_int = -1;
64
65 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110066 options->num_ports = 0;
67 options->ports_from_cmdline = 0;
68 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110069 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100070 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110071 options->server_key_bits = -1;
72 options->login_grace_time = -1;
73 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000074 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110075 options->ignore_rhosts = -1;
76 options->ignore_user_known_hosts = -1;
77 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000078 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110079 options->x11_forwarding = -1;
80 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110081 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100082 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110083 options->strict_modes = -1;
84 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110085 options->log_facility = SYSLOG_FACILITY_NOT_SET;
86 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110087 options->rhosts_authentication = -1;
88 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000089 options->hostbased_authentication = -1;
90 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110091 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110092 options->pubkey_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000093#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110094 options->kerberos_authentication = -1;
95 options->kerberos_or_local_passwd = -1;
96 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100097#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +000098#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110099 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000100#endif
101#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100102 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000103#endif
Damien Miller95def091999-11-25 00:26:21 +1100104 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100105 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000106 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100107 options->permit_empty_passwd = -1;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000108 options->permit_user_env = -1;
Damien Miller95def091999-11-25 00:26:21 +1100109 options->use_login = -1;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000110 options->compression = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100111 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100112 options->num_allow_users = 0;
113 options->num_deny_users = 0;
114 options->num_allow_groups = 0;
115 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000116 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000117 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000118 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000119 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000120 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000121 options->max_startups_begin = -1;
122 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000123 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000124 options->banner = NULL;
Damien Millerc5d86352002-02-05 12:13:41 +1100125 options->verify_reverse_mapping = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000126 options->client_alive_interval = -1;
127 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000128 options->authorized_keys_file = NULL;
129 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000130
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000131 /* Needs to be accessable in many places */
132 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000133}
134
Damien Miller4af51302000-04-16 11:18:38 +1000135void
Damien Miller95def091999-11-25 00:26:21 +1100136fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000137{
Damien Miller726273e2001-11-12 11:40:11 +1100138 /* Portable-specific options */
139 if (options->pam_authentication_via_kbd_int == -1)
140 options->pam_authentication_via_kbd_int = 0;
141
142 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100143 if (options->protocol == SSH_PROTO_UNKNOWN)
144 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
145 if (options->num_host_key_files == 0) {
146 /* fill default hostkeys for protocols */
147 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100148 options->host_key_files[options->num_host_key_files++] =
149 _PATH_HOST_KEY_FILE;
150 if (options->protocol & SSH_PROTO_2) {
151 options->host_key_files[options->num_host_key_files++] =
152 _PATH_HOST_RSA_KEY_FILE;
153 options->host_key_files[options->num_host_key_files++] =
154 _PATH_HOST_DSA_KEY_FILE;
155 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100156 }
Damien Miller34132e52000-01-14 15:45:46 +1100157 if (options->num_ports == 0)
158 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
159 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000160 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000161 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000162 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100163 if (options->server_key_bits == -1)
164 options->server_key_bits = 768;
165 if (options->login_grace_time == -1)
Damien Millerc1348632002-09-05 14:35:14 +1000166 options->login_grace_time = 120;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->key_regeneration_time == -1)
168 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000169 if (options->permit_root_login == PERMIT_NOT_SET)
170 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100171 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100172 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->ignore_user_known_hosts == -1)
174 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100175 if (options->print_motd == -1)
176 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000177 if (options->print_lastlog == -1)
178 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100179 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100180 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100181 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100182 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100183 if (options->x11_use_localhost == -1)
184 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000185 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000186 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100187 if (options->strict_modes == -1)
188 options->strict_modes = 1;
189 if (options->keepalives == -1)
190 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100191 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100192 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100193 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000194 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100195 if (options->rhosts_authentication == -1)
196 options->rhosts_authentication = 0;
197 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100198 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000199 if (options->hostbased_authentication == -1)
200 options->hostbased_authentication = 0;
201 if (options->hostbased_uses_name_from_packet_only == -1)
202 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100203 if (options->rsa_authentication == -1)
204 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100205 if (options->pubkey_authentication == -1)
206 options->pubkey_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000207#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000209 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->kerberos_or_local_passwd == -1)
211 options->kerberos_or_local_passwd = 1;
212 if (options->kerberos_ticket_cleanup == -1)
213 options->kerberos_ticket_cleanup = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000214#endif
215#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100216 if (options->kerberos_tgt_passing == -1)
217 options->kerberos_tgt_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000218#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100219#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100220 if (options->afs_token_passing == -1)
Damien Millere4ccf102002-04-23 20:40:28 +1000221 options->afs_token_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000222#endif
Damien Miller95def091999-11-25 00:26:21 +1100223 if (options->password_authentication == -1)
224 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100225 if (options->kbd_interactive_authentication == -1)
226 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000227 if (options->challenge_response_authentication == -1)
228 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100229 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100230 options->permit_empty_passwd = 0;
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000231 if (options->permit_user_env == -1)
232 options->permit_user_env = 0;
Damien Miller95def091999-11-25 00:26:21 +1100233 if (options->use_login == -1)
234 options->use_login = 0;
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000235 if (options->compression == -1)
236 options->compression = 1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100237 if (options->allow_tcp_forwarding == -1)
238 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000239 if (options->gateway_ports == -1)
240 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000241 if (options->max_startups == -1)
242 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000243 if (options->max_startups_rate == -1)
244 options->max_startups_rate = 100; /* 100% */
245 if (options->max_startups_begin == -1)
246 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100247 if (options->verify_reverse_mapping == -1)
248 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000249 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100250 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000251 if (options->client_alive_count_max == -1)
252 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100253 if (options->authorized_keys_file2 == NULL) {
254 /* authorized_keys_file2 falls back to authorized_keys_file */
255 if (options->authorized_keys_file != NULL)
256 options->authorized_keys_file2 = options->authorized_keys_file;
257 else
258 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
259 }
260 if (options->authorized_keys_file == NULL)
261 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000262
Ben Lindstromfb62a692002-06-06 19:47:11 +0000263 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000264 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000265 use_privsep = 1;
Damien Miller4903eb42002-06-21 16:20:44 +1000266
Tim Rice40017b02002-07-14 13:36:49 -0700267#ifndef HAVE_MMAP
Damien Miller4903eb42002-06-21 16:20:44 +1000268 if (use_privsep && options->compression == 1) {
269 error("This platform does not support both privilege "
270 "separation and compression");
271 error("Compression disabled");
272 options->compression = 0;
273 }
274#endif
275
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000276}
277
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000278/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100279typedef enum {
280 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100281 /* Portable-specific options */
282 sPAMAuthenticationViaKbdInt,
283 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100284 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
285 sPermitRootLogin, sLogFacility, sLogLevel,
286 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000287#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100288 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000289#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000290#if defined(AFS) || defined(KRB5)
291 sKerberosTgtPassing,
292#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000293#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000294 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000295#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000296 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100297 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000298 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100299 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000300 sStrictModes, sEmptyPasswd, sKeepAlives,
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000301 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
Damien Miller50a41ed2000-10-16 12:14:42 +1100302 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000303 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100304 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100305 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100306 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000307 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000308 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000309 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000310} ServerOpCodes;
311
312/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100313static struct {
314 const char *name;
315 ServerOpCodes opcode;
316} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100317 /* Portable-specific options */
318 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
319 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100320 { "port", sPort },
321 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100322 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000323 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100324 { "serverkeybits", sServerKeyBits },
325 { "logingracetime", sLoginGraceTime },
326 { "keyregenerationinterval", sKeyRegenerationTime },
327 { "permitrootlogin", sPermitRootLogin },
328 { "syslogfacility", sLogFacility },
329 { "loglevel", sLogLevel },
330 { "rhostsauthentication", sRhostsAuthentication },
331 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000332 { "hostbasedauthentication", sHostbasedAuthentication },
333 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100334 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100335 { "pubkeyauthentication", sPubkeyAuthentication },
336 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000337#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100338 { "kerberosauthentication", sKerberosAuthentication },
339 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
340 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000341#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000342#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100343 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000344#endif
345#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100346 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000347#endif
Damien Miller95def091999-11-25 00:26:21 +1100348 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100349 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000350 { "challengeresponseauthentication", sChallengeResponseAuthentication },
351 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000352 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100353 { "listenaddress", sListenAddress },
354 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000355 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100356 { "ignorerhosts", sIgnoreRhosts },
357 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
358 { "x11forwarding", sX11Forwarding },
359 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100360 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000361 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100362 { "strictmodes", sStrictModes },
363 { "permitemptypasswords", sEmptyPasswd },
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000364 { "permituserenvironment", sPermitUserEnvironment },
Damien Miller95def091999-11-25 00:26:21 +1100365 { "uselogin", sUseLogin },
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000366 { "compression", sCompression },
Damien Miller95def091999-11-25 00:26:21 +1100367 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100368 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100369 { "allowusers", sAllowUsers },
370 { "denyusers", sDenyUsers },
371 { "allowgroups", sAllowGroups },
372 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000373 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000374 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000375 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000376 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000377 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000378 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000379 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100380 { "verifyreversemapping", sVerifyReverseMapping },
381 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000382 { "clientaliveinterval", sClientAliveInterval },
383 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000384 { "authorizedkeysfile", sAuthorizedKeysFile },
385 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000386 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000387 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000388};
389
Damien Miller5428f641999-11-25 11:54:57 +1100390/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000391 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100392 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000393
Damien Miller4af51302000-04-16 11:18:38 +1000394static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100395parse_token(const char *cp, const char *filename,
396 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000397{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000398 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000399
Damien Miller95def091999-11-25 00:26:21 +1100400 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100401 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100402 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000403
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000404 error("%s: line %d: Bad configuration option: %s",
405 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100406 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000407}
408
Ben Lindstrombba81212001-06-25 05:01:22 +0000409static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000410add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100411{
Damien Miller34132e52000-01-14 15:45:46 +1100412 int i;
413
414 if (options->num_ports == 0)
415 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000416 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000417 for (i = 0; i < options->num_ports; i++)
418 add_one_listen_addr(options, addr, options->ports[i]);
419 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000420 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000421}
422
Ben Lindstrombba81212001-06-25 05:01:22 +0000423static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000424add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
425{
426 struct addrinfo hints, *ai, *aitop;
427 char strport[NI_MAXSERV];
428 int gaierr;
429
430 memset(&hints, 0, sizeof(hints));
431 hints.ai_family = IPv4or6;
432 hints.ai_socktype = SOCK_STREAM;
433 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
Ben Lindstrome1353632002-06-23 21:29:23 +0000434 snprintf(strport, sizeof strport, "%u", port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000435 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
436 fatal("bad addr or host: %s (%s)",
437 addr ? addr : "<NULL>",
438 gai_strerror(gaierr));
439 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
440 ;
441 ai->ai_next = options->listen_addrs;
442 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100443}
444
Ben Lindstromade03f62001-12-06 18:22:17 +0000445int
446process_server_config_line(ServerOptions *options, char *line,
447 const char *filename, int linenum)
448{
449 char *cp, **charptr, *arg, *p;
Ben Lindstrome1353632002-06-23 21:29:23 +0000450 int *intptr, value, i, n;
Ben Lindstromade03f62001-12-06 18:22:17 +0000451 ServerOpCodes opcode;
Ben Lindstromade03f62001-12-06 18:22:17 +0000452
453 cp = line;
454 arg = strdelim(&cp);
455 /* Ignore leading whitespace */
456 if (*arg == '\0')
457 arg = strdelim(&cp);
458 if (!arg || !*arg || *arg == '#')
459 return 0;
460 intptr = NULL;
461 charptr = NULL;
462 opcode = parse_token(arg, filename, linenum);
463 switch (opcode) {
464 /* Portable-specific options */
465 case sPAMAuthenticationViaKbdInt:
466 intptr = &options->pam_authentication_via_kbd_int;
467 goto parse_flag;
468
469 /* Standard Options */
470 case sBadOption:
471 return -1;
472 case sPort:
473 /* ignore ports from configfile if cmdline specifies ports */
474 if (options->ports_from_cmdline)
475 return 0;
476 if (options->listen_addrs != NULL)
477 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100478 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000479 if (options->num_ports >= MAX_PORTS)
480 fatal("%s line %d: too many ports.",
481 filename, linenum);
482 arg = strdelim(&cp);
483 if (!arg || *arg == '\0')
484 fatal("%s line %d: missing port number.",
485 filename, linenum);
486 options->ports[options->num_ports++] = a2port(arg);
487 if (options->ports[options->num_ports-1] == 0)
488 fatal("%s line %d: Badly formatted port number.",
489 filename, linenum);
490 break;
491
492 case sServerKeyBits:
493 intptr = &options->server_key_bits;
494parse_int:
495 arg = strdelim(&cp);
496 if (!arg || *arg == '\0')
497 fatal("%s line %d: missing integer value.",
498 filename, linenum);
499 value = atoi(arg);
500 if (*intptr == -1)
501 *intptr = value;
502 break;
503
504 case sLoginGraceTime:
505 intptr = &options->login_grace_time;
506parse_time:
507 arg = strdelim(&cp);
508 if (!arg || *arg == '\0')
509 fatal("%s line %d: missing time value.",
510 filename, linenum);
511 if ((value = convtime(arg)) == -1)
512 fatal("%s line %d: invalid time value.",
513 filename, linenum);
514 if (*intptr == -1)
515 *intptr = value;
516 break;
517
518 case sKeyRegenerationTime:
519 intptr = &options->key_regeneration_time;
520 goto parse_time;
521
522 case sListenAddress:
523 arg = strdelim(&cp);
524 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
525 fatal("%s line %d: missing inet addr.",
526 filename, linenum);
527 if (*arg == '[') {
528 if ((p = strchr(arg, ']')) == NULL)
529 fatal("%s line %d: bad ipv6 inet addr usage.",
530 filename, linenum);
531 arg++;
532 memmove(p, p+1, strlen(p+1)+1);
533 } else if (((p = strchr(arg, ':')) == NULL) ||
534 (strchr(p+1, ':') != NULL)) {
535 add_listen_addr(options, arg, 0);
536 break;
537 }
538 if (*p == ':') {
539 u_short port;
540
541 p++;
542 if (*p == '\0')
543 fatal("%s line %d: bad inet addr:port usage.",
544 filename, linenum);
545 else {
546 *(p-1) = '\0';
547 if ((port = a2port(p)) == 0)
548 fatal("%s line %d: bad port number.",
549 filename, linenum);
550 add_listen_addr(options, arg, port);
551 }
552 } else if (*p == '\0')
553 add_listen_addr(options, arg, 0);
554 else
555 fatal("%s line %d: bad inet addr usage.",
556 filename, linenum);
557 break;
558
559 case sHostKeyFile:
560 intptr = &options->num_host_key_files;
561 if (*intptr >= MAX_HOSTKEYS)
562 fatal("%s line %d: too many host keys specified (max %d).",
563 filename, linenum, MAX_HOSTKEYS);
564 charptr = &options->host_key_files[*intptr];
565parse_filename:
566 arg = strdelim(&cp);
567 if (!arg || *arg == '\0')
568 fatal("%s line %d: missing file name.",
569 filename, linenum);
570 if (*charptr == NULL) {
571 *charptr = tilde_expand_filename(arg, getuid());
572 /* increase optional counter */
573 if (intptr != NULL)
574 *intptr = *intptr + 1;
575 }
576 break;
577
578 case sPidFile:
579 charptr = &options->pid_file;
580 goto parse_filename;
581
582 case sPermitRootLogin:
583 intptr = &options->permit_root_login;
584 arg = strdelim(&cp);
585 if (!arg || *arg == '\0')
586 fatal("%s line %d: missing yes/"
587 "without-password/forced-commands-only/no "
588 "argument.", filename, linenum);
589 value = 0; /* silence compiler */
590 if (strcmp(arg, "without-password") == 0)
591 value = PERMIT_NO_PASSWD;
592 else if (strcmp(arg, "forced-commands-only") == 0)
593 value = PERMIT_FORCED_ONLY;
594 else if (strcmp(arg, "yes") == 0)
595 value = PERMIT_YES;
596 else if (strcmp(arg, "no") == 0)
597 value = PERMIT_NO;
598 else
599 fatal("%s line %d: Bad yes/"
600 "without-password/forced-commands-only/no "
601 "argument: %s", filename, linenum, arg);
602 if (*intptr == -1)
603 *intptr = value;
604 break;
605
606 case sIgnoreRhosts:
607 intptr = &options->ignore_rhosts;
608parse_flag:
609 arg = strdelim(&cp);
610 if (!arg || *arg == '\0')
611 fatal("%s line %d: missing yes/no argument.",
612 filename, linenum);
613 value = 0; /* silence compiler */
614 if (strcmp(arg, "yes") == 0)
615 value = 1;
616 else if (strcmp(arg, "no") == 0)
617 value = 0;
618 else
619 fatal("%s line %d: Bad yes/no argument: %s",
620 filename, linenum, arg);
621 if (*intptr == -1)
622 *intptr = value;
623 break;
624
625 case sIgnoreUserKnownHosts:
626 intptr = &options->ignore_user_known_hosts;
627 goto parse_flag;
628
629 case sRhostsAuthentication:
630 intptr = &options->rhosts_authentication;
631 goto parse_flag;
632
633 case sRhostsRSAAuthentication:
634 intptr = &options->rhosts_rsa_authentication;
635 goto parse_flag;
636
637 case sHostbasedAuthentication:
638 intptr = &options->hostbased_authentication;
639 goto parse_flag;
640
641 case sHostbasedUsesNameFromPacketOnly:
642 intptr = &options->hostbased_uses_name_from_packet_only;
643 goto parse_flag;
644
645 case sRSAAuthentication:
646 intptr = &options->rsa_authentication;
647 goto parse_flag;
648
649 case sPubkeyAuthentication:
650 intptr = &options->pubkey_authentication;
651 goto parse_flag;
652#if defined(KRB4) || defined(KRB5)
653 case sKerberosAuthentication:
654 intptr = &options->kerberos_authentication;
655 goto parse_flag;
656
657 case sKerberosOrLocalPasswd:
658 intptr = &options->kerberos_or_local_passwd;
659 goto parse_flag;
660
661 case sKerberosTicketCleanup:
662 intptr = &options->kerberos_ticket_cleanup;
663 goto parse_flag;
664#endif
665#if defined(AFS) || defined(KRB5)
666 case sKerberosTgtPassing:
667 intptr = &options->kerberos_tgt_passing;
668 goto parse_flag;
669#endif
670#ifdef AFS
671 case sAFSTokenPassing:
672 intptr = &options->afs_token_passing;
673 goto parse_flag;
674#endif
675
676 case sPasswordAuthentication:
677 intptr = &options->password_authentication;
678 goto parse_flag;
679
680 case sKbdInteractiveAuthentication:
681 intptr = &options->kbd_interactive_authentication;
682 goto parse_flag;
683
684 case sChallengeResponseAuthentication:
685 intptr = &options->challenge_response_authentication;
686 goto parse_flag;
687
688 case sPrintMotd:
689 intptr = &options->print_motd;
690 goto parse_flag;
691
692 case sPrintLastLog:
693 intptr = &options->print_lastlog;
694 goto parse_flag;
695
696 case sX11Forwarding:
697 intptr = &options->x11_forwarding;
698 goto parse_flag;
699
700 case sX11DisplayOffset:
701 intptr = &options->x11_display_offset;
702 goto parse_int;
703
Damien Miller95c249f2002-02-05 12:11:34 +1100704 case sX11UseLocalhost:
705 intptr = &options->x11_use_localhost;
706 goto parse_flag;
707
Ben Lindstromade03f62001-12-06 18:22:17 +0000708 case sXAuthLocation:
709 charptr = &options->xauth_location;
710 goto parse_filename;
711
712 case sStrictModes:
713 intptr = &options->strict_modes;
714 goto parse_flag;
715
716 case sKeepAlives:
717 intptr = &options->keepalives;
718 goto parse_flag;
719
720 case sEmptyPasswd:
721 intptr = &options->permit_empty_passwd;
722 goto parse_flag;
723
Ben Lindstrom5d860f02002-08-01 01:28:38 +0000724 case sPermitUserEnvironment:
725 intptr = &options->permit_user_env;
726 goto parse_flag;
727
Ben Lindstromade03f62001-12-06 18:22:17 +0000728 case sUseLogin:
729 intptr = &options->use_login;
730 goto parse_flag;
731
Ben Lindstrom23e0f662002-06-21 01:09:47 +0000732 case sCompression:
733 intptr = &options->compression;
734 goto parse_flag;
735
Ben Lindstromade03f62001-12-06 18:22:17 +0000736 case sGatewayPorts:
737 intptr = &options->gateway_ports;
738 goto parse_flag;
739
Damien Millerc5d86352002-02-05 12:13:41 +1100740 case sVerifyReverseMapping:
741 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000742 goto parse_flag;
743
744 case sLogFacility:
745 intptr = (int *) &options->log_facility;
746 arg = strdelim(&cp);
747 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100748 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000749 fatal("%.200s line %d: unsupported log facility '%s'",
750 filename, linenum, arg ? arg : "<NONE>");
751 if (*intptr == -1)
752 *intptr = (SyslogFacility) value;
753 break;
754
755 case sLogLevel:
756 intptr = (int *) &options->log_level;
757 arg = strdelim(&cp);
758 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100759 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000760 fatal("%.200s line %d: unsupported log level '%s'",
761 filename, linenum, arg ? arg : "<NONE>");
762 if (*intptr == -1)
763 *intptr = (LogLevel) value;
764 break;
765
766 case sAllowTcpForwarding:
767 intptr = &options->allow_tcp_forwarding;
768 goto parse_flag;
769
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000770 case sUsePrivilegeSeparation:
771 intptr = &use_privsep;
772 goto parse_flag;
773
Ben Lindstromade03f62001-12-06 18:22:17 +0000774 case sAllowUsers:
775 while ((arg = strdelim(&cp)) && *arg != '\0') {
776 if (options->num_allow_users >= MAX_ALLOW_USERS)
777 fatal("%s line %d: too many allow users.",
778 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000779 options->allow_users[options->num_allow_users++] =
780 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000781 }
782 break;
783
784 case sDenyUsers:
785 while ((arg = strdelim(&cp)) && *arg != '\0') {
786 if (options->num_deny_users >= MAX_DENY_USERS)
787 fatal( "%s line %d: too many deny users.",
788 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000789 options->deny_users[options->num_deny_users++] =
790 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000791 }
792 break;
793
794 case sAllowGroups:
795 while ((arg = strdelim(&cp)) && *arg != '\0') {
796 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
797 fatal("%s line %d: too many allow groups.",
798 filename, linenum);
Ben Lindstrome1353632002-06-23 21:29:23 +0000799 options->allow_groups[options->num_allow_groups++] =
800 xstrdup(arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000801 }
802 break;
803
804 case sDenyGroups:
805 while ((arg = strdelim(&cp)) && *arg != '\0') {
806 if (options->num_deny_groups >= MAX_DENY_GROUPS)
807 fatal("%s line %d: too many deny groups.",
808 filename, linenum);
809 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
810 }
811 break;
812
813 case sCiphers:
814 arg = strdelim(&cp);
815 if (!arg || *arg == '\0')
816 fatal("%s line %d: Missing argument.", filename, linenum);
817 if (!ciphers_valid(arg))
818 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
819 filename, linenum, arg ? arg : "<NONE>");
820 if (options->ciphers == NULL)
821 options->ciphers = xstrdup(arg);
822 break;
823
824 case sMacs:
825 arg = strdelim(&cp);
826 if (!arg || *arg == '\0')
827 fatal("%s line %d: Missing argument.", filename, linenum);
828 if (!mac_valid(arg))
829 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
830 filename, linenum, arg ? arg : "<NONE>");
831 if (options->macs == NULL)
832 options->macs = xstrdup(arg);
833 break;
834
835 case sProtocol:
836 intptr = &options->protocol;
837 arg = strdelim(&cp);
838 if (!arg || *arg == '\0')
839 fatal("%s line %d: Missing argument.", filename, linenum);
840 value = proto_spec(arg);
841 if (value == SSH_PROTO_UNKNOWN)
842 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100843 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000844 if (*intptr == SSH_PROTO_UNKNOWN)
845 *intptr = value;
846 break;
847
848 case sSubsystem:
849 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
850 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100851 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000852 }
853 arg = strdelim(&cp);
854 if (!arg || *arg == '\0')
855 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100856 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000857 for (i = 0; i < options->num_subsystems; i++)
858 if (strcmp(arg, options->subsystem_name[i]) == 0)
859 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100860 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000861 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
862 arg = strdelim(&cp);
863 if (!arg || *arg == '\0')
864 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100865 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000866 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
867 options->num_subsystems++;
868 break;
869
870 case sMaxStartups:
871 arg = strdelim(&cp);
872 if (!arg || *arg == '\0')
873 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100874 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000875 if ((n = sscanf(arg, "%d:%d:%d",
876 &options->max_startups_begin,
877 &options->max_startups_rate,
878 &options->max_startups)) == 3) {
879 if (options->max_startups_begin >
880 options->max_startups ||
881 options->max_startups_rate > 100 ||
882 options->max_startups_rate < 1)
883 fatal("%s line %d: Illegal MaxStartups spec.",
884 filename, linenum);
885 } else if (n != 1)
886 fatal("%s line %d: Illegal MaxStartups spec.",
887 filename, linenum);
888 else
889 options->max_startups = options->max_startups_begin;
890 break;
891
892 case sBanner:
893 charptr = &options->banner;
894 goto parse_filename;
895 /*
896 * These options can contain %X options expanded at
897 * connect time, so that you can specify paths like:
898 *
899 * AuthorizedKeysFile /etc/ssh_keys/%u
900 */
901 case sAuthorizedKeysFile:
902 case sAuthorizedKeysFile2:
903 charptr = (opcode == sAuthorizedKeysFile ) ?
904 &options->authorized_keys_file :
905 &options->authorized_keys_file2;
906 goto parse_filename;
907
908 case sClientAliveInterval:
909 intptr = &options->client_alive_interval;
910 goto parse_time;
911
912 case sClientAliveCountMax:
913 intptr = &options->client_alive_count_max;
914 goto parse_int;
915
916 case sDeprecated:
Damien Miller996acd22003-04-09 20:59:48 +1000917 logit("%s line %d: Deprecated option %s",
Ben Lindstromade03f62001-12-06 18:22:17 +0000918 filename, linenum, arg);
919 while (arg)
920 arg = strdelim(&cp);
921 break;
922
923 default:
924 fatal("%s line %d: Missing handler for opcode %s (%d)",
925 filename, linenum, arg, opcode);
926 }
927 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
928 fatal("%s line %d: garbage at end of line; \"%.200s\".",
929 filename, linenum, arg);
930 return 0;
931}
932
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000933/* Reads the server configuration file. */
934
Damien Miller4af51302000-04-16 11:18:38 +1000935void
Damien Miller95def091999-11-25 00:26:21 +1100936read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000937{
Ben Lindstrome1353632002-06-23 21:29:23 +0000938 int linenum, bad_options = 0;
Damien Miller95def091999-11-25 00:26:21 +1100939 char line[1024];
Ben Lindstrome1353632002-06-23 21:29:23 +0000940 FILE *f;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000941
Damien Miller9f82c8f2003-02-24 12:04:33 +1100942 debug2("read_server_config: filename %s", filename);
Damien Miller95def091999-11-25 00:26:21 +1100943 f = fopen(filename, "r");
944 if (!f) {
945 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000946 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100947 }
948 linenum = 0;
949 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000950 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100951 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000952 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100953 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000954 }
Damien Miller95def091999-11-25 00:26:21 +1100955 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000956 if (bad_options > 0)
957 fatal("%s: terminating, %d bad configuration options",
958 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000959}