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