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.146 2005/12/08 18:34:11 reyk 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->gsi_allow_limited_proxy = -1;
83 options->password_authentication = -1;
84 options->kbd_interactive_authentication = -1;
85 options->challenge_response_authentication = -1;
86 options->permit_empty_passwd = -1;
87 options->permit_user_env = -1;
88 options->use_login = -1;
89 options->compression = -1;
90 options->allow_tcp_forwarding = -1;
91 options->num_allow_users = 0;
92 options->num_deny_users = 0;
93 options->num_allow_groups = 0;
94 options->num_deny_groups = 0;
95 options->ciphers = NULL;
97 options->protocol = SSH_PROTO_UNKNOWN;
98 options->gateway_ports = -1;
99 options->num_subsystems = 0;
100 options->max_startups_begin = -1;
101 options->max_startups_rate = -1;
102 options->max_startups = -1;
103 options->max_authtries = -1;
104 options->banner = NULL;
105 options->use_dns = -1;
106 options->client_alive_interval = -1;
107 options->client_alive_count_max = -1;
108 options->authorized_keys_file = NULL;
109 options->authorized_keys_file2 = NULL;
110 options->num_accept_env = 0;
111 options->permit_tun = -1;
112 options->none_enabled = -1;
113 options->tcp_rcv_buf_poll = -1;
114 options->hpn_disabled = -1;
115 options->hpn_buffer_size = -1;
117 /* Needs to be accessable in many places */
122 fill_default_server_options(ServerOptions *options)
125 /* Portable-specific options */
126 if (options->use_pam == -1)
127 options->use_pam = 0;
129 /* Standard Options */
130 if (options->protocol == SSH_PROTO_UNKNOWN)
131 options->protocol = SSH_PROTO_1|SSH_PROTO_2;
132 if (options->num_host_key_files == 0) {
133 /* fill default hostkeys for protocols */
134 if (options->protocol & SSH_PROTO_1)
135 options->host_key_files[options->num_host_key_files++] =
137 if (options->protocol & SSH_PROTO_2) {
138 options->host_key_files[options->num_host_key_files++] =
139 _PATH_HOST_RSA_KEY_FILE;
140 options->host_key_files[options->num_host_key_files++] =
141 _PATH_HOST_DSA_KEY_FILE;
144 if (options->num_ports == 0)
145 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
146 if (options->listen_addrs == NULL)
147 add_listen_addr(options, NULL, 0);
148 if (options->pid_file == NULL)
149 options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
150 if (options->server_key_bits == -1)
151 options->server_key_bits = 768;
152 if (options->login_grace_time == -1)
153 options->login_grace_time = 120;
154 if (options->key_regeneration_time == -1)
155 options->key_regeneration_time = 3600;
156 if (options->permit_root_login == PERMIT_NOT_SET)
157 options->permit_root_login = PERMIT_YES;
158 if (options->ignore_rhosts == -1)
159 options->ignore_rhosts = 1;
160 if (options->ignore_user_known_hosts == -1)
161 options->ignore_user_known_hosts = 0;
162 if (options->print_motd == -1)
163 options->print_motd = 1;
164 if (options->print_lastlog == -1)
165 options->print_lastlog = 1;
166 if (options->x11_forwarding == -1)
167 options->x11_forwarding = 0;
168 if (options->x11_display_offset == -1)
169 options->x11_display_offset = 10;
170 if (options->x11_use_localhost == -1)
171 options->x11_use_localhost = 1;
172 if (options->xauth_location == NULL)
173 options->xauth_location = _PATH_XAUTH;
174 if (options->strict_modes == -1)
175 options->strict_modes = 1;
176 if (options->tcp_keep_alive == -1)
177 options->tcp_keep_alive = 1;
178 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
179 options->log_facility = SYSLOG_FACILITY_AUTH;
180 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
181 options->log_level = SYSLOG_LEVEL_INFO;
182 if (options->rhosts_rsa_authentication == -1)
183 options->rhosts_rsa_authentication = 0;
184 if (options->hostbased_authentication == -1)
185 options->hostbased_authentication = 0;
186 if (options->hostbased_uses_name_from_packet_only == -1)
187 options->hostbased_uses_name_from_packet_only = 0;
188 if (options->rsa_authentication == -1)
189 options->rsa_authentication = 1;
190 if (options->pubkey_authentication == -1)
191 options->pubkey_authentication = 1;
192 if (options->kerberos_authentication == -1)
193 options->kerberos_authentication = 0;
194 if (options->kerberos_or_local_passwd == -1)
195 options->kerberos_or_local_passwd = 1;
196 if (options->kerberos_ticket_cleanup == -1)
197 options->kerberos_ticket_cleanup = 1;
198 if (options->kerberos_get_afs_token == -1)
199 options->kerberos_get_afs_token = 0;
200 if (options->gss_authentication == -1)
201 options->gss_authentication = 1;
202 if (options->gss_keyex == -1)
203 options->gss_keyex = 1;
204 if (options->gss_cleanup_creds == -1)
205 options->gss_cleanup_creds = 1;
206 if (options->gsi_allow_limited_proxy == -1)
207 options->gsi_allow_limited_proxy = 0;
208 if (options->password_authentication == -1)
209 options->password_authentication = 1;
210 if (options->kbd_interactive_authentication == -1)
211 options->kbd_interactive_authentication = 0;
212 if (options->challenge_response_authentication == -1)
213 options->challenge_response_authentication = 1;
214 if (options->permit_empty_passwd == -1)
215 options->permit_empty_passwd = 0;
216 if (options->permit_user_env == -1)
217 options->permit_user_env = 0;
218 if (options->use_login == -1)
219 options->use_login = 0;
220 if (options->compression == -1)
221 options->compression = COMP_DELAYED;
222 if (options->allow_tcp_forwarding == -1)
223 options->allow_tcp_forwarding = 1;
224 if (options->gateway_ports == -1)
225 options->gateway_ports = 0;
226 if (options->max_startups == -1)
227 options->max_startups = 10;
228 if (options->max_startups_rate == -1)
229 options->max_startups_rate = 100; /* 100% */
230 if (options->max_startups_begin == -1)
231 options->max_startups_begin = options->max_startups;
232 if (options->max_authtries == -1)
233 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
234 if (options->use_dns == -1)
235 options->use_dns = 1;
236 if (options->client_alive_interval == -1)
237 options->client_alive_interval = 0;
238 if (options->client_alive_count_max == -1)
239 options->client_alive_count_max = 3;
240 if (options->authorized_keys_file2 == NULL) {
241 /* authorized_keys_file2 falls back to authorized_keys_file */
242 if (options->authorized_keys_file != NULL)
243 options->authorized_keys_file2 = options->authorized_keys_file;
245 options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
247 if (options->authorized_keys_file == NULL)
248 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
249 if (options->permit_tun == -1)
250 options->permit_tun = SSH_TUNMODE_NO;
252 if (options->hpn_disabled == -1)
253 options->hpn_disabled = 0;
255 if (options->hpn_buffer_size == -1)
256 options->hpn_buffer_size = 2*1024*1024;
258 if (options->hpn_buffer_size == 0)
259 options->hpn_buffer_size = 1;
260 /* limit the maximum buffer to 7MB */
261 if (options->hpn_buffer_size > 7168)
262 options->hpn_buffer_size = 7168;
263 options->hpn_buffer_size *=1024;
266 /* Turn privilege separation on by default */
267 if (use_privsep == -1)
273 if (use_privsep && options->compression == 1) {
274 error("This platform does not support both privilege "
275 "separation and compression");
276 error("Compression disabled");
277 options->compression = 0;
283 /* Keyword tokens. */
285 sBadOption, /* == unknown option */
286 /* Portable-specific options */
288 /* Standard Options */
289 sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
290 sPermitRootLogin, sLogFacility, sLogLevel,
291 sRhostsRSAAuthentication, sRSAAuthentication,
292 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
293 sKerberosGetAFSToken,
294 sKerberosTgtPassing, sChallengeResponseAuthentication,
296 sAllowSessionHooks, sSessionHookStartupCmd, sSessionHookShutdownCmd,
298 sPasswordAuthentication, sKbdInteractiveAuthentication,
299 sListenAddress, sAddressFamily,
300 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
301 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
302 sStrictModes, sEmptyPasswd, sTCPKeepAlive,
303 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
304 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
305 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
306 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
307 sMaxStartups, sMaxAuthTries,
308 sBanner, sUseDNS, sHostbasedAuthentication,
309 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
310 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
312 sGsiAllowLimitedProxy,
313 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
314 sUsePrivilegeSeparation, sNoneEnabled, sTcpRcvBufPoll,
315 sHPNDisabled, sHPNBufferSize,
316 sDeprecated, sUnsupported
319 /* Textual representation of the tokens. */
322 ServerOpCodes opcode;
324 /* Portable-specific options */
326 { "usepam", sUsePAM },
328 { "usepam", sUnsupported },
330 { "pamauthenticationviakbdint", sDeprecated },
331 /* Standard Options */
333 { "hostkey", sHostKeyFile },
334 { "hostdsakey", sHostKeyFile }, /* alias */
335 { "pidfile", sPidFile },
336 { "serverkeybits", sServerKeyBits },
337 { "logingracetime", sLoginGraceTime },
338 { "keyregenerationinterval", sKeyRegenerationTime },
339 { "permitrootlogin", sPermitRootLogin },
340 { "syslogfacility", sLogFacility },
341 { "loglevel", sLogLevel },
342 { "rhostsauthentication", sDeprecated },
343 { "rhostsrsaauthentication", sRhostsRSAAuthentication },
344 { "hostbasedauthentication", sHostbasedAuthentication },
345 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
346 { "rsaauthentication", sRSAAuthentication },
347 { "pubkeyauthentication", sPubkeyAuthentication },
348 { "dsaauthentication", sPubkeyAuthentication }, /* alias */
350 { "kerberosauthentication", sKerberosAuthentication },
351 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
352 { "kerberosticketcleanup", sKerberosTicketCleanup },
354 { "kerberosgetafstoken", sKerberosGetAFSToken },
356 { "kerberosgetafstoken", sUnsupported },
359 { "kerberosauthentication", sUnsupported },
360 { "kerberosorlocalpasswd", sUnsupported },
361 { "kerberosticketcleanup", sUnsupported },
362 { "kerberosgetafstoken", sUnsupported },
364 { "kerberostgtpassing", sUnsupported },
365 { "afstokenpassing", sUnsupported },
367 { "gssapiauthentication", sGssAuthentication },
368 { "gssapikeyexchange", sGssKeyEx },
369 { "gssapicleanupcredentials", sGssCleanupCreds },
371 { "gsiallowlimitedproxy", sGsiAllowLimitedProxy },
374 { "gssapiauthentication", sUnsupported },
375 { "gssapikeyexchange", sUnsupported },
376 { "gssapicleanupcredentials", sUnsupported },
379 { "allowsessionhooks", sAllowSessionHooks },
380 { "sessionhookstartupcmd", sSessionHookStartupCmd },
381 { "sessionhookshutdowncmd", sSessionHookShutdownCmd },
383 { "passwordauthentication", sPasswordAuthentication },
384 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
385 { "challengeresponseauthentication", sChallengeResponseAuthentication },
386 { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
387 { "checkmail", sDeprecated },
388 { "listenaddress", sListenAddress },
389 { "addressfamily", sAddressFamily },
390 { "printmotd", sPrintMotd },
391 { "printlastlog", sPrintLastLog },
392 { "ignorerhosts", sIgnoreRhosts },
393 { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
394 { "x11forwarding", sX11Forwarding },
395 { "x11displayoffset", sX11DisplayOffset },
396 { "x11uselocalhost", sX11UseLocalhost },
397 { "xauthlocation", sXAuthLocation },
398 { "strictmodes", sStrictModes },
399 { "permitemptypasswords", sEmptyPasswd },
400 { "permituserenvironment", sPermitUserEnvironment },
401 { "uselogin", sUseLogin },
402 { "compression", sCompression },
403 { "tcpkeepalive", sTCPKeepAlive },
404 { "keepalive", sTCPKeepAlive }, /* obsolete alias */
405 { "allowtcpforwarding", sAllowTcpForwarding },
406 { "allowusers", sAllowUsers },
407 { "denyusers", sDenyUsers },
408 { "allowgroups", sAllowGroups },
409 { "denygroups", sDenyGroups },
410 { "ciphers", sCiphers },
412 { "protocol", sProtocol },
413 { "gatewayports", sGatewayPorts },
414 { "subsystem", sSubsystem },
415 { "maxstartups", sMaxStartups },
416 { "maxauthtries", sMaxAuthTries },
417 { "banner", sBanner },
418 { "usedns", sUseDNS },
419 { "verifyreversemapping", sDeprecated },
420 { "reversemappingcheck", sDeprecated },
421 { "clientaliveinterval", sClientAliveInterval },
422 { "clientalivecountmax", sClientAliveCountMax },
423 { "authorizedkeysfile", sAuthorizedKeysFile },
424 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
425 { "useprivilegeseparation", sUsePrivilegeSeparation},
426 { "acceptenv", sAcceptEnv },
427 { "noneenabled", sNoneEnabled },
428 { "hpndisabled", sHPNDisabled },
429 { "hpnbuffersize", sHPNBufferSize },
430 { "tcprcvbufpoll", sTcpRcvBufPoll },
431 { "permittunnel", sPermitTunnel },
436 * Returns the number of the token pointed to by cp or sBadOption.
440 parse_token(const char *cp, const char *filename,
445 for (i = 0; keywords[i].name; i++)
446 if (strcasecmp(cp, keywords[i].name) == 0){
447 debug ("TOKEN IS %s", keywords[i].name);
448 return keywords[i].opcode;}
449 error("%s: line %d: Bad configuration option: %s",
450 filename, linenum, cp);
455 add_listen_addr(ServerOptions *options, char *addr, u_short port)
459 if (options->num_ports == 0)
460 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
461 if (options->address_family == -1)
462 options->address_family = AF_UNSPEC;
464 for (i = 0; i < options->num_ports; i++)
465 add_one_listen_addr(options, addr, options->ports[i]);
467 add_one_listen_addr(options, addr, port);
471 add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
473 struct addrinfo hints, *ai, *aitop;
474 char strport[NI_MAXSERV];
477 memset(&hints, 0, sizeof(hints));
478 hints.ai_family = options->address_family;
479 hints.ai_socktype = SOCK_STREAM;
480 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
481 snprintf(strport, sizeof strport, "%u", port);
482 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
483 fatal("bad addr or host: %s (%s)",
484 addr ? addr : "<NULL>",
485 gai_strerror(gaierr));
486 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
488 ai->ai_next = options->listen_addrs;
489 options->listen_addrs = aitop;
493 process_server_config_line(ServerOptions *options, char *line,
494 const char *filename, int linenum)
496 char *cp, **charptr, *arg, *p;
497 int *intptr, value, n;
498 ServerOpCodes opcode;
504 /* Ignore leading whitespace */
507 if (!arg || !*arg || *arg == '#')
511 opcode = parse_token(arg, filename, linenum);
514 /* Portable-specific options */
516 intptr = &options->use_pam;
519 /* Standard Options */
523 /* ignore ports from configfile if cmdline specifies ports */
524 if (options->ports_from_cmdline)
526 if (options->listen_addrs != NULL)
527 fatal("%s line %d: ports must be specified before "
528 "ListenAddress.", filename, linenum);
529 if (options->num_ports >= MAX_PORTS)
530 fatal("%s line %d: too many ports.",
533 if (!arg || *arg == '\0')
534 fatal("%s line %d: missing port number.",
536 options->ports[options->num_ports++] = a2port(arg);
537 if (options->ports[options->num_ports-1] == 0)
538 fatal("%s line %d: Badly formatted port number.",
543 intptr = &options->server_key_bits;
546 if (!arg || *arg == '\0')
547 fatal("%s line %d: missing integer value.",
554 case sLoginGraceTime:
555 intptr = &options->login_grace_time;
558 if (!arg || *arg == '\0')
559 fatal("%s line %d: missing time value.",
561 if ((value = convtime(arg)) == -1)
562 fatal("%s line %d: invalid time value.",
568 case sKeyRegenerationTime:
569 intptr = &options->key_regeneration_time;
574 if (arg == NULL || *arg == '\0')
575 fatal("%s line %d: missing address",
577 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
578 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
579 && strchr(p+1, ':') != NULL) {
580 add_listen_addr(options, arg, 0);
585 fatal("%s line %d: bad address:port usage",
587 p = cleanhostname(p);
590 else if ((port = a2port(arg)) == 0)
591 fatal("%s line %d: bad port number", filename, linenum);
593 add_listen_addr(options, p, port);
599 if (!arg || *arg == '\0')
600 fatal("%s line %d: missing address family.",
602 intptr = &options->address_family;
603 if (options->listen_addrs != NULL)
604 fatal("%s line %d: address family must be specified before "
605 "ListenAddress.", filename, linenum);
606 if (strcasecmp(arg, "inet") == 0)
608 else if (strcasecmp(arg, "inet6") == 0)
610 else if (strcasecmp(arg, "any") == 0)
613 fatal("%s line %d: unsupported address family \"%s\".",
614 filename, linenum, arg);
620 intptr = &options->num_host_key_files;
621 if (*intptr >= MAX_HOSTKEYS)
622 fatal("%s line %d: too many host keys specified (max %d).",
623 filename, linenum, MAX_HOSTKEYS);
624 charptr = &options->host_key_files[*intptr];
627 if (!arg || *arg == '\0')
628 fatal("%s line %d: missing file name.",
630 if (*charptr == NULL) {
631 *charptr = tilde_expand_filename(arg, getuid());
632 /* increase optional counter */
634 *intptr = *intptr + 1;
639 charptr = &options->pid_file;
642 case sPermitRootLogin:
643 intptr = &options->permit_root_login;
645 if (!arg || *arg == '\0')
646 fatal("%s line %d: missing yes/"
647 "without-password/forced-commands-only/no "
648 "argument.", filename, linenum);
649 value = 0; /* silence compiler */
650 if (strcmp(arg, "without-password") == 0)
651 value = PERMIT_NO_PASSWD;
652 else if (strcmp(arg, "forced-commands-only") == 0)
653 value = PERMIT_FORCED_ONLY;
654 else if (strcmp(arg, "yes") == 0)
656 else if (strcmp(arg, "no") == 0)
659 fatal("%s line %d: Bad yes/"
660 "without-password/forced-commands-only/no "
661 "argument: %s", filename, linenum, arg);
667 intptr = &options->ignore_rhosts;
670 if (!arg || *arg == '\0')
671 fatal("%s line %d: missing yes/no argument.",
673 value = 0; /* silence compiler */
674 if (strcmp(arg, "yes") == 0)
676 else if (strcmp(arg, "no") == 0)
679 fatal("%s line %d: Bad yes/no argument: %s",
680 filename, linenum, arg);
686 intptr = &options->none_enabled;
690 intptr = &options->tcp_rcv_buf_poll;
694 intptr = &options->hpn_disabled;
698 intptr = &options->hpn_buffer_size;
701 case sIgnoreUserKnownHosts:
702 intptr = &options->ignore_user_known_hosts;
705 case sRhostsRSAAuthentication:
706 intptr = &options->rhosts_rsa_authentication;
709 case sHostbasedAuthentication:
710 intptr = &options->hostbased_authentication;
713 case sHostbasedUsesNameFromPacketOnly:
714 intptr = &options->hostbased_uses_name_from_packet_only;
717 case sRSAAuthentication:
718 intptr = &options->rsa_authentication;
721 case sPubkeyAuthentication:
722 intptr = &options->pubkey_authentication;
725 case sKerberosAuthentication:
726 intptr = &options->kerberos_authentication;
729 case sKerberosOrLocalPasswd:
730 intptr = &options->kerberos_or_local_passwd;
733 case sKerberosTicketCleanup:
734 intptr = &options->kerberos_ticket_cleanup;
737 case sKerberosGetAFSToken:
738 intptr = &options->kerberos_get_afs_token;
741 case sGssAuthentication:
742 intptr = &options->gss_authentication;
746 intptr = &options->gss_keyex;
749 case sGssCleanupCreds:
750 intptr = &options->gss_cleanup_creds;
753 case sGsiAllowLimitedProxy:
754 intptr = &options->gsi_allow_limited_proxy;
758 case sAllowSessionHooks:
759 intptr = &options->session_hooks_allow;
761 case sSessionHookStartupCmd:
762 case sSessionHookShutdownCmd:
764 if (!arg || *arg == '\0')
765 fatal("%s line %d: empty session hook command",
767 if (opcode==sSessionHookStartupCmd)
768 options->session_hooks_startup_cmd = strdup(arg);
770 options->session_hooks_shutdown_cmd = strdup(arg);
774 case sPasswordAuthentication:
775 intptr = &options->password_authentication;
778 case sKbdInteractiveAuthentication:
779 intptr = &options->kbd_interactive_authentication;
782 case sChallengeResponseAuthentication:
783 intptr = &options->challenge_response_authentication;
787 intptr = &options->print_motd;
791 intptr = &options->print_lastlog;
795 intptr = &options->x11_forwarding;
798 case sX11DisplayOffset:
799 intptr = &options->x11_display_offset;
802 case sX11UseLocalhost:
803 intptr = &options->x11_use_localhost;
807 charptr = &options->xauth_location;
811 intptr = &options->strict_modes;
815 intptr = &options->tcp_keep_alive;
819 intptr = &options->permit_empty_passwd;
822 case sPermitUserEnvironment:
823 intptr = &options->permit_user_env;
827 intptr = &options->use_login;
831 intptr = &options->compression;
833 if (!arg || *arg == '\0')
834 fatal("%s line %d: missing yes/no/delayed "
835 "argument.", filename, linenum);
836 value = 0; /* silence compiler */
837 if (strcmp(arg, "delayed") == 0)
838 value = COMP_DELAYED;
839 else if (strcmp(arg, "yes") == 0)
841 else if (strcmp(arg, "no") == 0)
844 fatal("%s line %d: Bad yes/no/delayed "
845 "argument: %s", filename, linenum, arg);
851 intptr = &options->gateway_ports;
853 if (!arg || *arg == '\0')
854 fatal("%s line %d: missing yes/no/clientspecified "
855 "argument.", filename, linenum);
856 value = 0; /* silence compiler */
857 if (strcmp(arg, "clientspecified") == 0)
859 else if (strcmp(arg, "yes") == 0)
861 else if (strcmp(arg, "no") == 0)
864 fatal("%s line %d: Bad yes/no/clientspecified "
865 "argument: %s", filename, linenum, arg);
871 intptr = &options->use_dns;
875 intptr = (int *) &options->log_facility;
877 value = log_facility_number(arg);
878 if (value == SYSLOG_FACILITY_NOT_SET)
879 fatal("%.200s line %d: unsupported log facility '%s'",
880 filename, linenum, arg ? arg : "<NONE>");
882 *intptr = (SyslogFacility) value;
886 intptr = (int *) &options->log_level;
888 value = log_level_number(arg);
889 if (value == SYSLOG_LEVEL_NOT_SET)
890 fatal("%.200s line %d: unsupported log level '%s'",
891 filename, linenum, arg ? arg : "<NONE>");
893 *intptr = (LogLevel) value;
896 case sAllowTcpForwarding:
897 intptr = &options->allow_tcp_forwarding;
900 case sUsePrivilegeSeparation:
901 intptr = &use_privsep;
905 while ((arg = strdelim(&cp)) && *arg != '\0') {
906 if (options->num_allow_users >= MAX_ALLOW_USERS)
907 fatal("%s line %d: too many allow users.",
909 options->allow_users[options->num_allow_users++] =
915 while ((arg = strdelim(&cp)) && *arg != '\0') {
916 if (options->num_deny_users >= MAX_DENY_USERS)
917 fatal( "%s line %d: too many deny users.",
919 options->deny_users[options->num_deny_users++] =
925 while ((arg = strdelim(&cp)) && *arg != '\0') {
926 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
927 fatal("%s line %d: too many allow groups.",
929 options->allow_groups[options->num_allow_groups++] =
935 while ((arg = strdelim(&cp)) && *arg != '\0') {
936 if (options->num_deny_groups >= MAX_DENY_GROUPS)
937 fatal("%s line %d: too many deny groups.",
939 options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
945 if (!arg || *arg == '\0')
946 fatal("%s line %d: Missing argument.", filename, linenum);
947 if (!ciphers_valid(arg))
948 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
949 filename, linenum, arg ? arg : "<NONE>");
950 if (options->ciphers == NULL)
951 options->ciphers = xstrdup(arg);
956 if (!arg || *arg == '\0')
957 fatal("%s line %d: Missing argument.", filename, linenum);
959 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
960 filename, linenum, arg ? arg : "<NONE>");
961 if (options->macs == NULL)
962 options->macs = xstrdup(arg);
966 intptr = &options->protocol;
968 if (!arg || *arg == '\0')
969 fatal("%s line %d: Missing argument.", filename, linenum);
970 value = proto_spec(arg);
971 if (value == SSH_PROTO_UNKNOWN)
972 fatal("%s line %d: Bad protocol spec '%s'.",
973 filename, linenum, arg ? arg : "<NONE>");
974 if (*intptr == SSH_PROTO_UNKNOWN)
979 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
980 fatal("%s line %d: too many subsystems defined.",
984 if (!arg || *arg == '\0')
985 fatal("%s line %d: Missing subsystem name.",
987 for (i = 0; i < options->num_subsystems; i++)
988 if (strcmp(arg, options->subsystem_name[i]) == 0)
989 fatal("%s line %d: Subsystem '%s' already defined.",
990 filename, linenum, arg);
991 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
993 if (!arg || *arg == '\0')
994 fatal("%s line %d: Missing subsystem command.",
996 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
997 options->num_subsystems++;
1001 arg = strdelim(&cp);
1002 if (!arg || *arg == '\0')
1003 fatal("%s line %d: Missing MaxStartups spec.",
1005 if ((n = sscanf(arg, "%d:%d:%d",
1006 &options->max_startups_begin,
1007 &options->max_startups_rate,
1008 &options->max_startups)) == 3) {
1009 if (options->max_startups_begin >
1010 options->max_startups ||
1011 options->max_startups_rate > 100 ||
1012 options->max_startups_rate < 1)
1013 fatal("%s line %d: Illegal MaxStartups spec.",
1016 fatal("%s line %d: Illegal MaxStartups spec.",
1019 options->max_startups = options->max_startups_begin;
1023 intptr = &options->max_authtries;
1027 charptr = &options->banner;
1028 goto parse_filename;
1030 * These options can contain %X options expanded at
1031 * connect time, so that you can specify paths like:
1033 * AuthorizedKeysFile /etc/ssh_keys/%u
1035 case sAuthorizedKeysFile:
1036 case sAuthorizedKeysFile2:
1037 charptr = (opcode == sAuthorizedKeysFile ) ?
1038 &options->authorized_keys_file :
1039 &options->authorized_keys_file2;
1040 goto parse_filename;
1042 case sClientAliveInterval:
1043 intptr = &options->client_alive_interval;
1046 case sClientAliveCountMax:
1047 intptr = &options->client_alive_count_max;
1051 while ((arg = strdelim(&cp)) && *arg != '\0') {
1052 if (strchr(arg, '=') != NULL)
1053 fatal("%s line %d: Invalid environment name.",
1055 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1056 fatal("%s line %d: too many allow env.",
1058 options->accept_env[options->num_accept_env++] =
1064 intptr = &options->permit_tun;
1065 arg = strdelim(&cp);
1066 if (!arg || *arg == '\0')
1067 fatal("%s line %d: Missing yes/point-to-point/"
1068 "ethernet/no argument.", filename, linenum);
1069 value = 0; /* silence compiler */
1070 if (strcasecmp(arg, "ethernet") == 0)
1071 value = SSH_TUNMODE_ETHERNET;
1072 else if (strcasecmp(arg, "point-to-point") == 0)
1073 value = SSH_TUNMODE_POINTOPOINT;
1074 else if (strcasecmp(arg, "yes") == 0)
1075 value = SSH_TUNMODE_YES;
1076 else if (strcasecmp(arg, "no") == 0)
1077 value = SSH_TUNMODE_NO;
1079 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1080 "no argument: %s", filename, linenum, arg);
1086 logit("%s line %d: Deprecated option %s",
1087 filename, linenum, arg);
1089 arg = strdelim(&cp);
1093 logit("%s line %d: Unsupported option %s",
1094 filename, linenum, arg);
1096 arg = strdelim(&cp);
1100 fatal("%s line %d: Missing handler for opcode %s (%d)",
1101 filename, linenum, arg, opcode);
1103 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1104 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1105 filename, linenum, arg);
1109 /* Reads the server configuration file. */
1112 load_server_config(const char *filename, Buffer *conf)
1114 char line[1024], *cp;
1117 debug2("%s: filename %s", __func__, filename);
1118 if ((f = fopen(filename, "r")) == NULL) {
1123 while (fgets(line, sizeof(line), f)) {
1125 * Trim out comments and strip whitespace
1126 * NB - preserve newlines, they are needed to reproduce
1127 * line numbers later for error messages
1129 if ((cp = strchr(line, '#')) != NULL)
1130 memcpy(cp, "\n", 2);
1131 cp = line + strspn(line, " \t\r");
1133 buffer_append(conf, cp, strlen(cp));
1135 buffer_append(conf, "\0", 1);
1137 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1141 parse_server_config(ServerOptions *options, const char *filename, Buffer *conf)
1143 int linenum, bad_options = 0;
1144 char *cp, *obuf, *cbuf;
1146 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1148 obuf = cbuf = xstrdup(buffer_ptr(conf));
1150 while ((cp = strsep(&cbuf, "\n")) != NULL) {
1151 if (process_server_config_line(options, cp, filename,
1156 if (bad_options > 0)
1157 fatal("%s: terminating, %d bad configuration options",
1158 filename, bad_options);