2 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
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".
13 RCSID("$OpenBSD: servconf.c,v 1.120 2003/05/15 04:08:44 jakob Exp $");
24 * XXX: Bodge - but then, so is using the kerberos IV KEYFILE to get a
27 # define KEYFILE "/etc/krb5.keytab"
40 #include "pathnames.h"
41 #include "tildexpand.h"
47 static void add_listen_addr(ServerOptions *, char *, u_short);
48 static void add_one_listen_addr(ServerOptions *, char *, u_short);
50 /* AF_UNSPEC or AF_INET or AF_INET6 */
52 /* Use of privilege separation or not */
53 extern int use_privsep;
55 /* Initializes the server options to their default values. */
58 initialize_server_options(ServerOptions *options)
60 memset(options, 0, sizeof(*options));
62 /* Portable-specific options */
63 options->use_pam = -1;
65 /* Standard Options */
66 options->num_ports = 0;
67 options->ports_from_cmdline = 0;
68 options->listen_addrs = NULL;
69 options->num_host_key_files = 0;
70 options->pid_file = NULL;
71 options->server_key_bits = -1;
72 options->login_grace_time = -1;
73 options->key_regeneration_time = -1;
74 options->permit_root_login = PERMIT_NOT_SET;
75 options->ignore_rhosts = -1;
76 options->ignore_user_known_hosts = -1;
77 options->print_motd = -1;
78 options->print_lastlog = -1;
79 options->x11_forwarding = -1;
80 options->x11_display_offset = -1;
81 options->x11_use_localhost = -1;
82 options->xauth_location = NULL;
83 options->strict_modes = -1;
84 options->keepalives = -1;
85 options->log_facility = SYSLOG_FACILITY_NOT_SET;
86 options->log_level = SYSLOG_LEVEL_NOT_SET;
87 options->rhosts_authentication = -1;
88 options->rhosts_rsa_authentication = -1;
89 options->hostbased_authentication = -1;
90 options->hostbased_uses_name_from_packet_only = -1;
91 options->rsa_authentication = -1;
92 options->pubkey_authentication = -1;
93 options->kerberos_authentication = -1;
94 options->kerberos_or_local_passwd = -1;
95 options->kerberos_ticket_cleanup = -1;
96 options->kerberos_tgt_passing = -1;
97 options->afs_token_passing = -1;
98 options->password_authentication = -1;
99 options->kbd_interactive_authentication = -1;
100 options->challenge_response_authentication = -1;
101 options->permit_empty_passwd = -1;
102 options->permit_user_env = -1;
103 options->use_login = -1;
104 options->compression = -1;
105 options->allow_tcp_forwarding = -1;
106 options->num_allow_users = 0;
107 options->num_deny_users = 0;
108 options->num_allow_groups = 0;
109 options->num_deny_groups = 0;
110 options->ciphers = NULL;
111 options->macs = NULL;
112 options->protocol = SSH_PROTO_UNKNOWN;
113 options->gateway_ports = -1;
114 options->num_subsystems = 0;
115 options->max_startups_begin = -1;
116 options->max_startups_rate = -1;
117 options->max_startups = -1;
118 options->banner = NULL;
119 options->verify_reverse_mapping = -1;
120 options->client_alive_interval = -1;
121 options->client_alive_count_max = -1;
122 options->authorized_keys_file = NULL;
123 options->authorized_keys_file2 = NULL;
125 /* Needs to be accessable in many places */
130 fill_default_server_options(ServerOptions *options)
132 /* Portable-specific options */
133 if (options->use_pam == -1)
135 options->use_pam = 1;
137 options->use_pam = 0;
140 /* Standard Options */
141 if (options->protocol == SSH_PROTO_UNKNOWN)
142 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
143 if (options->num_host_key_files == 0) {
144 /* fill default hostkeys for protocols */
145 if (options->protocol & SSH_PROTO_1)
146 options->host_key_files[options->num_host_key_files++] =
148 if (options->protocol & SSH_PROTO_2) {
149 options->host_key_files[options->num_host_key_files++] =
150 _PATH_HOST_RSA_KEY_FILE;
151 options->host_key_files[options->num_host_key_files++] =
152 _PATH_HOST_DSA_KEY_FILE;
155 if (options->num_ports == 0)
156 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
157 if (options->listen_addrs == NULL)
158 add_listen_addr(options, NULL, 0);
159 if (options->pid_file == NULL)
160 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
161 if (options->server_key_bits == -1)
162 options->server_key_bits = 768;
163 if (options->login_grace_time == -1)
164 options->login_grace_time = 120;
165 if (options->key_regeneration_time == -1)
166 options->key_regeneration_time = 3600;
167 if (options->permit_root_login == PERMIT_NOT_SET)
168 options->permit_root_login = PERMIT_YES;
169 if (options->ignore_rhosts == -1)
170 options->ignore_rhosts = 1;
171 if (options->ignore_user_known_hosts == -1)
172 options->ignore_user_known_hosts = 0;
173 if (options->print_motd == -1)
174 options->print_motd = 1;
175 if (options->print_lastlog == -1)
176 options->print_lastlog = 1;
177 if (options->x11_forwarding == -1)
178 options->x11_forwarding = 0;
179 if (options->x11_display_offset == -1)
180 options->x11_display_offset = 10;
181 if (options->x11_use_localhost == -1)
182 options->x11_use_localhost = 1;
183 if (options->xauth_location == NULL)
184 options->xauth_location = _PATH_XAUTH;
185 if (options->strict_modes == -1)
186 options->strict_modes = 1;
187 if (options->keepalives == -1)
188 options->keepalives = 1;
189 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
190 options->log_facility = SYSLOG_FACILITY_AUTH;
191 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
192 options->log_level = SYSLOG_LEVEL_INFO;
193 if (options->rhosts_authentication == -1)
194 options->rhosts_authentication = 0;
195 if (options->rhosts_rsa_authentication == -1)
196 options->rhosts_rsa_authentication = 0;
197 if (options->hostbased_authentication == -1)
198 options->hostbased_authentication = 0;
199 if (options->hostbased_uses_name_from_packet_only == -1)
200 options->hostbased_uses_name_from_packet_only = 0;
201 if (options->rsa_authentication == -1)
202 options->rsa_authentication = 1;
203 if (options->pubkey_authentication == -1)
204 options->pubkey_authentication = 1;
205 if (options->kerberos_authentication == -1)
206 options->kerberos_authentication = 0;
207 if (options->kerberos_or_local_passwd == -1)
208 options->kerberos_or_local_passwd = 1;
209 if (options->kerberos_ticket_cleanup == -1)
210 #if defined(KRB4) || defined(KRB5)
211 options->kerberos_ticket_cleanup = 1;
213 options->kerberos_ticket_cleanup = 0;
215 if (options->kerberos_tgt_passing == -1)
216 options->kerberos_tgt_passing = 0;
217 if (options->afs_token_passing == -1)
218 options->afs_token_passing = 0;
219 if (options->password_authentication == -1)
220 options->password_authentication = 1;
221 if (options->kbd_interactive_authentication == -1)
222 options->kbd_interactive_authentication = 0;
223 if (options->challenge_response_authentication == -1)
224 options->challenge_response_authentication = 1;
225 if (options->permit_empty_passwd == -1)
226 options->permit_empty_passwd = 0;
227 if (options->permit_user_env == -1)
228 options->permit_user_env = 0;
229 if (options->use_login == -1)
230 options->use_login = 0;
231 if (options->compression == -1)
232 options->compression = 1;
233 if (options->allow_tcp_forwarding == -1)
234 options->allow_tcp_forwarding = 1;
235 if (options->gateway_ports == -1)
236 options->gateway_ports = 0;
237 if (options->max_startups == -1)
238 options->max_startups = 10;
239 if (options->max_startups_rate == -1)
240 options->max_startups_rate = 100; /* 100% */
241 if (options->max_startups_begin == -1)
242 options->max_startups_begin = options->max_startups;
243 if (options->verify_reverse_mapping == -1)
244 options->verify_reverse_mapping = 0;
245 if (options->client_alive_interval == -1)
246 options->client_alive_interval = 0;
247 if (options->client_alive_count_max == -1)
248 options->client_alive_count_max = 3;
249 if (options->authorized_keys_file2 == NULL) {
250 /* authorized_keys_file2 falls back to authorized_keys_file */
251 if (options->authorized_keys_file != NULL)
252 options->authorized_keys_file2 = options->authorized_keys_file;
254 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
256 if (options->authorized_keys_file == NULL)
257 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
259 /* Turn privilege separation on by default */
260 if (use_privsep == -1)
264 if (use_privsep && options->compression == 1) {
265 error("This platform does not support both privilege "
266 "separation and compression");
267 error("Compression disabled");
268 options->compression = 0;
274 /* Keyword tokens. */
276 sBadOption, /* == unknown option */
277 /* Portable-specific options */
279 /* Standard Options */
280 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
281 sPermitRootLogin, sLogFacility, sLogLevel,
282 sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
283 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
284 sKerberosTgtPassing, sAFSTokenPassing, sChallengeResponseAuthentication,
285 sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
286 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
287 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
288 sStrictModes, sEmptyPasswd, sKeepAlives,
289 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
290 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
291 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
292 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
293 sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
294 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
295 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
296 sUsePrivilegeSeparation,
300 /* Textual representation of the tokens. */
303 ServerOpCodes opcode;
305 /* Portable-specific options */
306 { "UsePAM", sUsePAM },
307 /* Standard Options */
309 { "hostkey", sHostKeyFile },
310 { "hostdsakey", sHostKeyFile }, /* alias */
311 { "pidfile", sPidFile },
312 { "serverkeybits", sServerKeyBits },
313 { "logingracetime", sLoginGraceTime },
314 { "keyregenerationinterval", sKeyRegenerationTime },
315 { "permitrootlogin", sPermitRootLogin },
316 { "syslogfacility", sLogFacility },
317 { "loglevel", sLogLevel },
318 { "rhostsauthentication", sRhostsAuthentication },
319 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
320 { "hostbasedauthentication", sHostbasedAuthentication },
321 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
322 { "rsaauthentication", sRSAAuthentication },
323 { "pubkeyauthentication", sPubkeyAuthentication },
324 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
325 { "kerberosauthentication", sKerberosAuthentication },
326 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
327 { "kerberosticketcleanup", sKerberosTicketCleanup },
328 { "kerberostgtpassing", sKerberosTgtPassing },
329 { "afstokenpassing", sAFSTokenPassing },
330 { "passwordauthentication", sPasswordAuthentication },
331 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
332 { "challengeresponseauthentication", sChallengeResponseAuthentication },
333 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
334 { "checkmail", sDeprecated },
335 { "listenaddress", sListenAddress },
336 { "printmotd", sPrintMotd },
337 { "printlastlog", sPrintLastLog },
338 { "ignorerhosts", sIgnoreRhosts },
339 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
340 { "x11forwarding", sX11Forwarding },
341 { "x11displayoffset", sX11DisplayOffset },
342 { "x11uselocalhost", sX11UseLocalhost },
343 { "xauthlocation", sXAuthLocation },
344 { "strictmodes", sStrictModes },
345 { "permitemptypasswords", sEmptyPasswd },
346 { "permituserenvironment", sPermitUserEnvironment },
347 { "uselogin", sUseLogin },
348 { "compression", sCompression },
349 { "keepalive", sKeepAlives },
350 { "allowtcpforwarding", sAllowTcpForwarding },
351 { "allowusers", sAllowUsers },
352 { "denyusers", sDenyUsers },
353 { "allowgroups", sAllowGroups },
354 { "denygroups", sDenyGroups },
355 { "ciphers", sCiphers },
357 { "protocol", sProtocol },
358 { "gatewayports", sGatewayPorts },
359 { "subsystem", sSubsystem },
360 { "maxstartups", sMaxStartups },
361 { "banner", sBanner },
362 { "verifyreversemapping", sVerifyReverseMapping },
363 { "reversemappingcheck", sVerifyReverseMapping },
364 { "clientaliveinterval", sClientAliveInterval },
365 { "clientalivecountmax", sClientAliveCountMax },
366 { "authorizedkeysfile", sAuthorizedKeysFile },
367 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
368 { "useprivilegeseparation", sUsePrivilegeSeparation},
373 * Returns the number of the token pointed to by cp or sBadOption.
377 parse_token(const char *cp, const char *filename,
382 for (i = 0; keywords[i].name; i++)
383 if (strcasecmp(cp, keywords[i].name) == 0)
384 return keywords[i].opcode;
386 error("%s: line %d: Bad configuration option: %s",
387 filename, linenum, cp);
392 add_listen_addr(ServerOptions *options, char *addr, u_short port)
396 if (options->num_ports == 0)
397 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
399 for (i = 0; i < options->num_ports; i++)
400 add_one_listen_addr(options, addr, options->ports[i]);
402 add_one_listen_addr(options, addr, port);
406 add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
408 struct addrinfo hints, *ai, *aitop;
409 char strport[NI_MAXSERV];
412 memset(&hints, 0, sizeof(hints));
413 hints.ai_family = IPv4or6;
414 hints.ai_socktype = SOCK_STREAM;
415 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
416 snprintf(strport, sizeof strport, "%u", port);
417 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
418 fatal("bad addr or host: %s (%s)",
419 addr ? addr : "<NULL>",
420 gai_strerror(gaierr));
421 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
423 ai->ai_next = options->listen_addrs;
424 options->listen_addrs = aitop;
428 process_server_config_line(ServerOptions *options, char *line,
429 const char *filename, int linenum)
431 char *cp, **charptr, *arg, *p;
432 int *intptr, value, i, n;
433 ServerOpCodes opcode;
437 /* Ignore leading whitespace */
440 if (!arg || !*arg || *arg == '#')
444 opcode = parse_token(arg, filename, linenum);
446 /* Portable-specific options */
448 intptr = &options->use_pam;
451 /* Standard Options */
455 /* ignore ports from configfile if cmdline specifies ports */
456 if (options->ports_from_cmdline)
458 if (options->listen_addrs != NULL)
459 fatal("%s line %d: ports must be specified before "
460 "ListenAddress.", filename, linenum);
461 if (options->num_ports >= MAX_PORTS)
462 fatal("%s line %d: too many ports.",
465 if (!arg || *arg == '\0')
466 fatal("%s line %d: missing port number.",
468 options->ports[options->num_ports++] = a2port(arg);
469 if (options->ports[options->num_ports-1] == 0)
470 fatal("%s line %d: Badly formatted port number.",
475 intptr = &options->server_key_bits;
478 if (!arg || *arg == '\0')
479 fatal("%s line %d: missing integer value.",
486 case sLoginGraceTime:
487 intptr = &options->login_grace_time;
490 if (!arg || *arg == '\0')
491 fatal("%s line %d: missing time value.",
493 if ((value = convtime(arg)) == -1)
494 fatal("%s line %d: invalid time value.",
500 case sKeyRegenerationTime:
501 intptr = &options->key_regeneration_time;
506 if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
507 fatal("%s line %d: missing inet addr.",
510 if ((p = strchr(arg, ']')) == NULL)
511 fatal("%s line %d: bad ipv6 inet addr usage.",
514 memmove(p, p+1, strlen(p+1)+1);
515 } else if (((p = strchr(arg, ':')) == NULL) ||
516 (strchr(p+1, ':') != NULL)) {
517 add_listen_addr(options, arg, 0);
525 fatal("%s line %d: bad inet addr:port usage.",
529 if ((port = a2port(p)) == 0)
530 fatal("%s line %d: bad port number.",
532 add_listen_addr(options, arg, port);
534 } else if (*p == '\0')
535 add_listen_addr(options, arg, 0);
537 fatal("%s line %d: bad inet addr usage.",
542 intptr = &options->num_host_key_files;
543 if (*intptr >= MAX_HOSTKEYS)
544 fatal("%s line %d: too many host keys specified (max %d).",
545 filename, linenum, MAX_HOSTKEYS);
546 charptr = &options->host_key_files[*intptr];
549 if (!arg || *arg == '\0')
550 fatal("%s line %d: missing file name.",
552 if (*charptr == NULL) {
553 *charptr = tilde_expand_filename(arg, getuid());
554 /* increase optional counter */
556 *intptr = *intptr + 1;
561 charptr = &options->pid_file;
564 case sPermitRootLogin:
565 intptr = &options->permit_root_login;
567 if (!arg || *arg == '\0')
568 fatal("%s line %d: missing yes/"
569 "without-password/forced-commands-only/no "
570 "argument.", filename, linenum);
571 value = 0; /* silence compiler */
572 if (strcmp(arg, "without-password") == 0)
573 value = PERMIT_NO_PASSWD;
574 else if (strcmp(arg, "forced-commands-only") == 0)
575 value = PERMIT_FORCED_ONLY;
576 else if (strcmp(arg, "yes") == 0)
578 else if (strcmp(arg, "no") == 0)
581 fatal("%s line %d: Bad yes/"
582 "without-password/forced-commands-only/no "
583 "argument: %s", filename, linenum, arg);
589 intptr = &options->ignore_rhosts;
592 if (!arg || *arg == '\0')
593 fatal("%s line %d: missing yes/no argument.",
595 value = 0; /* silence compiler */
596 if (strcmp(arg, "yes") == 0)
598 else if (strcmp(arg, "no") == 0)
601 fatal("%s line %d: Bad yes/no argument: %s",
602 filename, linenum, arg);
607 case sIgnoreUserKnownHosts:
608 intptr = &options->ignore_user_known_hosts;
611 case sRhostsAuthentication:
612 intptr = &options->rhosts_authentication;
615 case sRhostsRSAAuthentication:
616 intptr = &options->rhosts_rsa_authentication;
619 case sHostbasedAuthentication:
620 intptr = &options->hostbased_authentication;
623 case sHostbasedUsesNameFromPacketOnly:
624 intptr = &options->hostbased_uses_name_from_packet_only;
627 case sRSAAuthentication:
628 intptr = &options->rsa_authentication;
631 case sPubkeyAuthentication:
632 intptr = &options->pubkey_authentication;
635 case sKerberosAuthentication:
636 intptr = &options->kerberos_authentication;
639 case sKerberosOrLocalPasswd:
640 intptr = &options->kerberos_or_local_passwd;
643 case sKerberosTicketCleanup:
644 intptr = &options->kerberos_ticket_cleanup;
647 case sKerberosTgtPassing:
648 intptr = &options->kerberos_tgt_passing;
651 case sAFSTokenPassing:
652 intptr = &options->afs_token_passing;
655 case sPasswordAuthentication:
656 intptr = &options->password_authentication;
659 case sKbdInteractiveAuthentication:
660 intptr = &options->kbd_interactive_authentication;
663 case sChallengeResponseAuthentication:
664 intptr = &options->challenge_response_authentication;
668 intptr = &options->print_motd;
672 intptr = &options->print_lastlog;
676 intptr = &options->x11_forwarding;
679 case sX11DisplayOffset:
680 intptr = &options->x11_display_offset;
683 case sX11UseLocalhost:
684 intptr = &options->x11_use_localhost;
688 charptr = &options->xauth_location;
692 intptr = &options->strict_modes;
696 intptr = &options->keepalives;
700 intptr = &options->permit_empty_passwd;
703 case sPermitUserEnvironment:
704 intptr = &options->permit_user_env;
708 intptr = &options->use_login;
712 intptr = &options->compression;
716 intptr = &options->gateway_ports;
719 case sVerifyReverseMapping:
720 intptr = &options->verify_reverse_mapping;
724 intptr = (int *) &options->log_facility;
726 value = log_facility_number(arg);
727 if (value == SYSLOG_FACILITY_NOT_SET)
728 fatal("%.200s line %d: unsupported log facility '%s'",
729 filename, linenum, arg ? arg : "<NONE>");
731 *intptr = (SyslogFacility) value;
735 intptr = (int *) &options->log_level;
737 value = log_level_number(arg);
738 if (value == SYSLOG_LEVEL_NOT_SET)
739 fatal("%.200s line %d: unsupported log level '%s'",
740 filename, linenum, arg ? arg : "<NONE>");
742 *intptr = (LogLevel) value;
745 case sAllowTcpForwarding:
746 intptr = &options->allow_tcp_forwarding;
749 case sUsePrivilegeSeparation:
750 intptr = &use_privsep;
754 while ((arg = strdelim(&cp)) && *arg != '\0') {
755 if (options->num_allow_users >= MAX_ALLOW_USERS)
756 fatal("%s line %d: too many allow users.",
758 options->allow_users[options->num_allow_users++] =
764 while ((arg = strdelim(&cp)) && *arg != '\0') {
765 if (options->num_deny_users >= MAX_DENY_USERS)
766 fatal( "%s line %d: too many deny users.",
768 options->deny_users[options->num_deny_users++] =
774 while ((arg = strdelim(&cp)) && *arg != '\0') {
775 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
776 fatal("%s line %d: too many allow groups.",
778 options->allow_groups[options->num_allow_groups++] =
784 while ((arg = strdelim(&cp)) && *arg != '\0') {
785 if (options->num_deny_groups >= MAX_DENY_GROUPS)
786 fatal("%s line %d: too many deny groups.",
788 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
794 if (!arg || *arg == '\0')
795 fatal("%s line %d: Missing argument.", filename, linenum);
796 if (!ciphers_valid(arg))
797 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
798 filename, linenum, arg ? arg : "<NONE>");
799 if (options->ciphers == NULL)
800 options->ciphers = xstrdup(arg);
805 if (!arg || *arg == '\0')
806 fatal("%s line %d: Missing argument.", filename, linenum);
808 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
809 filename, linenum, arg ? arg : "<NONE>");
810 if (options->macs == NULL)
811 options->macs = xstrdup(arg);
815 intptr = &options->protocol;
817 if (!arg || *arg == '\0')
818 fatal("%s line %d: Missing argument.", filename, linenum);
819 value = proto_spec(arg);
820 if (value == SSH_PROTO_UNKNOWN)
821 fatal("%s line %d: Bad protocol spec '%s'.",
822 filename, linenum, arg ? arg : "<NONE>");
823 if (*intptr == SSH_PROTO_UNKNOWN)
828 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
829 fatal("%s line %d: too many subsystems defined.",
833 if (!arg || *arg == '\0')
834 fatal("%s line %d: Missing subsystem name.",
836 for (i = 0; i < options->num_subsystems; i++)
837 if (strcmp(arg, options->subsystem_name[i]) == 0)
838 fatal("%s line %d: Subsystem '%s' already defined.",
839 filename, linenum, arg);
840 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
842 if (!arg || *arg == '\0')
843 fatal("%s line %d: Missing subsystem command.",
845 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
846 options->num_subsystems++;
851 if (!arg || *arg == '\0')
852 fatal("%s line %d: Missing MaxStartups spec.",
854 if ((n = sscanf(arg, "%d:%d:%d",
855 &options->max_startups_begin,
856 &options->max_startups_rate,
857 &options->max_startups)) == 3) {
858 if (options->max_startups_begin >
859 options->max_startups ||
860 options->max_startups_rate > 100 ||
861 options->max_startups_rate < 1)
862 fatal("%s line %d: Illegal MaxStartups spec.",
865 fatal("%s line %d: Illegal MaxStartups spec.",
868 options->max_startups = options->max_startups_begin;
872 charptr = &options->banner;
875 * These options can contain %X options expanded at
876 * connect time, so that you can specify paths like:
878 * AuthorizedKeysFile /etc/ssh_keys/%u
880 case sAuthorizedKeysFile:
881 case sAuthorizedKeysFile2:
882 charptr = (opcode == sAuthorizedKeysFile ) ?
883 &options->authorized_keys_file :
884 &options->authorized_keys_file2;
887 case sClientAliveInterval:
888 intptr = &options->client_alive_interval;
891 case sClientAliveCountMax:
892 intptr = &options->client_alive_count_max;
896 logit("%s line %d: Deprecated option %s",
897 filename, linenum, arg);
903 fatal("%s line %d: Missing handler for opcode %s (%d)",
904 filename, linenum, arg, opcode);
906 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
907 fatal("%s line %d: garbage at end of line; \"%.200s\".",
908 filename, linenum, arg);
912 /* Reads the server configuration file. */
915 read_server_config(ServerOptions *options, const char *filename)
917 int linenum, bad_options = 0;
921 debug2("read_server_config: filename %s", filename);
922 f = fopen(filename, "r");
928 while (fgets(line, sizeof(line), f)) {
929 /* Update line number counter. */
931 if (process_server_config_line(options, line, filename, linenum) != 0)
936 fatal("%s: terminating, %d bad configuration options",
937 filename, bad_options);