blob: 7a776ac8e8a797a7a5134a72e62eaac42dfa6833 [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"
Ben Lindstromfb62a692002-06-06 19:47:11 +000013RCSID("$OpenBSD: servconf.c,v 1.110 2002/05/15 21:56:38 markus 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 Millerfd4c9ee2002-04-13 11:04:40 +100018#if defined(KRB5)
19#ifdef HEIMDAL
20#include <krb.h>
21#else
22/* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V
23 * keytab */
24#define KEYFILE "/etc/krb5.keytab"
25#endif
26#endif
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000027#ifdef AFS
28#include <kafs.h>
29#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100030
31#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000032#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100033#include "servconf.h"
34#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100035#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000036#include "pathnames.h"
37#include "tildexpand.h"
38#include "misc.h"
39#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000040#include "kex.h"
41#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000042
Ben Lindstrombba81212001-06-25 05:01:22 +000043static void add_listen_addr(ServerOptions *, char *, u_short);
44static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110045
Ben Lindstrom226cfa02001-01-22 05:34:40 +000046/* AF_UNSPEC or AF_INET or AF_INET6 */
47extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000048/* Use of privilege separation or not */
49extern int use_privsep;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000050
Damien Millerd4a8b7e1999-10-27 13:42:43 +100051/* Initializes the server options to their default values. */
52
Damien Miller4af51302000-04-16 11:18:38 +100053void
Damien Miller95def091999-11-25 00:26:21 +110054initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100055{
Damien Miller95def091999-11-25 00:26:21 +110056 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110057
58 /* Portable-specific options */
59 options->pam_authentication_via_kbd_int = -1;
60
61 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110062 options->num_ports = 0;
63 options->ports_from_cmdline = 0;
64 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110065 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100066 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110067 options->server_key_bits = -1;
68 options->login_grace_time = -1;
69 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000070 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110071 options->ignore_rhosts = -1;
72 options->ignore_user_known_hosts = -1;
73 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000074 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110075 options->x11_forwarding = -1;
76 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110077 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100078 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110079 options->strict_modes = -1;
80 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110081 options->log_facility = SYSLOG_FACILITY_NOT_SET;
82 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110083 options->rhosts_authentication = -1;
84 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000085 options->hostbased_authentication = -1;
86 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110087 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110088 options->pubkey_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000089#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110090 options->kerberos_authentication = -1;
91 options->kerberos_or_local_passwd = -1;
92 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100093#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +000094#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110095 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000096#endif
97#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110098 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100099#endif
Damien Miller95def091999-11-25 00:26:21 +1100100 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +1100101 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000102 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +1100103 options->permit_empty_passwd = -1;
104 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +1100105 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +1100106 options->num_allow_users = 0;
107 options->num_deny_users = 0;
108 options->num_allow_groups = 0;
109 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000110 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000111 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000112 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000113 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000114 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000115 options->max_startups_begin = -1;
116 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000117 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000118 options->banner = NULL;
Damien Millerc5d86352002-02-05 12:13:41 +1100119 options->verify_reverse_mapping = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000120 options->client_alive_interval = -1;
121 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000122 options->authorized_keys_file = NULL;
123 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000124
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000125 /* Needs to be accessable in many places */
126 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000127}
128
Damien Miller4af51302000-04-16 11:18:38 +1000129void
Damien Miller95def091999-11-25 00:26:21 +1100130fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000131{
Damien Miller726273e2001-11-12 11:40:11 +1100132 /* Portable-specific options */
133 if (options->pam_authentication_via_kbd_int == -1)
134 options->pam_authentication_via_kbd_int = 0;
135
136 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100137 if (options->protocol == SSH_PROTO_UNKNOWN)
138 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
139 if (options->num_host_key_files == 0) {
140 /* fill default hostkeys for protocols */
141 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100142 options->host_key_files[options->num_host_key_files++] =
143 _PATH_HOST_KEY_FILE;
144 if (options->protocol & SSH_PROTO_2) {
145 options->host_key_files[options->num_host_key_files++] =
146 _PATH_HOST_RSA_KEY_FILE;
147 options->host_key_files[options->num_host_key_files++] =
148 _PATH_HOST_DSA_KEY_FILE;
149 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100150 }
Damien Miller34132e52000-01-14 15:45:46 +1100151 if (options->num_ports == 0)
152 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
153 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000154 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000155 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000156 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100157 if (options->server_key_bits == -1)
158 options->server_key_bits = 768;
159 if (options->login_grace_time == -1)
160 options->login_grace_time = 600;
161 if (options->key_regeneration_time == -1)
162 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000163 if (options->permit_root_login == PERMIT_NOT_SET)
164 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100165 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100166 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100167 if (options->ignore_user_known_hosts == -1)
168 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100169 if (options->print_motd == -1)
170 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000171 if (options->print_lastlog == -1)
172 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100173 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100174 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100175 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100176 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100177 if (options->x11_use_localhost == -1)
178 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000179 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000180 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100181 if (options->strict_modes == -1)
182 options->strict_modes = 1;
183 if (options->keepalives == -1)
184 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100185 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100186 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100187 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000188 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100189 if (options->rhosts_authentication == -1)
190 options->rhosts_authentication = 0;
191 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100192 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000193 if (options->hostbased_authentication == -1)
194 options->hostbased_authentication = 0;
195 if (options->hostbased_uses_name_from_packet_only == -1)
196 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100197 if (options->rsa_authentication == -1)
198 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100199 if (options->pubkey_authentication == -1)
200 options->pubkey_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000201#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100202 if (options->kerberos_authentication == -1)
Damien Millerd7de14b2002-04-23 21:04:51 +1000203 options->kerberos_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100204 if (options->kerberos_or_local_passwd == -1)
205 options->kerberos_or_local_passwd = 1;
206 if (options->kerberos_ticket_cleanup == -1)
207 options->kerberos_ticket_cleanup = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000208#endif
209#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100210 if (options->kerberos_tgt_passing == -1)
211 options->kerberos_tgt_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000212#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100213#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100214 if (options->afs_token_passing == -1)
Damien Millere4ccf102002-04-23 20:40:28 +1000215 options->afs_token_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000216#endif
Damien Miller95def091999-11-25 00:26:21 +1100217 if (options->password_authentication == -1)
218 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100219 if (options->kbd_interactive_authentication == -1)
220 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000221 if (options->challenge_response_authentication == -1)
222 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100223 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100224 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100225 if (options->use_login == -1)
226 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100227 if (options->allow_tcp_forwarding == -1)
228 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000229 if (options->gateway_ports == -1)
230 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000231 if (options->max_startups == -1)
232 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000233 if (options->max_startups_rate == -1)
234 options->max_startups_rate = 100; /* 100% */
235 if (options->max_startups_begin == -1)
236 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100237 if (options->verify_reverse_mapping == -1)
238 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000239 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100240 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000241 if (options->client_alive_count_max == -1)
242 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100243 if (options->authorized_keys_file2 == NULL) {
244 /* authorized_keys_file2 falls back to authorized_keys_file */
245 if (options->authorized_keys_file != NULL)
246 options->authorized_keys_file2 = options->authorized_keys_file;
247 else
248 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
249 }
250 if (options->authorized_keys_file == NULL)
251 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000252
Ben Lindstromfb62a692002-06-06 19:47:11 +0000253 /* Turn privilege separation on by default */
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000254 if (use_privsep == -1)
Ben Lindstromfb62a692002-06-06 19:47:11 +0000255 use_privsep = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000256}
257
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000258/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100259typedef enum {
260 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100261 /* Portable-specific options */
262 sPAMAuthenticationViaKbdInt,
263 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100264 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
265 sPermitRootLogin, sLogFacility, sLogLevel,
266 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000267#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100268 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000269#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000270#if defined(AFS) || defined(KRB5)
271 sKerberosTgtPassing,
272#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000273#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000274 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000275#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000276 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100277 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000278 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100279 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000280 sStrictModes, sEmptyPasswd, sKeepAlives,
Damien Miller50a41ed2000-10-16 12:14:42 +1100281 sUseLogin, sAllowTcpForwarding,
282 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000283 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100284 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100285 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100286 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000287 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000288 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000289 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000290} ServerOpCodes;
291
292/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100293static struct {
294 const char *name;
295 ServerOpCodes opcode;
296} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100297 /* Portable-specific options */
298 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
299 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100300 { "port", sPort },
301 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100302 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000303 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100304 { "serverkeybits", sServerKeyBits },
305 { "logingracetime", sLoginGraceTime },
306 { "keyregenerationinterval", sKeyRegenerationTime },
307 { "permitrootlogin", sPermitRootLogin },
308 { "syslogfacility", sLogFacility },
309 { "loglevel", sLogLevel },
310 { "rhostsauthentication", sRhostsAuthentication },
311 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000312 { "hostbasedauthentication", sHostbasedAuthentication },
313 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100314 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100315 { "pubkeyauthentication", sPubkeyAuthentication },
316 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000317#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100318 { "kerberosauthentication", sKerberosAuthentication },
319 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
320 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000321#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000322#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100323 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000324#endif
325#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100326 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000327#endif
Damien Miller95def091999-11-25 00:26:21 +1100328 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100329 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000330 { "challengeresponseauthentication", sChallengeResponseAuthentication },
331 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000332 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100333 { "listenaddress", sListenAddress },
334 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000335 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100336 { "ignorerhosts", sIgnoreRhosts },
337 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
338 { "x11forwarding", sX11Forwarding },
339 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100340 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000341 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100342 { "strictmodes", sStrictModes },
343 { "permitemptypasswords", sEmptyPasswd },
344 { "uselogin", sUseLogin },
Damien Miller95def091999-11-25 00:26:21 +1100345 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100346 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100347 { "allowusers", sAllowUsers },
348 { "denyusers", sDenyUsers },
349 { "allowgroups", sAllowGroups },
350 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000351 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000352 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000353 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000354 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000355 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000356 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000357 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100358 { "verifyreversemapping", sVerifyReverseMapping },
359 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000360 { "clientaliveinterval", sClientAliveInterval },
361 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000362 { "authorizedkeysfile", sAuthorizedKeysFile },
363 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000364 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000365 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000366};
367
Damien Miller5428f641999-11-25 11:54:57 +1100368/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000369 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100370 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000371
Damien Miller4af51302000-04-16 11:18:38 +1000372static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100373parse_token(const char *cp, const char *filename,
374 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000375{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000376 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000377
Damien Miller95def091999-11-25 00:26:21 +1100378 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100379 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100380 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000382 error("%s: line %d: Bad configuration option: %s",
383 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100384 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000385}
386
Ben Lindstrombba81212001-06-25 05:01:22 +0000387static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000388add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100389{
Damien Miller34132e52000-01-14 15:45:46 +1100390 int i;
391
392 if (options->num_ports == 0)
393 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000394 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000395 for (i = 0; i < options->num_ports; i++)
396 add_one_listen_addr(options, addr, options->ports[i]);
397 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000398 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000399}
400
Ben Lindstrombba81212001-06-25 05:01:22 +0000401static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000402add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
403{
404 struct addrinfo hints, *ai, *aitop;
405 char strport[NI_MAXSERV];
406 int gaierr;
407
408 memset(&hints, 0, sizeof(hints));
409 hints.ai_family = IPv4or6;
410 hints.ai_socktype = SOCK_STREAM;
411 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
412 snprintf(strport, sizeof strport, "%d", port);
413 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
414 fatal("bad addr or host: %s (%s)",
415 addr ? addr : "<NULL>",
416 gai_strerror(gaierr));
417 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
418 ;
419 ai->ai_next = options->listen_addrs;
420 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100421}
422
Ben Lindstromade03f62001-12-06 18:22:17 +0000423int
424process_server_config_line(ServerOptions *options, char *line,
425 const char *filename, int linenum)
426{
427 char *cp, **charptr, *arg, *p;
428 int *intptr, value;
429 ServerOpCodes opcode;
430 int i, n;
431
432 cp = line;
433 arg = strdelim(&cp);
434 /* Ignore leading whitespace */
435 if (*arg == '\0')
436 arg = strdelim(&cp);
437 if (!arg || !*arg || *arg == '#')
438 return 0;
439 intptr = NULL;
440 charptr = NULL;
441 opcode = parse_token(arg, filename, linenum);
442 switch (opcode) {
443 /* Portable-specific options */
444 case sPAMAuthenticationViaKbdInt:
445 intptr = &options->pam_authentication_via_kbd_int;
446 goto parse_flag;
447
448 /* Standard Options */
449 case sBadOption:
450 return -1;
451 case sPort:
452 /* ignore ports from configfile if cmdline specifies ports */
453 if (options->ports_from_cmdline)
454 return 0;
455 if (options->listen_addrs != NULL)
456 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100457 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000458 if (options->num_ports >= MAX_PORTS)
459 fatal("%s line %d: too many ports.",
460 filename, linenum);
461 arg = strdelim(&cp);
462 if (!arg || *arg == '\0')
463 fatal("%s line %d: missing port number.",
464 filename, linenum);
465 options->ports[options->num_ports++] = a2port(arg);
466 if (options->ports[options->num_ports-1] == 0)
467 fatal("%s line %d: Badly formatted port number.",
468 filename, linenum);
469 break;
470
471 case sServerKeyBits:
472 intptr = &options->server_key_bits;
473parse_int:
474 arg = strdelim(&cp);
475 if (!arg || *arg == '\0')
476 fatal("%s line %d: missing integer value.",
477 filename, linenum);
478 value = atoi(arg);
479 if (*intptr == -1)
480 *intptr = value;
481 break;
482
483 case sLoginGraceTime:
484 intptr = &options->login_grace_time;
485parse_time:
486 arg = strdelim(&cp);
487 if (!arg || *arg == '\0')
488 fatal("%s line %d: missing time value.",
489 filename, linenum);
490 if ((value = convtime(arg)) == -1)
491 fatal("%s line %d: invalid time value.",
492 filename, linenum);
493 if (*intptr == -1)
494 *intptr = value;
495 break;
496
497 case sKeyRegenerationTime:
498 intptr = &options->key_regeneration_time;
499 goto parse_time;
500
501 case sListenAddress:
502 arg = strdelim(&cp);
503 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
504 fatal("%s line %d: missing inet addr.",
505 filename, linenum);
506 if (*arg == '[') {
507 if ((p = strchr(arg, ']')) == NULL)
508 fatal("%s line %d: bad ipv6 inet addr usage.",
509 filename, linenum);
510 arg++;
511 memmove(p, p+1, strlen(p+1)+1);
512 } else if (((p = strchr(arg, ':')) == NULL) ||
513 (strchr(p+1, ':') != NULL)) {
514 add_listen_addr(options, arg, 0);
515 break;
516 }
517 if (*p == ':') {
518 u_short port;
519
520 p++;
521 if (*p == '\0')
522 fatal("%s line %d: bad inet addr:port usage.",
523 filename, linenum);
524 else {
525 *(p-1) = '\0';
526 if ((port = a2port(p)) == 0)
527 fatal("%s line %d: bad port number.",
528 filename, linenum);
529 add_listen_addr(options, arg, port);
530 }
531 } else if (*p == '\0')
532 add_listen_addr(options, arg, 0);
533 else
534 fatal("%s line %d: bad inet addr usage.",
535 filename, linenum);
536 break;
537
538 case sHostKeyFile:
539 intptr = &options->num_host_key_files;
540 if (*intptr >= MAX_HOSTKEYS)
541 fatal("%s line %d: too many host keys specified (max %d).",
542 filename, linenum, MAX_HOSTKEYS);
543 charptr = &options->host_key_files[*intptr];
544parse_filename:
545 arg = strdelim(&cp);
546 if (!arg || *arg == '\0')
547 fatal("%s line %d: missing file name.",
548 filename, linenum);
549 if (*charptr == NULL) {
550 *charptr = tilde_expand_filename(arg, getuid());
551 /* increase optional counter */
552 if (intptr != NULL)
553 *intptr = *intptr + 1;
554 }
555 break;
556
557 case sPidFile:
558 charptr = &options->pid_file;
559 goto parse_filename;
560
561 case sPermitRootLogin:
562 intptr = &options->permit_root_login;
563 arg = strdelim(&cp);
564 if (!arg || *arg == '\0')
565 fatal("%s line %d: missing yes/"
566 "without-password/forced-commands-only/no "
567 "argument.", filename, linenum);
568 value = 0; /* silence compiler */
569 if (strcmp(arg, "without-password") == 0)
570 value = PERMIT_NO_PASSWD;
571 else if (strcmp(arg, "forced-commands-only") == 0)
572 value = PERMIT_FORCED_ONLY;
573 else if (strcmp(arg, "yes") == 0)
574 value = PERMIT_YES;
575 else if (strcmp(arg, "no") == 0)
576 value = PERMIT_NO;
577 else
578 fatal("%s line %d: Bad yes/"
579 "without-password/forced-commands-only/no "
580 "argument: %s", filename, linenum, arg);
581 if (*intptr == -1)
582 *intptr = value;
583 break;
584
585 case sIgnoreRhosts:
586 intptr = &options->ignore_rhosts;
587parse_flag:
588 arg = strdelim(&cp);
589 if (!arg || *arg == '\0')
590 fatal("%s line %d: missing yes/no argument.",
591 filename, linenum);
592 value = 0; /* silence compiler */
593 if (strcmp(arg, "yes") == 0)
594 value = 1;
595 else if (strcmp(arg, "no") == 0)
596 value = 0;
597 else
598 fatal("%s line %d: Bad yes/no argument: %s",
599 filename, linenum, arg);
600 if (*intptr == -1)
601 *intptr = value;
602 break;
603
604 case sIgnoreUserKnownHosts:
605 intptr = &options->ignore_user_known_hosts;
606 goto parse_flag;
607
608 case sRhostsAuthentication:
609 intptr = &options->rhosts_authentication;
610 goto parse_flag;
611
612 case sRhostsRSAAuthentication:
613 intptr = &options->rhosts_rsa_authentication;
614 goto parse_flag;
615
616 case sHostbasedAuthentication:
617 intptr = &options->hostbased_authentication;
618 goto parse_flag;
619
620 case sHostbasedUsesNameFromPacketOnly:
621 intptr = &options->hostbased_uses_name_from_packet_only;
622 goto parse_flag;
623
624 case sRSAAuthentication:
625 intptr = &options->rsa_authentication;
626 goto parse_flag;
627
628 case sPubkeyAuthentication:
629 intptr = &options->pubkey_authentication;
630 goto parse_flag;
631#if defined(KRB4) || defined(KRB5)
632 case sKerberosAuthentication:
633 intptr = &options->kerberos_authentication;
634 goto parse_flag;
635
636 case sKerberosOrLocalPasswd:
637 intptr = &options->kerberos_or_local_passwd;
638 goto parse_flag;
639
640 case sKerberosTicketCleanup:
641 intptr = &options->kerberos_ticket_cleanup;
642 goto parse_flag;
643#endif
644#if defined(AFS) || defined(KRB5)
645 case sKerberosTgtPassing:
646 intptr = &options->kerberos_tgt_passing;
647 goto parse_flag;
648#endif
649#ifdef AFS
650 case sAFSTokenPassing:
651 intptr = &options->afs_token_passing;
652 goto parse_flag;
653#endif
654
655 case sPasswordAuthentication:
656 intptr = &options->password_authentication;
657 goto parse_flag;
658
659 case sKbdInteractiveAuthentication:
660 intptr = &options->kbd_interactive_authentication;
661 goto parse_flag;
662
663 case sChallengeResponseAuthentication:
664 intptr = &options->challenge_response_authentication;
665 goto parse_flag;
666
667 case sPrintMotd:
668 intptr = &options->print_motd;
669 goto parse_flag;
670
671 case sPrintLastLog:
672 intptr = &options->print_lastlog;
673 goto parse_flag;
674
675 case sX11Forwarding:
676 intptr = &options->x11_forwarding;
677 goto parse_flag;
678
679 case sX11DisplayOffset:
680 intptr = &options->x11_display_offset;
681 goto parse_int;
682
Damien Miller95c249f2002-02-05 12:11:34 +1100683 case sX11UseLocalhost:
684 intptr = &options->x11_use_localhost;
685 goto parse_flag;
686
Ben Lindstromade03f62001-12-06 18:22:17 +0000687 case sXAuthLocation:
688 charptr = &options->xauth_location;
689 goto parse_filename;
690
691 case sStrictModes:
692 intptr = &options->strict_modes;
693 goto parse_flag;
694
695 case sKeepAlives:
696 intptr = &options->keepalives;
697 goto parse_flag;
698
699 case sEmptyPasswd:
700 intptr = &options->permit_empty_passwd;
701 goto parse_flag;
702
703 case sUseLogin:
704 intptr = &options->use_login;
705 goto parse_flag;
706
707 case sGatewayPorts:
708 intptr = &options->gateway_ports;
709 goto parse_flag;
710
Damien Millerc5d86352002-02-05 12:13:41 +1100711 case sVerifyReverseMapping:
712 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000713 goto parse_flag;
714
715 case sLogFacility:
716 intptr = (int *) &options->log_facility;
717 arg = strdelim(&cp);
718 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100719 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000720 fatal("%.200s line %d: unsupported log facility '%s'",
721 filename, linenum, arg ? arg : "<NONE>");
722 if (*intptr == -1)
723 *intptr = (SyslogFacility) value;
724 break;
725
726 case sLogLevel:
727 intptr = (int *) &options->log_level;
728 arg = strdelim(&cp);
729 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100730 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000731 fatal("%.200s line %d: unsupported log level '%s'",
732 filename, linenum, arg ? arg : "<NONE>");
733 if (*intptr == -1)
734 *intptr = (LogLevel) value;
735 break;
736
737 case sAllowTcpForwarding:
738 intptr = &options->allow_tcp_forwarding;
739 goto parse_flag;
740
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000741 case sUsePrivilegeSeparation:
742 intptr = &use_privsep;
743 goto parse_flag;
744
Ben Lindstromade03f62001-12-06 18:22:17 +0000745 case sAllowUsers:
746 while ((arg = strdelim(&cp)) && *arg != '\0') {
747 if (options->num_allow_users >= MAX_ALLOW_USERS)
748 fatal("%s line %d: too many allow users.",
749 filename, linenum);
750 options->allow_users[options->num_allow_users++] = xstrdup(arg);
751 }
752 break;
753
754 case sDenyUsers:
755 while ((arg = strdelim(&cp)) && *arg != '\0') {
756 if (options->num_deny_users >= MAX_DENY_USERS)
757 fatal( "%s line %d: too many deny users.",
758 filename, linenum);
759 options->deny_users[options->num_deny_users++] = xstrdup(arg);
760 }
761 break;
762
763 case sAllowGroups:
764 while ((arg = strdelim(&cp)) && *arg != '\0') {
765 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
766 fatal("%s line %d: too many allow groups.",
767 filename, linenum);
768 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
769 }
770 break;
771
772 case sDenyGroups:
773 while ((arg = strdelim(&cp)) && *arg != '\0') {
774 if (options->num_deny_groups >= MAX_DENY_GROUPS)
775 fatal("%s line %d: too many deny groups.",
776 filename, linenum);
777 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
778 }
779 break;
780
781 case sCiphers:
782 arg = strdelim(&cp);
783 if (!arg || *arg == '\0')
784 fatal("%s line %d: Missing argument.", filename, linenum);
785 if (!ciphers_valid(arg))
786 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
787 filename, linenum, arg ? arg : "<NONE>");
788 if (options->ciphers == NULL)
789 options->ciphers = xstrdup(arg);
790 break;
791
792 case sMacs:
793 arg = strdelim(&cp);
794 if (!arg || *arg == '\0')
795 fatal("%s line %d: Missing argument.", filename, linenum);
796 if (!mac_valid(arg))
797 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
798 filename, linenum, arg ? arg : "<NONE>");
799 if (options->macs == NULL)
800 options->macs = xstrdup(arg);
801 break;
802
803 case sProtocol:
804 intptr = &options->protocol;
805 arg = strdelim(&cp);
806 if (!arg || *arg == '\0')
807 fatal("%s line %d: Missing argument.", filename, linenum);
808 value = proto_spec(arg);
809 if (value == SSH_PROTO_UNKNOWN)
810 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100811 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000812 if (*intptr == SSH_PROTO_UNKNOWN)
813 *intptr = value;
814 break;
815
816 case sSubsystem:
817 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
818 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100819 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000820 }
821 arg = strdelim(&cp);
822 if (!arg || *arg == '\0')
823 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100824 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000825 for (i = 0; i < options->num_subsystems; i++)
826 if (strcmp(arg, options->subsystem_name[i]) == 0)
827 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100828 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000829 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
830 arg = strdelim(&cp);
831 if (!arg || *arg == '\0')
832 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100833 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000834 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
835 options->num_subsystems++;
836 break;
837
838 case sMaxStartups:
839 arg = strdelim(&cp);
840 if (!arg || *arg == '\0')
841 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100842 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000843 if ((n = sscanf(arg, "%d:%d:%d",
844 &options->max_startups_begin,
845 &options->max_startups_rate,
846 &options->max_startups)) == 3) {
847 if (options->max_startups_begin >
848 options->max_startups ||
849 options->max_startups_rate > 100 ||
850 options->max_startups_rate < 1)
851 fatal("%s line %d: Illegal MaxStartups spec.",
852 filename, linenum);
853 } else if (n != 1)
854 fatal("%s line %d: Illegal MaxStartups spec.",
855 filename, linenum);
856 else
857 options->max_startups = options->max_startups_begin;
858 break;
859
860 case sBanner:
861 charptr = &options->banner;
862 goto parse_filename;
863 /*
864 * These options can contain %X options expanded at
865 * connect time, so that you can specify paths like:
866 *
867 * AuthorizedKeysFile /etc/ssh_keys/%u
868 */
869 case sAuthorizedKeysFile:
870 case sAuthorizedKeysFile2:
871 charptr = (opcode == sAuthorizedKeysFile ) ?
872 &options->authorized_keys_file :
873 &options->authorized_keys_file2;
874 goto parse_filename;
875
876 case sClientAliveInterval:
877 intptr = &options->client_alive_interval;
878 goto parse_time;
879
880 case sClientAliveCountMax:
881 intptr = &options->client_alive_count_max;
882 goto parse_int;
883
884 case sDeprecated:
885 log("%s line %d: Deprecated option %s",
886 filename, linenum, arg);
887 while (arg)
888 arg = strdelim(&cp);
889 break;
890
891 default:
892 fatal("%s line %d: Missing handler for opcode %s (%d)",
893 filename, linenum, arg, opcode);
894 }
895 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
896 fatal("%s line %d: garbage at end of line; \"%.200s\".",
897 filename, linenum, arg);
898 return 0;
899}
900
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000901/* Reads the server configuration file. */
902
Damien Miller4af51302000-04-16 11:18:38 +1000903void
Damien Miller95def091999-11-25 00:26:21 +1100904read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000905{
Damien Miller95def091999-11-25 00:26:21 +1100906 FILE *f;
907 char line[1024];
Ben Lindstromade03f62001-12-06 18:22:17 +0000908 int linenum;
Damien Miller95def091999-11-25 00:26:21 +1100909 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000910
Damien Miller95def091999-11-25 00:26:21 +1100911 f = fopen(filename, "r");
912 if (!f) {
913 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000914 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100915 }
916 linenum = 0;
917 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000918 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100919 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000920 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100921 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000922 }
Damien Miller95def091999-11-25 00:26:21 +1100923 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000924 if (bad_options > 0)
925 fatal("%s: terminating, %d bad configuration options",
926 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000927}