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