blob: 8e6ee5bb3e182fd479c47c673bb16588e6fcc754 [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 Lindstromc7431342002-03-22 03:11:49 +000013RCSID("$OpenBSD: servconf.c,v 1.105 2002/03/20 19:12:24 stevesk Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
Damien Millerc4b7fea2001-07-14 12:20:32 +100015#if defined(KRB4) || defined(KRB5)
Ben Lindstrom226cfa02001-01-22 05:34:40 +000016#include <krb.h>
17#endif
Ben Lindstromeb7a84c2001-07-04 04:48:36 +000018#ifdef AFS
19#include <kafs.h>
20#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021
22#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000023#include "log.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024#include "servconf.h"
25#include "xmalloc.h"
Damien Miller78928792000-04-12 20:17:38 +100026#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000027#include "pathnames.h"
28#include "tildexpand.h"
29#include "misc.h"
30#include "cipher.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000031#include "kex.h"
32#include "mac.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000033
Ben Lindstrombba81212001-06-25 05:01:22 +000034static void add_listen_addr(ServerOptions *, char *, u_short);
35static void add_one_listen_addr(ServerOptions *, char *, u_short);
Damien Miller34132e52000-01-14 15:45:46 +110036
Ben Lindstrom226cfa02001-01-22 05:34:40 +000037/* AF_UNSPEC or AF_INET or AF_INET6 */
38extern int IPv4or6;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000039/* Use of privilege separation or not */
40extern int use_privsep;
Ben Lindstrom226cfa02001-01-22 05:34:40 +000041
Damien Millerd4a8b7e1999-10-27 13:42:43 +100042/* Initializes the server options to their default values. */
43
Damien Miller4af51302000-04-16 11:18:38 +100044void
Damien Miller95def091999-11-25 00:26:21 +110045initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046{
Damien Miller95def091999-11-25 00:26:21 +110047 memset(options, 0, sizeof(*options));
Damien Miller726273e2001-11-12 11:40:11 +110048
49 /* Portable-specific options */
50 options->pam_authentication_via_kbd_int = -1;
51
52 /* Standard Options */
Damien Miller34132e52000-01-14 15:45:46 +110053 options->num_ports = 0;
54 options->ports_from_cmdline = 0;
55 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110056 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100057 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110058 options->server_key_bits = -1;
59 options->login_grace_time = -1;
60 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000061 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110062 options->ignore_rhosts = -1;
63 options->ignore_user_known_hosts = -1;
64 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000065 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110066 options->x11_forwarding = -1;
67 options->x11_display_offset = -1;
Damien Miller95c249f2002-02-05 12:11:34 +110068 options->x11_use_localhost = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100069 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110070 options->strict_modes = -1;
71 options->keepalives = -1;
Damien Millerfcd93202002-02-05 12:26:34 +110072 options->log_facility = SYSLOG_FACILITY_NOT_SET;
73 options->log_level = SYSLOG_LEVEL_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110074 options->rhosts_authentication = -1;
75 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +000076 options->hostbased_authentication = -1;
77 options->hostbased_uses_name_from_packet_only = -1;
Damien Miller95def091999-11-25 00:26:21 +110078 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110079 options->pubkey_authentication = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000080#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110081 options->kerberos_authentication = -1;
82 options->kerberos_or_local_passwd = -1;
83 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100084#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +000085#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +110086 options->kerberos_tgt_passing = -1;
Ben Lindstromec95ed92001-07-04 04:21:14 +000087#endif
88#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110089 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100090#endif
Damien Miller95def091999-11-25 00:26:21 +110091 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110092 options->kbd_interactive_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +000093 options->challenge_response_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110094 options->permit_empty_passwd = -1;
95 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110096 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110097 options->num_allow_users = 0;
98 options->num_deny_users = 0;
99 options->num_allow_groups = 0;
100 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +1000101 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000102 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +1000103 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +1000104 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +1000105 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +1000106 options->max_startups_begin = -1;
107 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +1000108 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000109 options->banner = NULL;
Damien Millerc5d86352002-02-05 12:13:41 +1100110 options->verify_reverse_mapping = -1;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000111 options->client_alive_interval = -1;
112 options->client_alive_count_max = -1;
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000113 options->authorized_keys_file = NULL;
114 options->authorized_keys_file2 = NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000115
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000116 /* Needs to be accessable in many places */
117 use_privsep = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000118}
119
Damien Miller4af51302000-04-16 11:18:38 +1000120void
Damien Miller95def091999-11-25 00:26:21 +1100121fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000122{
Damien Miller726273e2001-11-12 11:40:11 +1100123 /* Portable-specific options */
124 if (options->pam_authentication_via_kbd_int == -1)
125 options->pam_authentication_via_kbd_int = 0;
126
127 /* Standard Options */
Damien Miller0bc1bd82000-11-13 22:57:25 +1100128 if (options->protocol == SSH_PROTO_UNKNOWN)
129 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
130 if (options->num_host_key_files == 0) {
131 /* fill default hostkeys for protocols */
132 if (options->protocol & SSH_PROTO_1)
Damien Miller7fc23732002-01-22 23:19:11 +1100133 options->host_key_files[options->num_host_key_files++] =
134 _PATH_HOST_KEY_FILE;
135 if (options->protocol & SSH_PROTO_2) {
136 options->host_key_files[options->num_host_key_files++] =
137 _PATH_HOST_RSA_KEY_FILE;
138 options->host_key_files[options->num_host_key_files++] =
139 _PATH_HOST_DSA_KEY_FILE;
140 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100141 }
Damien Miller34132e52000-01-14 15:45:46 +1100142 if (options->num_ports == 0)
143 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
144 if (options->listen_addrs == NULL)
Ben Lindstrom19066a12001-04-12 23:39:26 +0000145 add_listen_addr(options, NULL, 0);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000146 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000147 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100148 if (options->server_key_bits == -1)
149 options->server_key_bits = 768;
150 if (options->login_grace_time == -1)
151 options->login_grace_time = 600;
152 if (options->key_regeneration_time == -1)
153 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000154 if (options->permit_root_login == PERMIT_NOT_SET)
155 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100156 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100157 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100158 if (options->ignore_user_known_hosts == -1)
159 options->ignore_user_known_hosts = 0;
Damien Miller95def091999-11-25 00:26:21 +1100160 if (options->print_motd == -1)
161 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000162 if (options->print_lastlog == -1)
163 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100164 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100165 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100166 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100167 options->x11_display_offset = 10;
Damien Miller95c249f2002-02-05 12:11:34 +1100168 if (options->x11_use_localhost == -1)
169 options->x11_use_localhost = 1;
Damien Millerd3a18572000-06-07 19:55:44 +1000170 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +0000171 options->xauth_location = _PATH_XAUTH;
Damien Miller95def091999-11-25 00:26:21 +1100172 if (options->strict_modes == -1)
173 options->strict_modes = 1;
174 if (options->keepalives == -1)
175 options->keepalives = 1;
Damien Millerfcd93202002-02-05 12:26:34 +1100176 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
Damien Miller95def091999-11-25 00:26:21 +1100177 options->log_facility = SYSLOG_FACILITY_AUTH;
Damien Millerfcd93202002-02-05 12:26:34 +1100178 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000179 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100180 if (options->rhosts_authentication == -1)
181 options->rhosts_authentication = 0;
182 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100183 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000184 if (options->hostbased_authentication == -1)
185 options->hostbased_authentication = 0;
186 if (options->hostbased_uses_name_from_packet_only == -1)
187 options->hostbased_uses_name_from_packet_only = 0;
Damien Miller95def091999-11-25 00:26:21 +1100188 if (options->rsa_authentication == -1)
189 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100190 if (options->pubkey_authentication == -1)
191 options->pubkey_authentication = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000192#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100193 if (options->kerberos_authentication == -1)
194 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
195 if (options->kerberos_or_local_passwd == -1)
196 options->kerberos_or_local_passwd = 1;
197 if (options->kerberos_ticket_cleanup == -1)
198 options->kerberos_ticket_cleanup = 1;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000199#endif
200#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100201 if (options->kerberos_tgt_passing == -1)
202 options->kerberos_tgt_passing = 0;
Ben Lindstromec95ed92001-07-04 04:21:14 +0000203#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100204#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100205 if (options->afs_token_passing == -1)
206 options->afs_token_passing = k_hasafs();
Ben Lindstromec95ed92001-07-04 04:21:14 +0000207#endif
Damien Miller95def091999-11-25 00:26:21 +1100208 if (options->password_authentication == -1)
209 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100210 if (options->kbd_interactive_authentication == -1)
211 options->kbd_interactive_authentication = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000212 if (options->challenge_response_authentication == -1)
213 options->challenge_response_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100214 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100215 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100216 if (options->use_login == -1)
217 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100218 if (options->allow_tcp_forwarding == -1)
219 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000220 if (options->gateway_ports == -1)
221 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000222 if (options->max_startups == -1)
223 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000224 if (options->max_startups_rate == -1)
225 options->max_startups_rate = 100; /* 100% */
226 if (options->max_startups_begin == -1)
227 options->max_startups_begin = options->max_startups;
Damien Millerc5d86352002-02-05 12:13:41 +1100228 if (options->verify_reverse_mapping == -1)
229 options->verify_reverse_mapping = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000230 if (options->client_alive_interval == -1)
Damien Miller9f0f5c62001-12-21 14:45:46 +1100231 options->client_alive_interval = 0;
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000232 if (options->client_alive_count_max == -1)
233 options->client_alive_count_max = 3;
Damien Miller75413ac2001-11-12 11:14:35 +1100234 if (options->authorized_keys_file2 == NULL) {
235 /* authorized_keys_file2 falls back to authorized_keys_file */
236 if (options->authorized_keys_file != NULL)
237 options->authorized_keys_file2 = options->authorized_keys_file;
238 else
239 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
240 }
241 if (options->authorized_keys_file == NULL)
242 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000243
244 /* Turn privilege separation _off_ by default */
245 if (use_privsep == -1)
246 use_privsep = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000247}
248
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000249/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100250typedef enum {
251 sBadOption, /* == unknown option */
Damien Miller726273e2001-11-12 11:40:11 +1100252 /* Portable-specific options */
253 sPAMAuthenticationViaKbdInt,
254 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100255 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
256 sPermitRootLogin, sLogFacility, sLogLevel,
257 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Ben Lindstromec95ed92001-07-04 04:21:14 +0000258#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100259 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000260#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000261#if defined(AFS) || defined(KRB5)
262 sKerberosTgtPassing,
263#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000264#ifdef AFS
Ben Lindstromec95ed92001-07-04 04:21:14 +0000265 sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000266#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000267 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100268 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000269 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
Damien Miller95c249f2002-02-05 12:11:34 +1100270 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
Ben Lindstrom91e98682001-09-12 16:32:14 +0000271 sStrictModes, sEmptyPasswd, sKeepAlives,
Damien Miller50a41ed2000-10-16 12:14:42 +1100272 sUseLogin, sAllowTcpForwarding,
273 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000274 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100275 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Millerc5d86352002-02-05 12:13:41 +1100276 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
Damien Miller9f0f5c62001-12-21 14:45:46 +1100277 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000278 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Ben Lindstromc7431342002-03-22 03:11:49 +0000279 sUsePrivilegeSeparation,
Ben Lindstromade03f62001-12-06 18:22:17 +0000280 sDeprecated
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281} ServerOpCodes;
282
283/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100284static struct {
285 const char *name;
286 ServerOpCodes opcode;
287} keywords[] = {
Damien Miller726273e2001-11-12 11:40:11 +1100288 /* Portable-specific options */
289 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt },
290 /* Standard Options */
Damien Miller95def091999-11-25 00:26:21 +1100291 { "port", sPort },
292 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100293 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000294 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100295 { "serverkeybits", sServerKeyBits },
296 { "logingracetime", sLoginGraceTime },
297 { "keyregenerationinterval", sKeyRegenerationTime },
298 { "permitrootlogin", sPermitRootLogin },
299 { "syslogfacility", sLogFacility },
300 { "loglevel", sLogLevel },
301 { "rhostsauthentication", sRhostsAuthentication },
302 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000303 { "hostbasedauthentication", sHostbasedAuthentication },
304 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
Damien Miller95def091999-11-25 00:26:21 +1100305 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100306 { "pubkeyauthentication", sPubkeyAuthentication },
307 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Ben Lindstromec95ed92001-07-04 04:21:14 +0000308#if defined(KRB4) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100309 { "kerberosauthentication", sKerberosAuthentication },
310 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
311 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000312#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +0000313#if defined(AFS) || defined(KRB5)
Damien Miller95def091999-11-25 00:26:21 +1100314 { "kerberostgtpassing", sKerberosTgtPassing },
Ben Lindstromec95ed92001-07-04 04:21:14 +0000315#endif
316#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100317 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000318#endif
Damien Miller95def091999-11-25 00:26:21 +1100319 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100320 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000321 { "challengeresponseauthentication", sChallengeResponseAuthentication },
322 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Ben Lindstrom91e98682001-09-12 16:32:14 +0000323 { "checkmail", sDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100324 { "listenaddress", sListenAddress },
325 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000326 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100327 { "ignorerhosts", sIgnoreRhosts },
328 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
329 { "x11forwarding", sX11Forwarding },
330 { "x11displayoffset", sX11DisplayOffset },
Damien Miller95c249f2002-02-05 12:11:34 +1100331 { "x11uselocalhost", sX11UseLocalhost },
Damien Millerd3a18572000-06-07 19:55:44 +1000332 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100333 { "strictmodes", sStrictModes },
334 { "permitemptypasswords", sEmptyPasswd },
335 { "uselogin", sUseLogin },
Damien Miller95def091999-11-25 00:26:21 +1100336 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100337 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100338 { "allowusers", sAllowUsers },
339 { "denyusers", sDenyUsers },
340 { "allowgroups", sAllowGroups },
341 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000342 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000343 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000344 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000345 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000346 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000347 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000348 { "banner", sBanner },
Damien Millerc5d86352002-02-05 12:13:41 +1100349 { "verifyreversemapping", sVerifyReverseMapping },
350 { "reversemappingcheck", sVerifyReverseMapping },
Ben Lindstrom5744dc42001-04-13 23:28:01 +0000351 { "clientaliveinterval", sClientAliveInterval },
352 { "clientalivecountmax", sClientAliveCountMax },
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000353 { "authorizedkeysfile", sAuthorizedKeysFile },
354 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000355 { "useprivilegeseparation", sUsePrivilegeSeparation},
Ben Lindstrom65366a82001-12-06 16:32:47 +0000356 { NULL, sBadOption }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000357};
358
Damien Miller5428f641999-11-25 11:54:57 +1100359/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000360 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100361 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000362
Damien Miller4af51302000-04-16 11:18:38 +1000363static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100364parse_token(const char *cp, const char *filename,
365 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000366{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000367 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000368
Damien Miller95def091999-11-25 00:26:21 +1100369 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100370 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100371 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000372
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000373 error("%s: line %d: Bad configuration option: %s",
374 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100375 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000376}
377
Ben Lindstrombba81212001-06-25 05:01:22 +0000378static void
Ben Lindstrom19066a12001-04-12 23:39:26 +0000379add_listen_addr(ServerOptions *options, char *addr, u_short port)
Damien Miller34132e52000-01-14 15:45:46 +1100380{
Damien Miller34132e52000-01-14 15:45:46 +1100381 int i;
382
383 if (options->num_ports == 0)
384 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstrom19066a12001-04-12 23:39:26 +0000385 if (port == 0)
Ben Lindstromc510af42001-04-07 17:25:48 +0000386 for (i = 0; i < options->num_ports; i++)
387 add_one_listen_addr(options, addr, options->ports[i]);
388 else
Ben Lindstrom19066a12001-04-12 23:39:26 +0000389 add_one_listen_addr(options, addr, port);
Ben Lindstromc510af42001-04-07 17:25:48 +0000390}
391
Ben Lindstrombba81212001-06-25 05:01:22 +0000392static void
Ben Lindstromc510af42001-04-07 17:25:48 +0000393add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
394{
395 struct addrinfo hints, *ai, *aitop;
396 char strport[NI_MAXSERV];
397 int gaierr;
398
399 memset(&hints, 0, sizeof(hints));
400 hints.ai_family = IPv4or6;
401 hints.ai_socktype = SOCK_STREAM;
402 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
403 snprintf(strport, sizeof strport, "%d", port);
404 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
405 fatal("bad addr or host: %s (%s)",
406 addr ? addr : "<NULL>",
407 gai_strerror(gaierr));
408 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
409 ;
410 ai->ai_next = options->listen_addrs;
411 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100412}
413
Ben Lindstromade03f62001-12-06 18:22:17 +0000414int
415process_server_config_line(ServerOptions *options, char *line,
416 const char *filename, int linenum)
417{
418 char *cp, **charptr, *arg, *p;
419 int *intptr, value;
420 ServerOpCodes opcode;
421 int i, n;
422
423 cp = line;
424 arg = strdelim(&cp);
425 /* Ignore leading whitespace */
426 if (*arg == '\0')
427 arg = strdelim(&cp);
428 if (!arg || !*arg || *arg == '#')
429 return 0;
430 intptr = NULL;
431 charptr = NULL;
432 opcode = parse_token(arg, filename, linenum);
433 switch (opcode) {
434 /* Portable-specific options */
435 case sPAMAuthenticationViaKbdInt:
436 intptr = &options->pam_authentication_via_kbd_int;
437 goto parse_flag;
438
439 /* Standard Options */
440 case sBadOption:
441 return -1;
442 case sPort:
443 /* ignore ports from configfile if cmdline specifies ports */
444 if (options->ports_from_cmdline)
445 return 0;
446 if (options->listen_addrs != NULL)
447 fatal("%s line %d: ports must be specified before "
Damien Miller4fbf08a2002-01-22 23:35:09 +1100448 "ListenAddress.", filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000449 if (options->num_ports >= MAX_PORTS)
450 fatal("%s line %d: too many ports.",
451 filename, linenum);
452 arg = strdelim(&cp);
453 if (!arg || *arg == '\0')
454 fatal("%s line %d: missing port number.",
455 filename, linenum);
456 options->ports[options->num_ports++] = a2port(arg);
457 if (options->ports[options->num_ports-1] == 0)
458 fatal("%s line %d: Badly formatted port number.",
459 filename, linenum);
460 break;
461
462 case sServerKeyBits:
463 intptr = &options->server_key_bits;
464parse_int:
465 arg = strdelim(&cp);
466 if (!arg || *arg == '\0')
467 fatal("%s line %d: missing integer value.",
468 filename, linenum);
469 value = atoi(arg);
470 if (*intptr == -1)
471 *intptr = value;
472 break;
473
474 case sLoginGraceTime:
475 intptr = &options->login_grace_time;
476parse_time:
477 arg = strdelim(&cp);
478 if (!arg || *arg == '\0')
479 fatal("%s line %d: missing time value.",
480 filename, linenum);
481 if ((value = convtime(arg)) == -1)
482 fatal("%s line %d: invalid time value.",
483 filename, linenum);
484 if (*intptr == -1)
485 *intptr = value;
486 break;
487
488 case sKeyRegenerationTime:
489 intptr = &options->key_regeneration_time;
490 goto parse_time;
491
492 case sListenAddress:
493 arg = strdelim(&cp);
494 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
495 fatal("%s line %d: missing inet addr.",
496 filename, linenum);
497 if (*arg == '[') {
498 if ((p = strchr(arg, ']')) == NULL)
499 fatal("%s line %d: bad ipv6 inet addr usage.",
500 filename, linenum);
501 arg++;
502 memmove(p, p+1, strlen(p+1)+1);
503 } else if (((p = strchr(arg, ':')) == NULL) ||
504 (strchr(p+1, ':') != NULL)) {
505 add_listen_addr(options, arg, 0);
506 break;
507 }
508 if (*p == ':') {
509 u_short port;
510
511 p++;
512 if (*p == '\0')
513 fatal("%s line %d: bad inet addr:port usage.",
514 filename, linenum);
515 else {
516 *(p-1) = '\0';
517 if ((port = a2port(p)) == 0)
518 fatal("%s line %d: bad port number.",
519 filename, linenum);
520 add_listen_addr(options, arg, port);
521 }
522 } else if (*p == '\0')
523 add_listen_addr(options, arg, 0);
524 else
525 fatal("%s line %d: bad inet addr usage.",
526 filename, linenum);
527 break;
528
529 case sHostKeyFile:
530 intptr = &options->num_host_key_files;
531 if (*intptr >= MAX_HOSTKEYS)
532 fatal("%s line %d: too many host keys specified (max %d).",
533 filename, linenum, MAX_HOSTKEYS);
534 charptr = &options->host_key_files[*intptr];
535parse_filename:
536 arg = strdelim(&cp);
537 if (!arg || *arg == '\0')
538 fatal("%s line %d: missing file name.",
539 filename, linenum);
540 if (*charptr == NULL) {
541 *charptr = tilde_expand_filename(arg, getuid());
542 /* increase optional counter */
543 if (intptr != NULL)
544 *intptr = *intptr + 1;
545 }
546 break;
547
548 case sPidFile:
549 charptr = &options->pid_file;
550 goto parse_filename;
551
552 case sPermitRootLogin:
553 intptr = &options->permit_root_login;
554 arg = strdelim(&cp);
555 if (!arg || *arg == '\0')
556 fatal("%s line %d: missing yes/"
557 "without-password/forced-commands-only/no "
558 "argument.", filename, linenum);
559 value = 0; /* silence compiler */
560 if (strcmp(arg, "without-password") == 0)
561 value = PERMIT_NO_PASSWD;
562 else if (strcmp(arg, "forced-commands-only") == 0)
563 value = PERMIT_FORCED_ONLY;
564 else if (strcmp(arg, "yes") == 0)
565 value = PERMIT_YES;
566 else if (strcmp(arg, "no") == 0)
567 value = PERMIT_NO;
568 else
569 fatal("%s line %d: Bad yes/"
570 "without-password/forced-commands-only/no "
571 "argument: %s", filename, linenum, arg);
572 if (*intptr == -1)
573 *intptr = value;
574 break;
575
576 case sIgnoreRhosts:
577 intptr = &options->ignore_rhosts;
578parse_flag:
579 arg = strdelim(&cp);
580 if (!arg || *arg == '\0')
581 fatal("%s line %d: missing yes/no argument.",
582 filename, linenum);
583 value = 0; /* silence compiler */
584 if (strcmp(arg, "yes") == 0)
585 value = 1;
586 else if (strcmp(arg, "no") == 0)
587 value = 0;
588 else
589 fatal("%s line %d: Bad yes/no argument: %s",
590 filename, linenum, arg);
591 if (*intptr == -1)
592 *intptr = value;
593 break;
594
595 case sIgnoreUserKnownHosts:
596 intptr = &options->ignore_user_known_hosts;
597 goto parse_flag;
598
599 case sRhostsAuthentication:
600 intptr = &options->rhosts_authentication;
601 goto parse_flag;
602
603 case sRhostsRSAAuthentication:
604 intptr = &options->rhosts_rsa_authentication;
605 goto parse_flag;
606
607 case sHostbasedAuthentication:
608 intptr = &options->hostbased_authentication;
609 goto parse_flag;
610
611 case sHostbasedUsesNameFromPacketOnly:
612 intptr = &options->hostbased_uses_name_from_packet_only;
613 goto parse_flag;
614
615 case sRSAAuthentication:
616 intptr = &options->rsa_authentication;
617 goto parse_flag;
618
619 case sPubkeyAuthentication:
620 intptr = &options->pubkey_authentication;
621 goto parse_flag;
622#if defined(KRB4) || defined(KRB5)
623 case sKerberosAuthentication:
624 intptr = &options->kerberos_authentication;
625 goto parse_flag;
626
627 case sKerberosOrLocalPasswd:
628 intptr = &options->kerberos_or_local_passwd;
629 goto parse_flag;
630
631 case sKerberosTicketCleanup:
632 intptr = &options->kerberos_ticket_cleanup;
633 goto parse_flag;
634#endif
635#if defined(AFS) || defined(KRB5)
636 case sKerberosTgtPassing:
637 intptr = &options->kerberos_tgt_passing;
638 goto parse_flag;
639#endif
640#ifdef AFS
641 case sAFSTokenPassing:
642 intptr = &options->afs_token_passing;
643 goto parse_flag;
644#endif
645
646 case sPasswordAuthentication:
647 intptr = &options->password_authentication;
648 goto parse_flag;
649
650 case sKbdInteractiveAuthentication:
651 intptr = &options->kbd_interactive_authentication;
652 goto parse_flag;
653
654 case sChallengeResponseAuthentication:
655 intptr = &options->challenge_response_authentication;
656 goto parse_flag;
657
658 case sPrintMotd:
659 intptr = &options->print_motd;
660 goto parse_flag;
661
662 case sPrintLastLog:
663 intptr = &options->print_lastlog;
664 goto parse_flag;
665
666 case sX11Forwarding:
667 intptr = &options->x11_forwarding;
668 goto parse_flag;
669
670 case sX11DisplayOffset:
671 intptr = &options->x11_display_offset;
672 goto parse_int;
673
Damien Miller95c249f2002-02-05 12:11:34 +1100674 case sX11UseLocalhost:
675 intptr = &options->x11_use_localhost;
676 goto parse_flag;
677
Ben Lindstromade03f62001-12-06 18:22:17 +0000678 case sXAuthLocation:
679 charptr = &options->xauth_location;
680 goto parse_filename;
681
682 case sStrictModes:
683 intptr = &options->strict_modes;
684 goto parse_flag;
685
686 case sKeepAlives:
687 intptr = &options->keepalives;
688 goto parse_flag;
689
690 case sEmptyPasswd:
691 intptr = &options->permit_empty_passwd;
692 goto parse_flag;
693
694 case sUseLogin:
695 intptr = &options->use_login;
696 goto parse_flag;
697
698 case sGatewayPorts:
699 intptr = &options->gateway_ports;
700 goto parse_flag;
701
Damien Millerc5d86352002-02-05 12:13:41 +1100702 case sVerifyReverseMapping:
703 intptr = &options->verify_reverse_mapping;
Ben Lindstromade03f62001-12-06 18:22:17 +0000704 goto parse_flag;
705
706 case sLogFacility:
707 intptr = (int *) &options->log_facility;
708 arg = strdelim(&cp);
709 value = log_facility_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100710 if (value == SYSLOG_FACILITY_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000711 fatal("%.200s line %d: unsupported log facility '%s'",
712 filename, linenum, arg ? arg : "<NONE>");
713 if (*intptr == -1)
714 *intptr = (SyslogFacility) value;
715 break;
716
717 case sLogLevel:
718 intptr = (int *) &options->log_level;
719 arg = strdelim(&cp);
720 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +1100721 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromade03f62001-12-06 18:22:17 +0000722 fatal("%.200s line %d: unsupported log level '%s'",
723 filename, linenum, arg ? arg : "<NONE>");
724 if (*intptr == -1)
725 *intptr = (LogLevel) value;
726 break;
727
728 case sAllowTcpForwarding:
729 intptr = &options->allow_tcp_forwarding;
730 goto parse_flag;
731
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000732 case sUsePrivilegeSeparation:
733 intptr = &use_privsep;
734 goto parse_flag;
735
Ben Lindstromade03f62001-12-06 18:22:17 +0000736 case sAllowUsers:
737 while ((arg = strdelim(&cp)) && *arg != '\0') {
738 if (options->num_allow_users >= MAX_ALLOW_USERS)
739 fatal("%s line %d: too many allow users.",
740 filename, linenum);
741 options->allow_users[options->num_allow_users++] = xstrdup(arg);
742 }
743 break;
744
745 case sDenyUsers:
746 while ((arg = strdelim(&cp)) && *arg != '\0') {
747 if (options->num_deny_users >= MAX_DENY_USERS)
748 fatal( "%s line %d: too many deny users.",
749 filename, linenum);
750 options->deny_users[options->num_deny_users++] = xstrdup(arg);
751 }
752 break;
753
754 case sAllowGroups:
755 while ((arg = strdelim(&cp)) && *arg != '\0') {
756 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
757 fatal("%s line %d: too many allow groups.",
758 filename, linenum);
759 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
760 }
761 break;
762
763 case sDenyGroups:
764 while ((arg = strdelim(&cp)) && *arg != '\0') {
765 if (options->num_deny_groups >= MAX_DENY_GROUPS)
766 fatal("%s line %d: too many deny groups.",
767 filename, linenum);
768 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
769 }
770 break;
771
772 case sCiphers:
773 arg = strdelim(&cp);
774 if (!arg || *arg == '\0')
775 fatal("%s line %d: Missing argument.", filename, linenum);
776 if (!ciphers_valid(arg))
777 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
778 filename, linenum, arg ? arg : "<NONE>");
779 if (options->ciphers == NULL)
780 options->ciphers = xstrdup(arg);
781 break;
782
783 case sMacs:
784 arg = strdelim(&cp);
785 if (!arg || *arg == '\0')
786 fatal("%s line %d: Missing argument.", filename, linenum);
787 if (!mac_valid(arg))
788 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
789 filename, linenum, arg ? arg : "<NONE>");
790 if (options->macs == NULL)
791 options->macs = xstrdup(arg);
792 break;
793
794 case sProtocol:
795 intptr = &options->protocol;
796 arg = strdelim(&cp);
797 if (!arg || *arg == '\0')
798 fatal("%s line %d: Missing argument.", filename, linenum);
799 value = proto_spec(arg);
800 if (value == SSH_PROTO_UNKNOWN)
801 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100802 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstromade03f62001-12-06 18:22:17 +0000803 if (*intptr == SSH_PROTO_UNKNOWN)
804 *intptr = value;
805 break;
806
807 case sSubsystem:
808 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
809 fatal("%s line %d: too many subsystems defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100810 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000811 }
812 arg = strdelim(&cp);
813 if (!arg || *arg == '\0')
814 fatal("%s line %d: Missing subsystem name.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100815 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000816 for (i = 0; i < options->num_subsystems; i++)
817 if (strcmp(arg, options->subsystem_name[i]) == 0)
818 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100819 filename, linenum, arg);
Ben Lindstromade03f62001-12-06 18:22:17 +0000820 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
821 arg = strdelim(&cp);
822 if (!arg || *arg == '\0')
823 fatal("%s line %d: Missing subsystem command.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100824 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000825 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
826 options->num_subsystems++;
827 break;
828
829 case sMaxStartups:
830 arg = strdelim(&cp);
831 if (!arg || *arg == '\0')
832 fatal("%s line %d: Missing MaxStartups spec.",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100833 filename, linenum);
Ben Lindstromade03f62001-12-06 18:22:17 +0000834 if ((n = sscanf(arg, "%d:%d:%d",
835 &options->max_startups_begin,
836 &options->max_startups_rate,
837 &options->max_startups)) == 3) {
838 if (options->max_startups_begin >
839 options->max_startups ||
840 options->max_startups_rate > 100 ||
841 options->max_startups_rate < 1)
842 fatal("%s line %d: Illegal MaxStartups spec.",
843 filename, linenum);
844 } else if (n != 1)
845 fatal("%s line %d: Illegal MaxStartups spec.",
846 filename, linenum);
847 else
848 options->max_startups = options->max_startups_begin;
849 break;
850
851 case sBanner:
852 charptr = &options->banner;
853 goto parse_filename;
854 /*
855 * These options can contain %X options expanded at
856 * connect time, so that you can specify paths like:
857 *
858 * AuthorizedKeysFile /etc/ssh_keys/%u
859 */
860 case sAuthorizedKeysFile:
861 case sAuthorizedKeysFile2:
862 charptr = (opcode == sAuthorizedKeysFile ) ?
863 &options->authorized_keys_file :
864 &options->authorized_keys_file2;
865 goto parse_filename;
866
867 case sClientAliveInterval:
868 intptr = &options->client_alive_interval;
869 goto parse_time;
870
871 case sClientAliveCountMax:
872 intptr = &options->client_alive_count_max;
873 goto parse_int;
874
875 case sDeprecated:
876 log("%s line %d: Deprecated option %s",
877 filename, linenum, arg);
878 while (arg)
879 arg = strdelim(&cp);
880 break;
881
882 default:
883 fatal("%s line %d: Missing handler for opcode %s (%d)",
884 filename, linenum, arg, opcode);
885 }
886 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
887 fatal("%s line %d: garbage at end of line; \"%.200s\".",
888 filename, linenum, arg);
889 return 0;
890}
891
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000892/* Reads the server configuration file. */
893
Damien Miller4af51302000-04-16 11:18:38 +1000894void
Damien Miller95def091999-11-25 00:26:21 +1100895read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000896{
Damien Miller95def091999-11-25 00:26:21 +1100897 FILE *f;
898 char line[1024];
Ben Lindstromade03f62001-12-06 18:22:17 +0000899 int linenum;
Damien Miller95def091999-11-25 00:26:21 +1100900 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000901
Damien Miller95def091999-11-25 00:26:21 +1100902 f = fopen(filename, "r");
903 if (!f) {
904 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000905 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100906 }
907 linenum = 0;
908 while (fgets(line, sizeof(line), f)) {
Ben Lindstromade03f62001-12-06 18:22:17 +0000909 /* Update line number counter. */
Damien Miller95def091999-11-25 00:26:21 +1100910 linenum++;
Ben Lindstromade03f62001-12-06 18:22:17 +0000911 if (process_server_config_line(options, line, filename, linenum) != 0)
Damien Miller95def091999-11-25 00:26:21 +1100912 bad_options++;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000913 }
Damien Miller95def091999-11-25 00:26:21 +1100914 fclose(f);
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000915 if (bad_options > 0)
916 fatal("%s: terminating, %d bad configuration options",
917 filename, bad_options);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000918}