1 | /* |
---|
2 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
---|
3 | * All rights reserved |
---|
4 | * |
---|
5 | * 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". |
---|
10 | */ |
---|
11 | |
---|
12 | #include "includes.h" |
---|
13 | RCSID("$OpenBSD: servconf.c,v 1.115 2002/09/04 18:52:42 stevesk Exp $"); |
---|
14 | |
---|
15 | #if defined(KRB4) |
---|
16 | #include <krb.h> |
---|
17 | #endif |
---|
18 | #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 |
---|
27 | #ifdef AFS |
---|
28 | #include <kafs.h> |
---|
29 | #endif |
---|
30 | |
---|
31 | #include "ssh.h" |
---|
32 | #include "log.h" |
---|
33 | #include "servconf.h" |
---|
34 | #include "xmalloc.h" |
---|
35 | #include "compat.h" |
---|
36 | #include "pathnames.h" |
---|
37 | #include "tildexpand.h" |
---|
38 | #include "misc.h" |
---|
39 | #include "cipher.h" |
---|
40 | #include "kex.h" |
---|
41 | #include "mac.h" |
---|
42 | |
---|
43 | static void add_listen_addr(ServerOptions *, char *, u_short); |
---|
44 | static void add_one_listen_addr(ServerOptions *, char *, u_short); |
---|
45 | |
---|
46 | /* AF_UNSPEC or AF_INET or AF_INET6 */ |
---|
47 | extern int IPv4or6; |
---|
48 | /* Use of privilege separation or not */ |
---|
49 | extern int use_privsep; |
---|
50 | |
---|
51 | /* Initializes the server options to their default values. */ |
---|
52 | |
---|
53 | void |
---|
54 | initialize_server_options(ServerOptions *options) |
---|
55 | { |
---|
56 | memset(options, 0, sizeof(*options)); |
---|
57 | |
---|
58 | /* Portable-specific options */ |
---|
59 | options->pam_authentication_via_kbd_int = -1; |
---|
60 | |
---|
61 | /* Standard Options */ |
---|
62 | options->num_ports = 0; |
---|
63 | options->ports_from_cmdline = 0; |
---|
64 | options->listen_addrs = NULL; |
---|
65 | options->num_host_key_files = 0; |
---|
66 | options->pid_file = NULL; |
---|
67 | options->server_key_bits = -1; |
---|
68 | options->login_grace_time = -1; |
---|
69 | options->key_regeneration_time = -1; |
---|
70 | options->permit_root_login = PERMIT_NOT_SET; |
---|
71 | options->ignore_rhosts = -1; |
---|
72 | options->ignore_user_known_hosts = -1; |
---|
73 | options->print_motd = -1; |
---|
74 | options->print_lastlog = -1; |
---|
75 | options->x11_forwarding = -1; |
---|
76 | options->x11_display_offset = -1; |
---|
77 | options->x11_use_localhost = -1; |
---|
78 | options->xauth_location = NULL; |
---|
79 | options->strict_modes = -1; |
---|
80 | options->keepalives = -1; |
---|
81 | options->log_facility = SYSLOG_FACILITY_NOT_SET; |
---|
82 | options->log_level = SYSLOG_LEVEL_NOT_SET; |
---|
83 | options->rhosts_authentication = -1; |
---|
84 | options->rhosts_rsa_authentication = -1; |
---|
85 | options->hostbased_authentication = -1; |
---|
86 | options->hostbased_uses_name_from_packet_only = -1; |
---|
87 | options->rsa_authentication = -1; |
---|
88 | options->pubkey_authentication = -1; |
---|
89 | #ifdef GSSAPI |
---|
90 | options->gss_authentication=-1; |
---|
91 | options->gss_keyex=-1; |
---|
92 | options->gss_use_session_ccache = -1; |
---|
93 | options->gss_cleanup_creds = -1; |
---|
94 | #endif |
---|
95 | #if defined(KRB4) || defined(KRB5) |
---|
96 | options->kerberos_authentication = -1; |
---|
97 | options->kerberos_or_local_passwd = -1; |
---|
98 | options->kerberos_ticket_cleanup = -1; |
---|
99 | #endif |
---|
100 | #if defined(AFS) || defined(KRB5) |
---|
101 | options->kerberos_tgt_passing = -1; |
---|
102 | #endif |
---|
103 | #ifdef KRB5 |
---|
104 | options->kerberos524 = -1; |
---|
105 | #endif |
---|
106 | #ifdef AFS |
---|
107 | options->afs_token_passing = -1; |
---|
108 | #endif |
---|
109 | options->password_authentication = -1; |
---|
110 | options->kbd_interactive_authentication = -1; |
---|
111 | options->challenge_response_authentication = -1; |
---|
112 | options->permit_empty_passwd = -1; |
---|
113 | options->permit_user_env = -1; |
---|
114 | options->use_login = -1; |
---|
115 | options->compression = -1; |
---|
116 | options->allow_tcp_forwarding = -1; |
---|
117 | options->num_allow_users = 0; |
---|
118 | options->num_deny_users = 0; |
---|
119 | options->num_allow_groups = 0; |
---|
120 | options->num_deny_groups = 0; |
---|
121 | options->ciphers = NULL; |
---|
122 | options->macs = NULL; |
---|
123 | options->protocol = SSH_PROTO_UNKNOWN; |
---|
124 | options->gateway_ports = -1; |
---|
125 | options->num_subsystems = 0; |
---|
126 | options->max_startups_begin = -1; |
---|
127 | options->max_startups_rate = -1; |
---|
128 | options->max_startups = -1; |
---|
129 | options->banner = NULL; |
---|
130 | options->verify_reverse_mapping = -1; |
---|
131 | options->client_alive_interval = -1; |
---|
132 | options->client_alive_count_max = -1; |
---|
133 | options->authorized_keys_file = NULL; |
---|
134 | options->authorized_keys_file2 = NULL; |
---|
135 | |
---|
136 | /* Needs to be accessable in many places */ |
---|
137 | use_privsep = -1; |
---|
138 | } |
---|
139 | |
---|
140 | void |
---|
141 | fill_default_server_options(ServerOptions *options) |
---|
142 | { |
---|
143 | /* Portable-specific options */ |
---|
144 | if (options->pam_authentication_via_kbd_int == -1) |
---|
145 | options->pam_authentication_via_kbd_int = 0; |
---|
146 | |
---|
147 | /* Standard Options */ |
---|
148 | if (options->protocol == SSH_PROTO_UNKNOWN) |
---|
149 | options->protocol = SSH_PROTO_1|SSH_PROTO_2; |
---|
150 | if (options->num_host_key_files == 0) { |
---|
151 | /* fill default hostkeys for protocols */ |
---|
152 | if (options->protocol & SSH_PROTO_1) |
---|
153 | options->host_key_files[options->num_host_key_files++] = |
---|
154 | _PATH_HOST_KEY_FILE; |
---|
155 | if (options->protocol & SSH_PROTO_2) { |
---|
156 | options->host_key_files[options->num_host_key_files++] = |
---|
157 | _PATH_HOST_RSA_KEY_FILE; |
---|
158 | options->host_key_files[options->num_host_key_files++] = |
---|
159 | _PATH_HOST_DSA_KEY_FILE; |
---|
160 | } |
---|
161 | } |
---|
162 | if (options->num_ports == 0) |
---|
163 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
---|
164 | if (options->listen_addrs == NULL) |
---|
165 | add_listen_addr(options, NULL, 0); |
---|
166 | if (options->pid_file == NULL) |
---|
167 | options->pid_file = _PATH_SSH_DAEMON_PID_FILE; |
---|
168 | if (options->server_key_bits == -1) |
---|
169 | options->server_key_bits = 768; |
---|
170 | if (options->login_grace_time == -1) |
---|
171 | options->login_grace_time = 120; |
---|
172 | if (options->key_regeneration_time == -1) |
---|
173 | options->key_regeneration_time = 3600; |
---|
174 | if (options->permit_root_login == PERMIT_NOT_SET) |
---|
175 | options->permit_root_login = PERMIT_YES; |
---|
176 | if (options->ignore_rhosts == -1) |
---|
177 | options->ignore_rhosts = 1; |
---|
178 | if (options->ignore_user_known_hosts == -1) |
---|
179 | options->ignore_user_known_hosts = 0; |
---|
180 | if (options->print_motd == -1) |
---|
181 | options->print_motd = 1; |
---|
182 | if (options->print_lastlog == -1) |
---|
183 | options->print_lastlog = 1; |
---|
184 | if (options->x11_forwarding == -1) |
---|
185 | options->x11_forwarding = 0; |
---|
186 | if (options->x11_display_offset == -1) |
---|
187 | options->x11_display_offset = 10; |
---|
188 | if (options->x11_use_localhost == -1) |
---|
189 | options->x11_use_localhost = 1; |
---|
190 | if (options->xauth_location == NULL) |
---|
191 | options->xauth_location = _PATH_XAUTH; |
---|
192 | if (options->strict_modes == -1) |
---|
193 | options->strict_modes = 1; |
---|
194 | if (options->keepalives == -1) |
---|
195 | options->keepalives = 1; |
---|
196 | if (options->log_facility == SYSLOG_FACILITY_NOT_SET) |
---|
197 | options->log_facility = SYSLOG_FACILITY_AUTH; |
---|
198 | if (options->log_level == SYSLOG_LEVEL_NOT_SET) |
---|
199 | options->log_level = SYSLOG_LEVEL_INFO; |
---|
200 | if (options->rhosts_authentication == -1) |
---|
201 | options->rhosts_authentication = 0; |
---|
202 | if (options->rhosts_rsa_authentication == -1) |
---|
203 | options->rhosts_rsa_authentication = 0; |
---|
204 | if (options->hostbased_authentication == -1) |
---|
205 | options->hostbased_authentication = 0; |
---|
206 | if (options->hostbased_uses_name_from_packet_only == -1) |
---|
207 | options->hostbased_uses_name_from_packet_only = 0; |
---|
208 | if (options->rsa_authentication == -1) |
---|
209 | options->rsa_authentication = 1; |
---|
210 | if (options->pubkey_authentication == -1) |
---|
211 | options->pubkey_authentication = 1; |
---|
212 | #ifdef GSSAPI |
---|
213 | if (options->gss_authentication == -1) |
---|
214 | options->gss_authentication = 1; |
---|
215 | if (options->gss_keyex == -1) |
---|
216 | options->gss_keyex =1; |
---|
217 | if (options->gss_use_session_ccache == -1) |
---|
218 | options->gss_use_session_ccache = 1; |
---|
219 | if (options->gss_cleanup_creds == -1) |
---|
220 | options->gss_cleanup_creds = 1; |
---|
221 | #endif |
---|
222 | #if defined(KRB4) || defined(KRB5) |
---|
223 | if (options->kerberos_authentication == -1) |
---|
224 | options->kerberos_authentication = 1; |
---|
225 | if (options->kerberos_or_local_passwd == -1) |
---|
226 | options->kerberos_or_local_passwd = 1; |
---|
227 | if (options->kerberos_ticket_cleanup == -1) |
---|
228 | options->kerberos_ticket_cleanup = 1; |
---|
229 | #endif |
---|
230 | #if defined(AFS) || defined(KRB5) |
---|
231 | if (options->kerberos_tgt_passing == -1) |
---|
232 | options->kerberos_tgt_passing = 1; |
---|
233 | #endif |
---|
234 | #ifdef KRB5 |
---|
235 | if (options->kerberos524 == -1) |
---|
236 | options->kerberos524 = 1; |
---|
237 | #endif |
---|
238 | #ifdef AFS |
---|
239 | if (options->afs_token_passing == -1) |
---|
240 | options->afs_token_passing = 0; |
---|
241 | #endif |
---|
242 | if (options->password_authentication == -1) |
---|
243 | options->password_authentication = 1; |
---|
244 | if (options->kbd_interactive_authentication == -1) |
---|
245 | options->kbd_interactive_authentication = 0; |
---|
246 | if (options->challenge_response_authentication == -1) |
---|
247 | options->challenge_response_authentication = 1; |
---|
248 | if (options->permit_empty_passwd == -1) |
---|
249 | options->permit_empty_passwd = 0; |
---|
250 | if (options->permit_user_env == -1) |
---|
251 | options->permit_user_env = 0; |
---|
252 | if (options->use_login == -1) |
---|
253 | options->use_login = 0; |
---|
254 | if (options->compression == -1) |
---|
255 | options->compression = 1; |
---|
256 | if (options->allow_tcp_forwarding == -1) |
---|
257 | options->allow_tcp_forwarding = 1; |
---|
258 | if (options->gateway_ports == -1) |
---|
259 | options->gateway_ports = 0; |
---|
260 | if (options->max_startups == -1) |
---|
261 | options->max_startups = 10; |
---|
262 | if (options->max_startups_rate == -1) |
---|
263 | options->max_startups_rate = 100; /* 100% */ |
---|
264 | if (options->max_startups_begin == -1) |
---|
265 | options->max_startups_begin = options->max_startups; |
---|
266 | if (options->verify_reverse_mapping == -1) |
---|
267 | options->verify_reverse_mapping = 0; |
---|
268 | if (options->client_alive_interval == -1) |
---|
269 | options->client_alive_interval = 0; |
---|
270 | if (options->client_alive_count_max == -1) |
---|
271 | options->client_alive_count_max = 3; |
---|
272 | if (options->authorized_keys_file2 == NULL) { |
---|
273 | /* authorized_keys_file2 falls back to authorized_keys_file */ |
---|
274 | if (options->authorized_keys_file != NULL) |
---|
275 | options->authorized_keys_file2 = options->authorized_keys_file; |
---|
276 | else |
---|
277 | options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2; |
---|
278 | } |
---|
279 | if (options->authorized_keys_file == NULL) |
---|
280 | options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS; |
---|
281 | |
---|
282 | /* Turn privilege separation on by default */ |
---|
283 | if (use_privsep == -1) |
---|
284 | use_privsep = 1; |
---|
285 | |
---|
286 | #ifndef HAVE_MMAP |
---|
287 | if (use_privsep && options->compression == 1) { |
---|
288 | error("This platform does not support both privilege " |
---|
289 | "separation and compression"); |
---|
290 | error("Compression disabled"); |
---|
291 | options->compression = 0; |
---|
292 | } |
---|
293 | #endif |
---|
294 | |
---|
295 | } |
---|
296 | |
---|
297 | /* Keyword tokens. */ |
---|
298 | typedef enum { |
---|
299 | sBadOption, /* == unknown option */ |
---|
300 | /* Portable-specific options */ |
---|
301 | sPAMAuthenticationViaKbdInt, |
---|
302 | /* Standard Options */ |
---|
303 | sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime, |
---|
304 | sPermitRootLogin, sLogFacility, sLogLevel, |
---|
305 | sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication, |
---|
306 | #ifdef GSSAPI |
---|
307 | sGssAuthentication, sGssKeyEx, sGssUseSessionCredCache, sGssCleanupCreds, |
---|
308 | #endif |
---|
309 | #if defined(KRB4) || defined(KRB5) |
---|
310 | sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup, |
---|
311 | #endif |
---|
312 | #if defined(AFS) || defined(KRB5) |
---|
313 | sKerberosTgtPassing, |
---|
314 | #endif |
---|
315 | #ifdef KRB5 |
---|
316 | sKerberos524, |
---|
317 | #endif |
---|
318 | #ifdef AFS |
---|
319 | sAFSTokenPassing, |
---|
320 | #endif |
---|
321 | sChallengeResponseAuthentication, |
---|
322 | sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress, |
---|
323 | sPrintMotd, sPrintLastLog, sIgnoreRhosts, |
---|
324 | sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost, |
---|
325 | sStrictModes, sEmptyPasswd, sKeepAlives, |
---|
326 | sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression, |
---|
327 | sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups, |
---|
328 | sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile, |
---|
329 | sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups, |
---|
330 | sBanner, sVerifyReverseMapping, sHostbasedAuthentication, |
---|
331 | sHostbasedUsesNameFromPacketOnly, sClientAliveInterval, |
---|
332 | sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2, |
---|
333 | sUsePrivilegeSeparation, |
---|
334 | sDeprecated |
---|
335 | } ServerOpCodes; |
---|
336 | |
---|
337 | /* Textual representation of the tokens. */ |
---|
338 | static struct { |
---|
339 | const char *name; |
---|
340 | ServerOpCodes opcode; |
---|
341 | } keywords[] = { |
---|
342 | /* Portable-specific options */ |
---|
343 | { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt }, |
---|
344 | /* Standard Options */ |
---|
345 | { "port", sPort }, |
---|
346 | { "hostkey", sHostKeyFile }, |
---|
347 | { "hostdsakey", sHostKeyFile }, /* alias */ |
---|
348 | { "pidfile", sPidFile }, |
---|
349 | { "serverkeybits", sServerKeyBits }, |
---|
350 | { "logingracetime", sLoginGraceTime }, |
---|
351 | { "keyregenerationinterval", sKeyRegenerationTime }, |
---|
352 | { "permitrootlogin", sPermitRootLogin }, |
---|
353 | { "syslogfacility", sLogFacility }, |
---|
354 | { "loglevel", sLogLevel }, |
---|
355 | { "rhostsauthentication", sRhostsAuthentication }, |
---|
356 | { "rhostsrsaauthentication", sRhostsRSAAuthentication }, |
---|
357 | { "hostbasedauthentication", sHostbasedAuthentication }, |
---|
358 | { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly }, |
---|
359 | { "rsaauthentication", sRSAAuthentication }, |
---|
360 | { "pubkeyauthentication", sPubkeyAuthentication }, |
---|
361 | { "dsaauthentication", sPubkeyAuthentication }, /* alias */ |
---|
362 | #ifdef GSSAPI |
---|
363 | { "gssapiauthentication", sGssAuthentication }, |
---|
364 | { "gssapikeyexchange", sGssKeyEx }, |
---|
365 | { "gssusesessionccache", sGssUseSessionCredCache }, |
---|
366 | { "gssapiusesessioncredcache", sGssUseSessionCredCache }, |
---|
367 | { "gssapicleanupcreds", sGssCleanupCreds }, |
---|
368 | #endif |
---|
369 | #if defined(KRB4) || defined(KRB5) |
---|
370 | { "kerberosauthentication", sKerberosAuthentication }, |
---|
371 | { "kerberosorlocalpasswd", sKerberosOrLocalPasswd }, |
---|
372 | { "kerberosticketcleanup", sKerberosTicketCleanup }, |
---|
373 | #endif |
---|
374 | #if defined(AFS) || defined(KRB5) |
---|
375 | { "kerberostgtpassing", sKerberosTgtPassing }, |
---|
376 | #endif |
---|
377 | #ifdef KRB5 |
---|
378 | { "kerberos524", sKerberos524 }, |
---|
379 | #endif |
---|
380 | #ifdef AFS |
---|
381 | { "afstokenpassing", sAFSTokenPassing }, |
---|
382 | #endif |
---|
383 | { "passwordauthentication", sPasswordAuthentication }, |
---|
384 | { "kbdinteractiveauthentication", sKbdInteractiveAuthentication }, |
---|
385 | { "challengeresponseauthentication", sChallengeResponseAuthentication }, |
---|
386 | { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */ |
---|
387 | { "checkmail", sDeprecated }, |
---|
388 | { "listenaddress", sListenAddress }, |
---|
389 | { "printmotd", sPrintMotd }, |
---|
390 | { "printlastlog", sPrintLastLog }, |
---|
391 | { "ignorerhosts", sIgnoreRhosts }, |
---|
392 | { "ignoreuserknownhosts", sIgnoreUserKnownHosts }, |
---|
393 | { "x11forwarding", sX11Forwarding }, |
---|
394 | { "x11displayoffset", sX11DisplayOffset }, |
---|
395 | { "x11uselocalhost", sX11UseLocalhost }, |
---|
396 | { "xauthlocation", sXAuthLocation }, |
---|
397 | { "strictmodes", sStrictModes }, |
---|
398 | { "permitemptypasswords", sEmptyPasswd }, |
---|
399 | { "permituserenvironment", sPermitUserEnvironment }, |
---|
400 | { "uselogin", sUseLogin }, |
---|
401 | { "compression", sCompression }, |
---|
402 | { "keepalive", sKeepAlives }, |
---|
403 | { "allowtcpforwarding", sAllowTcpForwarding }, |
---|
404 | { "allowusers", sAllowUsers }, |
---|
405 | { "denyusers", sDenyUsers }, |
---|
406 | { "allowgroups", sAllowGroups }, |
---|
407 | { "denygroups", sDenyGroups }, |
---|
408 | { "ciphers", sCiphers }, |
---|
409 | { "macs", sMacs }, |
---|
410 | { "protocol", sProtocol }, |
---|
411 | { "gatewayports", sGatewayPorts }, |
---|
412 | { "subsystem", sSubsystem }, |
---|
413 | { "maxstartups", sMaxStartups }, |
---|
414 | { "banner", sBanner }, |
---|
415 | { "verifyreversemapping", sVerifyReverseMapping }, |
---|
416 | { "reversemappingcheck", sVerifyReverseMapping }, |
---|
417 | { "clientaliveinterval", sClientAliveInterval }, |
---|
418 | { "clientalivecountmax", sClientAliveCountMax }, |
---|
419 | { "authorizedkeysfile", sAuthorizedKeysFile }, |
---|
420 | { "authorizedkeysfile2", sAuthorizedKeysFile2 }, |
---|
421 | { "useprivilegeseparation", sUsePrivilegeSeparation}, |
---|
422 | { NULL, sBadOption } |
---|
423 | }; |
---|
424 | |
---|
425 | /* |
---|
426 | * Returns the number of the token pointed to by cp or sBadOption. |
---|
427 | */ |
---|
428 | |
---|
429 | static ServerOpCodes |
---|
430 | parse_token(const char *cp, const char *filename, |
---|
431 | int linenum) |
---|
432 | { |
---|
433 | u_int i; |
---|
434 | |
---|
435 | for (i = 0; keywords[i].name; i++) |
---|
436 | if (strcasecmp(cp, keywords[i].name) == 0) |
---|
437 | return keywords[i].opcode; |
---|
438 | |
---|
439 | error("%s: line %d: Bad configuration option: %s", |
---|
440 | filename, linenum, cp); |
---|
441 | return sBadOption; |
---|
442 | } |
---|
443 | |
---|
444 | static void |
---|
445 | add_listen_addr(ServerOptions *options, char *addr, u_short port) |
---|
446 | { |
---|
447 | int i; |
---|
448 | |
---|
449 | if (options->num_ports == 0) |
---|
450 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
---|
451 | if (port == 0) |
---|
452 | for (i = 0; i < options->num_ports; i++) |
---|
453 | add_one_listen_addr(options, addr, options->ports[i]); |
---|
454 | else |
---|
455 | add_one_listen_addr(options, addr, port); |
---|
456 | } |
---|
457 | |
---|
458 | static void |
---|
459 | add_one_listen_addr(ServerOptions *options, char *addr, u_short port) |
---|
460 | { |
---|
461 | struct addrinfo hints, *ai, *aitop; |
---|
462 | char strport[NI_MAXSERV]; |
---|
463 | int gaierr; |
---|
464 | |
---|
465 | memset(&hints, 0, sizeof(hints)); |
---|
466 | hints.ai_family = IPv4or6; |
---|
467 | hints.ai_socktype = SOCK_STREAM; |
---|
468 | hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; |
---|
469 | snprintf(strport, sizeof strport, "%u", port); |
---|
470 | if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0) |
---|
471 | fatal("bad addr or host: %s (%s)", |
---|
472 | addr ? addr : "<NULL>", |
---|
473 | gai_strerror(gaierr)); |
---|
474 | for (ai = aitop; ai->ai_next; ai = ai->ai_next) |
---|
475 | ; |
---|
476 | ai->ai_next = options->listen_addrs; |
---|
477 | options->listen_addrs = aitop; |
---|
478 | } |
---|
479 | |
---|
480 | int |
---|
481 | process_server_config_line(ServerOptions *options, char *line, |
---|
482 | const char *filename, int linenum) |
---|
483 | { |
---|
484 | char *cp, **charptr, *arg, *p; |
---|
485 | int *intptr, value, i, n; |
---|
486 | ServerOpCodes opcode; |
---|
487 | |
---|
488 | cp = line; |
---|
489 | arg = strdelim(&cp); |
---|
490 | /* Ignore leading whitespace */ |
---|
491 | if (*arg == '\0') |
---|
492 | arg = strdelim(&cp); |
---|
493 | if (!arg || !*arg || *arg == '#') |
---|
494 | return 0; |
---|
495 | intptr = NULL; |
---|
496 | charptr = NULL; |
---|
497 | opcode = parse_token(arg, filename, linenum); |
---|
498 | switch (opcode) { |
---|
499 | /* Portable-specific options */ |
---|
500 | case sPAMAuthenticationViaKbdInt: |
---|
501 | intptr = &options->pam_authentication_via_kbd_int; |
---|
502 | goto parse_flag; |
---|
503 | |
---|
504 | /* Standard Options */ |
---|
505 | case sBadOption: |
---|
506 | return -1; |
---|
507 | case sPort: |
---|
508 | /* ignore ports from configfile if cmdline specifies ports */ |
---|
509 | if (options->ports_from_cmdline) |
---|
510 | return 0; |
---|
511 | if (options->listen_addrs != NULL) |
---|
512 | fatal("%s line %d: ports must be specified before " |
---|
513 | "ListenAddress.", filename, linenum); |
---|
514 | if (options->num_ports >= MAX_PORTS) |
---|
515 | fatal("%s line %d: too many ports.", |
---|
516 | filename, linenum); |
---|
517 | arg = strdelim(&cp); |
---|
518 | if (!arg || *arg == '\0') |
---|
519 | fatal("%s line %d: missing port number.", |
---|
520 | filename, linenum); |
---|
521 | options->ports[options->num_ports++] = a2port(arg); |
---|
522 | if (options->ports[options->num_ports-1] == 0) |
---|
523 | fatal("%s line %d: Badly formatted port number.", |
---|
524 | filename, linenum); |
---|
525 | break; |
---|
526 | |
---|
527 | case sServerKeyBits: |
---|
528 | intptr = &options->server_key_bits; |
---|
529 | parse_int: |
---|
530 | arg = strdelim(&cp); |
---|
531 | if (!arg || *arg == '\0') |
---|
532 | fatal("%s line %d: missing integer value.", |
---|
533 | filename, linenum); |
---|
534 | value = atoi(arg); |
---|
535 | if (*intptr == -1) |
---|
536 | *intptr = value; |
---|
537 | break; |
---|
538 | |
---|
539 | case sLoginGraceTime: |
---|
540 | intptr = &options->login_grace_time; |
---|
541 | parse_time: |
---|
542 | arg = strdelim(&cp); |
---|
543 | if (!arg || *arg == '\0') |
---|
544 | fatal("%s line %d: missing time value.", |
---|
545 | filename, linenum); |
---|
546 | if ((value = convtime(arg)) == -1) |
---|
547 | fatal("%s line %d: invalid time value.", |
---|
548 | filename, linenum); |
---|
549 | if (*intptr == -1) |
---|
550 | *intptr = value; |
---|
551 | break; |
---|
552 | |
---|
553 | case sKeyRegenerationTime: |
---|
554 | intptr = &options->key_regeneration_time; |
---|
555 | goto parse_time; |
---|
556 | |
---|
557 | case sListenAddress: |
---|
558 | arg = strdelim(&cp); |
---|
559 | if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0) |
---|
560 | fatal("%s line %d: missing inet addr.", |
---|
561 | filename, linenum); |
---|
562 | if (*arg == '[') { |
---|
563 | if ((p = strchr(arg, ']')) == NULL) |
---|
564 | fatal("%s line %d: bad ipv6 inet addr usage.", |
---|
565 | filename, linenum); |
---|
566 | arg++; |
---|
567 | memmove(p, p+1, strlen(p+1)+1); |
---|
568 | } else if (((p = strchr(arg, ':')) == NULL) || |
---|
569 | (strchr(p+1, ':') != NULL)) { |
---|
570 | add_listen_addr(options, arg, 0); |
---|
571 | break; |
---|
572 | } |
---|
573 | if (*p == ':') { |
---|
574 | u_short port; |
---|
575 | |
---|
576 | p++; |
---|
577 | if (*p == '\0') |
---|
578 | fatal("%s line %d: bad inet addr:port usage.", |
---|
579 | filename, linenum); |
---|
580 | else { |
---|
581 | *(p-1) = '\0'; |
---|
582 | if ((port = a2port(p)) == 0) |
---|
583 | fatal("%s line %d: bad port number.", |
---|
584 | filename, linenum); |
---|
585 | add_listen_addr(options, arg, port); |
---|
586 | } |
---|
587 | } else if (*p == '\0') |
---|
588 | add_listen_addr(options, arg, 0); |
---|
589 | else |
---|
590 | fatal("%s line %d: bad inet addr usage.", |
---|
591 | filename, linenum); |
---|
592 | break; |
---|
593 | |
---|
594 | case sHostKeyFile: |
---|
595 | intptr = &options->num_host_key_files; |
---|
596 | if (*intptr >= MAX_HOSTKEYS) |
---|
597 | fatal("%s line %d: too many host keys specified (max %d).", |
---|
598 | filename, linenum, MAX_HOSTKEYS); |
---|
599 | charptr = &options->host_key_files[*intptr]; |
---|
600 | parse_filename: |
---|
601 | arg = strdelim(&cp); |
---|
602 | if (!arg || *arg == '\0') |
---|
603 | fatal("%s line %d: missing file name.", |
---|
604 | filename, linenum); |
---|
605 | if (*charptr == NULL) { |
---|
606 | *charptr = tilde_expand_filename(arg, getuid()); |
---|
607 | /* increase optional counter */ |
---|
608 | if (intptr != NULL) |
---|
609 | *intptr = *intptr + 1; |
---|
610 | } |
---|
611 | break; |
---|
612 | |
---|
613 | case sPidFile: |
---|
614 | charptr = &options->pid_file; |
---|
615 | goto parse_filename; |
---|
616 | |
---|
617 | case sPermitRootLogin: |
---|
618 | intptr = &options->permit_root_login; |
---|
619 | arg = strdelim(&cp); |
---|
620 | if (!arg || *arg == '\0') |
---|
621 | fatal("%s line %d: missing yes/" |
---|
622 | "without-password/forced-commands-only/no " |
---|
623 | "argument.", filename, linenum); |
---|
624 | value = 0; /* silence compiler */ |
---|
625 | if (strcmp(arg, "without-password") == 0) |
---|
626 | value = PERMIT_NO_PASSWD; |
---|
627 | else if (strcmp(arg, "forced-commands-only") == 0) |
---|
628 | value = PERMIT_FORCED_ONLY; |
---|
629 | else if (strcmp(arg, "yes") == 0) |
---|
630 | value = PERMIT_YES; |
---|
631 | else if (strcmp(arg, "no") == 0) |
---|
632 | value = PERMIT_NO; |
---|
633 | else |
---|
634 | fatal("%s line %d: Bad yes/" |
---|
635 | "without-password/forced-commands-only/no " |
---|
636 | "argument: %s", filename, linenum, arg); |
---|
637 | if (*intptr == -1) |
---|
638 | *intptr = value; |
---|
639 | break; |
---|
640 | |
---|
641 | case sIgnoreRhosts: |
---|
642 | intptr = &options->ignore_rhosts; |
---|
643 | parse_flag: |
---|
644 | arg = strdelim(&cp); |
---|
645 | if (!arg || *arg == '\0') |
---|
646 | fatal("%s line %d: missing yes/no argument.", |
---|
647 | filename, linenum); |
---|
648 | value = 0; /* silence compiler */ |
---|
649 | if (strcmp(arg, "yes") == 0) |
---|
650 | value = 1; |
---|
651 | else if (strcmp(arg, "no") == 0) |
---|
652 | value = 0; |
---|
653 | else |
---|
654 | fatal("%s line %d: Bad yes/no argument: %s", |
---|
655 | filename, linenum, arg); |
---|
656 | if (*intptr == -1) |
---|
657 | *intptr = value; |
---|
658 | break; |
---|
659 | |
---|
660 | case sIgnoreUserKnownHosts: |
---|
661 | intptr = &options->ignore_user_known_hosts; |
---|
662 | goto parse_flag; |
---|
663 | |
---|
664 | case sRhostsAuthentication: |
---|
665 | intptr = &options->rhosts_authentication; |
---|
666 | goto parse_flag; |
---|
667 | |
---|
668 | case sRhostsRSAAuthentication: |
---|
669 | intptr = &options->rhosts_rsa_authentication; |
---|
670 | goto parse_flag; |
---|
671 | |
---|
672 | case sHostbasedAuthentication: |
---|
673 | intptr = &options->hostbased_authentication; |
---|
674 | goto parse_flag; |
---|
675 | |
---|
676 | case sHostbasedUsesNameFromPacketOnly: |
---|
677 | intptr = &options->hostbased_uses_name_from_packet_only; |
---|
678 | goto parse_flag; |
---|
679 | |
---|
680 | case sRSAAuthentication: |
---|
681 | intptr = &options->rsa_authentication; |
---|
682 | goto parse_flag; |
---|
683 | |
---|
684 | case sPubkeyAuthentication: |
---|
685 | intptr = &options->pubkey_authentication; |
---|
686 | goto parse_flag; |
---|
687 | #ifdef GSSAPI |
---|
688 | case sGssAuthentication: |
---|
689 | intptr = &options->gss_authentication; |
---|
690 | goto parse_flag; |
---|
691 | case sGssKeyEx: |
---|
692 | intptr = &options->gss_keyex; |
---|
693 | goto parse_flag; |
---|
694 | case sGssUseSessionCredCache: |
---|
695 | intptr = &options->gss_use_session_ccache; |
---|
696 | goto parse_flag; |
---|
697 | case sGssCleanupCreds: |
---|
698 | intptr = &options->gss_cleanup_creds; |
---|
699 | goto parse_flag; |
---|
700 | #endif |
---|
701 | #if defined(KRB4) || defined(KRB5) |
---|
702 | case sKerberosAuthentication: |
---|
703 | intptr = &options->kerberos_authentication; |
---|
704 | goto parse_flag; |
---|
705 | |
---|
706 | case sKerberosOrLocalPasswd: |
---|
707 | intptr = &options->kerberos_or_local_passwd; |
---|
708 | goto parse_flag; |
---|
709 | |
---|
710 | case sKerberosTicketCleanup: |
---|
711 | intptr = &options->kerberos_ticket_cleanup; |
---|
712 | goto parse_flag; |
---|
713 | #endif |
---|
714 | #if defined(AFS) || defined(KRB5) |
---|
715 | case sKerberosTgtPassing: |
---|
716 | intptr = &options->kerberos_tgt_passing; |
---|
717 | goto parse_flag; |
---|
718 | #endif |
---|
719 | #ifdef KRB5 |
---|
720 | case sKerberos524: |
---|
721 | intptr = &options->kerberos524; |
---|
722 | goto parse_flag; |
---|
723 | #endif |
---|
724 | #ifdef AFS |
---|
725 | case sAFSTokenPassing: |
---|
726 | intptr = &options->afs_token_passing; |
---|
727 | goto parse_flag; |
---|
728 | #endif |
---|
729 | |
---|
730 | case sPasswordAuthentication: |
---|
731 | intptr = &options->password_authentication; |
---|
732 | goto parse_flag; |
---|
733 | |
---|
734 | case sKbdInteractiveAuthentication: |
---|
735 | intptr = &options->kbd_interactive_authentication; |
---|
736 | goto parse_flag; |
---|
737 | |
---|
738 | case sChallengeResponseAuthentication: |
---|
739 | intptr = &options->challenge_response_authentication; |
---|
740 | goto parse_flag; |
---|
741 | |
---|
742 | case sPrintMotd: |
---|
743 | intptr = &options->print_motd; |
---|
744 | goto parse_flag; |
---|
745 | |
---|
746 | case sPrintLastLog: |
---|
747 | intptr = &options->print_lastlog; |
---|
748 | goto parse_flag; |
---|
749 | |
---|
750 | case sX11Forwarding: |
---|
751 | intptr = &options->x11_forwarding; |
---|
752 | goto parse_flag; |
---|
753 | |
---|
754 | case sX11DisplayOffset: |
---|
755 | intptr = &options->x11_display_offset; |
---|
756 | goto parse_int; |
---|
757 | |
---|
758 | case sX11UseLocalhost: |
---|
759 | intptr = &options->x11_use_localhost; |
---|
760 | goto parse_flag; |
---|
761 | |
---|
762 | case sXAuthLocation: |
---|
763 | charptr = &options->xauth_location; |
---|
764 | goto parse_filename; |
---|
765 | |
---|
766 | case sStrictModes: |
---|
767 | intptr = &options->strict_modes; |
---|
768 | goto parse_flag; |
---|
769 | |
---|
770 | case sKeepAlives: |
---|
771 | intptr = &options->keepalives; |
---|
772 | goto parse_flag; |
---|
773 | |
---|
774 | case sEmptyPasswd: |
---|
775 | intptr = &options->permit_empty_passwd; |
---|
776 | goto parse_flag; |
---|
777 | |
---|
778 | case sPermitUserEnvironment: |
---|
779 | intptr = &options->permit_user_env; |
---|
780 | goto parse_flag; |
---|
781 | |
---|
782 | case sUseLogin: |
---|
783 | intptr = &options->use_login; |
---|
784 | goto parse_flag; |
---|
785 | |
---|
786 | case sCompression: |
---|
787 | intptr = &options->compression; |
---|
788 | goto parse_flag; |
---|
789 | |
---|
790 | case sGatewayPorts: |
---|
791 | intptr = &options->gateway_ports; |
---|
792 | goto parse_flag; |
---|
793 | |
---|
794 | case sVerifyReverseMapping: |
---|
795 | intptr = &options->verify_reverse_mapping; |
---|
796 | goto parse_flag; |
---|
797 | |
---|
798 | case sLogFacility: |
---|
799 | intptr = (int *) &options->log_facility; |
---|
800 | arg = strdelim(&cp); |
---|
801 | value = log_facility_number(arg); |
---|
802 | if (value == SYSLOG_FACILITY_NOT_SET) |
---|
803 | fatal("%.200s line %d: unsupported log facility '%s'", |
---|
804 | filename, linenum, arg ? arg : "<NONE>"); |
---|
805 | if (*intptr == -1) |
---|
806 | *intptr = (SyslogFacility) value; |
---|
807 | break; |
---|
808 | |
---|
809 | case sLogLevel: |
---|
810 | intptr = (int *) &options->log_level; |
---|
811 | arg = strdelim(&cp); |
---|
812 | value = log_level_number(arg); |
---|
813 | if (value == SYSLOG_LEVEL_NOT_SET) |
---|
814 | fatal("%.200s line %d: unsupported log level '%s'", |
---|
815 | filename, linenum, arg ? arg : "<NONE>"); |
---|
816 | if (*intptr == -1) |
---|
817 | *intptr = (LogLevel) value; |
---|
818 | break; |
---|
819 | |
---|
820 | case sAllowTcpForwarding: |
---|
821 | intptr = &options->allow_tcp_forwarding; |
---|
822 | goto parse_flag; |
---|
823 | |
---|
824 | case sUsePrivilegeSeparation: |
---|
825 | intptr = &use_privsep; |
---|
826 | goto parse_flag; |
---|
827 | |
---|
828 | case sAllowUsers: |
---|
829 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
---|
830 | if (options->num_allow_users >= MAX_ALLOW_USERS) |
---|
831 | fatal("%s line %d: too many allow users.", |
---|
832 | filename, linenum); |
---|
833 | options->allow_users[options->num_allow_users++] = |
---|
834 | xstrdup(arg); |
---|
835 | } |
---|
836 | break; |
---|
837 | |
---|
838 | case sDenyUsers: |
---|
839 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
---|
840 | if (options->num_deny_users >= MAX_DENY_USERS) |
---|
841 | fatal( "%s line %d: too many deny users.", |
---|
842 | filename, linenum); |
---|
843 | options->deny_users[options->num_deny_users++] = |
---|
844 | xstrdup(arg); |
---|
845 | } |
---|
846 | break; |
---|
847 | |
---|
848 | case sAllowGroups: |
---|
849 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
---|
850 | if (options->num_allow_groups >= MAX_ALLOW_GROUPS) |
---|
851 | fatal("%s line %d: too many allow groups.", |
---|
852 | filename, linenum); |
---|
853 | options->allow_groups[options->num_allow_groups++] = |
---|
854 | xstrdup(arg); |
---|
855 | } |
---|
856 | break; |
---|
857 | |
---|
858 | case sDenyGroups: |
---|
859 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
---|
860 | if (options->num_deny_groups >= MAX_DENY_GROUPS) |
---|
861 | fatal("%s line %d: too many deny groups.", |
---|
862 | filename, linenum); |
---|
863 | options->deny_groups[options->num_deny_groups++] = xstrdup(arg); |
---|
864 | } |
---|
865 | break; |
---|
866 | |
---|
867 | case sCiphers: |
---|
868 | arg = strdelim(&cp); |
---|
869 | if (!arg || *arg == '\0') |
---|
870 | fatal("%s line %d: Missing argument.", filename, linenum); |
---|
871 | if (!ciphers_valid(arg)) |
---|
872 | fatal("%s line %d: Bad SSH2 cipher spec '%s'.", |
---|
873 | filename, linenum, arg ? arg : "<NONE>"); |
---|
874 | if (options->ciphers == NULL) |
---|
875 | options->ciphers = xstrdup(arg); |
---|
876 | break; |
---|
877 | |
---|
878 | case sMacs: |
---|
879 | arg = strdelim(&cp); |
---|
880 | if (!arg || *arg == '\0') |
---|
881 | fatal("%s line %d: Missing argument.", filename, linenum); |
---|
882 | if (!mac_valid(arg)) |
---|
883 | fatal("%s line %d: Bad SSH2 mac spec '%s'.", |
---|
884 | filename, linenum, arg ? arg : "<NONE>"); |
---|
885 | if (options->macs == NULL) |
---|
886 | options->macs = xstrdup(arg); |
---|
887 | break; |
---|
888 | |
---|
889 | case sProtocol: |
---|
890 | intptr = &options->protocol; |
---|
891 | arg = strdelim(&cp); |
---|
892 | if (!arg || *arg == '\0') |
---|
893 | fatal("%s line %d: Missing argument.", filename, linenum); |
---|
894 | value = proto_spec(arg); |
---|
895 | if (value == SSH_PROTO_UNKNOWN) |
---|
896 | fatal("%s line %d: Bad protocol spec '%s'.", |
---|
897 | filename, linenum, arg ? arg : "<NONE>"); |
---|
898 | if (*intptr == SSH_PROTO_UNKNOWN) |
---|
899 | *intptr = value; |
---|
900 | break; |
---|
901 | |
---|
902 | case sSubsystem: |
---|
903 | if (options->num_subsystems >= MAX_SUBSYSTEMS) { |
---|
904 | fatal("%s line %d: too many subsystems defined.", |
---|
905 | filename, linenum); |
---|
906 | } |
---|
907 | arg = strdelim(&cp); |
---|
908 | if (!arg || *arg == '\0') |
---|
909 | fatal("%s line %d: Missing subsystem name.", |
---|
910 | filename, linenum); |
---|
911 | for (i = 0; i < options->num_subsystems; i++) |
---|
912 | if (strcmp(arg, options->subsystem_name[i]) == 0) |
---|
913 | fatal("%s line %d: Subsystem '%s' already defined.", |
---|
914 | filename, linenum, arg); |
---|
915 | options->subsystem_name[options->num_subsystems] = xstrdup(arg); |
---|
916 | arg = strdelim(&cp); |
---|
917 | if (!arg || *arg == '\0') |
---|
918 | fatal("%s line %d: Missing subsystem command.", |
---|
919 | filename, linenum); |
---|
920 | options->subsystem_command[options->num_subsystems] = xstrdup(arg); |
---|
921 | options->num_subsystems++; |
---|
922 | break; |
---|
923 | |
---|
924 | case sMaxStartups: |
---|
925 | arg = strdelim(&cp); |
---|
926 | if (!arg || *arg == '\0') |
---|
927 | fatal("%s line %d: Missing MaxStartups spec.", |
---|
928 | filename, linenum); |
---|
929 | if ((n = sscanf(arg, "%d:%d:%d", |
---|
930 | &options->max_startups_begin, |
---|
931 | &options->max_startups_rate, |
---|
932 | &options->max_startups)) == 3) { |
---|
933 | if (options->max_startups_begin > |
---|
934 | options->max_startups || |
---|
935 | options->max_startups_rate > 100 || |
---|
936 | options->max_startups_rate < 1) |
---|
937 | fatal("%s line %d: Illegal MaxStartups spec.", |
---|
938 | filename, linenum); |
---|
939 | } else if (n != 1) |
---|
940 | fatal("%s line %d: Illegal MaxStartups spec.", |
---|
941 | filename, linenum); |
---|
942 | else |
---|
943 | options->max_startups = options->max_startups_begin; |
---|
944 | break; |
---|
945 | |
---|
946 | case sBanner: |
---|
947 | charptr = &options->banner; |
---|
948 | goto parse_filename; |
---|
949 | /* |
---|
950 | * These options can contain %X options expanded at |
---|
951 | * connect time, so that you can specify paths like: |
---|
952 | * |
---|
953 | * AuthorizedKeysFile /etc/ssh_keys/%u |
---|
954 | */ |
---|
955 | case sAuthorizedKeysFile: |
---|
956 | case sAuthorizedKeysFile2: |
---|
957 | charptr = (opcode == sAuthorizedKeysFile ) ? |
---|
958 | &options->authorized_keys_file : |
---|
959 | &options->authorized_keys_file2; |
---|
960 | goto parse_filename; |
---|
961 | |
---|
962 | case sClientAliveInterval: |
---|
963 | intptr = &options->client_alive_interval; |
---|
964 | goto parse_time; |
---|
965 | |
---|
966 | case sClientAliveCountMax: |
---|
967 | intptr = &options->client_alive_count_max; |
---|
968 | goto parse_int; |
---|
969 | |
---|
970 | case sDeprecated: |
---|
971 | log("%s line %d: Deprecated option %s", |
---|
972 | filename, linenum, arg); |
---|
973 | while (arg) |
---|
974 | arg = strdelim(&cp); |
---|
975 | break; |
---|
976 | |
---|
977 | default: |
---|
978 | fatal("%s line %d: Missing handler for opcode %s (%d)", |
---|
979 | filename, linenum, arg, opcode); |
---|
980 | } |
---|
981 | if ((arg = strdelim(&cp)) != NULL && *arg != '\0') |
---|
982 | fatal("%s line %d: garbage at end of line; \"%.200s\".", |
---|
983 | filename, linenum, arg); |
---|
984 | return 0; |
---|
985 | } |
---|
986 | |
---|
987 | /* Reads the server configuration file. */ |
---|
988 | |
---|
989 | void |
---|
990 | read_server_config(ServerOptions *options, const char *filename) |
---|
991 | { |
---|
992 | int linenum, bad_options = 0; |
---|
993 | char line[1024]; |
---|
994 | FILE *f; |
---|
995 | |
---|
996 | f = fopen(filename, "r"); |
---|
997 | if (!f) { |
---|
998 | perror(filename); |
---|
999 | exit(1); |
---|
1000 | } |
---|
1001 | linenum = 0; |
---|
1002 | while (fgets(line, sizeof(line), f)) { |
---|
1003 | /* Update line number counter. */ |
---|
1004 | linenum++; |
---|
1005 | if (process_server_config_line(options, line, filename, linenum) != 0) |
---|
1006 | bad_options++; |
---|
1007 | } |
---|
1008 | fclose(f); |
---|
1009 | if (bad_options > 0) |
---|
1010 | fatal("%s: terminating, %d bad configuration options", |
---|
1011 | filename, bad_options); |
---|
1012 | } |
---|