2 /* $OpenBSD: servconf.c,v 1.306 2017/03/14 07:19:07 djm Exp $ */
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
17 #include <sys/types.h>
18 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <netinet/in_systm.h>
22 #include <netinet/ip.h>
40 #include "openbsd-compat/sys-queue.h"
48 #include "pathnames.h"
55 #include "groupaccess.h"
60 #include "myproposal.h"
64 static void add_listen_addr(ServerOptions *, char *, int);
65 static void add_one_listen_addr(ServerOptions *, char *, int);
67 /* Use of privilege separation or not */
68 extern int use_privsep;
71 /* Initializes the server options to their default values. */
74 initialize_server_options(ServerOptions *options)
76 memset(options, 0, sizeof(*options));
78 /* Portable-specific options */
79 options->use_pam = -1;
81 /* Standard Options */
82 options->num_ports = 0;
83 options->ports_from_cmdline = 0;
84 options->queued_listen_addrs = NULL;
85 options->num_queued_listens = 0;
86 options->listen_addrs = NULL;
87 options->address_family = -1;
88 options->num_host_key_files = 0;
89 options->num_host_cert_files = 0;
90 options->host_key_agent = NULL;
91 options->pid_file = NULL;
92 options->login_grace_time = -1;
93 options->permit_root_login = PERMIT_NOT_SET;
94 options->ignore_rhosts = -1;
95 options->ignore_user_known_hosts = -1;
96 options->print_motd = -1;
97 options->print_lastlog = -1;
98 options->x11_forwarding = -1;
99 options->x11_display_offset = -1;
100 options->x11_use_localhost = -1;
101 options->permit_tty = -1;
102 options->permit_user_rc = -1;
103 options->xauth_location = NULL;
104 options->strict_modes = -1;
105 options->tcp_keep_alive = -1;
106 options->log_facility = SYSLOG_FACILITY_NOT_SET;
107 options->log_level = SYSLOG_LEVEL_NOT_SET;
108 options->hostbased_authentication = -1;
109 options->hostbased_uses_name_from_packet_only = -1;
110 options->hostbased_key_types = NULL;
111 options->hostkeyalgorithms = NULL;
112 options->pubkey_authentication = -1;
113 options->pubkey_key_types = NULL;
114 options->kerberos_authentication = -1;
115 options->kerberos_or_local_passwd = -1;
116 options->kerberos_ticket_cleanup = -1;
117 options->kerberos_get_afs_token = -1;
118 options->gss_authentication=-1;
119 options->gss_cleanup_creds = -1;
120 options->gss_strict_acceptor = -1;
121 options->password_authentication = -1;
122 options->kbd_interactive_authentication = -1;
123 options->challenge_response_authentication = -1;
124 options->permit_empty_passwd = -1;
125 options->permit_user_env = -1;
126 options->compression = -1;
127 options->rekey_limit = -1;
128 options->rekey_interval = -1;
129 options->allow_tcp_forwarding = -1;
130 options->allow_streamlocal_forwarding = -1;
131 options->allow_agent_forwarding = -1;
132 options->num_allow_users = 0;
133 options->num_deny_users = 0;
134 options->num_allow_groups = 0;
135 options->num_deny_groups = 0;
136 options->ciphers = NULL;
137 options->macs = NULL;
138 options->kex_algorithms = NULL;
139 options->fwd_opts.gateway_ports = -1;
140 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
141 options->fwd_opts.streamlocal_bind_unlink = -1;
142 options->num_subsystems = 0;
143 options->max_startups_begin = -1;
144 options->max_startups_rate = -1;
145 options->max_startups = -1;
146 options->max_authtries = -1;
147 options->max_sessions = -1;
148 options->banner = NULL;
149 options->use_dns = -1;
150 options->client_alive_interval = -1;
151 options->client_alive_count_max = -1;
152 options->num_authkeys_files = 0;
153 options->num_accept_env = 0;
154 options->permit_tun = -1;
155 options->num_permitted_opens = -1;
156 options->adm_forced_command = NULL;
157 options->chroot_directory = NULL;
158 options->authorized_keys_command = NULL;
159 options->authorized_keys_command_user = NULL;
160 options->revoked_keys_file = NULL;
161 options->trusted_user_ca_keys = NULL;
162 options->authorized_principals_file = NULL;
163 options->authorized_principals_command = NULL;
164 options->authorized_principals_command_user = NULL;
165 options->ip_qos_interactive = -1;
166 options->ip_qos_bulk = -1;
167 options->version_addendum = NULL;
168 options->fingerprint_hash = -1;
169 options->disable_forwarding = -1;
170 options->use_blacklist = -1;
173 /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
175 option_clear_or_none(const char *o)
177 return o == NULL || strcasecmp(o, "none") == 0;
181 assemble_algorithms(ServerOptions *o)
183 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
184 kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
185 kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
186 kex_assemble_names(KEX_DEFAULT_PK_ALG,
187 &o->hostkeyalgorithms) != 0 ||
188 kex_assemble_names(KEX_DEFAULT_PK_ALG,
189 &o->hostbased_key_types) != 0 ||
190 kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
191 fatal("kex_assemble_names failed");
195 fill_default_server_options(ServerOptions *options)
199 /* Portable-specific options */
200 if (options->use_pam == -1)
201 options->use_pam = 1;
203 /* Standard Options */
204 #define add_host_key_file(path) \
206 if (access((path), O_RDONLY) == 0) \
207 options->host_key_files \
208 [options->num_host_key_files++] = (path); \
210 if (options->num_host_key_files == 0) {
211 /* fill default hostkeys for protocols */
212 add_host_key_file(_PATH_HOST_RSA_KEY_FILE);
213 add_host_key_file(_PATH_HOST_DSA_KEY_FILE);
214 #ifdef OPENSSL_HAS_ECC
215 add_host_key_file(_PATH_HOST_ECDSA_KEY_FILE);
217 add_host_key_file(_PATH_HOST_ED25519_KEY_FILE);
219 #undef add_host_key_file
220 if (options->num_host_key_files == 0)
221 fatal("No host key files found");
222 /* No certificates by default */
223 if (options->num_ports == 0)
224 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
225 if (options->address_family == -1)
226 options->address_family = AF_UNSPEC;
227 if (options->listen_addrs == NULL)
228 add_listen_addr(options, NULL, 0);
229 if (options->pid_file == NULL)
230 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
231 if (options->login_grace_time == -1)
232 options->login_grace_time = 120;
233 if (options->permit_root_login == PERMIT_NOT_SET)
234 options->permit_root_login = PERMIT_NO;
235 if (options->ignore_rhosts == -1)
236 options->ignore_rhosts = 1;
237 if (options->ignore_user_known_hosts == -1)
238 options->ignore_user_known_hosts = 0;
239 if (options->print_motd == -1)
240 options->print_motd = 1;
241 if (options->print_lastlog == -1)
242 options->print_lastlog = 1;
243 if (options->x11_forwarding == -1)
244 options->x11_forwarding = 1;
245 if (options->x11_display_offset == -1)
246 options->x11_display_offset = 10;
247 if (options->x11_use_localhost == -1)
248 options->x11_use_localhost = 1;
249 if (options->xauth_location == NULL)
250 options->xauth_location = xstrdup(_PATH_XAUTH);
251 if (options->permit_tty == -1)
252 options->permit_tty = 1;
253 if (options->permit_user_rc == -1)
254 options->permit_user_rc = 1;
255 if (options->strict_modes == -1)
256 options->strict_modes = 1;
257 if (options->tcp_keep_alive == -1)
258 options->tcp_keep_alive = 1;
259 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
260 options->log_facility = SYSLOG_FACILITY_AUTH;
261 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
262 options->log_level = SYSLOG_LEVEL_INFO;
263 if (options->hostbased_authentication == -1)
264 options->hostbased_authentication = 0;
265 if (options->hostbased_uses_name_from_packet_only == -1)
266 options->hostbased_uses_name_from_packet_only = 0;
267 if (options->pubkey_authentication == -1)
268 options->pubkey_authentication = 1;
269 if (options->kerberos_authentication == -1)
270 options->kerberos_authentication = 0;
271 if (options->kerberos_or_local_passwd == -1)
272 options->kerberos_or_local_passwd = 1;
273 if (options->kerberos_ticket_cleanup == -1)
274 options->kerberos_ticket_cleanup = 1;
275 if (options->kerberos_get_afs_token == -1)
276 options->kerberos_get_afs_token = 0;
277 if (options->gss_authentication == -1)
278 options->gss_authentication = 0;
279 if (options->gss_cleanup_creds == -1)
280 options->gss_cleanup_creds = 1;
281 if (options->gss_strict_acceptor == -1)
282 options->gss_strict_acceptor = 1;
283 if (options->password_authentication == -1)
284 options->password_authentication = 0;
285 if (options->kbd_interactive_authentication == -1)
286 options->kbd_interactive_authentication = 0;
287 if (options->challenge_response_authentication == -1)
288 options->challenge_response_authentication = 1;
289 if (options->permit_empty_passwd == -1)
290 options->permit_empty_passwd = 0;
291 if (options->permit_user_env == -1)
292 options->permit_user_env = 0;
293 if (options->compression == -1)
294 options->compression = COMP_DELAYED;
295 if (options->rekey_limit == -1)
296 options->rekey_limit = 0;
297 if (options->rekey_interval == -1)
298 options->rekey_interval = 0;
299 if (options->allow_tcp_forwarding == -1)
300 options->allow_tcp_forwarding = FORWARD_ALLOW;
301 if (options->allow_streamlocal_forwarding == -1)
302 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
303 if (options->allow_agent_forwarding == -1)
304 options->allow_agent_forwarding = 1;
305 if (options->fwd_opts.gateway_ports == -1)
306 options->fwd_opts.gateway_ports = 0;
307 if (options->max_startups == -1)
308 options->max_startups = 100;
309 if (options->max_startups_rate == -1)
310 options->max_startups_rate = 30; /* 30% */
311 if (options->max_startups_begin == -1)
312 options->max_startups_begin = 10;
313 if (options->max_authtries == -1)
314 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
315 if (options->max_sessions == -1)
316 options->max_sessions = DEFAULT_SESSIONS_MAX;
317 if (options->use_dns == -1)
318 options->use_dns = 1;
319 if (options->client_alive_interval == -1)
320 options->client_alive_interval = 0;
321 if (options->client_alive_count_max == -1)
322 options->client_alive_count_max = 3;
323 if (options->num_authkeys_files == 0) {
324 options->authorized_keys_files[options->num_authkeys_files++] =
325 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
326 options->authorized_keys_files[options->num_authkeys_files++] =
327 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
329 if (options->permit_tun == -1)
330 options->permit_tun = SSH_TUNMODE_NO;
331 if (options->ip_qos_interactive == -1)
332 options->ip_qos_interactive = IPTOS_LOWDELAY;
333 if (options->ip_qos_bulk == -1)
334 options->ip_qos_bulk = IPTOS_THROUGHPUT;
335 if (options->version_addendum == NULL)
336 options->version_addendum = xstrdup(SSH_VERSION_FREEBSD);
337 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
338 options->fwd_opts.streamlocal_bind_mask = 0177;
339 if (options->fwd_opts.streamlocal_bind_unlink == -1)
340 options->fwd_opts.streamlocal_bind_unlink = 0;
341 if (options->fingerprint_hash == -1)
342 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
343 if (options->disable_forwarding == -1)
344 options->disable_forwarding = 0;
345 if (options->use_blacklist == -1)
346 options->use_blacklist = 0;
348 assemble_algorithms(options);
350 /* Turn privilege separation and sandboxing on by default */
351 if (use_privsep == -1)
352 use_privsep = PRIVSEP_ON;
354 #define CLEAR_ON_NONE(v) \
356 if (option_clear_or_none(v)) { \
361 CLEAR_ON_NONE(options->pid_file);
362 CLEAR_ON_NONE(options->xauth_location);
363 CLEAR_ON_NONE(options->banner);
364 CLEAR_ON_NONE(options->trusted_user_ca_keys);
365 CLEAR_ON_NONE(options->revoked_keys_file);
366 CLEAR_ON_NONE(options->authorized_principals_file);
367 CLEAR_ON_NONE(options->adm_forced_command);
368 CLEAR_ON_NONE(options->chroot_directory);
369 for (i = 0; i < options->num_host_key_files; i++)
370 CLEAR_ON_NONE(options->host_key_files[i]);
371 for (i = 0; i < options->num_host_cert_files; i++)
372 CLEAR_ON_NONE(options->host_cert_files[i]);
375 /* Similar handling for AuthenticationMethods=any */
376 if (options->num_auth_methods == 1 &&
377 strcmp(options->auth_methods[0], "any") == 0) {
378 free(options->auth_methods[0]);
379 options->auth_methods[0] = NULL;
380 options->num_auth_methods = 0;
384 if (use_privsep && options->compression == 1) {
385 error("This platform does not support both privilege "
386 "separation and compression");
387 error("Compression disabled");
388 options->compression = 0;
394 /* Keyword tokens. */
396 sBadOption, /* == unknown option */
397 /* Portable-specific options */
399 /* Standard Options */
400 sPort, sHostKeyFile, sLoginGraceTime,
401 sPermitRootLogin, sLogFacility, sLogLevel,
402 sRhostsRSAAuthentication, sRSAAuthentication,
403 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
404 sKerberosGetAFSToken,
405 sKerberosTgtPassing, sChallengeResponseAuthentication,
406 sPasswordAuthentication, sKbdInteractiveAuthentication,
407 sListenAddress, sAddressFamily,
408 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
409 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
410 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
411 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
412 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
413 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
414 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
415 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
416 sBanner, sUseDNS, sHostbasedAuthentication,
417 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
419 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
420 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
421 sAcceptEnv, sPermitTunnel,
422 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
423 sUsePrivilegeSeparation, sAllowAgentForwarding,
425 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
426 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
427 sKexAlgorithms, sIPQoS, sVersionAddendum,
428 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
429 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
430 sStreamLocalBindMask, sStreamLocalBindUnlink,
431 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
433 sDeprecated, sIgnore, sUnsupported
436 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
437 #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
438 #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
440 /* Textual representation of the tokens. */
443 ServerOpCodes opcode;
446 /* Portable-specific options */
448 { "usepam", sUsePAM, SSHCFG_GLOBAL },
450 { "usepam", sUnsupported, SSHCFG_GLOBAL },
452 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
453 /* Standard Options */
454 { "port", sPort, SSHCFG_GLOBAL },
455 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
456 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
457 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
458 { "pidfile", sPidFile, SSHCFG_GLOBAL },
459 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
460 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
461 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
462 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
463 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
464 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
465 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
466 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
467 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
468 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
469 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
470 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
471 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
472 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
473 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
474 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
476 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
477 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
478 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
480 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
482 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
485 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
486 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
487 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
488 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
490 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
491 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
493 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
494 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
495 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
497 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
498 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
499 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
501 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
502 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
503 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
504 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
505 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
506 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
507 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
508 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
509 #ifdef DISABLE_LASTLOG
510 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
512 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
514 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
515 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
516 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
517 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
518 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
519 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
520 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
521 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
522 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
523 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
524 { "compression", sCompression, SSHCFG_GLOBAL },
525 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
526 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
527 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
528 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
529 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
530 { "allowusers", sAllowUsers, SSHCFG_ALL },
531 { "denyusers", sDenyUsers, SSHCFG_ALL },
532 { "allowgroups", sAllowGroups, SSHCFG_ALL },
533 { "denygroups", sDenyGroups, SSHCFG_ALL },
534 { "ciphers", sCiphers, SSHCFG_GLOBAL },
535 { "macs", sMacs, SSHCFG_GLOBAL },
536 { "protocol", sIgnore, SSHCFG_GLOBAL },
537 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
538 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
539 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
540 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
541 { "maxsessions", sMaxSessions, SSHCFG_ALL },
542 { "banner", sBanner, SSHCFG_ALL },
543 { "usedns", sUseDNS, SSHCFG_GLOBAL },
544 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
545 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
546 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
547 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
548 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
549 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
550 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
551 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
552 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
553 { "permittty", sPermitTTY, SSHCFG_ALL },
554 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
555 { "match", sMatch, SSHCFG_ALL },
556 { "permitopen", sPermitOpen, SSHCFG_ALL },
557 { "forcecommand", sForceCommand, SSHCFG_ALL },
558 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
559 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
560 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
561 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
562 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
563 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
564 { "ipqos", sIPQoS, SSHCFG_ALL },
565 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
566 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
567 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
568 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
569 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
570 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
571 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
572 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
573 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
574 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
575 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
576 { "useblacklist", sUseBlacklist, SSHCFG_GLOBAL },
577 { "noneenabled", sUnsupported, SSHCFG_ALL },
578 { "hpndisabled", sDeprecated, SSHCFG_ALL },
579 { "hpnbuffersize", sDeprecated, SSHCFG_ALL },
580 { "tcprcvbufpoll", sDeprecated, SSHCFG_ALL },
581 { NULL, sBadOption, 0 }
588 { SSH_TUNMODE_NO, "no" },
589 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
590 { SSH_TUNMODE_ETHERNET, "ethernet" },
591 { SSH_TUNMODE_YES, "yes" },
596 * Returns the number of the token pointed to by cp or sBadOption.
600 parse_token(const char *cp, const char *filename,
601 int linenum, u_int *flags)
605 for (i = 0; keywords[i].name; i++)
606 if (strcasecmp(cp, keywords[i].name) == 0) {
607 *flags = keywords[i].flags;
608 return keywords[i].opcode;
611 error("%s: line %d: Bad configuration option: %s",
612 filename, linenum, cp);
617 derelativise_path(const char *path)
619 char *expanded, *ret, cwd[PATH_MAX];
621 if (strcasecmp(path, "none") == 0)
622 return xstrdup("none");
623 expanded = tilde_expand_filename(path, getuid());
624 if (*expanded == '/')
626 if (getcwd(cwd, sizeof(cwd)) == NULL)
627 fatal("%s: getcwd: %s", __func__, strerror(errno));
628 xasprintf(&ret, "%s/%s", cwd, expanded);
634 add_listen_addr(ServerOptions *options, char *addr, int port)
639 for (i = 0; i < options->num_ports; i++)
640 add_one_listen_addr(options, addr, options->ports[i]);
642 add_one_listen_addr(options, addr, port);
646 add_one_listen_addr(ServerOptions *options, char *addr, int port)
648 struct addrinfo hints, *ai, *aitop;
649 char strport[NI_MAXSERV];
652 memset(&hints, 0, sizeof(hints));
653 hints.ai_family = options->address_family;
654 hints.ai_socktype = SOCK_STREAM;
655 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
656 snprintf(strport, sizeof strport, "%d", port);
657 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
658 fatal("bad addr or host: %s (%s)",
659 addr ? addr : "<NULL>",
660 ssh_gai_strerror(gaierr));
661 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
663 ai->ai_next = options->listen_addrs;
664 options->listen_addrs = aitop;
668 * Queue a ListenAddress to be processed once we have all of the Ports
669 * and AddressFamily options.
672 queue_listen_addr(ServerOptions *options, char *addr, int port)
674 options->queued_listen_addrs = xreallocarray(
675 options->queued_listen_addrs, options->num_queued_listens + 1,
677 options->queued_listen_ports = xreallocarray(
678 options->queued_listen_ports, options->num_queued_listens + 1,
680 options->queued_listen_addrs[options->num_queued_listens] =
682 options->queued_listen_ports[options->num_queued_listens] = port;
683 options->num_queued_listens++;
687 * Process queued (text) ListenAddress entries.
690 process_queued_listen_addrs(ServerOptions *options)
694 if (options->num_ports == 0)
695 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
696 if (options->address_family == -1)
697 options->address_family = AF_UNSPEC;
699 for (i = 0; i < options->num_queued_listens; i++) {
700 add_listen_addr(options, options->queued_listen_addrs[i],
701 options->queued_listen_ports[i]);
702 free(options->queued_listen_addrs[i]);
703 options->queued_listen_addrs[i] = NULL;
705 free(options->queued_listen_addrs);
706 options->queued_listen_addrs = NULL;
707 free(options->queued_listen_ports);
708 options->queued_listen_ports = NULL;
709 options->num_queued_listens = 0;
712 struct connection_info *
713 get_connection_info(int populate, int use_dns)
715 struct ssh *ssh = active_state; /* XXX */
716 static struct connection_info ci;
720 ci.host = auth_get_canonical_hostname(ssh, use_dns);
721 ci.address = ssh_remote_ipaddr(ssh);
722 ci.laddress = ssh_local_ipaddr(ssh);
723 ci.lport = ssh_local_port(ssh);
728 * The strategy for the Match blocks is that the config file is parsed twice.
730 * The first time is at startup. activep is initialized to 1 and the
731 * directives in the global context are processed and acted on. Hitting a
732 * Match directive unsets activep and the directives inside the block are
733 * checked for syntax only.
735 * The second time is after a connection has been established but before
736 * authentication. activep is initialized to 2 and global config directives
737 * are ignored since they have already been processed. If the criteria in a
738 * Match block is met, activep is set and the subsequent directives
739 * processed and actioned until EOF or another Match block unsets it. Any
740 * options set are copied into the main server config.
742 * Potential additions/improvements:
743 * - Add Match support for pre-kex directives, eg. Ciphers.
745 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
746 * Match Address 192.168.0.*
751 * AllowTcpForwarding yes
752 * GatewayPorts clientspecified
755 * - Add a PermittedChannelRequests directive
757 * PermittedChannelRequests session,forwarded-tcpip
761 match_cfg_line_group(const char *grps, int line, const char *user)
769 if ((pw = getpwnam(user)) == NULL) {
770 debug("Can't match group at line %d because user %.100s does "
771 "not exist", line, user);
772 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
773 debug("Can't Match group because user %.100s not in any group "
774 "at line %d", user, line);
775 } else if (ga_match_pattern_list(grps) != 1) {
776 debug("user %.100s does not match group list %.100s at line %d",
779 debug("user %.100s matched group list %.100s at line %d", user,
789 * All of the attributes on a single Match line are ANDed together, so we need
790 * to check every attribute and set the result to zero if any attribute does
794 match_cfg_line(char **condition, int line, struct connection_info *ci)
796 int result = 1, attributes = 0, port;
797 char *arg, *attrib, *cp = *condition;
800 debug3("checking syntax for 'Match %s'", cp);
802 debug3("checking match for '%s' user %s host %s addr %s "
803 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
804 ci->host ? ci->host : "(null)",
805 ci->address ? ci->address : "(null)",
806 ci->laddress ? ci->laddress : "(null)", ci->lport);
808 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
810 if (strcasecmp(attrib, "all") == 0) {
811 if (attributes != 1 ||
812 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
813 error("'all' cannot be combined with other "
820 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
821 error("Missing Match criteria for %s", attrib);
824 if (strcasecmp(attrib, "user") == 0) {
825 if (ci == NULL || ci->user == NULL) {
829 if (match_pattern_list(ci->user, arg, 0) != 1)
832 debug("user %.100s matched 'User %.100s' at "
833 "line %d", ci->user, arg, line);
834 } else if (strcasecmp(attrib, "group") == 0) {
835 if (ci == NULL || ci->user == NULL) {
839 switch (match_cfg_line_group(arg, line, ci->user)) {
845 } else if (strcasecmp(attrib, "host") == 0) {
846 if (ci == NULL || ci->host == NULL) {
850 if (match_hostname(ci->host, arg) != 1)
853 debug("connection from %.100s matched 'Host "
854 "%.100s' at line %d", ci->host, arg, line);
855 } else if (strcasecmp(attrib, "address") == 0) {
856 if (ci == NULL || ci->address == NULL) {
860 switch (addr_match_list(ci->address, arg)) {
862 debug("connection from %.100s matched 'Address "
863 "%.100s' at line %d", ci->address, arg, line);
872 } else if (strcasecmp(attrib, "localaddress") == 0){
873 if (ci == NULL || ci->laddress == NULL) {
877 switch (addr_match_list(ci->laddress, arg)) {
879 debug("connection from %.100s matched "
880 "'LocalAddress %.100s' at line %d",
881 ci->laddress, arg, line);
890 } else if (strcasecmp(attrib, "localport") == 0) {
891 if ((port = a2port(arg)) == -1) {
892 error("Invalid LocalPort '%s' on Match line",
896 if (ci == NULL || ci->lport == 0) {
900 /* TODO support port lists */
901 if (port == ci->lport)
902 debug("connection from %.100s matched "
903 "'LocalPort %d' at line %d",
904 ci->laddress, port, line);
908 error("Unsupported Match attribute %s", attrib);
912 if (attributes == 0) {
913 error("One or more attributes required for Match");
917 debug3("match %sfound", result ? "" : "not ");
922 #define WHITESPACE " \t\r\n"
924 /* Multistate option parsing */
929 static const struct multistate multistate_addressfamily[] = {
931 { "inet6", AF_INET6 },
932 { "any", AF_UNSPEC },
935 static const struct multistate multistate_permitrootlogin[] = {
936 { "without-password", PERMIT_NO_PASSWD },
937 { "prohibit-password", PERMIT_NO_PASSWD },
938 { "forced-commands-only", PERMIT_FORCED_ONLY },
939 { "yes", PERMIT_YES },
943 static const struct multistate multistate_compression[] = {
944 { "yes", COMP_DELAYED },
945 { "delayed", COMP_DELAYED },
949 static const struct multistate multistate_gatewayports[] = {
950 { "clientspecified", 2 },
955 static const struct multistate multistate_privsep[] = {
956 { "yes", PRIVSEP_NOSANDBOX },
957 { "sandbox", PRIVSEP_ON },
958 { "nosandbox", PRIVSEP_NOSANDBOX },
959 { "no", PRIVSEP_OFF },
962 static const struct multistate multistate_tcpfwd[] = {
963 { "yes", FORWARD_ALLOW },
964 { "all", FORWARD_ALLOW },
965 { "no", FORWARD_DENY },
966 { "remote", FORWARD_REMOTE },
967 { "local", FORWARD_LOCAL },
972 process_server_config_line(ServerOptions *options, char *line,
973 const char *filename, int linenum, int *activep,
974 struct connection_info *connectinfo)
976 char *cp, **charptr, *arg, *p;
977 int cmdline = 0, *intptr, value, value2, n, port;
978 SyslogFacility *log_facility_ptr;
979 LogLevel *log_level_ptr;
980 ServerOpCodes opcode;
984 const struct multistate *multistate_ptr;
986 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
987 if ((len = strlen(line)) == 0)
989 for (len--; len > 0; len--) {
990 if (strchr(WHITESPACE "\f", line[len]) == NULL)
996 if ((arg = strdelim(&cp)) == NULL)
998 /* Ignore leading whitespace */
1000 arg = strdelim(&cp);
1001 if (!arg || !*arg || *arg == '#')
1005 opcode = parse_token(arg, filename, linenum, &flags);
1007 if (activep == NULL) { /* We are processing a command line directive */
1011 if (*activep && opcode != sMatch)
1012 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1013 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1014 if (connectinfo == NULL) {
1015 fatal("%s line %d: Directive '%s' is not allowed "
1016 "within a Match block", filename, linenum, arg);
1017 } else { /* this is a directive we have already processed */
1019 arg = strdelim(&cp);
1025 /* Portable-specific options */
1027 intptr = &options->use_pam;
1030 /* Standard Options */
1034 /* ignore ports from configfile if cmdline specifies ports */
1035 if (options->ports_from_cmdline)
1037 if (options->num_ports >= MAX_PORTS)
1038 fatal("%s line %d: too many ports.",
1040 arg = strdelim(&cp);
1041 if (!arg || *arg == '\0')
1042 fatal("%s line %d: missing port number.",
1044 options->ports[options->num_ports++] = a2port(arg);
1045 if (options->ports[options->num_ports-1] <= 0)
1046 fatal("%s line %d: Badly formatted port number.",
1050 case sLoginGraceTime:
1051 intptr = &options->login_grace_time;
1053 arg = strdelim(&cp);
1054 if (!arg || *arg == '\0')
1055 fatal("%s line %d: missing time value.",
1057 if ((value = convtime(arg)) == -1)
1058 fatal("%s line %d: invalid time value.",
1060 if (*activep && *intptr == -1)
1064 case sListenAddress:
1065 arg = strdelim(&cp);
1066 if (arg == NULL || *arg == '\0')
1067 fatal("%s line %d: missing address",
1069 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1070 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1071 && strchr(p+1, ':') != NULL) {
1072 queue_listen_addr(options, arg, 0);
1077 fatal("%s line %d: bad address:port usage",
1079 p = cleanhostname(p);
1082 else if ((port = a2port(arg)) <= 0)
1083 fatal("%s line %d: bad port number", filename, linenum);
1085 queue_listen_addr(options, p, port);
1089 case sAddressFamily:
1090 intptr = &options->address_family;
1091 multistate_ptr = multistate_addressfamily;
1093 arg = strdelim(&cp);
1094 if (!arg || *arg == '\0')
1095 fatal("%s line %d: missing argument.",
1098 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1099 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1100 value = multistate_ptr[i].value;
1105 fatal("%s line %d: unsupported option \"%s\".",
1106 filename, linenum, arg);
1107 if (*activep && *intptr == -1)
1112 intptr = &options->num_host_key_files;
1113 if (*intptr >= MAX_HOSTKEYS)
1114 fatal("%s line %d: too many host keys specified (max %d).",
1115 filename, linenum, MAX_HOSTKEYS);
1116 charptr = &options->host_key_files[*intptr];
1118 arg = strdelim(&cp);
1119 if (!arg || *arg == '\0')
1120 fatal("%s line %d: missing file name.",
1122 if (*activep && *charptr == NULL) {
1123 *charptr = derelativise_path(arg);
1124 /* increase optional counter */
1126 *intptr = *intptr + 1;
1131 charptr = &options->host_key_agent;
1132 arg = strdelim(&cp);
1133 if (!arg || *arg == '\0')
1134 fatal("%s line %d: missing socket name.",
1136 if (*activep && *charptr == NULL)
1137 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1138 xstrdup(arg) : derelativise_path(arg);
1141 case sHostCertificate:
1142 intptr = &options->num_host_cert_files;
1143 if (*intptr >= MAX_HOSTKEYS)
1144 fatal("%s line %d: too many host certificates "
1145 "specified (max %d).", filename, linenum,
1147 charptr = &options->host_cert_files[*intptr];
1148 goto parse_filename;
1151 charptr = &options->pid_file;
1152 goto parse_filename;
1154 case sPermitRootLogin:
1155 intptr = &options->permit_root_login;
1156 multistate_ptr = multistate_permitrootlogin;
1157 goto parse_multistate;
1160 intptr = &options->ignore_rhosts;
1162 arg = strdelim(&cp);
1163 if (!arg || *arg == '\0')
1164 fatal("%s line %d: missing yes/no argument.",
1166 value = 0; /* silence compiler */
1167 if (strcmp(arg, "yes") == 0)
1169 else if (strcmp(arg, "no") == 0)
1172 fatal("%s line %d: Bad yes/no argument: %s",
1173 filename, linenum, arg);
1174 if (*activep && *intptr == -1)
1178 case sIgnoreUserKnownHosts:
1179 intptr = &options->ignore_user_known_hosts;
1182 case sHostbasedAuthentication:
1183 intptr = &options->hostbased_authentication;
1186 case sHostbasedUsesNameFromPacketOnly:
1187 intptr = &options->hostbased_uses_name_from_packet_only;
1190 case sHostbasedAcceptedKeyTypes:
1191 charptr = &options->hostbased_key_types;
1193 arg = strdelim(&cp);
1194 if (!arg || *arg == '\0')
1195 fatal("%s line %d: Missing argument.",
1198 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1199 fatal("%s line %d: Bad key types '%s'.",
1200 filename, linenum, arg ? arg : "<NONE>");
1201 if (*activep && *charptr == NULL)
1202 *charptr = xstrdup(arg);
1205 case sHostKeyAlgorithms:
1206 charptr = &options->hostkeyalgorithms;
1207 goto parse_keytypes;
1209 case sPubkeyAuthentication:
1210 intptr = &options->pubkey_authentication;
1213 case sPubkeyAcceptedKeyTypes:
1214 charptr = &options->pubkey_key_types;
1215 goto parse_keytypes;
1217 case sKerberosAuthentication:
1218 intptr = &options->kerberos_authentication;
1221 case sKerberosOrLocalPasswd:
1222 intptr = &options->kerberos_or_local_passwd;
1225 case sKerberosTicketCleanup:
1226 intptr = &options->kerberos_ticket_cleanup;
1229 case sKerberosGetAFSToken:
1230 intptr = &options->kerberos_get_afs_token;
1233 case sGssAuthentication:
1234 intptr = &options->gss_authentication;
1237 case sGssCleanupCreds:
1238 intptr = &options->gss_cleanup_creds;
1241 case sGssStrictAcceptor:
1242 intptr = &options->gss_strict_acceptor;
1245 case sPasswordAuthentication:
1246 intptr = &options->password_authentication;
1249 case sKbdInteractiveAuthentication:
1250 intptr = &options->kbd_interactive_authentication;
1253 case sChallengeResponseAuthentication:
1254 intptr = &options->challenge_response_authentication;
1258 intptr = &options->print_motd;
1262 intptr = &options->print_lastlog;
1265 case sX11Forwarding:
1266 intptr = &options->x11_forwarding;
1269 case sX11DisplayOffset:
1270 intptr = &options->x11_display_offset;
1272 arg = strdelim(&cp);
1273 if (!arg || *arg == '\0')
1274 fatal("%s line %d: missing integer value.",
1277 if (*activep && *intptr == -1)
1281 case sX11UseLocalhost:
1282 intptr = &options->x11_use_localhost;
1285 case sXAuthLocation:
1286 charptr = &options->xauth_location;
1287 goto parse_filename;
1290 intptr = &options->permit_tty;
1294 intptr = &options->permit_user_rc;
1298 intptr = &options->strict_modes;
1302 intptr = &options->tcp_keep_alive;
1306 intptr = &options->permit_empty_passwd;
1309 case sPermitUserEnvironment:
1310 intptr = &options->permit_user_env;
1314 intptr = &options->compression;
1315 multistate_ptr = multistate_compression;
1316 goto parse_multistate;
1319 arg = strdelim(&cp);
1320 if (!arg || *arg == '\0')
1321 fatal("%.200s line %d: Missing argument.", filename,
1323 if (strcmp(arg, "default") == 0) {
1326 if (scan_scaled(arg, &val64) == -1)
1327 fatal("%.200s line %d: Bad number '%s': %s",
1328 filename, linenum, arg, strerror(errno));
1329 if (val64 != 0 && val64 < 16)
1330 fatal("%.200s line %d: RekeyLimit too small",
1333 if (*activep && options->rekey_limit == -1)
1334 options->rekey_limit = val64;
1335 if (cp != NULL) { /* optional rekey interval present */
1336 if (strcmp(cp, "none") == 0) {
1337 (void)strdelim(&cp); /* discard */
1340 intptr = &options->rekey_interval;
1346 intptr = &options->fwd_opts.gateway_ports;
1347 multistate_ptr = multistate_gatewayports;
1348 goto parse_multistate;
1351 intptr = &options->use_dns;
1355 log_facility_ptr = &options->log_facility;
1356 arg = strdelim(&cp);
1357 value = log_facility_number(arg);
1358 if (value == SYSLOG_FACILITY_NOT_SET)
1359 fatal("%.200s line %d: unsupported log facility '%s'",
1360 filename, linenum, arg ? arg : "<NONE>");
1361 if (*log_facility_ptr == -1)
1362 *log_facility_ptr = (SyslogFacility) value;
1366 log_level_ptr = &options->log_level;
1367 arg = strdelim(&cp);
1368 value = log_level_number(arg);
1369 if (value == SYSLOG_LEVEL_NOT_SET)
1370 fatal("%.200s line %d: unsupported log level '%s'",
1371 filename, linenum, arg ? arg : "<NONE>");
1372 if (*log_level_ptr == -1)
1373 *log_level_ptr = (LogLevel) value;
1376 case sAllowTcpForwarding:
1377 intptr = &options->allow_tcp_forwarding;
1378 multistate_ptr = multistate_tcpfwd;
1379 goto parse_multistate;
1381 case sAllowStreamLocalForwarding:
1382 intptr = &options->allow_streamlocal_forwarding;
1383 multistate_ptr = multistate_tcpfwd;
1384 goto parse_multistate;
1386 case sAllowAgentForwarding:
1387 intptr = &options->allow_agent_forwarding;
1390 case sDisableForwarding:
1391 intptr = &options->disable_forwarding;
1395 while ((arg = strdelim(&cp)) && *arg != '\0') {
1396 if (options->num_allow_users >= MAX_ALLOW_USERS)
1397 fatal("%s line %d: too many allow users.",
1399 if (match_user(NULL, NULL, NULL, arg) == -1)
1400 fatal("%s line %d: invalid AllowUsers pattern: "
1401 "\"%.100s\"", filename, linenum, arg);
1404 options->allow_users[options->num_allow_users++] =
1410 while ((arg = strdelim(&cp)) && *arg != '\0') {
1411 if (options->num_deny_users >= MAX_DENY_USERS)
1412 fatal("%s line %d: too many deny users.",
1414 if (match_user(NULL, NULL, NULL, arg) == -1)
1415 fatal("%s line %d: invalid DenyUsers pattern: "
1416 "\"%.100s\"", filename, linenum, arg);
1419 options->deny_users[options->num_deny_users++] =
1425 while ((arg = strdelim(&cp)) && *arg != '\0') {
1426 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1427 fatal("%s line %d: too many allow groups.",
1431 options->allow_groups[options->num_allow_groups++] =
1437 while ((arg = strdelim(&cp)) && *arg != '\0') {
1438 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1439 fatal("%s line %d: too many deny groups.",
1443 options->deny_groups[options->num_deny_groups++] =
1449 arg = strdelim(&cp);
1450 if (!arg || *arg == '\0')
1451 fatal("%s line %d: Missing argument.", filename, linenum);
1452 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1453 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1454 filename, linenum, arg ? arg : "<NONE>");
1455 if (options->ciphers == NULL)
1456 options->ciphers = xstrdup(arg);
1460 arg = strdelim(&cp);
1461 if (!arg || *arg == '\0')
1462 fatal("%s line %d: Missing argument.", filename, linenum);
1463 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1464 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1465 filename, linenum, arg ? arg : "<NONE>");
1466 if (options->macs == NULL)
1467 options->macs = xstrdup(arg);
1470 case sKexAlgorithms:
1471 arg = strdelim(&cp);
1472 if (!arg || *arg == '\0')
1473 fatal("%s line %d: Missing argument.",
1476 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1477 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1478 filename, linenum, arg ? arg : "<NONE>");
1479 if (options->kex_algorithms == NULL)
1480 options->kex_algorithms = xstrdup(arg);
1484 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1485 fatal("%s line %d: too many subsystems defined.",
1488 arg = strdelim(&cp);
1489 if (!arg || *arg == '\0')
1490 fatal("%s line %d: Missing subsystem name.",
1493 arg = strdelim(&cp);
1496 for (i = 0; i < options->num_subsystems; i++)
1497 if (strcmp(arg, options->subsystem_name[i]) == 0)
1498 fatal("%s line %d: Subsystem '%s' already defined.",
1499 filename, linenum, arg);
1500 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1501 arg = strdelim(&cp);
1502 if (!arg || *arg == '\0')
1503 fatal("%s line %d: Missing subsystem command.",
1505 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1507 /* Collect arguments (separate to executable) */
1509 len = strlen(p) + 1;
1510 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1511 len += 1 + strlen(arg);
1512 p = xreallocarray(p, 1, len);
1513 strlcat(p, " ", len);
1514 strlcat(p, arg, len);
1516 options->subsystem_args[options->num_subsystems] = p;
1517 options->num_subsystems++;
1521 arg = strdelim(&cp);
1522 if (!arg || *arg == '\0')
1523 fatal("%s line %d: Missing MaxStartups spec.",
1525 if ((n = sscanf(arg, "%d:%d:%d",
1526 &options->max_startups_begin,
1527 &options->max_startups_rate,
1528 &options->max_startups)) == 3) {
1529 if (options->max_startups_begin >
1530 options->max_startups ||
1531 options->max_startups_rate > 100 ||
1532 options->max_startups_rate < 1)
1533 fatal("%s line %d: Illegal MaxStartups spec.",
1536 fatal("%s line %d: Illegal MaxStartups spec.",
1539 options->max_startups = options->max_startups_begin;
1543 intptr = &options->max_authtries;
1547 intptr = &options->max_sessions;
1551 charptr = &options->banner;
1552 goto parse_filename;
1555 * These options can contain %X options expanded at
1556 * connect time, so that you can specify paths like:
1558 * AuthorizedKeysFile /etc/ssh_keys/%u
1560 case sAuthorizedKeysFile:
1561 if (*activep && options->num_authkeys_files == 0) {
1562 while ((arg = strdelim(&cp)) && *arg != '\0') {
1563 if (options->num_authkeys_files >=
1565 fatal("%s line %d: "
1566 "too many authorized keys files.",
1568 options->authorized_keys_files[
1569 options->num_authkeys_files++] =
1570 tilde_expand_filename(arg, getuid());
1575 case sAuthorizedPrincipalsFile:
1576 charptr = &options->authorized_principals_file;
1577 arg = strdelim(&cp);
1578 if (!arg || *arg == '\0')
1579 fatal("%s line %d: missing file name.",
1581 if (*activep && *charptr == NULL) {
1582 *charptr = tilde_expand_filename(arg, getuid());
1583 /* increase optional counter */
1585 *intptr = *intptr + 1;
1589 case sClientAliveInterval:
1590 intptr = &options->client_alive_interval;
1593 case sClientAliveCountMax:
1594 intptr = &options->client_alive_count_max;
1598 while ((arg = strdelim(&cp)) && *arg != '\0') {
1599 if (strchr(arg, '=') != NULL)
1600 fatal("%s line %d: Invalid environment name.",
1602 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1603 fatal("%s line %d: too many allow env.",
1607 options->accept_env[options->num_accept_env++] =
1613 intptr = &options->permit_tun;
1614 arg = strdelim(&cp);
1615 if (!arg || *arg == '\0')
1616 fatal("%s line %d: Missing yes/point-to-point/"
1617 "ethernet/no argument.", filename, linenum);
1619 for (i = 0; tunmode_desc[i].val != -1; i++)
1620 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1621 value = tunmode_desc[i].val;
1625 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1626 "no argument: %s", filename, linenum, arg);
1627 if (*activep && *intptr == -1)
1633 fatal("Match directive not supported as a command-line "
1635 value = match_cfg_line(&cp, linenum, connectinfo);
1637 fatal("%s line %d: Bad Match condition", filename,
1643 arg = strdelim(&cp);
1644 if (!arg || *arg == '\0')
1645 fatal("%s line %d: missing PermitOpen specification",
1647 n = options->num_permitted_opens; /* modified later */
1648 if (strcmp(arg, "any") == 0) {
1649 if (*activep && n == -1) {
1650 channel_clear_adm_permitted_opens();
1651 options->num_permitted_opens = 0;
1655 if (strcmp(arg, "none") == 0) {
1656 if (*activep && n == -1) {
1657 options->num_permitted_opens = 1;
1658 channel_disable_adm_local_opens();
1662 if (*activep && n == -1)
1663 channel_clear_adm_permitted_opens();
1664 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1667 fatal("%s line %d: missing host in PermitOpen",
1669 p = cleanhostname(p);
1670 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1671 fatal("%s line %d: bad port number in "
1672 "PermitOpen", filename, linenum);
1673 if (*activep && n == -1)
1674 options->num_permitted_opens =
1675 channel_add_adm_permitted_opens(p, port);
1680 if (cp == NULL || *cp == '\0')
1681 fatal("%.200s line %d: Missing argument.", filename,
1683 len = strspn(cp, WHITESPACE);
1684 if (*activep && options->adm_forced_command == NULL)
1685 options->adm_forced_command = xstrdup(cp + len);
1688 case sChrootDirectory:
1689 charptr = &options->chroot_directory;
1691 arg = strdelim(&cp);
1692 if (!arg || *arg == '\0')
1693 fatal("%s line %d: missing file name.",
1695 if (*activep && *charptr == NULL)
1696 *charptr = xstrdup(arg);
1699 case sTrustedUserCAKeys:
1700 charptr = &options->trusted_user_ca_keys;
1701 goto parse_filename;
1704 charptr = &options->revoked_keys_file;
1705 goto parse_filename;
1708 arg = strdelim(&cp);
1709 if ((value = parse_ipqos(arg)) == -1)
1710 fatal("%s line %d: Bad IPQoS value: %s",
1711 filename, linenum, arg);
1712 arg = strdelim(&cp);
1715 else if ((value2 = parse_ipqos(arg)) == -1)
1716 fatal("%s line %d: Bad IPQoS value: %s",
1717 filename, linenum, arg);
1719 options->ip_qos_interactive = value;
1720 options->ip_qos_bulk = value2;
1724 case sVersionAddendum:
1725 if (cp == NULL || *cp == '\0')
1726 fatal("%.200s line %d: Missing argument.", filename,
1728 len = strspn(cp, WHITESPACE);
1729 if (*activep && options->version_addendum == NULL) {
1730 if (strcasecmp(cp + len, "none") == 0)
1731 options->version_addendum = xstrdup("");
1732 else if (strchr(cp + len, '\r') != NULL)
1733 fatal("%.200s line %d: Invalid argument",
1736 options->version_addendum = xstrdup(cp + len);
1740 case sAuthorizedKeysCommand:
1742 fatal("%.200s line %d: Missing argument.", filename,
1744 len = strspn(cp, WHITESPACE);
1745 if (*activep && options->authorized_keys_command == NULL) {
1746 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1747 fatal("%.200s line %d: AuthorizedKeysCommand "
1748 "must be an absolute path",
1750 options->authorized_keys_command = xstrdup(cp + len);
1754 case sAuthorizedKeysCommandUser:
1755 charptr = &options->authorized_keys_command_user;
1757 arg = strdelim(&cp);
1758 if (!arg || *arg == '\0')
1759 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1760 "argument.", filename, linenum);
1761 if (*activep && *charptr == NULL)
1762 *charptr = xstrdup(arg);
1765 case sAuthorizedPrincipalsCommand:
1767 fatal("%.200s line %d: Missing argument.", filename,
1769 len = strspn(cp, WHITESPACE);
1771 options->authorized_principals_command == NULL) {
1772 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1773 fatal("%.200s line %d: "
1774 "AuthorizedPrincipalsCommand must be "
1775 "an absolute path", filename, linenum);
1776 options->authorized_principals_command =
1781 case sAuthorizedPrincipalsCommandUser:
1782 charptr = &options->authorized_principals_command_user;
1784 arg = strdelim(&cp);
1785 if (!arg || *arg == '\0')
1786 fatal("%s line %d: missing "
1787 "AuthorizedPrincipalsCommandUser argument.",
1789 if (*activep && *charptr == NULL)
1790 *charptr = xstrdup(arg);
1793 case sAuthenticationMethods:
1794 if (options->num_auth_methods == 0) {
1795 value = 0; /* seen "any" pseudo-method */
1796 value2 = 0; /* sucessfully parsed any method */
1797 while ((arg = strdelim(&cp)) && *arg != '\0') {
1798 if (options->num_auth_methods >=
1800 fatal("%s line %d: "
1801 "too many authentication methods.",
1803 if (strcmp(arg, "any") == 0) {
1804 if (options->num_auth_methods > 0) {
1805 fatal("%s line %d: \"any\" "
1806 "must appear alone in "
1807 "AuthenticationMethods",
1812 fatal("%s line %d: \"any\" must appear "
1813 "alone in AuthenticationMethods",
1815 } else if (auth2_methods_valid(arg, 0) != 0) {
1816 fatal("%s line %d: invalid "
1817 "authentication method list.",
1823 options->auth_methods[
1824 options->num_auth_methods++] = xstrdup(arg);
1827 fatal("%s line %d: no AuthenticationMethods "
1828 "specified", filename, linenum);
1833 case sStreamLocalBindMask:
1834 arg = strdelim(&cp);
1835 if (!arg || *arg == '\0')
1836 fatal("%s line %d: missing StreamLocalBindMask "
1837 "argument.", filename, linenum);
1838 /* Parse mode in octal format */
1839 value = strtol(arg, &p, 8);
1840 if (arg == p || value < 0 || value > 0777)
1841 fatal("%s line %d: Bad mask.", filename, linenum);
1843 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1846 case sStreamLocalBindUnlink:
1847 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1850 case sFingerprintHash:
1851 arg = strdelim(&cp);
1852 if (!arg || *arg == '\0')
1853 fatal("%.200s line %d: Missing argument.",
1855 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1856 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1857 filename, linenum, arg);
1859 options->fingerprint_hash = value;
1863 intptr = &options->use_blacklist;
1869 do_log2(opcode == sIgnore ?
1870 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1871 "%s line %d: %s option %s", filename, linenum,
1872 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1874 arg = strdelim(&cp);
1878 fatal("%s line %d: Missing handler for opcode %s (%d)",
1879 filename, linenum, arg, opcode);
1881 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1882 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1883 filename, linenum, arg);
1887 /* Reads the server configuration file. */
1890 load_server_config(const char *filename, Buffer *conf)
1892 char line[4096], *cp;
1896 debug2("%s: filename %s", __func__, filename);
1897 if ((f = fopen(filename, "r")) == NULL) {
1902 while (fgets(line, sizeof(line), f)) {
1904 if (strlen(line) == sizeof(line) - 1)
1905 fatal("%s line %d too long", filename, lineno);
1907 * Trim out comments and strip whitespace
1908 * NB - preserve newlines, they are needed to reproduce
1909 * line numbers later for error messages
1911 if ((cp = strchr(line, '#')) != NULL)
1912 memcpy(cp, "\n", 2);
1913 cp = line + strspn(line, " \t\r");
1915 buffer_append(conf, cp, strlen(cp));
1917 buffer_append(conf, "\0", 1);
1919 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1923 parse_server_match_config(ServerOptions *options,
1924 struct connection_info *connectinfo)
1928 initialize_server_options(&mo);
1929 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1930 copy_set_server_options(options, &mo, 0);
1933 int parse_server_match_testspec(struct connection_info *ci, char *spec)
1937 while ((p = strsep(&spec, ",")) && *p != '\0') {
1938 if (strncmp(p, "addr=", 5) == 0) {
1939 ci->address = xstrdup(p + 5);
1940 } else if (strncmp(p, "host=", 5) == 0) {
1941 ci->host = xstrdup(p + 5);
1942 } else if (strncmp(p, "user=", 5) == 0) {
1943 ci->user = xstrdup(p + 5);
1944 } else if (strncmp(p, "laddr=", 6) == 0) {
1945 ci->laddress = xstrdup(p + 6);
1946 } else if (strncmp(p, "lport=", 6) == 0) {
1947 ci->lport = a2port(p + 6);
1948 if (ci->lport == -1) {
1949 fprintf(stderr, "Invalid port '%s' in test mode"
1950 " specification %s\n", p+6, p);
1954 fprintf(stderr, "Invalid test mode specification %s\n",
1963 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1966 int server_match_spec_complete(struct connection_info *ci)
1968 if (ci->user && ci->host && ci->address)
1969 return 1; /* complete */
1970 if (!ci->user && !ci->host && !ci->address)
1971 return -1; /* empty */
1972 return 0; /* partial */
1976 * Copy any supported values that are set.
1978 * If the preauth flag is set, we do not bother copying the string or
1979 * array values that are not used pre-authentication, because any that we
1980 * do use must be explictly sent in mm_getpwnamallow().
1983 copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1985 #define M_CP_INTOPT(n) do {\
1990 M_CP_INTOPT(password_authentication);
1991 M_CP_INTOPT(gss_authentication);
1992 M_CP_INTOPT(pubkey_authentication);
1993 M_CP_INTOPT(kerberos_authentication);
1994 M_CP_INTOPT(hostbased_authentication);
1995 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1996 M_CP_INTOPT(kbd_interactive_authentication);
1997 M_CP_INTOPT(permit_root_login);
1998 M_CP_INTOPT(permit_empty_passwd);
2000 M_CP_INTOPT(allow_tcp_forwarding);
2001 M_CP_INTOPT(allow_streamlocal_forwarding);
2002 M_CP_INTOPT(allow_agent_forwarding);
2003 M_CP_INTOPT(disable_forwarding);
2004 M_CP_INTOPT(permit_tun);
2005 M_CP_INTOPT(fwd_opts.gateway_ports);
2006 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
2007 M_CP_INTOPT(x11_display_offset);
2008 M_CP_INTOPT(x11_forwarding);
2009 M_CP_INTOPT(x11_use_localhost);
2010 M_CP_INTOPT(permit_tty);
2011 M_CP_INTOPT(permit_user_rc);
2012 M_CP_INTOPT(max_sessions);
2013 M_CP_INTOPT(max_authtries);
2014 M_CP_INTOPT(client_alive_count_max);
2015 M_CP_INTOPT(client_alive_interval);
2016 M_CP_INTOPT(ip_qos_interactive);
2017 M_CP_INTOPT(ip_qos_bulk);
2018 M_CP_INTOPT(rekey_limit);
2019 M_CP_INTOPT(rekey_interval);
2022 * The bind_mask is a mode_t that may be unsigned, so we can't use
2023 * M_CP_INTOPT - it does a signed comparison that causes compiler
2026 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
2027 dst->fwd_opts.streamlocal_bind_mask =
2028 src->fwd_opts.streamlocal_bind_mask;
2031 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2032 #define M_CP_STROPT(n) do {\
2033 if (src->n != NULL && dst->n != src->n) { \
2038 #define M_CP_STRARRAYOPT(n, num_n) do {\
2039 if (src->num_n != 0) { \
2040 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2041 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2045 /* See comment in servconf.h */
2046 COPY_MATCH_STRING_OPTS();
2048 /* Arguments that accept '+...' need to be expanded */
2049 assemble_algorithms(dst);
2052 * The only things that should be below this point are string options
2053 * which are only used after authentication.
2058 /* These options may be "none" to clear a global setting */
2059 M_CP_STROPT(adm_forced_command);
2060 if (option_clear_or_none(dst->adm_forced_command)) {
2061 free(dst->adm_forced_command);
2062 dst->adm_forced_command = NULL;
2064 M_CP_STROPT(chroot_directory);
2065 if (option_clear_or_none(dst->chroot_directory)) {
2066 free(dst->chroot_directory);
2067 dst->chroot_directory = NULL;
2073 #undef M_CP_STRARRAYOPT
2076 parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
2077 struct connection_info *connectinfo)
2079 int active, linenum, bad_options = 0;
2080 char *cp, *obuf, *cbuf;
2082 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2084 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2085 fatal("%s: sshbuf_dup_string failed", __func__);
2086 active = connectinfo ? 0 : 1;
2088 while ((cp = strsep(&cbuf, "\n")) != NULL) {
2089 if (process_server_config_line(options, cp, filename,
2090 linenum++, &active, connectinfo) != 0)
2094 if (bad_options > 0)
2095 fatal("%s: terminating, %d bad configuration options",
2096 filename, bad_options);
2097 process_queued_listen_addrs(options);
2101 fmt_multistate_int(int val, const struct multistate *m)
2105 for (i = 0; m[i].key != NULL; i++) {
2106 if (m[i].value == val)
2113 fmt_intarg(ServerOpCodes code, int val)
2118 case sAddressFamily:
2119 return fmt_multistate_int(val, multistate_addressfamily);
2120 case sPermitRootLogin:
2121 return fmt_multistate_int(val, multistate_permitrootlogin);
2123 return fmt_multistate_int(val, multistate_gatewayports);
2125 return fmt_multistate_int(val, multistate_compression);
2126 case sAllowTcpForwarding:
2127 return fmt_multistate_int(val, multistate_tcpfwd);
2128 case sAllowStreamLocalForwarding:
2129 return fmt_multistate_int(val, multistate_tcpfwd);
2130 case sFingerprintHash:
2131 return ssh_digest_alg_name(val);
2145 lookup_opcode_name(ServerOpCodes code)
2149 for (i = 0; keywords[i].name != NULL; i++)
2150 if (keywords[i].opcode == code)
2151 return(keywords[i].name);
2156 dump_cfg_int(ServerOpCodes code, int val)
2158 printf("%s %d\n", lookup_opcode_name(code), val);
2162 dump_cfg_oct(ServerOpCodes code, int val)
2164 printf("%s 0%o\n", lookup_opcode_name(code), val);
2168 dump_cfg_fmtint(ServerOpCodes code, int val)
2170 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2174 dump_cfg_string(ServerOpCodes code, const char *val)
2176 printf("%s %s\n", lookup_opcode_name(code),
2177 val == NULL ? "none" : val);
2181 dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2185 for (i = 0; i < count; i++)
2186 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2190 dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2194 if (count <= 0 && code != sAuthenticationMethods)
2196 printf("%s", lookup_opcode_name(code));
2197 for (i = 0; i < count; i++)
2198 printf(" %s", vals[i]);
2199 if (code == sAuthenticationMethods && count == 0)
2205 dump_config(ServerOptions *o)
2209 struct addrinfo *ai;
2210 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
2211 char *laddr1 = xstrdup(""), *laddr2 = NULL;
2213 /* these are usually at the top of the config */
2214 for (i = 0; i < o->num_ports; i++)
2215 printf("port %d\n", o->ports[i]);
2216 dump_cfg_fmtint(sAddressFamily, o->address_family);
2219 * ListenAddress must be after Port. add_one_listen_addr pushes
2220 * addresses onto a stack, so to maintain ordering we need to
2221 * print these in reverse order.
2223 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2224 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2225 sizeof(addr), port, sizeof(port),
2226 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2227 error("getnameinfo failed: %.100s",
2228 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2232 if (ai->ai_family == AF_INET6)
2233 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2234 addr, port, laddr2);
2236 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2237 addr, port, laddr2);
2241 printf("%s", laddr1);
2244 /* integer arguments */
2246 dump_cfg_fmtint(sUsePAM, o->use_pam);
2248 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2249 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2250 dump_cfg_int(sMaxAuthTries, o->max_authtries);
2251 dump_cfg_int(sMaxSessions, o->max_sessions);
2252 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2253 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
2254 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
2256 /* formatted integer arguments */
2257 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2258 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2259 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2260 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2261 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2262 o->hostbased_uses_name_from_packet_only);
2263 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
2265 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2266 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2267 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
2269 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
2273 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2274 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
2276 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2277 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2278 o->kbd_interactive_authentication);
2279 dump_cfg_fmtint(sChallengeResponseAuthentication,
2280 o->challenge_response_authentication);
2281 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2282 #ifndef DISABLE_LASTLOG
2283 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2285 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2286 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
2287 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
2288 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
2289 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2290 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2291 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2292 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2293 dump_cfg_fmtint(sCompression, o->compression);
2294 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
2295 dump_cfg_fmtint(sUseDNS, o->use_dns);
2296 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2297 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
2298 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
2299 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
2300 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2301 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
2302 dump_cfg_fmtint(sUseBlacklist, o->use_blacklist);
2304 /* string arguments */
2305 dump_cfg_string(sPidFile, o->pid_file);
2306 dump_cfg_string(sXAuthLocation, o->xauth_location);
2307 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2308 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
2309 dump_cfg_string(sBanner, o->banner);
2310 dump_cfg_string(sForceCommand, o->adm_forced_command);
2311 dump_cfg_string(sChrootDirectory, o->chroot_directory);
2312 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2313 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
2314 dump_cfg_string(sAuthorizedPrincipalsFile,
2315 o->authorized_principals_file);
2316 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2317 ? "none" : o->version_addendum);
2318 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2319 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
2320 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2321 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
2322 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
2323 dump_cfg_string(sKexAlgorithms,
2324 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
2325 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2326 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
2327 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2328 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
2329 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2330 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
2332 /* string arguments requiring a lookup */
2333 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2334 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2336 /* string array arguments */
2337 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2338 o->authorized_keys_files);
2339 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2341 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
2342 o->host_cert_files);
2343 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2344 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2345 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2346 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2347 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
2348 dump_cfg_strarray_oneline(sAuthenticationMethods,
2349 o->num_auth_methods, o->auth_methods);
2351 /* other arguments */
2352 for (i = 0; i < o->num_subsystems; i++)
2353 printf("subsystem %s %s\n", o->subsystem_name[i],
2354 o->subsystem_args[i]);
2356 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2357 o->max_startups_rate, o->max_startups);
2359 for (i = 0; tunmode_desc[i].val != -1; i++)
2360 if (tunmode_desc[i].val == o->permit_tun) {
2361 s = tunmode_desc[i].text;
2364 dump_cfg_string(sPermitTunnel, s);
2366 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2367 printf("%s\n", iptos2str(o->ip_qos_bulk));
2369 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
2372 channel_print_adm_permitted_opens();