blob: 4d5eb53ae8532f1ce4b205467b967c3c6a3c154a [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 Lindstromc510af42001-04-07 17:25:48 +000013RCSID("$OpenBSD: servconf.c,v 1.74 2001/04/06 22:25:25 stevesk Exp $");
Ben Lindstrom226cfa02001-01-22 05:34:40 +000014
15#ifdef KRB4
16#include <krb.h>
17#endif
18#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
Damien Miller34132e52000-01-14 15:45:46 +110034/* add listen address */
Ben Lindstromc510af42001-04-07 17:25:48 +000035void add_listen_addr(ServerOptions *options, char *addr, char *port);
36void add_one_listen_addr(ServerOptions *options, char *addr, u_short port);
Damien Miller34132e52000-01-14 15:45:46 +110037
Ben Lindstrom226cfa02001-01-22 05:34:40 +000038/* AF_UNSPEC or AF_INET or AF_INET6 */
39extern int IPv4or6;
40
Damien Millerd4a8b7e1999-10-27 13:42:43 +100041/* Initializes the server options to their default values. */
42
Damien Miller4af51302000-04-16 11:18:38 +100043void
Damien Miller95def091999-11-25 00:26:21 +110044initialize_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045{
Damien Miller95def091999-11-25 00:26:21 +110046 memset(options, 0, sizeof(*options));
Damien Miller34132e52000-01-14 15:45:46 +110047 options->num_ports = 0;
48 options->ports_from_cmdline = 0;
49 options->listen_addrs = NULL;
Damien Miller0bc1bd82000-11-13 22:57:25 +110050 options->num_host_key_files = 0;
Damien Miller6f83b8e2000-05-02 09:23:45 +100051 options->pid_file = NULL;
Damien Miller95def091999-11-25 00:26:21 +110052 options->server_key_bits = -1;
53 options->login_grace_time = -1;
54 options->key_regeneration_time = -1;
Ben Lindstromd8a90212001-02-15 03:08:27 +000055 options->permit_root_login = PERMIT_NOT_SET;
Damien Miller95def091999-11-25 00:26:21 +110056 options->ignore_rhosts = -1;
57 options->ignore_user_known_hosts = -1;
58 options->print_motd = -1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +000059 options->print_lastlog = -1;
Damien Miller95def091999-11-25 00:26:21 +110060 options->check_mail = -1;
61 options->x11_forwarding = -1;
62 options->x11_display_offset = -1;
Damien Millerd3a18572000-06-07 19:55:44 +100063 options->xauth_location = NULL;
Damien Miller95def091999-11-25 00:26:21 +110064 options->strict_modes = -1;
65 options->keepalives = -1;
66 options->log_facility = (SyslogFacility) - 1;
67 options->log_level = (LogLevel) - 1;
68 options->rhosts_authentication = -1;
69 options->rhosts_rsa_authentication = -1;
70 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +110071 options->pubkey_authentication = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100072#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +110073 options->kerberos_authentication = -1;
74 options->kerberos_or_local_passwd = -1;
75 options->kerberos_ticket_cleanup = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100076#endif
77#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +110078 options->kerberos_tgt_passing = -1;
79 options->afs_token_passing = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080#endif
Damien Miller95def091999-11-25 00:26:21 +110081 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +110082 options->kbd_interactive_authentication = -1;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +000083 options->challenge_reponse_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +110084 options->permit_empty_passwd = -1;
85 options->use_login = -1;
Damien Miller50a41ed2000-10-16 12:14:42 +110086 options->allow_tcp_forwarding = -1;
Damien Miller95def091999-11-25 00:26:21 +110087 options->num_allow_users = 0;
88 options->num_deny_users = 0;
89 options->num_allow_groups = 0;
90 options->num_deny_groups = 0;
Damien Miller78928792000-04-12 20:17:38 +100091 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000092 options->macs = NULL;
Damien Miller78928792000-04-12 20:17:38 +100093 options->protocol = SSH_PROTO_UNKNOWN;
Damien Millere247cc42000-05-07 12:03:14 +100094 options->gateway_ports = -1;
Damien Millerf6d9e222000-06-18 14:50:44 +100095 options->num_subsystems = 0;
Damien Miller942da032000-08-18 13:59:06 +100096 options->max_startups_begin = -1;
97 options->max_startups_rate = -1;
Damien Miller37023962000-07-11 17:31:38 +100098 options->max_startups = -1;
Ben Lindstrom48bd7c12001-01-09 00:35:42 +000099 options->banner = NULL;
Damien Miller33804262001-02-04 23:20:18 +1100100 options->reverse_mapping_check = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000101}
102
Damien Miller4af51302000-04-16 11:18:38 +1000103void
Damien Miller95def091999-11-25 00:26:21 +1100104fill_default_server_options(ServerOptions *options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105{
Damien Miller0bc1bd82000-11-13 22:57:25 +1100106 if (options->protocol == SSH_PROTO_UNKNOWN)
107 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
108 if (options->num_host_key_files == 0) {
109 /* fill default hostkeys for protocols */
110 if (options->protocol & SSH_PROTO_1)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000111 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100112 if (options->protocol & SSH_PROTO_2)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000113 options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100114 }
Damien Miller34132e52000-01-14 15:45:46 +1100115 if (options->num_ports == 0)
116 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
117 if (options->listen_addrs == NULL)
Ben Lindstromc510af42001-04-07 17:25:48 +0000118 add_listen_addr(options, NULL, NULL);
Damien Miller6f83b8e2000-05-02 09:23:45 +1000119 if (options->pid_file == NULL)
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000120 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
Damien Miller95def091999-11-25 00:26:21 +1100121 if (options->server_key_bits == -1)
122 options->server_key_bits = 768;
123 if (options->login_grace_time == -1)
124 options->login_grace_time = 600;
125 if (options->key_regeneration_time == -1)
126 options->key_regeneration_time = 3600;
Ben Lindstromd8a90212001-02-15 03:08:27 +0000127 if (options->permit_root_login == PERMIT_NOT_SET)
128 options->permit_root_login = PERMIT_YES;
Damien Miller95def091999-11-25 00:26:21 +1100129 if (options->ignore_rhosts == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100130 options->ignore_rhosts = 1;
Damien Miller95def091999-11-25 00:26:21 +1100131 if (options->ignore_user_known_hosts == -1)
132 options->ignore_user_known_hosts = 0;
133 if (options->check_mail == -1)
134 options->check_mail = 0;
135 if (options->print_motd == -1)
136 options->print_motd = 1;
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000137 if (options->print_lastlog == -1)
138 options->print_lastlog = 1;
Damien Miller95def091999-11-25 00:26:21 +1100139 if (options->x11_forwarding == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100140 options->x11_forwarding = 0;
Damien Miller95def091999-11-25 00:26:21 +1100141 if (options->x11_display_offset == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100142 options->x11_display_offset = 10;
Damien Millerd3a18572000-06-07 19:55:44 +1000143#ifdef XAUTH_PATH
144 if (options->xauth_location == NULL)
145 options->xauth_location = XAUTH_PATH;
146#endif /* XAUTH_PATH */
Damien Miller95def091999-11-25 00:26:21 +1100147 if (options->strict_modes == -1)
148 options->strict_modes = 1;
149 if (options->keepalives == -1)
150 options->keepalives = 1;
151 if (options->log_facility == (SyslogFacility) (-1))
152 options->log_facility = SYSLOG_FACILITY_AUTH;
153 if (options->log_level == (LogLevel) (-1))
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000154 options->log_level = SYSLOG_LEVEL_INFO;
Damien Miller95def091999-11-25 00:26:21 +1100155 if (options->rhosts_authentication == -1)
156 options->rhosts_authentication = 0;
157 if (options->rhosts_rsa_authentication == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100158 options->rhosts_rsa_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +1100159 if (options->rsa_authentication == -1)
160 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100161 if (options->pubkey_authentication == -1)
162 options->pubkey_authentication = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000163#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100164 if (options->kerberos_authentication == -1)
165 options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
166 if (options->kerberos_or_local_passwd == -1)
167 options->kerberos_or_local_passwd = 1;
168 if (options->kerberos_ticket_cleanup == -1)
169 options->kerberos_ticket_cleanup = 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000170#endif /* KRB4 */
171#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100172 if (options->kerberos_tgt_passing == -1)
173 options->kerberos_tgt_passing = 0;
174 if (options->afs_token_passing == -1)
175 options->afs_token_passing = k_hasafs();
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000176#endif /* AFS */
Damien Miller95def091999-11-25 00:26:21 +1100177 if (options->password_authentication == -1)
178 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +1100179 if (options->kbd_interactive_authentication == -1)
180 options->kbd_interactive_authentication = 0;
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000181 if (options->challenge_reponse_authentication == -1)
182 options->challenge_reponse_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +1100183 if (options->permit_empty_passwd == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +1100184 options->permit_empty_passwd = 0;
Damien Miller95def091999-11-25 00:26:21 +1100185 if (options->use_login == -1)
186 options->use_login = 0;
Damien Miller50a41ed2000-10-16 12:14:42 +1100187 if (options->allow_tcp_forwarding == -1)
188 options->allow_tcp_forwarding = 1;
Damien Millere247cc42000-05-07 12:03:14 +1000189 if (options->gateway_ports == -1)
190 options->gateway_ports = 0;
Damien Miller37023962000-07-11 17:31:38 +1000191 if (options->max_startups == -1)
192 options->max_startups = 10;
Damien Miller942da032000-08-18 13:59:06 +1000193 if (options->max_startups_rate == -1)
194 options->max_startups_rate = 100; /* 100% */
195 if (options->max_startups_begin == -1)
196 options->max_startups_begin = options->max_startups;
Damien Miller33804262001-02-04 23:20:18 +1100197 if (options->reverse_mapping_check == -1)
198 options->reverse_mapping_check = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000199}
200
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000201/* Keyword tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100202typedef enum {
203 sBadOption, /* == unknown option */
204 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
205 sPermitRootLogin, sLogFacility, sLogLevel,
206 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000207#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100208 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000209#endif
210#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100211 sKerberosTgtPassing, sAFSTokenPassing,
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000212#endif
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000213 sChallengeResponseAuthentication,
Damien Miller874d77b2000-10-14 16:23:11 +1100214 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000215 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
216 sX11Forwarding, sX11DisplayOffset,
Ben Lindstromd9cae222001-03-05 07:42:03 +0000217 sStrictModes, sEmptyPasswd, sKeepAlives, sCheckMail,
Damien Miller50a41ed2000-10-16 12:14:42 +1100218 sUseLogin, sAllowTcpForwarding,
219 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000220 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100221 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
Damien Miller33804262001-02-04 23:20:18 +1100222 sBanner, sReverseMappingCheck
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000223} ServerOpCodes;
224
225/* Textual representation of the tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100226static struct {
227 const char *name;
228 ServerOpCodes opcode;
229} keywords[] = {
230 { "port", sPort },
231 { "hostkey", sHostKeyFile },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100232 { "hostdsakey", sHostKeyFile }, /* alias */
Kevin Stevesef4eea92001-02-05 12:42:17 +0000233 { "pidfile", sPidFile },
Damien Miller95def091999-11-25 00:26:21 +1100234 { "serverkeybits", sServerKeyBits },
235 { "logingracetime", sLoginGraceTime },
236 { "keyregenerationinterval", sKeyRegenerationTime },
237 { "permitrootlogin", sPermitRootLogin },
238 { "syslogfacility", sLogFacility },
239 { "loglevel", sLogLevel },
240 { "rhostsauthentication", sRhostsAuthentication },
241 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
242 { "rsaauthentication", sRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100243 { "pubkeyauthentication", sPubkeyAuthentication },
244 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000245#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100246 { "kerberosauthentication", sKerberosAuthentication },
247 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
248 { "kerberosticketcleanup", sKerberosTicketCleanup },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000249#endif
250#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100251 { "kerberostgtpassing", sKerberosTgtPassing },
252 { "afstokenpassing", sAFSTokenPassing },
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000253#endif
Damien Miller95def091999-11-25 00:26:21 +1100254 { "passwordauthentication", sPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100255 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000256 { "challengeresponseauthentication", sChallengeResponseAuthentication },
257 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100258 { "checkmail", sCheckMail },
259 { "listenaddress", sListenAddress },
260 { "printmotd", sPrintMotd },
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000261 { "printlastlog", sPrintLastLog },
Damien Miller95def091999-11-25 00:26:21 +1100262 { "ignorerhosts", sIgnoreRhosts },
263 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
264 { "x11forwarding", sX11Forwarding },
265 { "x11displayoffset", sX11DisplayOffset },
Damien Millerd3a18572000-06-07 19:55:44 +1000266 { "xauthlocation", sXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100267 { "strictmodes", sStrictModes },
268 { "permitemptypasswords", sEmptyPasswd },
269 { "uselogin", sUseLogin },
Damien Miller95def091999-11-25 00:26:21 +1100270 { "keepalive", sKeepAlives },
Damien Miller50a41ed2000-10-16 12:14:42 +1100271 { "allowtcpforwarding", sAllowTcpForwarding },
Damien Miller95def091999-11-25 00:26:21 +1100272 { "allowusers", sAllowUsers },
273 { "denyusers", sDenyUsers },
274 { "allowgroups", sAllowGroups },
275 { "denygroups", sDenyGroups },
Damien Miller78928792000-04-12 20:17:38 +1000276 { "ciphers", sCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000277 { "macs", sMacs },
Damien Miller78928792000-04-12 20:17:38 +1000278 { "protocol", sProtocol },
Damien Millere247cc42000-05-07 12:03:14 +1000279 { "gatewayports", sGatewayPorts },
Damien Millerf6d9e222000-06-18 14:50:44 +1000280 { "subsystem", sSubsystem },
Damien Miller37023962000-07-11 17:31:38 +1000281 { "maxstartups", sMaxStartups },
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000282 { "banner", sBanner },
Damien Miller33804262001-02-04 23:20:18 +1100283 { "reversemappingcheck", sReverseMappingCheck },
Damien Miller95def091999-11-25 00:26:21 +1100284 { NULL, 0 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000285};
286
Damien Miller5428f641999-11-25 11:54:57 +1100287/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000288 * Returns the number of the token pointed to by cp or sBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100289 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000290
Damien Miller4af51302000-04-16 11:18:38 +1000291static ServerOpCodes
Damien Miller95def091999-11-25 00:26:21 +1100292parse_token(const char *cp, const char *filename,
293 int linenum)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000294{
Ben Lindstrom46c16222000-12-22 01:43:59 +0000295 u_int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000296
Damien Miller95def091999-11-25 00:26:21 +1100297 for (i = 0; keywords[i].name; i++)
Damien Miller5428f641999-11-25 11:54:57 +1100298 if (strcasecmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100299 return keywords[i].opcode;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000300
Damien Miller95def091999-11-25 00:26:21 +1100301 fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
302 filename, linenum, cp);
303 return sBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000304}
305
Damien Miller34132e52000-01-14 15:45:46 +1100306/*
307 * add listen address
308 */
Damien Miller4af51302000-04-16 11:18:38 +1000309void
Ben Lindstromc510af42001-04-07 17:25:48 +0000310add_listen_addr(ServerOptions *options, char *addr, char *port)
Damien Miller34132e52000-01-14 15:45:46 +1100311{
Damien Miller34132e52000-01-14 15:45:46 +1100312 int i;
313
314 if (options->num_ports == 0)
315 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
Ben Lindstromc510af42001-04-07 17:25:48 +0000316 if (port == NULL)
317 for (i = 0; i < options->num_ports; i++)
318 add_one_listen_addr(options, addr, options->ports[i]);
319 else
320 add_one_listen_addr(options, addr, atoi(port));
321}
322
323void
324add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
325{
326 struct addrinfo hints, *ai, *aitop;
327 char strport[NI_MAXSERV];
328 int gaierr;
329
330 memset(&hints, 0, sizeof(hints));
331 hints.ai_family = IPv4or6;
332 hints.ai_socktype = SOCK_STREAM;
333 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
334 snprintf(strport, sizeof strport, "%d", port);
335 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
336 fatal("bad addr or host: %s (%s)",
337 addr ? addr : "<NULL>",
338 gai_strerror(gaierr));
339 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
340 ;
341 ai->ai_next = options->listen_addrs;
342 options->listen_addrs = aitop;
Damien Miller34132e52000-01-14 15:45:46 +1100343}
344
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000345/* Reads the server configuration file. */
346
Damien Miller4af51302000-04-16 11:18:38 +1000347void
Damien Miller95def091999-11-25 00:26:21 +1100348read_server_config(ServerOptions *options, const char *filename)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000349{
Damien Miller95def091999-11-25 00:26:21 +1100350 FILE *f;
351 char line[1024];
Ben Lindstromc510af42001-04-07 17:25:48 +0000352 char *cp, **charptr, *arg, *p;
Damien Miller95def091999-11-25 00:26:21 +1100353 int linenum, *intptr, value;
354 int bad_options = 0;
355 ServerOpCodes opcode;
Damien Millerf6d9e222000-06-18 14:50:44 +1000356 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000357
Damien Miller95def091999-11-25 00:26:21 +1100358 f = fopen(filename, "r");
359 if (!f) {
360 perror(filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000361 exit(1);
Damien Miller95def091999-11-25 00:26:21 +1100362 }
363 linenum = 0;
364 while (fgets(line, sizeof(line), f)) {
365 linenum++;
Damien Millerbe484b52000-07-15 14:14:16 +1000366 cp = line;
367 arg = strdelim(&cp);
368 /* Ignore leading whitespace */
369 if (*arg == '\0')
370 arg = strdelim(&cp);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000371 if (!arg || !*arg || *arg == '#')
Damien Miller95def091999-11-25 00:26:21 +1100372 continue;
Damien Miller0bc1bd82000-11-13 22:57:25 +1100373 intptr = NULL;
374 charptr = NULL;
Damien Miller37023962000-07-11 17:31:38 +1000375 opcode = parse_token(arg, filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100376 switch (opcode) {
377 case sBadOption:
378 bad_options++;
379 continue;
380 case sPort:
Damien Miller34132e52000-01-14 15:45:46 +1100381 /* ignore ports from configfile if cmdline specifies ports */
382 if (options->ports_from_cmdline)
383 continue;
384 if (options->listen_addrs != NULL)
385 fatal("%s line %d: ports must be specified before "
386 "ListenAdress.\n", filename, linenum);
387 if (options->num_ports >= MAX_PORTS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000388 fatal("%s line %d: too many ports.",
Damien Miller4af51302000-04-16 11:18:38 +1000389 filename, linenum);
Damien Millerbe484b52000-07-15 14:14:16 +1000390 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000391 if (!arg || *arg == '\0')
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000392 fatal("%s line %d: missing port number.",
Damien Miller34132e52000-01-14 15:45:46 +1100393 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000394 options->ports[options->num_ports++] = atoi(arg);
Damien Miller34132e52000-01-14 15:45:46 +1100395 break;
396
397 case sServerKeyBits:
398 intptr = &options->server_key_bits;
Damien Miller95def091999-11-25 00:26:21 +1100399parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +1000400 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000401 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100402 fprintf(stderr, "%s line %d: missing integer value.\n",
403 filename, linenum);
404 exit(1);
405 }
Damien Miller37023962000-07-11 17:31:38 +1000406 value = atoi(arg);
Damien Miller95def091999-11-25 00:26:21 +1100407 if (*intptr == -1)
408 *intptr = value;
409 break;
Damien Miller32265091999-11-12 11:33:04 +1100410
Damien Miller95def091999-11-25 00:26:21 +1100411 case sLoginGraceTime:
412 intptr = &options->login_grace_time;
413 goto parse_int;
414
415 case sKeyRegenerationTime:
416 intptr = &options->key_regeneration_time;
417 goto parse_int;
418
419 case sListenAddress:
Damien Millerbe484b52000-07-15 14:14:16 +1000420 arg = strdelim(&cp);
Ben Lindstromc510af42001-04-07 17:25:48 +0000421 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000422 fatal("%s line %d: missing inet addr.",
Damien Miller34132e52000-01-14 15:45:46 +1100423 filename, linenum);
Ben Lindstromc510af42001-04-07 17:25:48 +0000424 if (*arg == '[') {
425 if ((p = strchr(arg, ']')) == NULL)
426 fatal("%s line %d: bad ipv6 inet addr usage.",
427 filename, linenum);
428 arg++;
429 memmove(p, p+1, strlen(p+1)+1);
430 } else if (((p = strchr(arg, ':')) == NULL) ||
431 (strchr(p+1, ':') != NULL)) {
432 add_listen_addr(options, arg, NULL);
433 break;
434 }
435 if (*p == ':') {
436 p++;
437 if (*p == '\0')
438 fatal("%s line %d: bad inet addr:port usage.",
439 filename, linenum);
440 else {
441 *(p-1) = '\0';
442 add_listen_addr(options, arg, p);
443 }
444 } else if (*p == '\0')
445 add_listen_addr(options, arg, NULL);
446 else
447 fatal("%s line %d: bad inet addr usage.",
448 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100449 break;
450
451 case sHostKeyFile:
Damien Miller0bc1bd82000-11-13 22:57:25 +1100452 intptr = &options->num_host_key_files;
453 if (*intptr >= MAX_HOSTKEYS) {
Ben Lindstrom33a3cc32001-03-05 05:07:52 +0000454 fprintf(stderr,
455 "%s line %d: too many host keys specified (max %d).\n",
Damien Miller0bc1bd82000-11-13 22:57:25 +1100456 filename, linenum, MAX_HOSTKEYS);
457 exit(1);
458 }
459 charptr = &options->host_key_files[*intptr];
Damien Millerd3a18572000-06-07 19:55:44 +1000460parse_filename:
Damien Millerbe484b52000-07-15 14:14:16 +1000461 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000462 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100463 fprintf(stderr, "%s line %d: missing file name.\n",
Damien Miller6f83b8e2000-05-02 09:23:45 +1000464 filename, linenum);
465 exit(1);
466 }
Damien Miller0bc1bd82000-11-13 22:57:25 +1100467 if (*charptr == NULL) {
Damien Miller37023962000-07-11 17:31:38 +1000468 *charptr = tilde_expand_filename(arg, getuid());
Damien Miller0bc1bd82000-11-13 22:57:25 +1100469 /* increase optional counter */
470 if (intptr != NULL)
471 *intptr = *intptr + 1;
472 }
Damien Miller6f83b8e2000-05-02 09:23:45 +1000473 break;
474
475 case sPidFile:
476 charptr = &options->pid_file;
Damien Millerd3a18572000-06-07 19:55:44 +1000477 goto parse_filename;
Damien Miller95def091999-11-25 00:26:21 +1100478
Damien Miller95def091999-11-25 00:26:21 +1100479 case sPermitRootLogin:
480 intptr = &options->permit_root_login;
Damien Millerbe484b52000-07-15 14:14:16 +1000481 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000482 if (!arg || *arg == '\0') {
Ben Lindstrom35f1f4e2001-03-06 01:02:41 +0000483 fprintf(stderr, "%s line %d: missing yes/"
484 "without-password/forced-commands-only/no "
485 "argument.\n", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100486 exit(1);
487 }
Damien Miller37023962000-07-11 17:31:38 +1000488 if (strcmp(arg, "without-password") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000489 value = PERMIT_NO_PASSWD;
490 else if (strcmp(arg, "forced-commands-only") == 0)
491 value = PERMIT_FORCED_ONLY;
Damien Miller37023962000-07-11 17:31:38 +1000492 else if (strcmp(arg, "yes") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000493 value = PERMIT_YES;
Damien Miller37023962000-07-11 17:31:38 +1000494 else if (strcmp(arg, "no") == 0)
Ben Lindstromd8a90212001-02-15 03:08:27 +0000495 value = PERMIT_NO;
Damien Miller95def091999-11-25 00:26:21 +1100496 else {
Ben Lindstromd8a90212001-02-15 03:08:27 +0000497 fprintf(stderr, "%s line %d: Bad yes/"
498 "without-password/forced-commands-only/no "
499 "argument: %s\n", filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100500 exit(1);
501 }
502 if (*intptr == -1)
503 *intptr = value;
504 break;
505
506 case sIgnoreRhosts:
507 intptr = &options->ignore_rhosts;
508parse_flag:
Damien Millerbe484b52000-07-15 14:14:16 +1000509 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000510 if (!arg || *arg == '\0') {
Damien Miller95def091999-11-25 00:26:21 +1100511 fprintf(stderr, "%s line %d: missing yes/no argument.\n",
512 filename, linenum);
513 exit(1);
514 }
Damien Miller37023962000-07-11 17:31:38 +1000515 if (strcmp(arg, "yes") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100516 value = 1;
Damien Miller37023962000-07-11 17:31:38 +1000517 else if (strcmp(arg, "no") == 0)
Damien Miller95def091999-11-25 00:26:21 +1100518 value = 0;
519 else {
520 fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
Damien Miller37023962000-07-11 17:31:38 +1000521 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100522 exit(1);
523 }
524 if (*intptr == -1)
525 *intptr = value;
526 break;
527
528 case sIgnoreUserKnownHosts:
529 intptr = &options->ignore_user_known_hosts;
Damien Miller98c7ad62000-03-09 21:27:49 +1100530 goto parse_flag;
Damien Miller95def091999-11-25 00:26:21 +1100531
532 case sRhostsAuthentication:
533 intptr = &options->rhosts_authentication;
534 goto parse_flag;
535
536 case sRhostsRSAAuthentication:
537 intptr = &options->rhosts_rsa_authentication;
538 goto parse_flag;
539
540 case sRSAAuthentication:
541 intptr = &options->rsa_authentication;
542 goto parse_flag;
543
Damien Miller0bc1bd82000-11-13 22:57:25 +1100544 case sPubkeyAuthentication:
545 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000546 goto parse_flag;
547
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000548#ifdef KRB4
Damien Miller95def091999-11-25 00:26:21 +1100549 case sKerberosAuthentication:
550 intptr = &options->kerberos_authentication;
551 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000552
Damien Miller95def091999-11-25 00:26:21 +1100553 case sKerberosOrLocalPasswd:
554 intptr = &options->kerberos_or_local_passwd;
555 goto parse_flag;
556
557 case sKerberosTicketCleanup:
558 intptr = &options->kerberos_ticket_cleanup;
559 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000560#endif
Damien Miller95def091999-11-25 00:26:21 +1100561
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000562#ifdef AFS
Damien Miller95def091999-11-25 00:26:21 +1100563 case sKerberosTgtPassing:
564 intptr = &options->kerberos_tgt_passing;
565 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000566
Damien Miller95def091999-11-25 00:26:21 +1100567 case sAFSTokenPassing:
568 intptr = &options->afs_token_passing;
569 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000570#endif
571
Damien Miller95def091999-11-25 00:26:21 +1100572 case sPasswordAuthentication:
573 intptr = &options->password_authentication;
574 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000575
Damien Miller874d77b2000-10-14 16:23:11 +1100576 case sKbdInteractiveAuthentication:
577 intptr = &options->kbd_interactive_authentication;
578 goto parse_flag;
579
Damien Miller95def091999-11-25 00:26:21 +1100580 case sCheckMail:
581 intptr = &options->check_mail;
582 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000583
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000584 case sChallengeResponseAuthentication:
585 intptr = &options->challenge_reponse_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100586 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000587
Damien Miller95def091999-11-25 00:26:21 +1100588 case sPrintMotd:
589 intptr = &options->print_motd;
590 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000591
Ben Lindstrom7bfff362001-03-26 05:45:53 +0000592 case sPrintLastLog:
593 intptr = &options->print_lastlog;
594 goto parse_flag;
595
Damien Miller95def091999-11-25 00:26:21 +1100596 case sX11Forwarding:
597 intptr = &options->x11_forwarding;
598 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000599
Damien Miller95def091999-11-25 00:26:21 +1100600 case sX11DisplayOffset:
601 intptr = &options->x11_display_offset;
602 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000603
Damien Millerd3a18572000-06-07 19:55:44 +1000604 case sXAuthLocation:
605 charptr = &options->xauth_location;
606 goto parse_filename;
Kevin Stevesef4eea92001-02-05 12:42:17 +0000607
Damien Miller95def091999-11-25 00:26:21 +1100608 case sStrictModes:
609 intptr = &options->strict_modes;
610 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000611
Damien Miller95def091999-11-25 00:26:21 +1100612 case sKeepAlives:
613 intptr = &options->keepalives;
614 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000615
Damien Miller95def091999-11-25 00:26:21 +1100616 case sEmptyPasswd:
617 intptr = &options->permit_empty_passwd;
618 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000619
Damien Miller95def091999-11-25 00:26:21 +1100620 case sUseLogin:
621 intptr = &options->use_login;
622 goto parse_flag;
Damien Miller5ce662a1999-11-11 17:57:39 +1100623
Damien Millere247cc42000-05-07 12:03:14 +1000624 case sGatewayPorts:
625 intptr = &options->gateway_ports;
626 goto parse_flag;
627
Damien Miller33804262001-02-04 23:20:18 +1100628 case sReverseMappingCheck:
629 intptr = &options->reverse_mapping_check;
630 goto parse_flag;
631
Damien Miller95def091999-11-25 00:26:21 +1100632 case sLogFacility:
633 intptr = (int *) &options->log_facility;
Damien Millerbe484b52000-07-15 14:14:16 +1000634 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000635 value = log_facility_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100636 if (value == (SyslogFacility) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000637 fatal("%.200s line %d: unsupported log facility '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000638 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100639 if (*intptr == -1)
640 *intptr = (SyslogFacility) value;
641 break;
642
643 case sLogLevel:
644 intptr = (int *) &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +1000645 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000646 value = log_level_number(arg);
Damien Miller95def091999-11-25 00:26:21 +1100647 if (value == (LogLevel) - 1)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000648 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller37023962000-07-11 17:31:38 +1000649 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +1100650 if (*intptr == -1)
651 *intptr = (LogLevel) value;
652 break;
653
Damien Miller50a41ed2000-10-16 12:14:42 +1100654 case sAllowTcpForwarding:
655 intptr = &options->allow_tcp_forwarding;
656 goto parse_flag;
657
Damien Miller95def091999-11-25 00:26:21 +1100658 case sAllowUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000659 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000660 if (options->num_allow_users >= MAX_ALLOW_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000661 fatal("%s line %d: too many allow users.",
Damien Miller78928792000-04-12 20:17:38 +1000662 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000663 options->allow_users[options->num_allow_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100664 }
665 break;
666
667 case sDenyUsers:
Damien Millerbe484b52000-07-15 14:14:16 +1000668 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000669 if (options->num_deny_users >= MAX_DENY_USERS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000670 fatal( "%s line %d: too many deny users.",
Damien Miller78928792000-04-12 20:17:38 +1000671 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000672 options->deny_users[options->num_deny_users++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100673 }
674 break;
675
676 case sAllowGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000677 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000678 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000679 fatal("%s line %d: too many allow groups.",
Damien Miller78928792000-04-12 20:17:38 +1000680 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000681 options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100682 }
683 break;
684
685 case sDenyGroups:
Damien Millerbe484b52000-07-15 14:14:16 +1000686 while ((arg = strdelim(&cp)) && *arg != '\0') {
Damien Miller78928792000-04-12 20:17:38 +1000687 if (options->num_deny_groups >= MAX_DENY_GROUPS)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000688 fatal("%s line %d: too many deny groups.",
Damien Miller78928792000-04-12 20:17:38 +1000689 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000690 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100691 }
692 break;
693
Damien Miller78928792000-04-12 20:17:38 +1000694 case sCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +1000695 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000696 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000697 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000698 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +1000699 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000700 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000701 if (options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000702 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +1000703 break;
704
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000705 case sMacs:
706 arg = strdelim(&cp);
707 if (!arg || *arg == '\0')
708 fatal("%s line %d: Missing argument.", filename, linenum);
709 if (!mac_valid(arg))
710 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
711 filename, linenum, arg ? arg : "<NONE>");
712 if (options->macs == NULL)
713 options->macs = xstrdup(arg);
714 break;
715
Damien Miller78928792000-04-12 20:17:38 +1000716 case sProtocol:
717 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +1000718 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000719 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +1000720 fatal("%s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000721 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +1000722 if (value == SSH_PROTO_UNKNOWN)
723 fatal("%s line %d: Bad protocol spec '%s'.",
Damien Miller37023962000-07-11 17:31:38 +1000724 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +1000725 if (*intptr == SSH_PROTO_UNKNOWN)
726 *intptr = value;
727 break;
728
Damien Millerf6d9e222000-06-18 14:50:44 +1000729 case sSubsystem:
730 if(options->num_subsystems >= MAX_SUBSYSTEMS) {
731 fatal("%s line %d: too many subsystems defined.",
732 filename, linenum);
733 }
Damien Millerbe484b52000-07-15 14:14:16 +1000734 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000735 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000736 fatal("%s line %d: Missing subsystem name.",
737 filename, linenum);
738 for (i = 0; i < options->num_subsystems; i++)
Damien Miller37023962000-07-11 17:31:38 +1000739 if(strcmp(arg, options->subsystem_name[i]) == 0)
Damien Millerf6d9e222000-06-18 14:50:44 +1000740 fatal("%s line %d: Subsystem '%s' already defined.",
Damien Miller37023962000-07-11 17:31:38 +1000741 filename, linenum, arg);
742 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
Damien Millerbe484b52000-07-15 14:14:16 +1000743 arg = strdelim(&cp);
Damien Miller37023962000-07-11 17:31:38 +1000744 if (!arg || *arg == '\0')
Damien Millerf6d9e222000-06-18 14:50:44 +1000745 fatal("%s line %d: Missing subsystem command.",
746 filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +1000747 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
Damien Millerf6d9e222000-06-18 14:50:44 +1000748 options->num_subsystems++;
749 break;
750
Damien Miller37023962000-07-11 17:31:38 +1000751 case sMaxStartups:
Damien Miller942da032000-08-18 13:59:06 +1000752 arg = strdelim(&cp);
753 if (!arg || *arg == '\0')
754 fatal("%s line %d: Missing MaxStartups spec.",
755 filename, linenum);
756 if (sscanf(arg, "%d:%d:%d",
757 &options->max_startups_begin,
758 &options->max_startups_rate,
759 &options->max_startups) == 3) {
760 if (options->max_startups_begin >
761 options->max_startups ||
762 options->max_startups_rate > 100 ||
763 options->max_startups_rate < 1)
764 fatal("%s line %d: Illegal MaxStartups spec.",
765 filename, linenum);
766 break;
767 }
Damien Miller37023962000-07-11 17:31:38 +1000768 intptr = &options->max_startups;
769 goto parse_int;
770
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000771 case sBanner:
772 charptr = &options->banner;
773 goto parse_filename;
Kevin Stevesef4eea92001-02-05 12:42:17 +0000774
Damien Miller95def091999-11-25 00:26:21 +1100775 default:
776 fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
Damien Miller37023962000-07-11 17:31:38 +1000777 filename, linenum, arg, opcode);
Damien Miller95def091999-11-25 00:26:21 +1100778 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000779 }
Damien Millerbe484b52000-07-15 14:14:16 +1000780 if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
Kevin Stevesef4eea92001-02-05 12:42:17 +0000781 fprintf(stderr,
Damien Miller37023962000-07-11 17:31:38 +1000782 "%s line %d: garbage at end of line; \"%.200s\".\n",
783 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100784 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000785 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000786 }
Damien Miller95def091999-11-25 00:26:21 +1100787 fclose(f);
788 if (bad_options > 0) {
789 fprintf(stderr, "%s: terminating, %d bad configuration options\n",
790 filename, bad_options);
791 exit(1);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000792 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000793}