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.139 2005/03/01 10:09:52 djm Exp $");
20 #include "pathnames.h"
26 static void add_listen_addr(ServerOptions *, char *, u_short);
27 static void add_one_listen_addr(ServerOptions *, char *, u_short);
29 /* Use of privilege separation or not */
30 extern int use_privsep;
32 /* Initializes the server options to their default values. */
35 initialize_server_options(ServerOptions *options)
37 memset(options, 0, sizeof(*options));
39 /* Portable-specific options */
40 options->use_pam = -1;
42 /* Standard Options */
43 options->num_ports = 0;
44 options->ports_from_cmdline = 0;
45 options->listen_addrs = NULL;
46 options->address_family = -1;
47 options->num_host_key_files = 0;
48 options->pid_file = NULL;
49 options->server_key_bits = -1;
50 options->login_grace_time = -1;
51 options->key_regeneration_time = -1;
52 options->permit_root_login = PERMIT_NOT_SET;
53 options->ignore_rhosts = -1;
54 options->ignore_user_known_hosts = -1;
55 options->print_motd = -1;
56 options->print_lastlog = -1;
57 options->x11_forwarding = -1;
58 options->x11_display_offset = -1;
59 options->x11_use_localhost = -1;
60 options->xauth_location = NULL;
61 options->strict_modes = -1;
62 options->tcp_keep_alive = -1;
63 options->log_facility = SYSLOG_FACILITY_NOT_SET;
64 options->log_level = SYSLOG_LEVEL_NOT_SET;
65 options->rhosts_rsa_authentication = -1;
66 options->hostbased_authentication = -1;
67 options->hostbased_uses_name_from_packet_only = -1;
68 options->rsa_authentication = -1;
69 options->pubkey_authentication = -1;
70 options->kerberos_authentication = -1;
71 options->kerberos_or_local_passwd = -1;
72 options->kerberos_ticket_cleanup = -1;
74 options->session_hooks_allow = -1;
75 options->session_hooks_startup_cmd = NULL;
76 options->session_hooks_shutdown_cmd = NULL;
78 options->kerberos_get_afs_token = -1;
79 options->gss_authentication=-1;
80 options->gss_keyex=-1;
81 options->gss_cleanup_creds = -1;
82 options->password_authentication = -1;
83 options->kbd_interactive_authentication = -1;
84 options->challenge_response_authentication = -1;
85 options->permit_empty_passwd = -1;
86 options->permit_user_env = -1;
87 options->use_login = -1;
88 options->compression = -1;
89 options->allow_tcp_forwarding = -1;
90 options->num_allow_users = 0;
91 options->num_deny_users = 0;
92 options->num_allow_groups = 0;
93 options->num_deny_groups = 0;
94 options->ciphers = NULL;
96 options->protocol = SSH_PROTO_UNKNOWN;
97 options->gateway_ports = -1;
98 options->num_subsystems = 0;
99 options->max_startups_begin = -1;
100 options->max_startups_rate = -1;
101 options->max_startups = -1;
102 options->max_authtries = -1;
103 options->banner = NULL;
104 options->use_dns = -1;
105 options->client_alive_interval = -1;
106 options->client_alive_count_max = -1;
107 options->authorized_keys_file = NULL;
108 options->authorized_keys_file2 = NULL;
109 options->num_accept_env = 0;
111 /* Needs to be accessable in many places */
116 fill_default_server_options(ServerOptions *options)
118 /* Portable-specific options */
119 if (options->use_pam == -1)
120 options->use_pam = 0;
122 /* Standard Options */
123 if (options->protocol == SSH_PROTO_UNKNOWN)
124 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
125 if (options->num_host_key_files == 0) {
126 /* fill default hostkeys for protocols */
127 if (options->protocol & SSH_PROTO_1)
128 options->host_key_files[options->num_host_key_files++] =
130 if (options->protocol & SSH_PROTO_2) {
131 options->host_key_files[options->num_host_key_files++] =
132 _PATH_HOST_RSA_KEY_FILE;
133 options->host_key_files[options->num_host_key_files++] =
134 _PATH_HOST_DSA_KEY_FILE;
137 if (options->num_ports == 0)
138 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
139 if (options->listen_addrs == NULL)
140 add_listen_addr(options, NULL, 0);
141 if (options->pid_file == NULL)
142 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
143 if (options->server_key_bits == -1)
144 options->server_key_bits = 768;
145 if (options->login_grace_time == -1)
146 options->login_grace_time = 120;
147 if (options->key_regeneration_time == -1)
148 options->key_regeneration_time = 3600;
149 if (options->permit_root_login == PERMIT_NOT_SET)
150 options->permit_root_login = PERMIT_YES;
151 if (options->ignore_rhosts == -1)
152 options->ignore_rhosts = 1;
153 if (options->ignore_user_known_hosts == -1)
154 options->ignore_user_known_hosts = 0;
155 if (options->print_motd == -1)
156 options->print_motd = 1;
157 if (options->print_lastlog == -1)
158 options->print_lastlog = 1;
159 if (options->x11_forwarding == -1)
160 options->x11_forwarding = 0;
161 if (options->x11_display_offset == -1)
162 options->x11_display_offset = 10;
163 if (options->x11_use_localhost == -1)
164 options->x11_use_localhost = 1;
165 if (options->xauth_location == NULL)
166 options->xauth_location = _PATH_XAUTH;
167 if (options->strict_modes == -1)
168 options->strict_modes = 1;
169 if (options->tcp_keep_alive == -1)
170 options->tcp_keep_alive = 1;
171 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
172 options->log_facility = SYSLOG_FACILITY_AUTH;
173 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
174 options->log_level = SYSLOG_LEVEL_INFO;
175 if (options->rhosts_rsa_authentication == -1)
176 options->rhosts_rsa_authentication = 0;
177 if (options->hostbased_authentication == -1)
178 options->hostbased_authentication = 0;
179 if (options->hostbased_uses_name_from_packet_only == -1)
180 options->hostbased_uses_name_from_packet_only = 0;
181 if (options->rsa_authentication == -1)
182 options->rsa_authentication = 1;
183 if (options->pubkey_authentication == -1)
184 options->pubkey_authentication = 1;
185 if (options->kerberos_authentication == -1)
186 options->kerberos_authentication = 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 if (options->kerberos_get_afs_token == -1)
192 options->kerberos_get_afs_token = 0;
193 if (options->gss_authentication == -1)
194 options->gss_authentication = 1;
195 if (options->gss_keyex == -1)
196 options->gss_keyex = 1;
197 if (options->gss_cleanup_creds == -1)
198 options->gss_cleanup_creds = 1;
199 if (options->password_authentication == -1)
200 options->password_authentication = 1;
201 if (options->kbd_interactive_authentication == -1)
202 options->kbd_interactive_authentication = 0;
203 if (options->challenge_response_authentication == -1)
204 options->challenge_response_authentication = 1;
205 if (options->permit_empty_passwd == -1)
206 options->permit_empty_passwd = 0;
207 if (options->permit_user_env == -1)
208 options->permit_user_env = 0;
209 if (options->use_login == -1)
210 options->use_login = 0;
211 if (options->compression == -1)
212 options->compression = 1;
213 if (options->allow_tcp_forwarding == -1)
214 options->allow_tcp_forwarding = 1;
215 if (options->gateway_ports == -1)
216 options->gateway_ports = 0;
217 if (options->max_startups == -1)
218 options->max_startups = 10;
219 if (options->max_startups_rate == -1)
220 options->max_startups_rate = 100; /* 100% */
221 if (options->max_startups_begin == -1)
222 options->max_startups_begin = options->max_startups;
223 if (options->max_authtries == -1)
224 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
225 if (options->use_dns == -1)
226 options->use_dns = 1;
227 if (options->client_alive_interval == -1)
228 options->client_alive_interval = 0;
229 if (options->client_alive_count_max == -1)
230 options->client_alive_count_max = 3;
231 if (options->authorized_keys_file2 == NULL) {
232 /* authorized_keys_file2 falls back to authorized_keys_file */
233 if (options->authorized_keys_file != NULL)
234 options->authorized_keys_file2 = options->authorized_keys_file;
236 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
238 if (options->authorized_keys_file == NULL)
239 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
241 /* Turn privilege separation on by default */
242 if (use_privsep == -1)
246 if (use_privsep && options->compression == 1) {
247 error("This platform does not support both privilege "
248 "separation and compression");
249 error("Compression disabled");
250 options->compression = 0;
256 /* Keyword tokens. */
258 sBadOption, /* == unknown option */
259 /* Portable-specific options */
261 /* Standard Options */
262 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
263 sPermitRootLogin, sLogFacility, sLogLevel,
264 sRhostsRSAAuthentication, sRSAAuthentication,
265 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
266 sKerberosGetAFSToken,
267 sKerberosTgtPassing, sChallengeResponseAuthentication,
269 sAllowSessionHooks, sSessionHookStartupCmd, sSessionHookShutdownCmd,
271 sPasswordAuthentication, sKbdInteractiveAuthentication,
272 sListenAddress, sAddressFamily,
273 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
274 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
275 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
276 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
277 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
278 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
279 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
280 sMaxStartups, sMaxAuthTries,
281 sBanner, sUseDNS, sHostbasedAuthentication,
282 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
283 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
284 sGssAuthentication, sGssCleanupCreds, sAcceptEnv,
286 sUsePrivilegeSeparation,
287 sDeprecated, sUnsupported
290 /* Textual representation of the tokens. */
293 ServerOpCodes opcode;
295 /* Portable-specific options */
297 { "usepam", sUsePAM },
299 { "usepam", sUnsupported },
301 { "pamauthenticationviakbdint", sDeprecated },
302 /* Standard Options */
304 { "hostkey", sHostKeyFile },
305 { "hostdsakey", sHostKeyFile }, /* alias */
306 { "pidfile", sPidFile },
307 { "serverkeybits", sServerKeyBits },
308 { "logingracetime", sLoginGraceTime },
309 { "keyregenerationinterval", sKeyRegenerationTime },
310 { "permitrootlogin", sPermitRootLogin },
311 { "syslogfacility", sLogFacility },
312 { "loglevel", sLogLevel },
313 { "rhostsauthentication", sDeprecated },
314 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
315 { "hostbasedauthentication", sHostbasedAuthentication },
316 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
317 { "rsaauthentication", sRSAAuthentication },
318 { "pubkeyauthentication", sPubkeyAuthentication },
319 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
321 { "kerberosauthentication", sKerberosAuthentication },
322 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
323 { "kerberosticketcleanup", sKerberosTicketCleanup },
325 { "kerberosgetafstoken", sKerberosGetAFSToken },
327 { "kerberosgetafstoken", sUnsupported },
330 { "kerberosauthentication", sUnsupported },
331 { "kerberosorlocalpasswd", sUnsupported },
332 { "kerberosticketcleanup", sUnsupported },
333 { "kerberosgetafstoken", sUnsupported },
335 { "kerberostgtpassing", sUnsupported },
336 { "afstokenpassing", sUnsupported },
338 { "gssapiauthentication", sGssAuthentication },
339 { "gssapikeyexchange", sGssKeyEx },
340 { "gssapicleanupcredentials", sGssCleanupCreds },
342 { "gssapiauthentication", sUnsupported },
343 { "gssapikeyexchange", sUnsupported },
344 { "gssapicleanupcredentials", sUnsupported },
347 { "allowsessionhooks", sAllowSessionHooks },
348 { "sessionhookstartupcmd", sSessionHookStartupCmd },
349 { "sessionhookshutdowncmd", sSessionHookShutdownCmd },
351 { "passwordauthentication", sPasswordAuthentication },
352 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
353 { "challengeresponseauthentication", sChallengeResponseAuthentication },
354 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
355 { "checkmail", sDeprecated },
356 { "listenaddress", sListenAddress },
357 { "addressfamily", sAddressFamily },
358 { "printmotd", sPrintMotd },
359 { "printlastlog", sPrintLastLog },
360 { "ignorerhosts", sIgnoreRhosts },
361 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
362 { "x11forwarding", sX11Forwarding },
363 { "x11displayoffset", sX11DisplayOffset },
364 { "x11uselocalhost", sX11UseLocalhost },
365 { "xauthlocation", sXAuthLocation },
366 { "strictmodes", sStrictModes },
367 { "permitemptypasswords", sEmptyPasswd },
368 { "permituserenvironment", sPermitUserEnvironment },
369 { "uselogin", sUseLogin },
370 { "compression", sCompression },
371 { "tcpkeepalive", sTCPKeepAlive },
372 { "keepalive", sTCPKeepAlive }, /* obsolete alias */
373 { "allowtcpforwarding", sAllowTcpForwarding },
374 { "allowusers", sAllowUsers },
375 { "denyusers", sDenyUsers },
376 { "allowgroups", sAllowGroups },
377 { "denygroups", sDenyGroups },
378 { "ciphers", sCiphers },
380 { "protocol", sProtocol },
381 { "gatewayports", sGatewayPorts },
382 { "subsystem", sSubsystem },
383 { "maxstartups", sMaxStartups },
384 { "maxauthtries", sMaxAuthTries },
385 { "banner", sBanner },
386 { "usedns", sUseDNS },
387 { "verifyreversemapping", sDeprecated },
388 { "reversemappingcheck", sDeprecated },
389 { "clientaliveinterval", sClientAliveInterval },
390 { "clientalivecountmax", sClientAliveCountMax },
391 { "authorizedkeysfile", sAuthorizedKeysFile },
392 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
393 { "useprivilegeseparation", sUsePrivilegeSeparation},
394 { "acceptenv", sAcceptEnv },
399 * Returns the number of the token pointed to by cp or sBadOption.
403 parse_token(const char *cp, const char *filename,
408 for (i = 0; keywords[i].name; i++)
409 if (strcasecmp(cp, keywords[i].name) == 0)
410 return keywords[i].opcode;
412 error("%s: line %d: Bad configuration option: %s",
413 filename, linenum, cp);
418 add_listen_addr(ServerOptions *options, char *addr, u_short port)
422 if (options->num_ports == 0)
423 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
424 if (options->address_family == -1)
425 options->address_family = AF_UNSPEC;
427 for (i = 0; i < options->num_ports; i++)
428 add_one_listen_addr(options, addr, options->ports[i]);
430 add_one_listen_addr(options, addr, port);
434 add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
436 struct addrinfo hints, *ai, *aitop;
437 char strport[NI_MAXSERV];
440 memset(&hints, 0, sizeof(hints));
441 hints.ai_family = options->address_family;
442 hints.ai_socktype = SOCK_STREAM;
443 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
444 snprintf(strport, sizeof strport, "%u", port);
445 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
446 fatal("bad addr or host: %s (%s)",
447 addr ? addr : "<NULL>",
448 gai_strerror(gaierr));
449 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
451 ai->ai_next = options->listen_addrs;
452 options->listen_addrs = aitop;
456 process_server_config_line(ServerOptions *options, char *line,
457 const char *filename, int linenum)
459 char *cp, **charptr, *arg, *p;
460 int *intptr, value, i, n;
461 ServerOpCodes opcode;
466 /* Ignore leading whitespace */
469 if (!arg || !*arg || *arg == '#')
473 opcode = parse_token(arg, filename, linenum);
475 /* Portable-specific options */
477 intptr = &options->use_pam;
480 /* Standard Options */
484 /* ignore ports from configfile if cmdline specifies ports */
485 if (options->ports_from_cmdline)
487 if (options->listen_addrs != NULL)
488 fatal("%s line %d: ports must be specified before "
489 "ListenAddress.", filename, linenum);
490 if (options->num_ports >= MAX_PORTS)
491 fatal("%s line %d: too many ports.",
494 if (!arg || *arg == '\0')
495 fatal("%s line %d: missing port number.",
497 options->ports[options->num_ports++] = a2port(arg);
498 if (options->ports[options->num_ports-1] == 0)
499 fatal("%s line %d: Badly formatted port number.",
504 intptr = &options->server_key_bits;
507 if (!arg || *arg == '\0')
508 fatal("%s line %d: missing integer value.",
515 case sLoginGraceTime:
516 intptr = &options->login_grace_time;
519 if (!arg || *arg == '\0')
520 fatal("%s line %d: missing time value.",
522 if ((value = convtime(arg)) == -1)
523 fatal("%s line %d: invalid time value.",
529 case sKeyRegenerationTime:
530 intptr = &options->key_regeneration_time;
535 if (arg == NULL || *arg == '\0')
536 fatal("%s line %d: missing address",
540 fatal("%s line %d: bad address:port usage",
542 p = cleanhostname(p);
545 else if ((port = a2port(arg)) == 0)
546 fatal("%s line %d: bad port number", filename, linenum);
548 add_listen_addr(options, p, port);
554 intptr = &options->address_family;
555 if (options->listen_addrs != NULL)
556 fatal("%s line %d: address family must be specified before "
557 "ListenAddress.", filename, linenum);
558 if (strcasecmp(arg, "inet") == 0)
560 else if (strcasecmp(arg, "inet6") == 0)
562 else if (strcasecmp(arg, "any") == 0)
565 fatal("%s line %d: unsupported address family \"%s\".",
566 filename, linenum, arg);
572 intptr = &options->num_host_key_files;
573 if (*intptr >= MAX_HOSTKEYS)
574 fatal("%s line %d: too many host keys specified (max %d).",
575 filename, linenum, MAX_HOSTKEYS);
576 charptr = &options->host_key_files[*intptr];
579 if (!arg || *arg == '\0')
580 fatal("%s line %d: missing file name.",
582 if (*charptr == NULL) {
583 *charptr = tilde_expand_filename(arg, getuid());
584 /* increase optional counter */
586 *intptr = *intptr + 1;
591 charptr = &options->pid_file;
594 case sPermitRootLogin:
595 intptr = &options->permit_root_login;
597 if (!arg || *arg == '\0')
598 fatal("%s line %d: missing yes/"
599 "without-password/forced-commands-only/no "
600 "argument.", filename, linenum);
601 value = 0; /* silence compiler */
602 if (strcmp(arg, "without-password") == 0)
603 value = PERMIT_NO_PASSWD;
604 else if (strcmp(arg, "forced-commands-only") == 0)
605 value = PERMIT_FORCED_ONLY;
606 else if (strcmp(arg, "yes") == 0)
608 else if (strcmp(arg, "no") == 0)
611 fatal("%s line %d: Bad yes/"
612 "without-password/forced-commands-only/no "
613 "argument: %s", filename, linenum, arg);
619 intptr = &options->ignore_rhosts;
622 if (!arg || *arg == '\0')
623 fatal("%s line %d: missing yes/no argument.",
625 value = 0; /* silence compiler */
626 if (strcmp(arg, "yes") == 0)
628 else if (strcmp(arg, "no") == 0)
631 fatal("%s line %d: Bad yes/no argument: %s",
632 filename, linenum, arg);
637 case sIgnoreUserKnownHosts:
638 intptr = &options->ignore_user_known_hosts;
641 case sRhostsRSAAuthentication:
642 intptr = &options->rhosts_rsa_authentication;
645 case sHostbasedAuthentication:
646 intptr = &options->hostbased_authentication;
649 case sHostbasedUsesNameFromPacketOnly:
650 intptr = &options->hostbased_uses_name_from_packet_only;
653 case sRSAAuthentication:
654 intptr = &options->rsa_authentication;
657 case sPubkeyAuthentication:
658 intptr = &options->pubkey_authentication;
661 case sKerberosAuthentication:
662 intptr = &options->kerberos_authentication;
665 case sKerberosOrLocalPasswd:
666 intptr = &options->kerberos_or_local_passwd;
669 case sKerberosTicketCleanup:
670 intptr = &options->kerberos_ticket_cleanup;
673 case sKerberosGetAFSToken:
674 intptr = &options->kerberos_get_afs_token;
677 case sGssAuthentication:
678 intptr = &options->gss_authentication;
682 intptr = &options->gss_keyex;
685 case sGssCleanupCreds:
686 intptr = &options->gss_cleanup_creds;
690 case sAllowSessionHooks:
691 intptr = &options->session_hooks_allow;
693 case sSessionHookStartupCmd:
694 case sSessionHookShutdownCmd:
696 if (!arg || *arg == '\0')
697 fatal("%s line %d: empty session hook command",
699 if (opcode==sSessionHookStartupCmd)
700 options->session_hooks_startup_cmd = strdup(arg);
702 options->session_hooks_shutdown_cmd = strdup(arg);
706 case sPasswordAuthentication:
707 intptr = &options->password_authentication;
710 case sKbdInteractiveAuthentication:
711 intptr = &options->kbd_interactive_authentication;
714 case sChallengeResponseAuthentication:
715 intptr = &options->challenge_response_authentication;
719 intptr = &options->print_motd;
723 intptr = &options->print_lastlog;
727 intptr = &options->x11_forwarding;
730 case sX11DisplayOffset:
731 intptr = &options->x11_display_offset;
734 case sX11UseLocalhost:
735 intptr = &options->x11_use_localhost;
739 charptr = &options->xauth_location;
743 intptr = &options->strict_modes;
747 intptr = &options->tcp_keep_alive;
751 intptr = &options->permit_empty_passwd;
754 case sPermitUserEnvironment:
755 intptr = &options->permit_user_env;
759 intptr = &options->use_login;
763 intptr = &options->compression;
767 intptr = &options->gateway_ports;
769 if (!arg || *arg == '\0')
770 fatal("%s line %d: missing yes/no/clientspecified "
771 "argument.", filename, linenum);
772 value = 0; /* silence compiler */
773 if (strcmp(arg, "clientspecified") == 0)
775 else if (strcmp(arg, "yes") == 0)
777 else if (strcmp(arg, "no") == 0)
780 fatal("%s line %d: Bad yes/no/clientspecified "
781 "argument: %s", filename, linenum, arg);
787 intptr = &options->use_dns;
791 intptr = (int *) &options->log_facility;
793 value = log_facility_number(arg);
794 if (value == SYSLOG_FACILITY_NOT_SET)
795 fatal("%.200s line %d: unsupported log facility '%s'",
796 filename, linenum, arg ? arg : "<NONE>");
798 *intptr = (SyslogFacility) value;
802 intptr = (int *) &options->log_level;
804 value = log_level_number(arg);
805 if (value == SYSLOG_LEVEL_NOT_SET)
806 fatal("%.200s line %d: unsupported log level '%s'",
807 filename, linenum, arg ? arg : "<NONE>");
809 *intptr = (LogLevel) value;
812 case sAllowTcpForwarding:
813 intptr = &options->allow_tcp_forwarding;
816 case sUsePrivilegeSeparation:
817 intptr = &use_privsep;
821 while ((arg = strdelim(&cp)) && *arg != '\0') {
822 if (options->num_allow_users >= MAX_ALLOW_USERS)
823 fatal("%s line %d: too many allow users.",
825 options->allow_users[options->num_allow_users++] =
831 while ((arg = strdelim(&cp)) && *arg != '\0') {
832 if (options->num_deny_users >= MAX_DENY_USERS)
833 fatal( "%s line %d: too many deny users.",
835 options->deny_users[options->num_deny_users++] =
841 while ((arg = strdelim(&cp)) && *arg != '\0') {
842 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
843 fatal("%s line %d: too many allow groups.",
845 options->allow_groups[options->num_allow_groups++] =
851 while ((arg = strdelim(&cp)) && *arg != '\0') {
852 if (options->num_deny_groups >= MAX_DENY_GROUPS)
853 fatal("%s line %d: too many deny groups.",
855 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
861 if (!arg || *arg == '\0')
862 fatal("%s line %d: Missing argument.", filename, linenum);
863 if (!ciphers_valid(arg))
864 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
865 filename, linenum, arg ? arg : "<NONE>");
866 if (options->ciphers == NULL)
867 options->ciphers = xstrdup(arg);
872 if (!arg || *arg == '\0')
873 fatal("%s line %d: Missing argument.", filename, linenum);
875 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
876 filename, linenum, arg ? arg : "<NONE>");
877 if (options->macs == NULL)
878 options->macs = xstrdup(arg);
882 intptr = &options->protocol;
884 if (!arg || *arg == '\0')
885 fatal("%s line %d: Missing argument.", filename, linenum);
886 value = proto_spec(arg);
887 if (value == SSH_PROTO_UNKNOWN)
888 fatal("%s line %d: Bad protocol spec '%s'.",
889 filename, linenum, arg ? arg : "<NONE>");
890 if (*intptr == SSH_PROTO_UNKNOWN)
895 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
896 fatal("%s line %d: too many subsystems defined.",
900 if (!arg || *arg == '\0')
901 fatal("%s line %d: Missing subsystem name.",
903 for (i = 0; i < options->num_subsystems; i++)
904 if (strcmp(arg, options->subsystem_name[i]) == 0)
905 fatal("%s line %d: Subsystem '%s' already defined.",
906 filename, linenum, arg);
907 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
909 if (!arg || *arg == '\0')
910 fatal("%s line %d: Missing subsystem command.",
912 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
913 options->num_subsystems++;
918 if (!arg || *arg == '\0')
919 fatal("%s line %d: Missing MaxStartups spec.",
921 if ((n = sscanf(arg, "%d:%d:%d",
922 &options->max_startups_begin,
923 &options->max_startups_rate,
924 &options->max_startups)) == 3) {
925 if (options->max_startups_begin >
926 options->max_startups ||
927 options->max_startups_rate > 100 ||
928 options->max_startups_rate < 1)
929 fatal("%s line %d: Illegal MaxStartups spec.",
932 fatal("%s line %d: Illegal MaxStartups spec.",
935 options->max_startups = options->max_startups_begin;
939 intptr = &options->max_authtries;
943 charptr = &options->banner;
946 * These options can contain %X options expanded at
947 * connect time, so that you can specify paths like:
949 * AuthorizedKeysFile /etc/ssh_keys/%u
951 case sAuthorizedKeysFile:
952 case sAuthorizedKeysFile2:
953 charptr = (opcode == sAuthorizedKeysFile ) ?
954 &options->authorized_keys_file :
955 &options->authorized_keys_file2;
958 case sClientAliveInterval:
959 intptr = &options->client_alive_interval;
962 case sClientAliveCountMax:
963 intptr = &options->client_alive_count_max;
967 while ((arg = strdelim(&cp)) && *arg != '\0') {
968 if (strchr(arg, '=') != NULL)
969 fatal("%s line %d: Invalid environment name.",
971 if (options->num_accept_env >= MAX_ACCEPT_ENV)
972 fatal("%s line %d: too many allow env.",
974 options->accept_env[options->num_accept_env++] =
980 logit("%s line %d: Deprecated option %s",
981 filename, linenum, arg);
987 logit("%s line %d: Unsupported option %s",
988 filename, linenum, arg);
994 fatal("%s line %d: Missing handler for opcode %s (%d)",
995 filename, linenum, arg, opcode);
997 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
998 fatal("%s line %d: garbage at end of line; \"%.200s\".",
999 filename, linenum, arg);
1003 /* Reads the server configuration file. */
1006 load_server_config(const char *filename, Buffer *conf)
1008 char line[1024], *cp;
1011 debug2("%s: filename %s", __func__, filename);
1012 if ((f = fopen(filename, "r")) == NULL) {
1017 while (fgets(line, sizeof(line), f)) {
1019 * Trim out comments and strip whitespace
1020 * NB - preserve newlines, they are needed to reproduce
1021 * line numbers later for error messages
1023 if ((cp = strchr(line, '#')) != NULL)
1024 memcpy(cp, "\n", 2);
1025 cp = line + strspn(line, " \t\r");
1027 buffer_append(conf, cp, strlen(cp));
1029 buffer_append(conf, "\0", 1);
1031 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1035 parse_server_config(ServerOptions *options, const char *filename, Buffer *conf)
1037 int linenum, bad_options = 0;
1038 char *cp, *obuf, *cbuf;
1040 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1042 obuf = cbuf = xstrdup(buffer_ptr(conf));
1044 while((cp = strsep(&cbuf, "\n")) != NULL) {
1045 if (process_server_config_line(options, cp, filename,
1050 if (bad_options > 0)
1051 fatal("%s: terminating, %d bad configuration options",
1052 filename, bad_options);