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".
16 #include <sys/types.h>
17 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <netinet/in_systm.h>
21 #include <netinet/ip.h>
38 #include "openbsd-compat/sys-queue.h"
46 #include "pathnames.h"
53 #include "groupaccess.h"
58 #include "myproposal.h"
62 #include <cutils/properties.h>
65 static void add_listen_addr(ServerOptions *, char *, int);
66 static void add_one_listen_addr(ServerOptions *, char *, int);
68 /* Use of privilege separation or not */
69 extern int use_privsep;
72 /* Initializes the server options to their default values. */
75 initialize_server_options(ServerOptions *options)
77 memset(options, 0, sizeof(*options));
79 /* Portable-specific options */
80 options->use_pam = -1;
82 /* Standard Options */
83 options->num_ports = 0;
84 options->ports_from_cmdline = 0;
85 options->queued_listen_addrs = NULL;
86 options->num_queued_listens = 0;
87 options->listen_addrs = NULL;
88 options->address_family = -1;
89 options->num_host_key_files = 0;
90 options->num_host_cert_files = 0;
91 options->host_key_agent = NULL;
92 options->pid_file = NULL;
93 options->login_grace_time = -1;
94 options->permit_root_login = PERMIT_NOT_SET;
95 options->ignore_rhosts = -1;
96 options->ignore_user_known_hosts = -1;
97 options->print_motd = -1;
98 options->print_lastlog = -1;
99 options->x11_forwarding = -1;
100 options->x11_display_offset = -1;
101 options->x11_use_localhost = -1;
102 options->permit_tty = -1;
103 options->permit_user_rc = -1;
104 options->xauth_location = NULL;
105 options->strict_modes = -1;
106 options->tcp_keep_alive = -1;
107 options->log_facility = SYSLOG_FACILITY_NOT_SET;
108 options->log_level = SYSLOG_LEVEL_NOT_SET;
109 options->hostbased_authentication = -1;
110 options->hostbased_uses_name_from_packet_only = -1;
111 options->hostbased_key_types = NULL;
112 options->hostkeyalgorithms = NULL;
113 options->pubkey_authentication = -1;
114 options->pubkey_key_types = NULL;
115 options->kerberos_authentication = -1;
116 options->kerberos_or_local_passwd = -1;
117 options->kerberos_ticket_cleanup = -1;
118 options->kerberos_get_afs_token = -1;
119 options->gss_authentication=-1;
120 options->gss_cleanup_creds = -1;
121 options->gss_strict_acceptor = -1;
122 options->password_authentication = -1;
123 options->kbd_interactive_authentication = -1;
124 options->challenge_response_authentication = -1;
125 options->permit_empty_passwd = -1;
126 options->permit_user_env = -1;
127 options->compression = -1;
128 options->rekey_limit = -1;
129 options->rekey_interval = -1;
130 options->allow_tcp_forwarding = -1;
131 options->allow_streamlocal_forwarding = -1;
132 options->allow_agent_forwarding = -1;
133 options->num_allow_users = 0;
134 options->num_deny_users = 0;
135 options->num_allow_groups = 0;
136 options->num_deny_groups = 0;
137 options->ciphers = NULL;
138 options->macs = NULL;
139 options->kex_algorithms = NULL;
140 options->fwd_opts.gateway_ports = -1;
141 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
142 options->fwd_opts.streamlocal_bind_unlink = -1;
143 options->num_subsystems = 0;
144 options->max_startups_begin = -1;
145 options->max_startups_rate = -1;
146 options->max_startups = -1;
147 options->max_authtries = -1;
148 options->max_sessions = -1;
149 options->banner = NULL;
150 options->use_dns = -1;
151 options->client_alive_interval = -1;
152 options->client_alive_count_max = -1;
153 options->num_authkeys_files = 0;
154 options->num_accept_env = 0;
155 options->permit_tun = -1;
156 options->num_permitted_opens = -1;
157 options->adm_forced_command = NULL;
158 options->chroot_directory = NULL;
159 options->authorized_keys_command = NULL;
160 options->authorized_keys_command_user = NULL;
161 options->revoked_keys_file = NULL;
162 options->trusted_user_ca_keys = NULL;
163 options->authorized_principals_file = NULL;
164 options->authorized_principals_command = NULL;
165 options->authorized_principals_command_user = NULL;
166 options->ip_qos_interactive = -1;
167 options->ip_qos_bulk = -1;
168 options->version_addendum = NULL;
169 options->fingerprint_hash = -1;
170 options->disable_forwarding = -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 = 0;
203 /* Standard Options */
204 if (options->num_host_key_files == 0) {
205 /* fill default hostkeys for protocols */
206 options->host_key_files[options->num_host_key_files++] =
207 _PATH_HOST_RSA_KEY_FILE;
208 options->host_key_files[options->num_host_key_files++] =
209 _PATH_HOST_DSA_KEY_FILE;
210 #ifdef OPENSSL_HAS_ECC
211 options->host_key_files[options->num_host_key_files++] =
212 _PATH_HOST_ECDSA_KEY_FILE;
214 options->host_key_files[options->num_host_key_files++] =
215 _PATH_HOST_ED25519_KEY_FILE;
217 /* No certificates by default */
218 if (options->num_ports == 0)
219 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
220 if (options->address_family == -1)
221 options->address_family = AF_UNSPEC;
222 if (options->listen_addrs == NULL)
223 add_listen_addr(options, NULL, 0);
224 if (options->pid_file == NULL)
225 options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
226 if (options->login_grace_time == -1)
227 options->login_grace_time = 120;
228 if (options->permit_root_login == PERMIT_NOT_SET)
229 options->permit_root_login = PERMIT_NO_PASSWD;
230 if (options->ignore_rhosts == -1)
231 options->ignore_rhosts = 1;
232 if (options->ignore_user_known_hosts == -1)
233 options->ignore_user_known_hosts = 0;
234 if (options->print_motd == -1)
235 options->print_motd = 1;
236 if (options->print_lastlog == -1)
237 options->print_lastlog = 1;
238 if (options->x11_forwarding == -1)
239 options->x11_forwarding = 0;
240 if (options->x11_display_offset == -1)
241 options->x11_display_offset = 10;
242 if (options->x11_use_localhost == -1)
243 options->x11_use_localhost = 1;
244 if (options->xauth_location == NULL)
245 options->xauth_location = xstrdup(_PATH_XAUTH);
246 if (options->permit_tty == -1)
247 options->permit_tty = 1;
248 if (options->permit_user_rc == -1)
249 options->permit_user_rc = 1;
250 if (options->strict_modes == -1)
251 options->strict_modes = 1;
252 if (options->tcp_keep_alive == -1)
253 options->tcp_keep_alive = 1;
254 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
255 options->log_facility = SYSLOG_FACILITY_AUTH;
256 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
257 options->log_level = SYSLOG_LEVEL_INFO;
258 if (options->hostbased_authentication == -1)
259 options->hostbased_authentication = 0;
260 if (options->hostbased_uses_name_from_packet_only == -1)
261 options->hostbased_uses_name_from_packet_only = 0;
262 if (options->pubkey_authentication == -1)
263 options->pubkey_authentication = 1;
264 if (options->kerberos_authentication == -1)
265 options->kerberos_authentication = 0;
266 if (options->kerberos_or_local_passwd == -1)
267 options->kerberos_or_local_passwd = 1;
268 if (options->kerberos_ticket_cleanup == -1)
269 options->kerberos_ticket_cleanup = 1;
270 if (options->kerberos_get_afs_token == -1)
271 options->kerberos_get_afs_token = 0;
272 if (options->gss_authentication == -1)
273 options->gss_authentication = 0;
274 if (options->gss_cleanup_creds == -1)
275 options->gss_cleanup_creds = 1;
276 if (options->gss_strict_acceptor == -1)
277 options->gss_strict_acceptor = 1;
278 if (options->password_authentication == -1)
279 options->password_authentication = 1;
280 if (options->kbd_interactive_authentication == -1)
281 options->kbd_interactive_authentication = 0;
282 if (options->challenge_response_authentication == -1)
283 options->challenge_response_authentication = 1;
284 if (options->permit_empty_passwd == -1)
285 options->permit_empty_passwd = 0;
286 if (options->permit_user_env == -1)
287 options->permit_user_env = 0;
288 if (options->compression == -1)
289 options->compression = COMP_DELAYED;
290 if (options->rekey_limit == -1)
291 options->rekey_limit = 0;
292 if (options->rekey_interval == -1)
293 options->rekey_interval = 0;
294 if (options->allow_tcp_forwarding == -1)
295 options->allow_tcp_forwarding = FORWARD_ALLOW;
296 if (options->allow_streamlocal_forwarding == -1)
297 options->allow_streamlocal_forwarding = FORWARD_ALLOW;
298 if (options->allow_agent_forwarding == -1)
299 options->allow_agent_forwarding = 1;
300 if (options->fwd_opts.gateway_ports == -1)
301 options->fwd_opts.gateway_ports = 0;
302 if (options->max_startups == -1)
303 options->max_startups = 100;
304 if (options->max_startups_rate == -1)
305 options->max_startups_rate = 30; /* 30% */
306 if (options->max_startups_begin == -1)
307 options->max_startups_begin = 10;
308 if (options->max_authtries == -1)
309 options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
310 if (options->max_sessions == -1)
311 options->max_sessions = DEFAULT_SESSIONS_MAX;
312 if (options->use_dns == -1)
313 options->use_dns = 0;
314 if (options->client_alive_interval == -1)
315 options->client_alive_interval = 0;
316 if (options->client_alive_count_max == -1)
317 options->client_alive_count_max = 3;
318 if (options->num_authkeys_files == 0) {
319 options->authorized_keys_files[options->num_authkeys_files++] =
320 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
321 options->authorized_keys_files[options->num_authkeys_files++] =
322 xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
324 if (options->permit_tun == -1)
325 options->permit_tun = SSH_TUNMODE_NO;
326 if (options->ip_qos_interactive == -1)
327 options->ip_qos_interactive = IPTOS_LOWDELAY;
328 if (options->ip_qos_bulk == -1)
329 options->ip_qos_bulk = IPTOS_THROUGHPUT;
330 if (options->version_addendum == NULL)
331 options->version_addendum = xstrdup("");
332 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
333 options->fwd_opts.streamlocal_bind_mask = 0177;
334 if (options->fwd_opts.streamlocal_bind_unlink == -1)
335 options->fwd_opts.streamlocal_bind_unlink = 0;
336 if (options->fingerprint_hash == -1)
337 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
338 if (options->disable_forwarding == -1)
339 options->disable_forwarding = 0;
341 assemble_algorithms(options);
343 /* Turn privilege separation and sandboxing on by default */
344 if (use_privsep == -1)
345 use_privsep = PRIVSEP_ON;
347 #define CLEAR_ON_NONE(v) \
349 if (option_clear_or_none(v)) { \
354 CLEAR_ON_NONE(options->pid_file);
355 CLEAR_ON_NONE(options->xauth_location);
356 CLEAR_ON_NONE(options->banner);
357 CLEAR_ON_NONE(options->trusted_user_ca_keys);
358 CLEAR_ON_NONE(options->revoked_keys_file);
359 CLEAR_ON_NONE(options->authorized_principals_file);
360 CLEAR_ON_NONE(options->adm_forced_command);
361 CLEAR_ON_NONE(options->chroot_directory);
362 for (i = 0; i < options->num_host_key_files; i++)
363 CLEAR_ON_NONE(options->host_key_files[i]);
364 for (i = 0; i < options->num_host_cert_files; i++)
365 CLEAR_ON_NONE(options->host_cert_files[i]);
368 /* Similar handling for AuthenticationMethods=any */
369 if (options->num_auth_methods == 1 &&
370 strcmp(options->auth_methods[0], "any") == 0) {
371 free(options->auth_methods[0]);
372 options->auth_methods[0] = NULL;
373 options->num_auth_methods = 0;
377 if (use_privsep && options->compression == 1) {
378 error("This platform does not support both privilege "
379 "separation and compression");
380 error("Compression disabled");
381 options->compression = 0;
387 /* Keyword tokens. */
389 sBadOption, /* == unknown option */
390 /* Portable-specific options */
392 /* Standard Options */
393 sPort, sHostKeyFile, sLoginGraceTime,
394 sPermitRootLogin, sLogFacility, sLogLevel,
395 sRhostsRSAAuthentication, sRSAAuthentication,
396 sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
397 sKerberosGetAFSToken,
398 sKerberosTgtPassing, sChallengeResponseAuthentication,
399 sPasswordAuthentication, sKbdInteractiveAuthentication,
400 sListenAddress, sAddressFamily,
401 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
402 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
403 sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
404 sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
405 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
406 sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
407 sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
408 sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
409 sBanner, sUseDNS, sHostbasedAuthentication,
410 sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
412 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
413 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
414 sAcceptEnv, sPermitTunnel,
415 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
416 sUsePrivilegeSeparation, sAllowAgentForwarding,
418 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
419 sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
420 sKexAlgorithms, sIPQoS, sVersionAddendum,
421 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
422 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
423 sStreamLocalBindMask, sStreamLocalBindUnlink,
424 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
425 sDeprecated, sIgnore, sUnsupported
428 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
429 #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
430 #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
432 /* Textual representation of the tokens. */
435 ServerOpCodes opcode;
438 /* Portable-specific options */
440 { "usepam", sUsePAM, SSHCFG_GLOBAL },
442 { "usepam", sUnsupported, SSHCFG_GLOBAL },
444 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
445 /* Standard Options */
446 { "port", sPort, SSHCFG_GLOBAL },
447 { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
448 { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
449 { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
450 { "pidfile", sPidFile, SSHCFG_GLOBAL },
451 { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
452 { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
453 { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
454 { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
455 { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
456 { "loglevel", sLogLevel, SSHCFG_GLOBAL },
457 { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
458 { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
459 { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
460 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
461 { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
462 { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
463 { "rsaauthentication", sDeprecated, SSHCFG_ALL },
464 { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
465 { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
466 { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
468 { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
469 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
470 { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
472 { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
474 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
477 { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
478 { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
479 { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
480 { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
482 { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
483 { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
485 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
486 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
487 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
489 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
490 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
491 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
493 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
494 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
495 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
496 { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
497 { "checkmail", sDeprecated, SSHCFG_GLOBAL },
498 { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
499 { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
500 { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
501 #ifdef DISABLE_LASTLOG
502 { "printlastlog", sUnsupported, SSHCFG_GLOBAL },
504 { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
506 { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
507 { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
508 { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
509 { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
510 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
511 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
512 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
513 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
514 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
515 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
516 { "compression", sCompression, SSHCFG_GLOBAL },
517 { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
518 { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
519 { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
520 { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
521 { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
522 { "allowusers", sAllowUsers, SSHCFG_ALL },
523 { "denyusers", sDenyUsers, SSHCFG_ALL },
524 { "allowgroups", sAllowGroups, SSHCFG_ALL },
525 { "denygroups", sDenyGroups, SSHCFG_ALL },
526 { "ciphers", sCiphers, SSHCFG_GLOBAL },
527 { "macs", sMacs, SSHCFG_GLOBAL },
528 { "protocol", sIgnore, SSHCFG_GLOBAL },
529 { "gatewayports", sGatewayPorts, SSHCFG_ALL },
530 { "subsystem", sSubsystem, SSHCFG_GLOBAL },
531 { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
532 { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
533 { "maxsessions", sMaxSessions, SSHCFG_ALL },
534 { "banner", sBanner, SSHCFG_ALL },
535 { "usedns", sUseDNS, SSHCFG_GLOBAL },
536 { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
537 { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
538 { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
539 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
540 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
541 { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
542 { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
543 { "acceptenv", sAcceptEnv, SSHCFG_ALL },
544 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
545 { "permittty", sPermitTTY, SSHCFG_ALL },
546 { "permituserrc", sPermitUserRC, SSHCFG_ALL },
547 { "match", sMatch, SSHCFG_ALL },
548 { "permitopen", sPermitOpen, SSHCFG_ALL },
549 { "forcecommand", sForceCommand, SSHCFG_ALL },
550 { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
551 { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
552 { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
553 { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
554 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
555 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
556 { "ipqos", sIPQoS, SSHCFG_ALL },
557 { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
558 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
559 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
560 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
561 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
562 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
563 { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
564 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
565 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
566 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
567 { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
568 { NULL, sBadOption, 0 }
575 { SSH_TUNMODE_NO, "no" },
576 { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
577 { SSH_TUNMODE_ETHERNET, "ethernet" },
578 { SSH_TUNMODE_YES, "yes" },
583 * Returns the number of the token pointed to by cp or sBadOption.
587 parse_token(const char *cp, const char *filename,
588 int linenum, u_int *flags)
592 for (i = 0; keywords[i].name; i++)
593 if (strcasecmp(cp, keywords[i].name) == 0) {
594 *flags = keywords[i].flags;
595 return keywords[i].opcode;
598 error("%s: line %d: Bad configuration option: %s",
599 filename, linenum, cp);
604 derelativise_path(const char *path)
606 char *expanded, *ret, cwd[PATH_MAX];
608 if (strcasecmp(path, "none") == 0)
609 return xstrdup("none");
610 expanded = tilde_expand_filename(path, getuid());
611 if (*expanded == '/')
613 if (getcwd(cwd, sizeof(cwd)) == NULL)
614 fatal("%s: getcwd: %s", __func__, strerror(errno));
615 xasprintf(&ret, "%s/%s", cwd, expanded);
621 add_listen_addr(ServerOptions *options, char *addr, int port)
626 for (i = 0; i < options->num_ports; i++)
627 add_one_listen_addr(options, addr, options->ports[i]);
629 add_one_listen_addr(options, addr, port);
633 add_one_listen_addr(ServerOptions *options, char *addr, int port)
635 struct addrinfo hints, *ai, *aitop;
636 char strport[NI_MAXSERV];
639 memset(&hints, 0, sizeof(hints));
640 hints.ai_family = options->address_family;
641 hints.ai_socktype = SOCK_STREAM;
642 hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
643 snprintf(strport, sizeof strport, "%d", port);
644 if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
645 fatal("bad addr or host: %s (%s)",
646 addr ? addr : "<NULL>",
647 ssh_gai_strerror(gaierr));
648 for (ai = aitop; ai->ai_next; ai = ai->ai_next)
650 ai->ai_next = options->listen_addrs;
651 options->listen_addrs = aitop;
655 * Queue a ListenAddress to be processed once we have all of the Ports
656 * and AddressFamily options.
659 queue_listen_addr(ServerOptions *options, char *addr, int port)
661 options->queued_listen_addrs = xreallocarray(
662 options->queued_listen_addrs, options->num_queued_listens + 1,
664 options->queued_listen_ports = xreallocarray(
665 options->queued_listen_ports, options->num_queued_listens + 1,
667 options->queued_listen_addrs[options->num_queued_listens] =
669 options->queued_listen_ports[options->num_queued_listens] = port;
670 options->num_queued_listens++;
674 * Process queued (text) ListenAddress entries.
677 process_queued_listen_addrs(ServerOptions *options)
681 if (options->num_ports == 0)
682 options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
683 if (options->address_family == -1)
684 options->address_family = AF_UNSPEC;
686 for (i = 0; i < options->num_queued_listens; i++) {
687 add_listen_addr(options, options->queued_listen_addrs[i],
688 options->queued_listen_ports[i]);
689 free(options->queued_listen_addrs[i]);
690 options->queued_listen_addrs[i] = NULL;
692 free(options->queued_listen_addrs);
693 options->queued_listen_addrs = NULL;
694 free(options->queued_listen_ports);
695 options->queued_listen_ports = NULL;
696 options->num_queued_listens = 0;
699 struct connection_info *
700 get_connection_info(int populate, int use_dns)
702 struct ssh *ssh = active_state; /* XXX */
703 static struct connection_info ci;
707 ci.host = auth_get_canonical_hostname(ssh, use_dns);
708 ci.address = ssh_remote_ipaddr(ssh);
709 ci.laddress = ssh_local_ipaddr(ssh);
710 ci.lport = ssh_local_port(ssh);
715 * The strategy for the Match blocks is that the config file is parsed twice.
717 * The first time is at startup. activep is initialized to 1 and the
718 * directives in the global context are processed and acted on. Hitting a
719 * Match directive unsets activep and the directives inside the block are
720 * checked for syntax only.
722 * The second time is after a connection has been established but before
723 * authentication. activep is initialized to 2 and global config directives
724 * are ignored since they have already been processed. If the criteria in a
725 * Match block is met, activep is set and the subsequent directives
726 * processed and actioned until EOF or another Match block unsets it. Any
727 * options set are copied into the main server config.
729 * Potential additions/improvements:
730 * - Add Match support for pre-kex directives, eg. Ciphers.
732 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
733 * Match Address 192.168.0.*
738 * AllowTcpForwarding yes
739 * GatewayPorts clientspecified
742 * - Add a PermittedChannelRequests directive
744 * PermittedChannelRequests session,forwarded-tcpip
748 match_cfg_line_group(const char *grps, int line, const char *user)
756 if ((pw = getpwnam(user)) == NULL) {
757 debug("Can't match group at line %d because user %.100s does "
758 "not exist", line, user);
759 } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
760 debug("Can't Match group because user %.100s not in any group "
761 "at line %d", user, line);
762 } else if (ga_match_pattern_list(grps) != 1) {
763 debug("user %.100s does not match group list %.100s at line %d",
766 debug("user %.100s matched group list %.100s at line %d", user,
776 * All of the attributes on a single Match line are ANDed together, so we need
777 * to check every attribute and set the result to zero if any attribute does
781 match_cfg_line(char **condition, int line, struct connection_info *ci)
783 int result = 1, attributes = 0, port;
784 char *arg, *attrib, *cp = *condition;
787 debug3("checking syntax for 'Match %s'", cp);
789 debug3("checking match for '%s' user %s host %s addr %s "
790 "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
791 ci->host ? ci->host : "(null)",
792 ci->address ? ci->address : "(null)",
793 ci->laddress ? ci->laddress : "(null)", ci->lport);
795 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
797 if (strcasecmp(attrib, "all") == 0) {
798 if (attributes != 1 ||
799 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
800 error("'all' cannot be combined with other "
807 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
808 error("Missing Match criteria for %s", attrib);
811 if (strcasecmp(attrib, "user") == 0) {
812 if (ci == NULL || ci->user == NULL) {
816 if (match_pattern_list(ci->user, arg, 0) != 1)
819 debug("user %.100s matched 'User %.100s' at "
820 "line %d", ci->user, arg, line);
821 } else if (strcasecmp(attrib, "group") == 0) {
822 if (ci == NULL || ci->user == NULL) {
826 switch (match_cfg_line_group(arg, line, ci->user)) {
832 } else if (strcasecmp(attrib, "host") == 0) {
833 if (ci == NULL || ci->host == NULL) {
837 if (match_hostname(ci->host, arg) != 1)
840 debug("connection from %.100s matched 'Host "
841 "%.100s' at line %d", ci->host, arg, line);
842 } else if (strcasecmp(attrib, "address") == 0) {
843 if (ci == NULL || ci->address == NULL) {
847 switch (addr_match_list(ci->address, arg)) {
849 debug("connection from %.100s matched 'Address "
850 "%.100s' at line %d", ci->address, arg, line);
859 } else if (strcasecmp(attrib, "localaddress") == 0){
860 if (ci == NULL || ci->laddress == NULL) {
864 switch (addr_match_list(ci->laddress, arg)) {
866 debug("connection from %.100s matched "
867 "'LocalAddress %.100s' at line %d",
868 ci->laddress, arg, line);
877 } else if (strcasecmp(attrib, "localport") == 0) {
878 if ((port = a2port(arg)) == -1) {
879 error("Invalid LocalPort '%s' on Match line",
883 if (ci == NULL || ci->lport == 0) {
887 /* TODO support port lists */
888 if (port == ci->lport)
889 debug("connection from %.100s matched "
890 "'LocalPort %d' at line %d",
891 ci->laddress, port, line);
895 error("Unsupported Match attribute %s", attrib);
899 if (attributes == 0) {
900 error("One or more attributes required for Match");
904 debug3("match %sfound", result ? "" : "not ");
909 #define WHITESPACE " \t\r\n"
911 /* Multistate option parsing */
916 static const struct multistate multistate_addressfamily[] = {
918 { "inet6", AF_INET6 },
919 { "any", AF_UNSPEC },
922 static const struct multistate multistate_permitrootlogin[] = {
923 { "without-password", PERMIT_NO_PASSWD },
924 { "prohibit-password", PERMIT_NO_PASSWD },
925 { "forced-commands-only", PERMIT_FORCED_ONLY },
926 { "yes", PERMIT_YES },
930 static const struct multistate multistate_compression[] = {
931 { "yes", COMP_DELAYED },
932 { "delayed", COMP_DELAYED },
936 static const struct multistate multistate_gatewayports[] = {
937 { "clientspecified", 2 },
942 static const struct multistate multistate_privsep[] = {
943 { "yes", PRIVSEP_NOSANDBOX },
944 { "sandbox", PRIVSEP_ON },
945 { "nosandbox", PRIVSEP_NOSANDBOX },
946 { "no", PRIVSEP_OFF },
949 static const struct multistate multistate_tcpfwd[] = {
950 { "yes", FORWARD_ALLOW },
951 { "all", FORWARD_ALLOW },
952 { "no", FORWARD_DENY },
953 { "remote", FORWARD_REMOTE },
954 { "local", FORWARD_LOCAL },
959 process_server_config_line(ServerOptions *options, char *line,
960 const char *filename, int linenum, int *activep,
961 struct connection_info *connectinfo)
963 char *cp, **charptr, *arg, *p;
964 int cmdline = 0, *intptr, value, value2, n, port;
965 SyslogFacility *log_facility_ptr;
966 LogLevel *log_level_ptr;
967 ServerOpCodes opcode;
971 const struct multistate *multistate_ptr;
973 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
974 if ((len = strlen(line)) == 0)
976 for (len--; len > 0; len--) {
977 if (strchr(WHITESPACE "\f", line[len]) == NULL)
983 if ((arg = strdelim(&cp)) == NULL)
985 /* Ignore leading whitespace */
988 if (!arg || !*arg || *arg == '#')
992 opcode = parse_token(arg, filename, linenum, &flags);
994 if (activep == NULL) { /* We are processing a command line directive */
998 if (*activep && opcode != sMatch)
999 debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1000 if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1001 if (connectinfo == NULL) {
1002 fatal("%s line %d: Directive '%s' is not allowed "
1003 "within a Match block", filename, linenum, arg);
1004 } else { /* this is a directive we have already processed */
1006 arg = strdelim(&cp);
1012 /* Portable-specific options */
1014 intptr = &options->use_pam;
1017 /* Standard Options */
1021 /* ignore ports from configfile if cmdline specifies ports */
1022 if (options->ports_from_cmdline)
1024 if (options->num_ports >= MAX_PORTS)
1025 fatal("%s line %d: too many ports.",
1027 arg = strdelim(&cp);
1028 if (!arg || *arg == '\0')
1029 fatal("%s line %d: missing port number.",
1031 options->ports[options->num_ports++] = a2port(arg);
1032 if (options->ports[options->num_ports-1] <= 0)
1033 fatal("%s line %d: Badly formatted port number.",
1037 case sLoginGraceTime:
1038 intptr = &options->login_grace_time;
1040 arg = strdelim(&cp);
1041 if (!arg || *arg == '\0')
1042 fatal("%s line %d: missing time value.",
1044 if ((value = convtime(arg)) == -1)
1045 fatal("%s line %d: invalid time value.",
1047 if (*activep && *intptr == -1)
1051 case sListenAddress:
1052 arg = strdelim(&cp);
1053 if (arg == NULL || *arg == '\0')
1054 fatal("%s line %d: missing address",
1056 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1057 if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1058 && strchr(p+1, ':') != NULL) {
1059 queue_listen_addr(options, arg, 0);
1064 fatal("%s line %d: bad address:port usage",
1066 p = cleanhostname(p);
1069 else if ((port = a2port(arg)) <= 0)
1070 fatal("%s line %d: bad port number", filename, linenum);
1072 queue_listen_addr(options, p, port);
1076 case sAddressFamily:
1077 intptr = &options->address_family;
1078 multistate_ptr = multistate_addressfamily;
1080 arg = strdelim(&cp);
1081 if (!arg || *arg == '\0')
1082 fatal("%s line %d: missing argument.",
1085 for (i = 0; multistate_ptr[i].key != NULL; i++) {
1086 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1087 value = multistate_ptr[i].value;
1092 fatal("%s line %d: unsupported option \"%s\".",
1093 filename, linenum, arg);
1094 if (*activep && *intptr == -1)
1099 intptr = &options->num_host_key_files;
1100 if (*intptr >= MAX_HOSTKEYS)
1101 fatal("%s line %d: too many host keys specified (max %d).",
1102 filename, linenum, MAX_HOSTKEYS);
1103 charptr = &options->host_key_files[*intptr];
1105 arg = strdelim(&cp);
1106 if (!arg || *arg == '\0')
1107 fatal("%s line %d: missing file name.",
1109 if (*activep && *charptr == NULL) {
1110 *charptr = derelativise_path(arg);
1111 /* increase optional counter */
1113 *intptr = *intptr + 1;
1118 charptr = &options->host_key_agent;
1119 arg = strdelim(&cp);
1120 if (!arg || *arg == '\0')
1121 fatal("%s line %d: missing socket name.",
1123 if (*activep && *charptr == NULL)
1124 *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1125 xstrdup(arg) : derelativise_path(arg);
1128 case sHostCertificate:
1129 intptr = &options->num_host_cert_files;
1130 if (*intptr >= MAX_HOSTKEYS)
1131 fatal("%s line %d: too many host certificates "
1132 "specified (max %d).", filename, linenum,
1134 charptr = &options->host_cert_files[*intptr];
1135 goto parse_filename;
1138 charptr = &options->pid_file;
1139 goto parse_filename;
1141 case sPermitRootLogin:
1142 intptr = &options->permit_root_login;
1143 multistate_ptr = multistate_permitrootlogin;
1144 goto parse_multistate;
1147 intptr = &options->ignore_rhosts;
1149 arg = strdelim(&cp);
1150 if (!arg || *arg == '\0')
1151 fatal("%s line %d: missing yes/no argument.",
1153 value = 0; /* silence compiler */
1154 if (strcmp(arg, "yes") == 0)
1156 else if (strcmp(arg, "no") == 0)
1159 fatal("%s line %d: Bad yes/no argument: %s",
1160 filename, linenum, arg);
1161 if (*activep && *intptr == -1)
1165 case sIgnoreUserKnownHosts:
1166 intptr = &options->ignore_user_known_hosts;
1169 case sHostbasedAuthentication:
1170 intptr = &options->hostbased_authentication;
1173 case sHostbasedUsesNameFromPacketOnly:
1174 intptr = &options->hostbased_uses_name_from_packet_only;
1177 case sHostbasedAcceptedKeyTypes:
1178 charptr = &options->hostbased_key_types;
1180 arg = strdelim(&cp);
1181 if (!arg || *arg == '\0')
1182 fatal("%s line %d: Missing argument.",
1185 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1186 fatal("%s line %d: Bad key types '%s'.",
1187 filename, linenum, arg ? arg : "<NONE>");
1188 if (*activep && *charptr == NULL)
1189 *charptr = xstrdup(arg);
1192 case sHostKeyAlgorithms:
1193 charptr = &options->hostkeyalgorithms;
1194 goto parse_keytypes;
1196 case sPubkeyAuthentication:
1197 intptr = &options->pubkey_authentication;
1200 case sPubkeyAcceptedKeyTypes:
1201 charptr = &options->pubkey_key_types;
1202 goto parse_keytypes;
1204 case sKerberosAuthentication:
1205 intptr = &options->kerberos_authentication;
1208 case sKerberosOrLocalPasswd:
1209 intptr = &options->kerberos_or_local_passwd;
1212 case sKerberosTicketCleanup:
1213 intptr = &options->kerberos_ticket_cleanup;
1216 case sKerberosGetAFSToken:
1217 intptr = &options->kerberos_get_afs_token;
1220 case sGssAuthentication:
1221 intptr = &options->gss_authentication;
1224 case sGssCleanupCreds:
1225 intptr = &options->gss_cleanup_creds;
1228 case sGssStrictAcceptor:
1229 intptr = &options->gss_strict_acceptor;
1232 case sPasswordAuthentication:
1233 intptr = &options->password_authentication;
1236 case sKbdInteractiveAuthentication:
1237 intptr = &options->kbd_interactive_authentication;
1240 case sChallengeResponseAuthentication:
1241 intptr = &options->challenge_response_authentication;
1245 intptr = &options->print_motd;
1249 intptr = &options->print_lastlog;
1252 case sX11Forwarding:
1253 intptr = &options->x11_forwarding;
1256 case sX11DisplayOffset:
1257 intptr = &options->x11_display_offset;
1259 arg = strdelim(&cp);
1260 if (!arg || *arg == '\0')
1261 fatal("%s line %d: missing integer value.",
1264 if (*activep && *intptr == -1)
1268 case sX11UseLocalhost:
1269 intptr = &options->x11_use_localhost;
1272 case sXAuthLocation:
1273 charptr = &options->xauth_location;
1274 goto parse_filename;
1277 intptr = &options->permit_tty;
1281 intptr = &options->permit_user_rc;
1285 intptr = &options->strict_modes;
1289 intptr = &options->tcp_keep_alive;
1293 intptr = &options->permit_empty_passwd;
1296 case sPermitUserEnvironment:
1297 intptr = &options->permit_user_env;
1301 intptr = &options->compression;
1302 multistate_ptr = multistate_compression;
1303 goto parse_multistate;
1306 arg = strdelim(&cp);
1307 if (!arg || *arg == '\0')
1308 fatal("%.200s line %d: Missing argument.", filename,
1310 if (strcmp(arg, "default") == 0) {
1313 if (scan_scaled(arg, &val64) == -1)
1314 fatal("%.200s line %d: Bad number '%s': %s",
1315 filename, linenum, arg, strerror(errno));
1316 if (val64 != 0 && val64 < 16)
1317 fatal("%.200s line %d: RekeyLimit too small",
1320 if (*activep && options->rekey_limit == -1)
1321 options->rekey_limit = val64;
1322 if (cp != NULL) { /* optional rekey interval present */
1323 if (strcmp(cp, "none") == 0) {
1324 (void)strdelim(&cp); /* discard */
1327 intptr = &options->rekey_interval;
1333 intptr = &options->fwd_opts.gateway_ports;
1334 multistate_ptr = multistate_gatewayports;
1335 goto parse_multistate;
1338 intptr = &options->use_dns;
1342 log_facility_ptr = &options->log_facility;
1343 arg = strdelim(&cp);
1344 value = log_facility_number(arg);
1345 if (value == SYSLOG_FACILITY_NOT_SET)
1346 fatal("%.200s line %d: unsupported log facility '%s'",
1347 filename, linenum, arg ? arg : "<NONE>");
1348 if (*log_facility_ptr == -1)
1349 *log_facility_ptr = (SyslogFacility) value;
1353 log_level_ptr = &options->log_level;
1354 arg = strdelim(&cp);
1355 value = log_level_number(arg);
1356 if (value == SYSLOG_LEVEL_NOT_SET)
1357 fatal("%.200s line %d: unsupported log level '%s'",
1358 filename, linenum, arg ? arg : "<NONE>");
1359 if (*log_level_ptr == -1)
1360 *log_level_ptr = (LogLevel) value;
1363 case sAllowTcpForwarding:
1364 intptr = &options->allow_tcp_forwarding;
1365 multistate_ptr = multistate_tcpfwd;
1366 goto parse_multistate;
1368 case sAllowStreamLocalForwarding:
1369 intptr = &options->allow_streamlocal_forwarding;
1370 multistate_ptr = multistate_tcpfwd;
1371 goto parse_multistate;
1373 case sAllowAgentForwarding:
1374 intptr = &options->allow_agent_forwarding;
1377 case sDisableForwarding:
1378 intptr = &options->disable_forwarding;
1382 while ((arg = strdelim(&cp)) && *arg != '\0') {
1383 if (options->num_allow_users >= MAX_ALLOW_USERS)
1384 fatal("%s line %d: too many allow users.",
1386 if (match_user(NULL, NULL, NULL, arg) == -1)
1387 fatal("%s line %d: invalid AllowUsers pattern: "
1388 "\"%.100s\"", filename, linenum, arg);
1391 options->allow_users[options->num_allow_users++] =
1397 while ((arg = strdelim(&cp)) && *arg != '\0') {
1398 if (options->num_deny_users >= MAX_DENY_USERS)
1399 fatal("%s line %d: too many deny users.",
1401 if (match_user(NULL, NULL, NULL, arg) == -1)
1402 fatal("%s line %d: invalid DenyUsers pattern: "
1403 "\"%.100s\"", filename, linenum, arg);
1406 options->deny_users[options->num_deny_users++] =
1412 while ((arg = strdelim(&cp)) && *arg != '\0') {
1413 if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1414 fatal("%s line %d: too many allow groups.",
1418 options->allow_groups[options->num_allow_groups++] =
1424 while ((arg = strdelim(&cp)) && *arg != '\0') {
1425 if (options->num_deny_groups >= MAX_DENY_GROUPS)
1426 fatal("%s line %d: too many deny groups.",
1430 options->deny_groups[options->num_deny_groups++] =
1436 arg = strdelim(&cp);
1437 if (!arg || *arg == '\0')
1438 fatal("%s line %d: Missing argument.", filename, linenum);
1439 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1440 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1441 filename, linenum, arg ? arg : "<NONE>");
1442 if (options->ciphers == NULL)
1443 options->ciphers = xstrdup(arg);
1447 arg = strdelim(&cp);
1448 if (!arg || *arg == '\0')
1449 fatal("%s line %d: Missing argument.", filename, linenum);
1450 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1451 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1452 filename, linenum, arg ? arg : "<NONE>");
1453 if (options->macs == NULL)
1454 options->macs = xstrdup(arg);
1457 case sKexAlgorithms:
1458 arg = strdelim(&cp);
1459 if (!arg || *arg == '\0')
1460 fatal("%s line %d: Missing argument.",
1463 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1464 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1465 filename, linenum, arg ? arg : "<NONE>");
1466 if (options->kex_algorithms == NULL)
1467 options->kex_algorithms = xstrdup(arg);
1471 if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1472 fatal("%s line %d: too many subsystems defined.",
1475 arg = strdelim(&cp);
1476 if (!arg || *arg == '\0')
1477 fatal("%s line %d: Missing subsystem name.",
1480 arg = strdelim(&cp);
1483 for (i = 0; i < options->num_subsystems; i++)
1484 if (strcmp(arg, options->subsystem_name[i]) == 0)
1485 fatal("%s line %d: Subsystem '%s' already defined.",
1486 filename, linenum, arg);
1487 options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1488 arg = strdelim(&cp);
1489 if (!arg || *arg == '\0')
1490 fatal("%s line %d: Missing subsystem command.",
1492 options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1494 /* Collect arguments (separate to executable) */
1496 len = strlen(p) + 1;
1497 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1498 len += 1 + strlen(arg);
1499 p = xreallocarray(p, 1, len);
1500 strlcat(p, " ", len);
1501 strlcat(p, arg, len);
1503 options->subsystem_args[options->num_subsystems] = p;
1504 options->num_subsystems++;
1508 arg = strdelim(&cp);
1509 if (!arg || *arg == '\0')
1510 fatal("%s line %d: Missing MaxStartups spec.",
1512 if ((n = sscanf(arg, "%d:%d:%d",
1513 &options->max_startups_begin,
1514 &options->max_startups_rate,
1515 &options->max_startups)) == 3) {
1516 if (options->max_startups_begin >
1517 options->max_startups ||
1518 options->max_startups_rate > 100 ||
1519 options->max_startups_rate < 1)
1520 fatal("%s line %d: Illegal MaxStartups spec.",
1523 fatal("%s line %d: Illegal MaxStartups spec.",
1526 options->max_startups = options->max_startups_begin;
1530 intptr = &options->max_authtries;
1534 intptr = &options->max_sessions;
1538 charptr = &options->banner;
1539 goto parse_filename;
1542 * These options can contain %X options expanded at
1543 * connect time, so that you can specify paths like:
1545 * AuthorizedKeysFile /etc/ssh_keys/%u
1547 case sAuthorizedKeysFile:
1548 if (*activep && options->num_authkeys_files == 0) {
1549 while ((arg = strdelim(&cp)) && *arg != '\0') {
1550 if (options->num_authkeys_files >=
1552 fatal("%s line %d: "
1553 "too many authorized keys files.",
1555 options->authorized_keys_files[
1556 options->num_authkeys_files++] =
1557 tilde_expand_filename(arg, getuid());
1562 case sAuthorizedPrincipalsFile:
1563 charptr = &options->authorized_principals_file;
1564 arg = strdelim(&cp);
1565 if (!arg || *arg == '\0')
1566 fatal("%s line %d: missing file name.",
1568 if (*activep && *charptr == NULL) {
1569 *charptr = tilde_expand_filename(arg, getuid());
1570 /* increase optional counter */
1572 *intptr = *intptr + 1;
1576 case sClientAliveInterval:
1577 intptr = &options->client_alive_interval;
1580 case sClientAliveCountMax:
1581 intptr = &options->client_alive_count_max;
1585 while ((arg = strdelim(&cp)) && *arg != '\0') {
1586 if (strchr(arg, '=') != NULL)
1587 fatal("%s line %d: Invalid environment name.",
1589 if (options->num_accept_env >= MAX_ACCEPT_ENV)
1590 fatal("%s line %d: too many allow env.",
1594 options->accept_env[options->num_accept_env++] =
1600 intptr = &options->permit_tun;
1601 arg = strdelim(&cp);
1602 if (!arg || *arg == '\0')
1603 fatal("%s line %d: Missing yes/point-to-point/"
1604 "ethernet/no argument.", filename, linenum);
1606 for (i = 0; tunmode_desc[i].val != -1; i++)
1607 if (strcmp(tunmode_desc[i].text, arg) == 0) {
1608 value = tunmode_desc[i].val;
1612 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1613 "no argument: %s", filename, linenum, arg);
1614 if (*activep && *intptr == -1)
1620 fatal("Match directive not supported as a command-line "
1622 value = match_cfg_line(&cp, linenum, connectinfo);
1624 fatal("%s line %d: Bad Match condition", filename,
1630 arg = strdelim(&cp);
1631 if (!arg || *arg == '\0')
1632 fatal("%s line %d: missing PermitOpen specification",
1634 n = options->num_permitted_opens; /* modified later */
1635 if (strcmp(arg, "any") == 0) {
1636 if (*activep && n == -1) {
1637 channel_clear_adm_permitted_opens();
1638 options->num_permitted_opens = 0;
1642 if (strcmp(arg, "none") == 0) {
1643 if (*activep && n == -1) {
1644 options->num_permitted_opens = 1;
1645 channel_disable_adm_local_opens();
1649 if (*activep && n == -1)
1650 channel_clear_adm_permitted_opens();
1651 for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1654 fatal("%s line %d: missing host in PermitOpen",
1656 p = cleanhostname(p);
1657 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1658 fatal("%s line %d: bad port number in "
1659 "PermitOpen", filename, linenum);
1660 if (*activep && n == -1)
1661 options->num_permitted_opens =
1662 channel_add_adm_permitted_opens(p, port);
1667 if (cp == NULL || *cp == '\0')
1668 fatal("%.200s line %d: Missing argument.", filename,
1670 len = strspn(cp, WHITESPACE);
1671 if (*activep && options->adm_forced_command == NULL)
1672 options->adm_forced_command = xstrdup(cp + len);
1675 case sChrootDirectory:
1676 charptr = &options->chroot_directory;
1678 arg = strdelim(&cp);
1679 if (!arg || *arg == '\0')
1680 fatal("%s line %d: missing file name.",
1682 if (*activep && *charptr == NULL)
1683 *charptr = xstrdup(arg);
1686 case sTrustedUserCAKeys:
1687 charptr = &options->trusted_user_ca_keys;
1688 goto parse_filename;
1691 charptr = &options->revoked_keys_file;
1692 goto parse_filename;
1695 arg = strdelim(&cp);
1696 if ((value = parse_ipqos(arg)) == -1)
1697 fatal("%s line %d: Bad IPQoS value: %s",
1698 filename, linenum, arg);
1699 arg = strdelim(&cp);
1702 else if ((value2 = parse_ipqos(arg)) == -1)
1703 fatal("%s line %d: Bad IPQoS value: %s",
1704 filename, linenum, arg);
1706 options->ip_qos_interactive = value;
1707 options->ip_qos_bulk = value2;
1711 case sVersionAddendum:
1712 if (cp == NULL || *cp == '\0')
1713 fatal("%.200s line %d: Missing argument.", filename,
1715 len = strspn(cp, WHITESPACE);
1716 if (*activep && options->version_addendum == NULL) {
1717 if (strcasecmp(cp + len, "none") == 0)
1718 options->version_addendum = xstrdup("");
1719 else if (strchr(cp + len, '\r') != NULL)
1720 fatal("%.200s line %d: Invalid argument",
1723 options->version_addendum = xstrdup(cp + len);
1727 case sAuthorizedKeysCommand:
1729 fatal("%.200s line %d: Missing argument.", filename,
1731 len = strspn(cp, WHITESPACE);
1732 if (*activep && options->authorized_keys_command == NULL) {
1733 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1734 fatal("%.200s line %d: AuthorizedKeysCommand "
1735 "must be an absolute path",
1737 options->authorized_keys_command = xstrdup(cp + len);
1741 case sAuthorizedKeysCommandUser:
1742 charptr = &options->authorized_keys_command_user;
1744 arg = strdelim(&cp);
1745 if (!arg || *arg == '\0')
1746 fatal("%s line %d: missing AuthorizedKeysCommandUser "
1747 "argument.", filename, linenum);
1748 if (*activep && *charptr == NULL)
1749 *charptr = xstrdup(arg);
1752 case sAuthorizedPrincipalsCommand:
1754 fatal("%.200s line %d: Missing argument.", filename,
1756 len = strspn(cp, WHITESPACE);
1758 options->authorized_principals_command == NULL) {
1759 if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1760 fatal("%.200s line %d: "
1761 "AuthorizedPrincipalsCommand must be "
1762 "an absolute path", filename, linenum);
1763 options->authorized_principals_command =
1768 case sAuthorizedPrincipalsCommandUser:
1769 charptr = &options->authorized_principals_command_user;
1771 arg = strdelim(&cp);
1772 if (!arg || *arg == '\0')
1773 fatal("%s line %d: missing "
1774 "AuthorizedPrincipalsCommandUser argument.",
1776 if (*activep && *charptr == NULL)
1777 *charptr = xstrdup(arg);
1780 case sAuthenticationMethods:
1781 if (options->num_auth_methods == 0) {
1782 value = 0; /* seen "any" pseudo-method */
1783 value2 = 0; /* sucessfully parsed any method */
1784 while ((arg = strdelim(&cp)) && *arg != '\0') {
1785 if (options->num_auth_methods >=
1787 fatal("%s line %d: "
1788 "too many authentication methods.",
1790 if (strcmp(arg, "any") == 0) {
1791 if (options->num_auth_methods > 0) {
1792 fatal("%s line %d: \"any\" "
1793 "must appear alone in "
1794 "AuthenticationMethods",
1799 fatal("%s line %d: \"any\" must appear "
1800 "alone in AuthenticationMethods",
1802 } else if (auth2_methods_valid(arg, 0) != 0) {
1803 fatal("%s line %d: invalid "
1804 "authentication method list.",
1810 options->auth_methods[
1811 options->num_auth_methods++] = xstrdup(arg);
1814 fatal("%s line %d: no AuthenticationMethods "
1815 "specified", filename, linenum);
1820 case sStreamLocalBindMask:
1821 arg = strdelim(&cp);
1822 if (!arg || *arg == '\0')
1823 fatal("%s line %d: missing StreamLocalBindMask "
1824 "argument.", filename, linenum);
1825 /* Parse mode in octal format */
1826 value = strtol(arg, &p, 8);
1827 if (arg == p || value < 0 || value > 0777)
1828 fatal("%s line %d: Bad mask.", filename, linenum);
1830 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1833 case sStreamLocalBindUnlink:
1834 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1837 case sFingerprintHash:
1838 arg = strdelim(&cp);
1839 if (!arg || *arg == '\0')
1840 fatal("%.200s line %d: Missing argument.",
1842 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1843 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1844 filename, linenum, arg);
1846 options->fingerprint_hash = value;
1852 do_log2(opcode == sIgnore ?
1853 SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
1854 "%s line %d: %s option %s", filename, linenum,
1855 opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1857 arg = strdelim(&cp);
1861 fatal("%s line %d: Missing handler for opcode %s (%d)",
1862 filename, linenum, arg, opcode);
1864 if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1865 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1866 filename, linenum, arg);
1870 /* Reads the server configuration file. */
1873 load_server_config(const char *filename, Buffer *conf)
1875 char line[4096], *cp;
1879 debug2("%s: filename %s", __func__, filename);
1880 if ((f = fopen(filename, "r")) == NULL) {
1885 while (fgets(line, sizeof(line), f)) {
1887 if (strlen(line) == sizeof(line) - 1)
1888 fatal("%s line %d too long", filename, lineno);
1890 * Trim out comments and strip whitespace
1891 * NB - preserve newlines, they are needed to reproduce
1892 * line numbers later for error messages
1894 if ((cp = strchr(line, '#')) != NULL)
1895 memcpy(cp, "\n", 2);
1896 cp = line + strspn(line, " \t\r");
1898 buffer_append(conf, cp, strlen(cp));
1900 buffer_append(conf, "\0", 1);
1902 debug2("%s: done config len = %d", __func__, buffer_len(conf));
1906 parse_server_match_config(ServerOptions *options,
1907 struct connection_info *connectinfo)
1910 #if defined(ANDROID)
1911 char value[PROPERTY_VALUE_MAX];
1914 initialize_server_options(&mo);
1915 parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1916 #if defined(ANDROID)
1917 /* Allow root login if ro.debuggable is set. */
1918 property_get("ro.debuggable", value, "");
1919 if (strcmp(value, "1") == 0) {
1920 mo.permit_root_login = PERMIT_YES;
1923 copy_set_server_options(options, &mo, 0);
1926 int parse_server_match_testspec(struct connection_info *ci, char *spec)
1930 while ((p = strsep(&spec, ",")) && *p != '\0') {
1931 if (strncmp(p, "addr=", 5) == 0) {
1932 ci->address = xstrdup(p + 5);
1933 } else if (strncmp(p, "host=", 5) == 0) {
1934 ci->host = xstrdup(p + 5);
1935 } else if (strncmp(p, "user=", 5) == 0) {
1936 ci->user = xstrdup(p + 5);
1937 } else if (strncmp(p, "laddr=", 6) == 0) {
1938 ci->laddress = xstrdup(p + 6);
1939 } else if (strncmp(p, "lport=", 6) == 0) {
1940 ci->lport = a2port(p + 6);
1941 if (ci->lport == -1) {
1942 fprintf(stderr, "Invalid port '%s' in test mode"
1943 " specification %s\n", p+6, p);
1947 fprintf(stderr, "Invalid test mode specification %s\n",
1956 * returns 1 for a complete spec, 0 for partial spec and -1 for an
1959 int server_match_spec_complete(struct connection_info *ci)
1961 if (ci->user && ci->host && ci->address)
1962 return 1; /* complete */
1963 if (!ci->user && !ci->host && !ci->address)
1964 return -1; /* empty */
1965 return 0; /* partial */
1969 * Copy any supported values that are set.
1971 * If the preauth flag is set, we do not bother copying the string or
1972 * array values that are not used pre-authentication, because any that we
1973 * do use must be explictly sent in mm_getpwnamallow().
1976 copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1978 #define M_CP_INTOPT(n) do {\
1983 M_CP_INTOPT(password_authentication);
1984 M_CP_INTOPT(gss_authentication);
1985 M_CP_INTOPT(pubkey_authentication);
1986 M_CP_INTOPT(kerberos_authentication);
1987 M_CP_INTOPT(hostbased_authentication);
1988 M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1989 M_CP_INTOPT(kbd_interactive_authentication);
1990 M_CP_INTOPT(permit_root_login);
1991 M_CP_INTOPT(permit_empty_passwd);
1993 M_CP_INTOPT(allow_tcp_forwarding);
1994 M_CP_INTOPT(allow_streamlocal_forwarding);
1995 M_CP_INTOPT(allow_agent_forwarding);
1996 M_CP_INTOPT(disable_forwarding);
1997 M_CP_INTOPT(permit_tun);
1998 M_CP_INTOPT(fwd_opts.gateway_ports);
1999 M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
2000 M_CP_INTOPT(x11_display_offset);
2001 M_CP_INTOPT(x11_forwarding);
2002 M_CP_INTOPT(x11_use_localhost);
2003 M_CP_INTOPT(permit_tty);
2004 M_CP_INTOPT(permit_user_rc);
2005 M_CP_INTOPT(max_sessions);
2006 M_CP_INTOPT(max_authtries);
2007 M_CP_INTOPT(client_alive_count_max);
2008 M_CP_INTOPT(client_alive_interval);
2009 M_CP_INTOPT(ip_qos_interactive);
2010 M_CP_INTOPT(ip_qos_bulk);
2011 M_CP_INTOPT(rekey_limit);
2012 M_CP_INTOPT(rekey_interval);
2015 * The bind_mask is a mode_t that may be unsigned, so we can't use
2016 * M_CP_INTOPT - it does a signed comparison that causes compiler
2019 if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
2020 dst->fwd_opts.streamlocal_bind_mask =
2021 src->fwd_opts.streamlocal_bind_mask;
2024 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2025 #define M_CP_STROPT(n) do {\
2026 if (src->n != NULL && dst->n != src->n) { \
2031 #define M_CP_STRARRAYOPT(n, num_n) do {\
2032 if (src->num_n != 0) { \
2033 for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
2034 dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
2038 /* See comment in servconf.h */
2039 COPY_MATCH_STRING_OPTS();
2041 /* Arguments that accept '+...' need to be expanded */
2042 assemble_algorithms(dst);
2045 * The only things that should be below this point are string options
2046 * which are only used after authentication.
2051 /* These options may be "none" to clear a global setting */
2052 M_CP_STROPT(adm_forced_command);
2053 if (option_clear_or_none(dst->adm_forced_command)) {
2054 free(dst->adm_forced_command);
2055 dst->adm_forced_command = NULL;
2057 M_CP_STROPT(chroot_directory);
2058 if (option_clear_or_none(dst->chroot_directory)) {
2059 free(dst->chroot_directory);
2060 dst->chroot_directory = NULL;
2066 #undef M_CP_STRARRAYOPT
2069 parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
2070 struct connection_info *connectinfo)
2072 int active, linenum, bad_options = 0;
2073 char *cp, *obuf, *cbuf;
2075 debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
2077 if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2078 fatal("%s: sshbuf_dup_string failed", __func__);
2079 active = connectinfo ? 0 : 1;
2081 while ((cp = strsep(&cbuf, "\n")) != NULL) {
2082 if (process_server_config_line(options, cp, filename,
2083 linenum++, &active, connectinfo) != 0)
2087 if (bad_options > 0)
2088 fatal("%s: terminating, %d bad configuration options",
2089 filename, bad_options);
2090 process_queued_listen_addrs(options);
2094 fmt_multistate_int(int val, const struct multistate *m)
2098 for (i = 0; m[i].key != NULL; i++) {
2099 if (m[i].value == val)
2106 fmt_intarg(ServerOpCodes code, int val)
2111 case sAddressFamily:
2112 return fmt_multistate_int(val, multistate_addressfamily);
2113 case sPermitRootLogin:
2114 return fmt_multistate_int(val, multistate_permitrootlogin);
2116 return fmt_multistate_int(val, multistate_gatewayports);
2118 return fmt_multistate_int(val, multistate_compression);
2119 case sAllowTcpForwarding:
2120 return fmt_multistate_int(val, multistate_tcpfwd);
2121 case sAllowStreamLocalForwarding:
2122 return fmt_multistate_int(val, multistate_tcpfwd);
2123 case sFingerprintHash:
2124 return ssh_digest_alg_name(val);
2138 lookup_opcode_name(ServerOpCodes code)
2142 for (i = 0; keywords[i].name != NULL; i++)
2143 if (keywords[i].opcode == code)
2144 return(keywords[i].name);
2149 dump_cfg_int(ServerOpCodes code, int val)
2151 printf("%s %d\n", lookup_opcode_name(code), val);
2155 dump_cfg_oct(ServerOpCodes code, int val)
2157 printf("%s 0%o\n", lookup_opcode_name(code), val);
2161 dump_cfg_fmtint(ServerOpCodes code, int val)
2163 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2167 dump_cfg_string(ServerOpCodes code, const char *val)
2169 printf("%s %s\n", lookup_opcode_name(code),
2170 val == NULL ? "none" : val);
2174 dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2178 for (i = 0; i < count; i++)
2179 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2183 dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2187 if (count <= 0 && code != sAuthenticationMethods)
2189 printf("%s", lookup_opcode_name(code));
2190 for (i = 0; i < count; i++)
2191 printf(" %s", vals[i]);
2192 if (code == sAuthenticationMethods && count == 0)
2198 dump_config(ServerOptions *o)
2202 struct addrinfo *ai;
2203 char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
2204 char *laddr1 = xstrdup(""), *laddr2 = NULL;
2206 /* these are usually at the top of the config */
2207 for (i = 0; i < o->num_ports; i++)
2208 printf("port %d\n", o->ports[i]);
2209 dump_cfg_fmtint(sAddressFamily, o->address_family);
2212 * ListenAddress must be after Port. add_one_listen_addr pushes
2213 * addresses onto a stack, so to maintain ordering we need to
2214 * print these in reverse order.
2216 for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
2217 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
2218 sizeof(addr), port, sizeof(port),
2219 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
2220 error("getnameinfo failed: %.100s",
2221 (ret != EAI_SYSTEM) ? gai_strerror(ret) :
2225 if (ai->ai_family == AF_INET6)
2226 xasprintf(&laddr1, "listenaddress [%s]:%s\n%s",
2227 addr, port, laddr2);
2229 xasprintf(&laddr1, "listenaddress %s:%s\n%s",
2230 addr, port, laddr2);
2234 printf("%s", laddr1);
2237 /* integer arguments */
2239 dump_cfg_fmtint(sUsePAM, o->use_pam);
2241 dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2242 dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2243 dump_cfg_int(sMaxAuthTries, o->max_authtries);
2244 dump_cfg_int(sMaxSessions, o->max_sessions);
2245 dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2246 dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
2247 dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
2249 /* formatted integer arguments */
2250 dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2251 dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2252 dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2253 dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2254 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2255 o->hostbased_uses_name_from_packet_only);
2256 dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
2258 dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2259 dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2260 dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
2262 dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
2266 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2267 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
2269 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2270 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2271 o->kbd_interactive_authentication);
2272 dump_cfg_fmtint(sChallengeResponseAuthentication,
2273 o->challenge_response_authentication);
2274 dump_cfg_fmtint(sPrintMotd, o->print_motd);
2275 #ifndef DISABLE_LASTLOG
2276 dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2278 dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2279 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
2280 dump_cfg_fmtint(sPermitTTY, o->permit_tty);
2281 dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
2282 dump_cfg_fmtint(sStrictModes, o->strict_modes);
2283 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2284 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2285 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2286 dump_cfg_fmtint(sCompression, o->compression);
2287 dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
2288 dump_cfg_fmtint(sUseDNS, o->use_dns);
2289 dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2290 dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
2291 dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
2292 dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
2293 dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2294 dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
2296 /* string arguments */
2297 dump_cfg_string(sPidFile, o->pid_file);
2298 dump_cfg_string(sXAuthLocation, o->xauth_location);
2299 dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2300 dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
2301 dump_cfg_string(sBanner, o->banner);
2302 dump_cfg_string(sForceCommand, o->adm_forced_command);
2303 dump_cfg_string(sChrootDirectory, o->chroot_directory);
2304 dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2305 dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
2306 dump_cfg_string(sAuthorizedPrincipalsFile,
2307 o->authorized_principals_file);
2308 dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2309 ? "none" : o->version_addendum);
2310 dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2311 dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
2312 dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2313 dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
2314 dump_cfg_string(sHostKeyAgent, o->host_key_agent);
2315 dump_cfg_string(sKexAlgorithms,
2316 o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
2317 dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2318 o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
2319 dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2320 o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
2321 dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2322 o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
2324 /* string arguments requiring a lookup */
2325 dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2326 dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2328 /* string array arguments */
2329 dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2330 o->authorized_keys_files);
2331 dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2333 dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
2334 o->host_cert_files);
2335 dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2336 dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2337 dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2338 dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2339 dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
2340 dump_cfg_strarray_oneline(sAuthenticationMethods,
2341 o->num_auth_methods, o->auth_methods);
2343 /* other arguments */
2344 for (i = 0; i < o->num_subsystems; i++)
2345 printf("subsystem %s %s\n", o->subsystem_name[i],
2346 o->subsystem_args[i]);
2348 printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2349 o->max_startups_rate, o->max_startups);
2351 for (i = 0; tunmode_desc[i].val != -1; i++)
2352 if (tunmode_desc[i].val == o->permit_tun) {
2353 s = tunmode_desc[i].text;
2356 dump_cfg_string(sPermitTunnel, s);
2358 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2359 printf("%s\n", iptos2str(o->ip_qos_bulk));
2361 printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
2364 channel_print_adm_permitted_opens();