1 /* $OpenBSD: servconf.c,v 1.405 2024/03/04 02:16:11 djm Exp $ */
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 * As far as I am concerned, the code I have written for this software
7 * can be used freely for any purpose. Any derived versions of this
8 * software must be clearly marked as such, and if the derived work is
9 * incompatible with the protocol description in the RFC file, it must be
10 * called by a name other than "ssh" or "Secure Shell".
15 #include <sys/types.h>
16 #include <sys/socket.h>
19 #include <sys/sysctl.h>
22 #include <netinet/in.h>
23 #include <netinet/in_systm.h>
24 #include <netinet/ip.h>
25 #ifdef HAVE_NET_ROUTE_H
26 #include <net/route.h>
43 #ifdef USE_SYSTEM_GLOB
46 # include "openbsd-compat/glob.h"
49 #include "openbsd-compat/sys-queue.h"
56 #include "pathnames.h"
63 #include "groupaccess.h"
69 #include "myproposal.h"
73 static void add_listen_addr(ServerOptions
*, const char *,
75 static void add_one_listen_addr(ServerOptions
*, const char *,
77 static void parse_server_config_depth(ServerOptions
*options
,
78 const char *filename
, struct sshbuf
*conf
, struct include_list
*includes
,
79 struct connection_info
*connectinfo
, int flags
, int *activep
, int depth
);
81 /* Use of privilege separation or not */
82 extern int use_privsep
;
83 extern struct sshbuf
*cfg
;
85 /* Initializes the server options to their default values. */
88 initialize_server_options(ServerOptions
*options
)
90 memset(options
, 0, sizeof(*options
));
92 /* Portable-specific options */
93 options
->use_pam
= -1;
95 /* Standard Options */
96 options
->num_ports
= 0;
97 options
->ports_from_cmdline
= 0;
98 options
->queued_listen_addrs
= NULL
;
99 options
->num_queued_listens
= 0;
100 options
->listen_addrs
= NULL
;
101 options
->num_listen_addrs
= 0;
102 options
->address_family
= -1;
103 options
->routing_domain
= NULL
;
104 options
->num_host_key_files
= 0;
105 options
->num_host_cert_files
= 0;
106 options
->host_key_agent
= NULL
;
107 options
->pid_file
= NULL
;
108 options
->login_grace_time
= -1;
109 options
->permit_root_login
= PERMIT_NOT_SET
;
110 options
->ignore_rhosts
= -1;
111 options
->ignore_user_known_hosts
= -1;
112 options
->print_motd
= -1;
113 options
->print_lastlog
= -1;
114 options
->x11_forwarding
= -1;
115 options
->x11_display_offset
= -1;
116 options
->x11_use_localhost
= -1;
117 options
->permit_tty
= -1;
118 options
->permit_user_rc
= -1;
119 options
->xauth_location
= NULL
;
120 options
->strict_modes
= -1;
121 options
->tcp_keep_alive
= -1;
122 options
->log_facility
= SYSLOG_FACILITY_NOT_SET
;
123 options
->log_level
= SYSLOG_LEVEL_NOT_SET
;
124 options
->num_log_verbose
= 0;
125 options
->log_verbose
= NULL
;
126 options
->hostbased_authentication
= -1;
127 options
->hostbased_uses_name_from_packet_only
= -1;
128 options
->hostbased_accepted_algos
= NULL
;
129 options
->hostkeyalgorithms
= NULL
;
130 options
->pubkey_authentication
= -1;
131 options
->pubkey_auth_options
= -1;
132 options
->pubkey_accepted_algos
= NULL
;
133 options
->kerberos_authentication
= -1;
134 options
->kerberos_or_local_passwd
= -1;
135 options
->kerberos_ticket_cleanup
= -1;
136 options
->kerberos_get_afs_token
= -1;
137 options
->gss_authentication
=-1;
138 options
->gss_cleanup_creds
= -1;
139 options
->gss_strict_acceptor
= -1;
140 options
->password_authentication
= -1;
141 options
->kbd_interactive_authentication
= -1;
142 options
->permit_empty_passwd
= -1;
143 options
->permit_user_env
= -1;
144 options
->permit_user_env_allowlist
= NULL
;
145 options
->compression
= -1;
146 options
->rekey_limit
= -1;
147 options
->rekey_interval
= -1;
148 options
->allow_tcp_forwarding
= -1;
149 options
->allow_streamlocal_forwarding
= -1;
150 options
->allow_agent_forwarding
= -1;
151 options
->num_allow_users
= 0;
152 options
->num_deny_users
= 0;
153 options
->num_allow_groups
= 0;
154 options
->num_deny_groups
= 0;
155 options
->ciphers
= NULL
;
156 options
->macs
= NULL
;
157 options
->kex_algorithms
= NULL
;
158 options
->ca_sign_algorithms
= NULL
;
159 options
->fwd_opts
.gateway_ports
= -1;
160 options
->fwd_opts
.streamlocal_bind_mask
= (mode_t
)-1;
161 options
->fwd_opts
.streamlocal_bind_unlink
= -1;
162 options
->num_subsystems
= 0;
163 options
->max_startups_begin
= -1;
164 options
->max_startups_rate
= -1;
165 options
->max_startups
= -1;
166 options
->per_source_max_startups
= -1;
167 options
->per_source_masklen_ipv4
= -1;
168 options
->per_source_masklen_ipv6
= -1;
169 options
->max_authtries
= -1;
170 options
->max_sessions
= -1;
171 options
->banner
= NULL
;
172 options
->use_dns
= -1;
173 options
->client_alive_interval
= -1;
174 options
->client_alive_count_max
= -1;
175 options
->num_authkeys_files
= 0;
176 options
->num_accept_env
= 0;
177 options
->num_setenv
= 0;
178 options
->permit_tun
= -1;
179 options
->permitted_opens
= NULL
;
180 options
->permitted_listens
= NULL
;
181 options
->adm_forced_command
= NULL
;
182 options
->chroot_directory
= NULL
;
183 options
->authorized_keys_command
= NULL
;
184 options
->authorized_keys_command_user
= NULL
;
185 options
->revoked_keys_file
= NULL
;
186 options
->sk_provider
= NULL
;
187 options
->trusted_user_ca_keys
= NULL
;
188 options
->authorized_principals_file
= NULL
;
189 options
->authorized_principals_command
= NULL
;
190 options
->authorized_principals_command_user
= NULL
;
191 options
->ip_qos_interactive
= -1;
192 options
->ip_qos_bulk
= -1;
193 options
->version_addendum
= NULL
;
194 options
->fingerprint_hash
= -1;
195 options
->disable_forwarding
= -1;
196 options
->expose_userauth_info
= -1;
197 options
->required_rsa_size
= -1;
198 options
->channel_timeouts
= NULL
;
199 options
->num_channel_timeouts
= 0;
200 options
->unused_connection_timeout
= -1;
201 options
->use_blacklist
= -1;
204 /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
206 option_clear_or_none(const char *o
)
208 return o
== NULL
|| strcasecmp(o
, "none") == 0;
212 assemble_algorithms(ServerOptions
*o
)
214 char *all_cipher
, *all_mac
, *all_kex
, *all_key
, *all_sig
;
215 char *def_cipher
, *def_mac
, *def_kex
, *def_key
, *def_sig
;
218 all_cipher
= cipher_alg_list(',', 0);
219 all_mac
= mac_alg_list(',');
220 all_kex
= kex_alg_list(',');
221 all_key
= sshkey_alg_list(0, 0, 1, ',');
222 all_sig
= sshkey_alg_list(0, 1, 1, ',');
223 /* remove unsupported algos from default lists */
224 def_cipher
= match_filter_allowlist(KEX_SERVER_ENCRYPT
, all_cipher
);
225 def_mac
= match_filter_allowlist(KEX_SERVER_MAC
, all_mac
);
226 def_kex
= match_filter_allowlist(KEX_SERVER_KEX
, all_kex
);
227 def_key
= match_filter_allowlist(KEX_DEFAULT_PK_ALG
, all_key
);
228 def_sig
= match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS
, all_sig
);
229 #define ASSEMBLE(what, defaults, all) \
231 if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
232 fatal_fr(r, "%s", #what); \
234 ASSEMBLE(ciphers
, def_cipher
, all_cipher
);
235 ASSEMBLE(macs
, def_mac
, all_mac
);
236 ASSEMBLE(kex_algorithms
, def_kex
, all_kex
);
237 ASSEMBLE(hostkeyalgorithms
, def_key
, all_key
);
238 ASSEMBLE(hostbased_accepted_algos
, def_key
, all_key
);
239 ASSEMBLE(pubkey_accepted_algos
, def_key
, all_key
);
240 ASSEMBLE(ca_sign_algorithms
, def_sig
, all_sig
);
254 static const char *defaultkey
= "[default]";
257 servconf_add_hostkey(const char *file
, const int line
,
258 ServerOptions
*options
, const char *path
, int userprovided
)
260 char *apath
= derelativise_path(path
);
262 if (file
== defaultkey
&& access(path
, R_OK
) != 0)
264 opt_array_append2(file
, line
, "HostKey",
265 &options
->host_key_files
, &options
->host_key_file_userprovided
,
266 &options
->num_host_key_files
, apath
, userprovided
);
271 servconf_add_hostcert(const char *file
, const int line
,
272 ServerOptions
*options
, const char *path
)
274 char *apath
= derelativise_path(path
);
276 opt_array_append(file
, line
, "HostCertificate",
277 &options
->host_cert_files
, &options
->num_host_cert_files
, apath
);
282 fill_default_server_options(ServerOptions
*options
)
286 /* Portable-specific options */
287 if (options
->use_pam
== -1)
288 options
->use_pam
= 1;
290 /* Standard Options */
291 if (options
->num_host_key_files
== 0) {
292 /* fill default hostkeys for protocols */
293 servconf_add_hostkey(defaultkey
, 0, options
,
294 _PATH_HOST_RSA_KEY_FILE
, 0);
295 #ifdef OPENSSL_HAS_ECC
296 servconf_add_hostkey(defaultkey
, 0, options
,
297 _PATH_HOST_ECDSA_KEY_FILE
, 0);
299 servconf_add_hostkey(defaultkey
, 0, options
,
300 _PATH_HOST_ED25519_KEY_FILE
, 0);
302 servconf_add_hostkey(defaultkey
, 0, options
,
303 _PATH_HOST_XMSS_KEY_FILE
, 0);
304 #endif /* WITH_XMSS */
306 if (options
->num_host_key_files
== 0)
307 fatal("No host key files found");
308 /* No certificates by default */
309 if (options
->num_ports
== 0)
310 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
311 if (options
->address_family
== -1)
312 options
->address_family
= AF_UNSPEC
;
313 if (options
->listen_addrs
== NULL
)
314 add_listen_addr(options
, NULL
, NULL
, 0);
315 if (options
->pid_file
== NULL
)
316 options
->pid_file
= xstrdup(_PATH_SSH_DAEMON_PID_FILE
);
317 if (options
->moduli_file
== NULL
)
318 options
->moduli_file
= xstrdup(_PATH_DH_MODULI
);
319 if (options
->login_grace_time
== -1)
320 options
->login_grace_time
= 120;
321 if (options
->permit_root_login
== PERMIT_NOT_SET
)
322 options
->permit_root_login
= PERMIT_NO
;
323 if (options
->ignore_rhosts
== -1)
324 options
->ignore_rhosts
= 1;
325 if (options
->ignore_user_known_hosts
== -1)
326 options
->ignore_user_known_hosts
= 0;
327 if (options
->print_motd
== -1)
328 options
->print_motd
= 1;
329 if (options
->print_lastlog
== -1)
330 options
->print_lastlog
= 1;
331 if (options
->x11_forwarding
== -1)
332 options
->x11_forwarding
= 0;
333 if (options
->x11_display_offset
== -1)
334 options
->x11_display_offset
= 10;
335 if (options
->x11_use_localhost
== -1)
336 options
->x11_use_localhost
= 1;
337 if (options
->xauth_location
== NULL
)
338 options
->xauth_location
= xstrdup(_PATH_XAUTH
);
339 if (options
->permit_tty
== -1)
340 options
->permit_tty
= 1;
341 if (options
->permit_user_rc
== -1)
342 options
->permit_user_rc
= 1;
343 if (options
->strict_modes
== -1)
344 options
->strict_modes
= 1;
345 if (options
->tcp_keep_alive
== -1)
346 options
->tcp_keep_alive
= 1;
347 if (options
->log_facility
== SYSLOG_FACILITY_NOT_SET
)
348 options
->log_facility
= SYSLOG_FACILITY_AUTH
;
349 if (options
->log_level
== SYSLOG_LEVEL_NOT_SET
)
350 options
->log_level
= SYSLOG_LEVEL_INFO
;
351 if (options
->hostbased_authentication
== -1)
352 options
->hostbased_authentication
= 0;
353 if (options
->hostbased_uses_name_from_packet_only
== -1)
354 options
->hostbased_uses_name_from_packet_only
= 0;
355 if (options
->pubkey_authentication
== -1)
356 options
->pubkey_authentication
= 1;
357 if (options
->pubkey_auth_options
== -1)
358 options
->pubkey_auth_options
= 0;
359 if (options
->kerberos_authentication
== -1)
360 options
->kerberos_authentication
= 0;
361 if (options
->kerberos_or_local_passwd
== -1)
362 options
->kerberos_or_local_passwd
= 1;
363 if (options
->kerberos_ticket_cleanup
== -1)
364 options
->kerberos_ticket_cleanup
= 1;
365 if (options
->kerberos_get_afs_token
== -1)
366 options
->kerberos_get_afs_token
= 0;
367 if (options
->gss_authentication
== -1)
368 options
->gss_authentication
= 0;
369 if (options
->gss_cleanup_creds
== -1)
370 options
->gss_cleanup_creds
= 1;
371 if (options
->gss_strict_acceptor
== -1)
372 options
->gss_strict_acceptor
= 1;
373 if (options
->password_authentication
== -1)
374 options
->password_authentication
= 0;
375 if (options
->kbd_interactive_authentication
== -1)
376 options
->kbd_interactive_authentication
= 1;
377 if (options
->permit_empty_passwd
== -1)
378 options
->permit_empty_passwd
= 0;
379 if (options
->permit_user_env
== -1) {
380 options
->permit_user_env
= 0;
381 options
->permit_user_env_allowlist
= NULL
;
383 if (options
->compression
== -1)
385 options
->compression
= COMP_DELAYED
;
387 options
->compression
= COMP_NONE
;
390 if (options
->rekey_limit
== -1)
391 options
->rekey_limit
= 0;
392 if (options
->rekey_interval
== -1)
393 options
->rekey_interval
= 0;
394 if (options
->allow_tcp_forwarding
== -1)
395 options
->allow_tcp_forwarding
= FORWARD_ALLOW
;
396 if (options
->allow_streamlocal_forwarding
== -1)
397 options
->allow_streamlocal_forwarding
= FORWARD_ALLOW
;
398 if (options
->allow_agent_forwarding
== -1)
399 options
->allow_agent_forwarding
= 1;
400 if (options
->fwd_opts
.gateway_ports
== -1)
401 options
->fwd_opts
.gateway_ports
= 0;
402 if (options
->max_startups
== -1)
403 options
->max_startups
= 100;
404 if (options
->max_startups_rate
== -1)
405 options
->max_startups_rate
= 30; /* 30% */
406 if (options
->max_startups_begin
== -1)
407 options
->max_startups_begin
= 10;
408 if (options
->per_source_max_startups
== -1)
409 options
->per_source_max_startups
= INT_MAX
;
410 if (options
->per_source_masklen_ipv4
== -1)
411 options
->per_source_masklen_ipv4
= 32;
412 if (options
->per_source_masklen_ipv6
== -1)
413 options
->per_source_masklen_ipv6
= 128;
414 if (options
->max_authtries
== -1)
415 options
->max_authtries
= DEFAULT_AUTH_FAIL_MAX
;
416 if (options
->max_sessions
== -1)
417 options
->max_sessions
= DEFAULT_SESSIONS_MAX
;
418 if (options
->use_dns
== -1)
419 options
->use_dns
= 1;
420 if (options
->client_alive_interval
== -1)
421 options
->client_alive_interval
= 0;
422 if (options
->client_alive_count_max
== -1)
423 options
->client_alive_count_max
= 3;
424 if (options
->num_authkeys_files
== 0) {
425 opt_array_append(defaultkey
, 0, "AuthorizedKeysFiles",
426 &options
->authorized_keys_files
,
427 &options
->num_authkeys_files
,
428 _PATH_SSH_USER_PERMITTED_KEYS
);
429 opt_array_append(defaultkey
, 0, "AuthorizedKeysFiles",
430 &options
->authorized_keys_files
,
431 &options
->num_authkeys_files
,
432 _PATH_SSH_USER_PERMITTED_KEYS2
);
434 if (options
->permit_tun
== -1)
435 options
->permit_tun
= SSH_TUNMODE_NO
;
436 if (options
->ip_qos_interactive
== -1)
437 options
->ip_qos_interactive
= IPTOS_DSCP_AF21
;
438 if (options
->ip_qos_bulk
== -1)
439 options
->ip_qos_bulk
= IPTOS_DSCP_CS1
;
440 if (options
->version_addendum
== NULL
)
441 options
->version_addendum
= xstrdup(SSH_VERSION_FREEBSD
);
442 if (options
->fwd_opts
.streamlocal_bind_mask
== (mode_t
)-1)
443 options
->fwd_opts
.streamlocal_bind_mask
= 0177;
444 if (options
->fwd_opts
.streamlocal_bind_unlink
== -1)
445 options
->fwd_opts
.streamlocal_bind_unlink
= 0;
446 if (options
->fingerprint_hash
== -1)
447 options
->fingerprint_hash
= SSH_FP_HASH_DEFAULT
;
448 if (options
->disable_forwarding
== -1)
449 options
->disable_forwarding
= 0;
450 if (options
->expose_userauth_info
== -1)
451 options
->expose_userauth_info
= 0;
452 if (options
->sk_provider
== NULL
)
453 options
->sk_provider
= xstrdup("internal");
454 if (options
->required_rsa_size
== -1)
455 options
->required_rsa_size
= SSH_RSA_MINIMUM_MODULUS_SIZE
;
456 if (options
->unused_connection_timeout
== -1)
457 options
->unused_connection_timeout
= 0;
458 if (options
->use_blacklist
== -1)
459 options
->use_blacklist
= 0;
461 assemble_algorithms(options
);
463 /* Turn privilege separation and sandboxing on by default */
464 if (use_privsep
== -1)
465 use_privsep
= PRIVSEP_ON
;
467 #define CLEAR_ON_NONE(v) \
469 if (option_clear_or_none(v)) { \
474 #define CLEAR_ON_NONE_ARRAY(v, nv, none) \
476 if (options->nv == 1 && \
477 strcasecmp(options->v[0], none) == 0) { \
478 free(options->v[0]); \
484 CLEAR_ON_NONE(options
->pid_file
);
485 CLEAR_ON_NONE(options
->xauth_location
);
486 CLEAR_ON_NONE(options
->banner
);
487 CLEAR_ON_NONE(options
->trusted_user_ca_keys
);
488 CLEAR_ON_NONE(options
->revoked_keys_file
);
489 CLEAR_ON_NONE(options
->sk_provider
);
490 CLEAR_ON_NONE(options
->authorized_principals_file
);
491 CLEAR_ON_NONE(options
->adm_forced_command
);
492 CLEAR_ON_NONE(options
->chroot_directory
);
493 CLEAR_ON_NONE(options
->routing_domain
);
494 CLEAR_ON_NONE(options
->host_key_agent
);
496 for (i
= 0; i
< options
->num_host_key_files
; i
++)
497 CLEAR_ON_NONE(options
->host_key_files
[i
]);
498 for (i
= 0; i
< options
->num_host_cert_files
; i
++)
499 CLEAR_ON_NONE(options
->host_cert_files
[i
]);
501 CLEAR_ON_NONE_ARRAY(channel_timeouts
, num_channel_timeouts
, "none");
502 CLEAR_ON_NONE_ARRAY(auth_methods
, num_auth_methods
, "any");
504 #undef CLEAR_ON_NONE_ARRAY
507 /* Keyword tokens. */
509 sBadOption
, /* == unknown option */
510 /* Portable-specific options */
512 /* Standard Options */
513 sPort
, sHostKeyFile
, sLoginGraceTime
,
514 sPermitRootLogin
, sLogFacility
, sLogLevel
, sLogVerbose
,
515 sKerberosAuthentication
, sKerberosOrLocalPasswd
, sKerberosTicketCleanup
,
516 sKerberosGetAFSToken
, sPasswordAuthentication
,
517 sKbdInteractiveAuthentication
, sListenAddress
, sAddressFamily
,
518 sPrintMotd
, sPrintLastLog
, sIgnoreRhosts
,
519 sX11Forwarding
, sX11DisplayOffset
, sX11UseLocalhost
,
520 sPermitTTY
, sStrictModes
, sEmptyPasswd
, sTCPKeepAlive
,
521 sPermitUserEnvironment
, sAllowTcpForwarding
, sCompression
,
522 sRekeyLimit
, sAllowUsers
, sDenyUsers
, sAllowGroups
, sDenyGroups
,
523 sIgnoreUserKnownHosts
, sCiphers
, sMacs
, sPidFile
, sModuliFile
,
524 sGatewayPorts
, sPubkeyAuthentication
, sPubkeyAcceptedAlgorithms
,
525 sXAuthLocation
, sSubsystem
, sMaxStartups
, sMaxAuthTries
, sMaxSessions
,
526 sBanner
, sUseDNS
, sHostbasedAuthentication
,
527 sHostbasedUsesNameFromPacketOnly
, sHostbasedAcceptedAlgorithms
,
528 sHostKeyAlgorithms
, sPerSourceMaxStartups
, sPerSourceNetBlockSize
,
529 sClientAliveInterval
, sClientAliveCountMax
, sAuthorizedKeysFile
,
530 sGssAuthentication
, sGssCleanupCreds
, sGssStrictAcceptor
,
531 sAcceptEnv
, sSetEnv
, sPermitTunnel
,
532 sMatch
, sPermitOpen
, sPermitListen
, sForceCommand
, sChrootDirectory
,
533 sUsePrivilegeSeparation
, sAllowAgentForwarding
,
534 sHostCertificate
, sInclude
,
535 sRevokedKeys
, sTrustedUserCAKeys
, sAuthorizedPrincipalsFile
,
536 sAuthorizedPrincipalsCommand
, sAuthorizedPrincipalsCommandUser
,
537 sKexAlgorithms
, sCASignatureAlgorithms
, sIPQoS
, sVersionAddendum
,
538 sAuthorizedKeysCommand
, sAuthorizedKeysCommandUser
,
539 sAuthenticationMethods
, sHostKeyAgent
, sPermitUserRC
,
540 sStreamLocalBindMask
, sStreamLocalBindUnlink
,
541 sAllowStreamLocalForwarding
, sFingerprintHash
, sDisableForwarding
,
542 sExposeAuthInfo
, sRDomain
, sPubkeyAuthOptions
, sSecurityKeyProvider
,
543 sRequiredRSASize
, sChannelTimeout
, sUnusedConnectionTimeout
,
545 sDeprecated
, sIgnore
, sUnsupported
548 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of config */
549 #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
550 #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
551 #define SSHCFG_NEVERMATCH 0x04 /* Match never matches; internal only */
552 #define SSHCFG_MATCH_ONLY 0x08 /* Match only in conditional blocks; internal only */
554 /* Textual representation of the tokens. */
557 ServerOpCodes opcode
;
560 /* Portable-specific options */
562 { "usepam", sUsePAM
, SSHCFG_GLOBAL
},
564 { "usepam", sUnsupported
, SSHCFG_GLOBAL
},
566 { "pamauthenticationviakbdint", sDeprecated
, SSHCFG_GLOBAL
},
567 /* Standard Options */
568 { "port", sPort
, SSHCFG_GLOBAL
},
569 { "hostkey", sHostKeyFile
, SSHCFG_GLOBAL
},
570 { "hostdsakey", sHostKeyFile
, SSHCFG_GLOBAL
}, /* alias */
571 { "hostkeyagent", sHostKeyAgent
, SSHCFG_GLOBAL
},
572 { "pidfile", sPidFile
, SSHCFG_GLOBAL
},
573 { "modulifile", sModuliFile
, SSHCFG_GLOBAL
},
574 { "serverkeybits", sDeprecated
, SSHCFG_GLOBAL
},
575 { "logingracetime", sLoginGraceTime
, SSHCFG_GLOBAL
},
576 { "keyregenerationinterval", sDeprecated
, SSHCFG_GLOBAL
},
577 { "permitrootlogin", sPermitRootLogin
, SSHCFG_ALL
},
578 { "syslogfacility", sLogFacility
, SSHCFG_GLOBAL
},
579 { "loglevel", sLogLevel
, SSHCFG_ALL
},
580 { "logverbose", sLogVerbose
, SSHCFG_ALL
},
581 { "rhostsauthentication", sDeprecated
, SSHCFG_GLOBAL
},
582 { "rhostsrsaauthentication", sDeprecated
, SSHCFG_ALL
},
583 { "hostbasedauthentication", sHostbasedAuthentication
, SSHCFG_ALL
},
584 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly
, SSHCFG_ALL
},
585 { "hostbasedacceptedalgorithms", sHostbasedAcceptedAlgorithms
, SSHCFG_ALL
},
586 { "hostbasedacceptedkeytypes", sHostbasedAcceptedAlgorithms
, SSHCFG_ALL
}, /* obsolete */
587 { "hostkeyalgorithms", sHostKeyAlgorithms
, SSHCFG_GLOBAL
},
588 { "rsaauthentication", sDeprecated
, SSHCFG_ALL
},
589 { "pubkeyauthentication", sPubkeyAuthentication
, SSHCFG_ALL
},
590 { "pubkeyacceptedalgorithms", sPubkeyAcceptedAlgorithms
, SSHCFG_ALL
},
591 { "pubkeyacceptedkeytypes", sPubkeyAcceptedAlgorithms
, SSHCFG_ALL
}, /* obsolete */
592 { "pubkeyauthoptions", sPubkeyAuthOptions
, SSHCFG_ALL
},
593 { "dsaauthentication", sPubkeyAuthentication
, SSHCFG_GLOBAL
}, /* alias */
595 { "kerberosauthentication", sKerberosAuthentication
, SSHCFG_ALL
},
596 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd
, SSHCFG_GLOBAL
},
597 { "kerberosticketcleanup", sKerberosTicketCleanup
, SSHCFG_GLOBAL
},
599 { "kerberosgetafstoken", sKerberosGetAFSToken
, SSHCFG_GLOBAL
},
601 { "kerberosgetafstoken", sUnsupported
, SSHCFG_GLOBAL
},
604 { "kerberosauthentication", sUnsupported
, SSHCFG_ALL
},
605 { "kerberosorlocalpasswd", sUnsupported
, SSHCFG_GLOBAL
},
606 { "kerberosticketcleanup", sUnsupported
, SSHCFG_GLOBAL
},
607 { "kerberosgetafstoken", sUnsupported
, SSHCFG_GLOBAL
},
609 { "kerberostgtpassing", sUnsupported
, SSHCFG_GLOBAL
},
610 { "afstokenpassing", sUnsupported
, SSHCFG_GLOBAL
},
612 { "gssapiauthentication", sGssAuthentication
, SSHCFG_ALL
},
613 { "gssapicleanupcredentials", sGssCleanupCreds
, SSHCFG_GLOBAL
},
614 { "gssapistrictacceptorcheck", sGssStrictAcceptor
, SSHCFG_GLOBAL
},
616 { "gssapiauthentication", sUnsupported
, SSHCFG_ALL
},
617 { "gssapicleanupcredentials", sUnsupported
, SSHCFG_GLOBAL
},
618 { "gssapistrictacceptorcheck", sUnsupported
, SSHCFG_GLOBAL
},
620 { "passwordauthentication", sPasswordAuthentication
, SSHCFG_ALL
},
621 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication
, SSHCFG_ALL
},
622 { "challengeresponseauthentication", sKbdInteractiveAuthentication
, SSHCFG_ALL
}, /* alias */
623 { "skeyauthentication", sKbdInteractiveAuthentication
, SSHCFG_ALL
}, /* alias */
624 { "checkmail", sDeprecated
, SSHCFG_GLOBAL
},
625 { "listenaddress", sListenAddress
, SSHCFG_GLOBAL
},
626 { "addressfamily", sAddressFamily
, SSHCFG_GLOBAL
},
627 { "printmotd", sPrintMotd
, SSHCFG_GLOBAL
},
628 #ifdef DISABLE_LASTLOG
629 { "printlastlog", sUnsupported
, SSHCFG_GLOBAL
},
631 { "printlastlog", sPrintLastLog
, SSHCFG_GLOBAL
},
633 { "ignorerhosts", sIgnoreRhosts
, SSHCFG_ALL
},
634 { "ignoreuserknownhosts", sIgnoreUserKnownHosts
, SSHCFG_GLOBAL
},
635 { "x11forwarding", sX11Forwarding
, SSHCFG_ALL
},
636 { "x11displayoffset", sX11DisplayOffset
, SSHCFG_ALL
},
637 { "x11uselocalhost", sX11UseLocalhost
, SSHCFG_ALL
},
638 { "xauthlocation", sXAuthLocation
, SSHCFG_GLOBAL
},
639 { "strictmodes", sStrictModes
, SSHCFG_GLOBAL
},
640 { "permitemptypasswords", sEmptyPasswd
, SSHCFG_ALL
},
641 { "permituserenvironment", sPermitUserEnvironment
, SSHCFG_GLOBAL
},
642 { "uselogin", sDeprecated
, SSHCFG_GLOBAL
},
643 { "compression", sCompression
, SSHCFG_GLOBAL
},
644 { "rekeylimit", sRekeyLimit
, SSHCFG_ALL
},
645 { "tcpkeepalive", sTCPKeepAlive
, SSHCFG_GLOBAL
},
646 { "keepalive", sTCPKeepAlive
, SSHCFG_GLOBAL
}, /* obsolete alias */
647 { "allowtcpforwarding", sAllowTcpForwarding
, SSHCFG_ALL
},
648 { "allowagentforwarding", sAllowAgentForwarding
, SSHCFG_ALL
},
649 { "allowusers", sAllowUsers
, SSHCFG_ALL
},
650 { "denyusers", sDenyUsers
, SSHCFG_ALL
},
651 { "allowgroups", sAllowGroups
, SSHCFG_ALL
},
652 { "denygroups", sDenyGroups
, SSHCFG_ALL
},
653 { "ciphers", sCiphers
, SSHCFG_GLOBAL
},
654 { "macs", sMacs
, SSHCFG_GLOBAL
},
655 { "protocol", sIgnore
, SSHCFG_GLOBAL
},
656 { "gatewayports", sGatewayPorts
, SSHCFG_ALL
},
657 { "subsystem", sSubsystem
, SSHCFG_ALL
},
658 { "maxstartups", sMaxStartups
, SSHCFG_GLOBAL
},
659 { "persourcemaxstartups", sPerSourceMaxStartups
, SSHCFG_GLOBAL
},
660 { "persourcenetblocksize", sPerSourceNetBlockSize
, SSHCFG_GLOBAL
},
661 { "maxauthtries", sMaxAuthTries
, SSHCFG_ALL
},
662 { "maxsessions", sMaxSessions
, SSHCFG_ALL
},
663 { "banner", sBanner
, SSHCFG_ALL
},
664 { "usedns", sUseDNS
, SSHCFG_GLOBAL
},
665 { "verifyreversemapping", sDeprecated
, SSHCFG_GLOBAL
},
666 { "reversemappingcheck", sDeprecated
, SSHCFG_GLOBAL
},
667 { "clientaliveinterval", sClientAliveInterval
, SSHCFG_ALL
},
668 { "clientalivecountmax", sClientAliveCountMax
, SSHCFG_ALL
},
669 { "authorizedkeysfile", sAuthorizedKeysFile
, SSHCFG_ALL
},
670 { "authorizedkeysfile2", sDeprecated
, SSHCFG_ALL
},
671 { "useprivilegeseparation", sDeprecated
, SSHCFG_GLOBAL
},
672 { "acceptenv", sAcceptEnv
, SSHCFG_ALL
},
673 { "setenv", sSetEnv
, SSHCFG_ALL
},
674 { "permittunnel", sPermitTunnel
, SSHCFG_ALL
},
675 { "permittty", sPermitTTY
, SSHCFG_ALL
},
676 { "permituserrc", sPermitUserRC
, SSHCFG_ALL
},
677 { "match", sMatch
, SSHCFG_ALL
},
678 { "permitopen", sPermitOpen
, SSHCFG_ALL
},
679 { "permitlisten", sPermitListen
, SSHCFG_ALL
},
680 { "forcecommand", sForceCommand
, SSHCFG_ALL
},
681 { "chrootdirectory", sChrootDirectory
, SSHCFG_ALL
},
682 { "hostcertificate", sHostCertificate
, SSHCFG_GLOBAL
},
683 { "revokedkeys", sRevokedKeys
, SSHCFG_ALL
},
684 { "trustedusercakeys", sTrustedUserCAKeys
, SSHCFG_ALL
},
685 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile
, SSHCFG_ALL
},
686 { "kexalgorithms", sKexAlgorithms
, SSHCFG_GLOBAL
},
687 { "include", sInclude
, SSHCFG_ALL
},
688 { "ipqos", sIPQoS
, SSHCFG_ALL
},
689 { "authorizedkeyscommand", sAuthorizedKeysCommand
, SSHCFG_ALL
},
690 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser
, SSHCFG_ALL
},
691 { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand
, SSHCFG_ALL
},
692 { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser
, SSHCFG_ALL
},
693 { "versionaddendum", sVersionAddendum
, SSHCFG_GLOBAL
},
694 { "authenticationmethods", sAuthenticationMethods
, SSHCFG_ALL
},
695 { "streamlocalbindmask", sStreamLocalBindMask
, SSHCFG_ALL
},
696 { "streamlocalbindunlink", sStreamLocalBindUnlink
, SSHCFG_ALL
},
697 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding
, SSHCFG_ALL
},
698 { "fingerprinthash", sFingerprintHash
, SSHCFG_GLOBAL
},
699 { "disableforwarding", sDisableForwarding
, SSHCFG_ALL
},
700 { "exposeauthinfo", sExposeAuthInfo
, SSHCFG_ALL
},
701 { "rdomain", sRDomain
, SSHCFG_ALL
},
702 { "casignaturealgorithms", sCASignatureAlgorithms
, SSHCFG_ALL
},
703 { "securitykeyprovider", sSecurityKeyProvider
, SSHCFG_GLOBAL
},
704 { "requiredrsasize", sRequiredRSASize
, SSHCFG_ALL
},
705 { "channeltimeout", sChannelTimeout
, SSHCFG_ALL
},
706 { "unusedconnectiontimeout", sUnusedConnectionTimeout
, SSHCFG_ALL
},
707 { "useblacklist", sUseBlacklist
, SSHCFG_GLOBAL
},
708 { "useblocklist", sUseBlacklist
, SSHCFG_GLOBAL
}, /* alias */
710 { NULL
, sBadOption
, 0 }
717 { SSH_TUNMODE_NO
, "no" },
718 { SSH_TUNMODE_POINTOPOINT
, "point-to-point" },
719 { SSH_TUNMODE_ETHERNET
, "ethernet" },
720 { SSH_TUNMODE_YES
, "yes" },
724 /* Returns an opcode name from its number */
727 lookup_opcode_name(ServerOpCodes code
)
731 for (i
= 0; keywords
[i
].name
!= NULL
; i
++)
732 if (keywords
[i
].opcode
== code
)
733 return(keywords
[i
].name
);
739 * Returns the number of the token pointed to by cp or sBadOption.
743 parse_token(const char *cp
, const char *filename
,
744 int linenum
, u_int
*flags
)
748 for (i
= 0; keywords
[i
].name
; i
++)
749 if (strcasecmp(cp
, keywords
[i
].name
) == 0) {
750 *flags
= keywords
[i
].flags
;
751 return keywords
[i
].opcode
;
754 error("%s: line %d: Bad configuration option: %s",
755 filename
, linenum
, cp
);
760 derelativise_path(const char *path
)
762 char *expanded
, *ret
, cwd
[PATH_MAX
];
764 if (strcasecmp(path
, "none") == 0)
765 return xstrdup("none");
766 expanded
= tilde_expand_filename(path
, getuid());
767 if (path_absolute(expanded
))
769 if (getcwd(cwd
, sizeof(cwd
)) == NULL
)
770 fatal_f("getcwd: %s", strerror(errno
));
771 xasprintf(&ret
, "%s/%s", cwd
, expanded
);
777 add_listen_addr(ServerOptions
*options
, const char *addr
,
778 const char *rdomain
, int port
)
783 add_one_listen_addr(options
, addr
, rdomain
, port
);
785 for (i
= 0; i
< options
->num_ports
; i
++) {
786 add_one_listen_addr(options
, addr
, rdomain
,
793 add_one_listen_addr(ServerOptions
*options
, const char *addr
,
794 const char *rdomain
, int port
)
796 struct addrinfo hints
, *ai
, *aitop
;
797 char strport
[NI_MAXSERV
];
801 /* Find listen_addrs entry for this rdomain */
802 for (i
= 0; i
< options
->num_listen_addrs
; i
++) {
803 if (rdomain
== NULL
&& options
->listen_addrs
[i
].rdomain
== NULL
)
805 if (rdomain
== NULL
|| options
->listen_addrs
[i
].rdomain
== NULL
)
807 if (strcmp(rdomain
, options
->listen_addrs
[i
].rdomain
) == 0)
810 if (i
>= options
->num_listen_addrs
) {
811 /* No entry for this rdomain; allocate one */
813 fatal_f("too many listen addresses");
814 options
->listen_addrs
= xrecallocarray(options
->listen_addrs
,
815 options
->num_listen_addrs
, options
->num_listen_addrs
+ 1,
816 sizeof(*options
->listen_addrs
));
817 i
= options
->num_listen_addrs
++;
819 options
->listen_addrs
[i
].rdomain
= xstrdup(rdomain
);
821 /* options->listen_addrs[i] points to the addresses for this rdomain */
823 memset(&hints
, 0, sizeof(hints
));
824 hints
.ai_family
= options
->address_family
;
825 hints
.ai_socktype
= SOCK_STREAM
;
826 hints
.ai_flags
= (addr
== NULL
) ? AI_PASSIVE
: 0;
827 snprintf(strport
, sizeof strport
, "%d", port
);
828 if ((gaierr
= getaddrinfo(addr
, strport
, &hints
, &aitop
)) != 0)
829 fatal("bad addr or host: %s (%s)",
830 addr
? addr
: "<NULL>",
831 ssh_gai_strerror(gaierr
));
832 for (ai
= aitop
; ai
->ai_next
; ai
= ai
->ai_next
)
834 ai
->ai_next
= options
->listen_addrs
[i
].addrs
;
835 options
->listen_addrs
[i
].addrs
= aitop
;
838 /* Returns nonzero if the routing domain name is valid */
840 valid_rdomain(const char *name
)
842 #if defined(HAVE_SYS_VALID_RDOMAIN)
843 return sys_valid_rdomain(name
);
844 #elif defined(__OpenBSD__)
847 struct rt_tableinfo info
;
849 size_t miblen
= sizeof(mib
);
854 num
= strtonum(name
, 0, 255, &errstr
);
858 /* Check whether the table actually exists */
859 memset(mib
, 0, sizeof(mib
));
862 mib
[4] = NET_RT_TABLE
;
864 if (sysctl(mib
, 6, &info
, &miblen
, NULL
, 0) == -1)
868 #else /* defined(__OpenBSD__) */
869 error("Routing domains are not supported on this platform");
875 * Queue a ListenAddress to be processed once we have all of the Ports
876 * and AddressFamily options.
879 queue_listen_addr(ServerOptions
*options
, const char *addr
,
880 const char *rdomain
, int port
)
882 struct queued_listenaddr
*qla
;
884 options
->queued_listen_addrs
= xrecallocarray(
885 options
->queued_listen_addrs
,
886 options
->num_queued_listens
, options
->num_queued_listens
+ 1,
887 sizeof(*options
->queued_listen_addrs
));
888 qla
= &options
->queued_listen_addrs
[options
->num_queued_listens
++];
889 qla
->addr
= xstrdup(addr
);
891 qla
->rdomain
= rdomain
== NULL
? NULL
: xstrdup(rdomain
);
895 * Process queued (text) ListenAddress entries.
898 process_queued_listen_addrs(ServerOptions
*options
)
901 struct queued_listenaddr
*qla
;
903 if (options
->num_ports
== 0)
904 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
905 if (options
->address_family
== -1)
906 options
->address_family
= AF_UNSPEC
;
908 for (i
= 0; i
< options
->num_queued_listens
; i
++) {
909 qla
= &options
->queued_listen_addrs
[i
];
910 add_listen_addr(options
, qla
->addr
, qla
->rdomain
, qla
->port
);
914 free(options
->queued_listen_addrs
);
915 options
->queued_listen_addrs
= NULL
;
916 options
->num_queued_listens
= 0;
920 * Inform channels layer of permitopen options for a single forwarding
921 * direction (local/remote).
924 process_permitopen_list(struct ssh
*ssh
, ServerOpCodes opcode
,
925 char **opens
, u_int num_opens
)
929 char *host
, *arg
, *oarg
;
930 int where
= opcode
== sPermitOpen
? FORWARD_LOCAL
: FORWARD_REMOTE
;
931 const char *what
= lookup_opcode_name(opcode
);
933 channel_clear_permission(ssh
, FORWARD_ADM
, where
);
935 return; /* permit any */
937 /* handle keywords: "any" / "none" */
938 if (num_opens
== 1 && strcmp(opens
[0], "any") == 0)
940 if (num_opens
== 1 && strcmp(opens
[0], "none") == 0) {
941 channel_disable_admin(ssh
, where
);
944 /* Otherwise treat it as a list of permitted host:port */
945 for (i
= 0; i
< num_opens
; i
++) {
946 oarg
= arg
= xstrdup(opens
[i
]);
947 host
= hpdelim(&arg
);
949 fatal_f("missing host in %s", what
);
950 host
= cleanhostname(host
);
951 if (arg
== NULL
|| ((port
= permitopen_port(arg
)) < 0))
952 fatal_f("bad port number in %s", what
);
953 /* Send it to channels layer */
954 channel_add_permission(ssh
, FORWARD_ADM
,
961 * Inform channels layer of permitopen options from configuration.
964 process_permitopen(struct ssh
*ssh
, ServerOptions
*options
)
966 process_permitopen_list(ssh
, sPermitOpen
,
967 options
->permitted_opens
, options
->num_permitted_opens
);
968 process_permitopen_list(ssh
, sPermitListen
,
969 options
->permitted_listens
,
970 options
->num_permitted_listens
);
974 process_channel_timeouts(struct ssh
*ssh
, ServerOptions
*options
)
980 debug3_f("setting %u timeouts", options
->num_channel_timeouts
);
981 channel_clear_timeouts(ssh
);
982 for (i
= 0; i
< options
->num_channel_timeouts
; i
++) {
983 if (parse_pattern_interval(options
->channel_timeouts
[i
],
984 &type
, &secs
) != 0) {
985 fatal_f("internal error: bad timeout %s",
986 options
->channel_timeouts
[i
]);
988 channel_add_timeout(ssh
, type
, secs
);
993 struct connection_info
*
994 get_connection_info(struct ssh
*ssh
, int populate
, int use_dns
)
996 static struct connection_info ci
;
998 if (ssh
== NULL
|| !populate
)
1000 ci
.host
= auth_get_canonical_hostname(ssh
, use_dns
);
1001 ci
.address
= ssh_remote_ipaddr(ssh
);
1002 ci
.laddress
= ssh_local_ipaddr(ssh
);
1003 ci
.lport
= ssh_local_port(ssh
);
1004 ci
.rdomain
= ssh_packet_rdomain_in(ssh
);
1009 * The strategy for the Match blocks is that the config file is parsed twice.
1011 * The first time is at startup. activep is initialized to 1 and the
1012 * directives in the global context are processed and acted on. Hitting a
1013 * Match directive unsets activep and the directives inside the block are
1014 * checked for syntax only.
1016 * The second time is after a connection has been established but before
1017 * authentication. activep is initialized to 2 and global config directives
1018 * are ignored since they have already been processed. If the criteria in a
1019 * Match block is met, activep is set and the subsequent directives
1020 * processed and actioned until EOF or another Match block unsets it. Any
1021 * options set are copied into the main server config.
1023 * Potential additions/improvements:
1024 * - Add Match support for pre-kex directives, eg. Ciphers.
1026 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
1027 * Match Address 192.168.0.*
1032 * AllowTcpForwarding yes
1033 * GatewayPorts clientspecified
1036 * - Add a PermittedChannelRequests directive
1038 * PermittedChannelRequests session,forwarded-tcpip
1042 match_cfg_line_group(const char *grps
, int line
, const char *user
)
1050 if ((pw
= getpwnam(user
)) == NULL
) {
1051 debug("Can't match group at line %d because user %.100s does "
1052 "not exist", line
, user
);
1053 } else if (ga_init(pw
->pw_name
, pw
->pw_gid
) == 0) {
1054 debug("Can't Match group because user %.100s not in any group "
1055 "at line %d", user
, line
);
1056 } else if (ga_match_pattern_list(grps
) != 1) {
1057 debug("user %.100s does not match group list %.100s at line %d",
1060 debug("user %.100s matched group list %.100s at line %d", user
,
1070 match_test_missing_fatal(const char *criteria
, const char *attrib
)
1072 fatal("'Match %s' in configuration but '%s' not in connection "
1073 "test specification.", criteria
, attrib
);
1077 * All of the attributes on a single Match line are ANDed together, so we need
1078 * to check every attribute and set the result to zero if any attribute does
1082 match_cfg_line(char **condition
, int line
, struct connection_info
*ci
)
1084 int result
= 1, attributes
= 0, port
;
1085 char *arg
, *attrib
, *cp
= *condition
;
1088 debug3("checking syntax for 'Match %s'", cp
);
1090 debug3("checking match for '%s' user %s host %s addr %s "
1091 "laddr %s lport %d", cp
, ci
->user
? ci
->user
: "(null)",
1092 ci
->host
? ci
->host
: "(null)",
1093 ci
->address
? ci
->address
: "(null)",
1094 ci
->laddress
? ci
->laddress
: "(null)", ci
->lport
);
1096 while ((attrib
= strdelim(&cp
)) && *attrib
!= '\0') {
1097 /* Terminate on comment */
1098 if (*attrib
== '#') {
1099 cp
= NULL
; /* mark all arguments consumed */
1104 /* Criterion "all" has no argument and must appear alone */
1105 if (strcasecmp(attrib
, "all") == 0) {
1106 if (attributes
> 1 || ((arg
= strdelim(&cp
)) != NULL
&&
1107 *arg
!= '\0' && *arg
!= '#')) {
1108 error("'all' cannot be combined with other "
1109 "Match attributes");
1112 if (arg
!= NULL
&& *arg
== '#')
1113 cp
= NULL
; /* mark all arguments consumed */
1117 /* All other criteria require an argument */
1118 if ((arg
= strdelim(&cp
)) == NULL
||
1119 *arg
== '\0' || *arg
== '#') {
1120 error("Missing Match criteria for %s", attrib
);
1123 if (strcasecmp(attrib
, "user") == 0) {
1124 if (ci
== NULL
|| (ci
->test
&& ci
->user
== NULL
)) {
1128 if (ci
->user
== NULL
)
1129 match_test_missing_fatal("User", "user");
1130 if (match_usergroup_pattern_list(ci
->user
, arg
) != 1)
1133 debug("user %.100s matched 'User %.100s' at "
1134 "line %d", ci
->user
, arg
, line
);
1135 } else if (strcasecmp(attrib
, "group") == 0) {
1136 if (ci
== NULL
|| (ci
->test
&& ci
->user
== NULL
)) {
1140 if (ci
->user
== NULL
)
1141 match_test_missing_fatal("Group", "user");
1142 switch (match_cfg_line_group(arg
, line
, ci
->user
)) {
1148 } else if (strcasecmp(attrib
, "host") == 0) {
1149 if (ci
== NULL
|| (ci
->test
&& ci
->host
== NULL
)) {
1153 if (ci
->host
== NULL
)
1154 match_test_missing_fatal("Host", "host");
1155 if (match_hostname(ci
->host
, arg
) != 1)
1158 debug("connection from %.100s matched 'Host "
1159 "%.100s' at line %d", ci
->host
, arg
, line
);
1160 } else if (strcasecmp(attrib
, "address") == 0) {
1161 if (ci
== NULL
|| (ci
->test
&& ci
->address
== NULL
)) {
1162 if (addr_match_list(NULL
, arg
) != 0)
1163 fatal("Invalid Match address argument "
1164 "'%s' at line %d", arg
, line
);
1168 if (ci
->address
== NULL
)
1169 match_test_missing_fatal("Address", "addr");
1170 switch (addr_match_list(ci
->address
, arg
)) {
1172 debug("connection from %.100s matched 'Address "
1173 "%.100s' at line %d", ci
->address
, arg
, line
);
1182 } else if (strcasecmp(attrib
, "localaddress") == 0){
1183 if (ci
== NULL
|| (ci
->test
&& ci
->laddress
== NULL
)) {
1184 if (addr_match_list(NULL
, arg
) != 0)
1185 fatal("Invalid Match localaddress "
1186 "argument '%s' at line %d", arg
,
1191 if (ci
->laddress
== NULL
)
1192 match_test_missing_fatal("LocalAddress",
1194 switch (addr_match_list(ci
->laddress
, arg
)) {
1196 debug("connection from %.100s matched "
1197 "'LocalAddress %.100s' at line %d",
1198 ci
->laddress
, arg
, line
);
1207 } else if (strcasecmp(attrib
, "localport") == 0) {
1208 if ((port
= a2port(arg
)) == -1) {
1209 error("Invalid LocalPort '%s' on Match line",
1213 if (ci
== NULL
|| (ci
->test
&& ci
->lport
== -1)) {
1218 match_test_missing_fatal("LocalPort", "lport");
1219 /* TODO support port lists */
1220 if (port
== ci
->lport
)
1221 debug("connection from %.100s matched "
1222 "'LocalPort %d' at line %d",
1223 ci
->laddress
, port
, line
);
1226 } else if (strcasecmp(attrib
, "rdomain") == 0) {
1227 if (ci
== NULL
|| (ci
->test
&& ci
->rdomain
== NULL
)) {
1231 if (ci
->rdomain
== NULL
)
1232 match_test_missing_fatal("RDomain", "rdomain");
1233 if (match_pattern_list(ci
->rdomain
, arg
, 0) != 1)
1236 debug("user %.100s matched 'RDomain %.100s' at "
1237 "line %d", ci
->rdomain
, arg
, line
);
1239 error("Unsupported Match attribute %s", attrib
);
1243 if (attributes
== 0) {
1244 error("One or more attributes required for Match");
1248 debug3("match %sfound", result
? "" : "not ");
1253 #define WHITESPACE " \t\r\n"
1255 /* Multistate option parsing */
1260 static const struct multistate multistate_flag
[] = {
1265 static const struct multistate multistate_ignore_rhosts
[] = {
1266 { "yes", IGNORE_RHOSTS_YES
},
1267 { "no", IGNORE_RHOSTS_NO
},
1268 { "shosts-only", IGNORE_RHOSTS_SHOSTS
},
1271 static const struct multistate multistate_addressfamily
[] = {
1272 { "inet", AF_INET
},
1273 { "inet6", AF_INET6
},
1274 { "any", AF_UNSPEC
},
1277 static const struct multistate multistate_permitrootlogin
[] = {
1278 { "without-password", PERMIT_NO_PASSWD
},
1279 { "prohibit-password", PERMIT_NO_PASSWD
},
1280 { "forced-commands-only", PERMIT_FORCED_ONLY
},
1281 { "yes", PERMIT_YES
},
1282 { "no", PERMIT_NO
},
1285 static const struct multistate multistate_compression
[] = {
1287 { "yes", COMP_DELAYED
},
1288 { "delayed", COMP_DELAYED
},
1290 { "no", COMP_NONE
},
1293 static const struct multistate multistate_gatewayports
[] = {
1294 { "clientspecified", 2 },
1299 static const struct multistate multistate_tcpfwd
[] = {
1300 { "yes", FORWARD_ALLOW
},
1301 { "all", FORWARD_ALLOW
},
1302 { "no", FORWARD_DENY
},
1303 { "remote", FORWARD_REMOTE
},
1304 { "local", FORWARD_LOCAL
},
1309 process_server_config_line_depth(ServerOptions
*options
, char *line
,
1310 const char *filename
, int linenum
, int *activep
,
1311 struct connection_info
*connectinfo
, int *inc_flags
, int depth
,
1312 struct include_list
*includes
)
1314 char *str
, ***chararrayptr
, **charptr
, *arg
, *arg2
, *p
, *keyword
;
1315 int cmdline
= 0, *intptr
, value
, value2
, n
, port
, oactive
, r
;
1316 int ca_only
= 0, found
= 0;
1317 SyslogFacility
*log_facility_ptr
;
1318 LogLevel
*log_level_ptr
;
1319 ServerOpCodes opcode
;
1320 u_int i
, *uintptr
, flags
= 0;
1323 const struct multistate
*multistate_ptr
;
1325 struct include_item
*item
;
1327 char **oav
= NULL
, **av
;
1330 char **strs
= NULL
; /* string array arguments; freed implicitly */
1333 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1334 if ((len
= strlen(line
)) == 0)
1336 for (len
--; len
> 0; len
--) {
1337 if (strchr(WHITESPACE
"\f", line
[len
]) == NULL
)
1343 if ((keyword
= strdelim(&str
)) == NULL
)
1345 /* Ignore leading whitespace */
1346 if (*keyword
== '\0')
1347 keyword
= strdelim(&str
);
1348 if (!keyword
|| !*keyword
|| *keyword
== '#')
1350 if (str
== NULL
|| *str
== '\0') {
1351 error("%s line %d: no argument after keyword \"%s\"",
1352 filename
, linenum
, keyword
);
1357 opcode
= parse_token(keyword
, filename
, linenum
, &flags
);
1359 if (argv_split(str
, &oac
, &oav
, 1) != 0) {
1360 error("%s line %d: invalid quotes", filename
, linenum
);
1366 if (activep
== NULL
) { /* We are processing a command line directive */
1370 if (*activep
&& opcode
!= sMatch
&& opcode
!= sInclude
)
1371 debug3("%s:%d setting %s %s", filename
, linenum
, keyword
, str
);
1372 if (*activep
== 0 && !(flags
& SSHCFG_MATCH
)) {
1373 if (connectinfo
== NULL
) {
1374 fatal("%s line %d: Directive '%s' is not allowed "
1375 "within a Match block", filename
, linenum
, keyword
);
1376 } else { /* this is a directive we have already processed */
1383 /* Portable-specific options */
1385 intptr
= &options
->use_pam
;
1388 /* Standard Options */
1392 /* ignore ports from configfile if cmdline specifies ports */
1393 if (options
->ports_from_cmdline
) {
1397 if (options
->num_ports
>= MAX_PORTS
)
1398 fatal("%s line %d: too many ports.",
1400 arg
= argv_next(&ac
, &av
);
1401 if (!arg
|| *arg
== '\0')
1402 fatal("%s line %d: missing port number.",
1404 options
->ports
[options
->num_ports
++] = a2port(arg
);
1405 if (options
->ports
[options
->num_ports
-1] <= 0)
1406 fatal("%s line %d: Badly formatted port number.",
1410 case sLoginGraceTime
:
1411 intptr
= &options
->login_grace_time
;
1413 arg
= argv_next(&ac
, &av
);
1414 if (!arg
|| *arg
== '\0')
1415 fatal("%s line %d: missing time value.",
1417 if ((value
= convtime(arg
)) == -1)
1418 fatal("%s line %d: invalid time value.",
1420 if (*activep
&& *intptr
== -1)
1424 case sListenAddress
:
1425 arg
= argv_next(&ac
, &av
);
1426 if (arg
== NULL
|| *arg
== '\0')
1427 fatal("%s line %d: missing address",
1429 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1430 if (strchr(arg
, '[') == NULL
&& (p
= strchr(arg
, ':')) != NULL
1431 && strchr(p
+1, ':') != NULL
) {
1438 fatal("%s line %d: bad address:port usage",
1440 p
= cleanhostname(p
);
1443 else if ((port
= a2port(arg
)) <= 0)
1444 fatal("%s line %d: bad port number",
1447 /* Optional routing table */
1449 if ((arg
= argv_next(&ac
, &av
)) != NULL
) {
1450 if (strcmp(arg
, "rdomain") != 0 ||
1451 (arg2
= argv_next(&ac
, &av
)) == NULL
)
1452 fatal("%s line %d: bad ListenAddress syntax",
1454 if (!valid_rdomain(arg2
))
1455 fatal("%s line %d: bad routing domain",
1458 queue_listen_addr(options
, p
, arg2
, port
);
1462 case sAddressFamily
:
1463 intptr
= &options
->address_family
;
1464 multistate_ptr
= multistate_addressfamily
;
1466 arg
= argv_next(&ac
, &av
);
1467 if (!arg
|| *arg
== '\0')
1468 fatal("%s line %d: missing argument.",
1471 for (i
= 0; multistate_ptr
[i
].key
!= NULL
; i
++) {
1472 if (strcasecmp(arg
, multistate_ptr
[i
].key
) == 0) {
1473 value
= multistate_ptr
[i
].value
;
1478 fatal("%s line %d: unsupported option \"%s\".",
1479 filename
, linenum
, arg
);
1480 if (*activep
&& *intptr
== -1)
1485 arg
= argv_next(&ac
, &av
);
1486 if (!arg
|| *arg
== '\0')
1487 fatal("%s line %d: missing file name.",
1490 servconf_add_hostkey(filename
, linenum
,
1496 charptr
= &options
->host_key_agent
;
1497 arg
= argv_next(&ac
, &av
);
1498 if (!arg
|| *arg
== '\0')
1499 fatal("%s line %d: missing socket name.",
1501 if (*activep
&& *charptr
== NULL
)
1502 *charptr
= !strcmp(arg
, SSH_AUTHSOCKET_ENV_NAME
) ?
1503 xstrdup(arg
) : derelativise_path(arg
);
1506 case sHostCertificate
:
1507 arg
= argv_next(&ac
, &av
);
1508 if (!arg
|| *arg
== '\0')
1509 fatal("%s line %d: missing file name.",
1512 servconf_add_hostcert(filename
, linenum
, options
, arg
);
1516 charptr
= &options
->pid_file
;
1518 arg
= argv_next(&ac
, &av
);
1519 if (!arg
|| *arg
== '\0')
1520 fatal("%s line %d: missing file name.",
1522 if (*activep
&& *charptr
== NULL
) {
1523 *charptr
= derelativise_path(arg
);
1524 /* increase optional counter */
1526 *intptr
= *intptr
+ 1;
1531 charptr
= &options
->moduli_file
;
1532 goto parse_filename
;
1534 case sPermitRootLogin
:
1535 intptr
= &options
->permit_root_login
;
1536 multistate_ptr
= multistate_permitrootlogin
;
1537 goto parse_multistate
;
1540 intptr
= &options
->ignore_rhosts
;
1541 multistate_ptr
= multistate_ignore_rhosts
;
1542 goto parse_multistate
;
1544 case sIgnoreUserKnownHosts
:
1545 intptr
= &options
->ignore_user_known_hosts
;
1547 multistate_ptr
= multistate_flag
;
1548 goto parse_multistate
;
1550 case sHostbasedAuthentication
:
1551 intptr
= &options
->hostbased_authentication
;
1554 case sHostbasedUsesNameFromPacketOnly
:
1555 intptr
= &options
->hostbased_uses_name_from_packet_only
;
1558 case sHostbasedAcceptedAlgorithms
:
1559 charptr
= &options
->hostbased_accepted_algos
;
1562 arg
= argv_next(&ac
, &av
);
1563 if (!arg
|| *arg
== '\0')
1564 fatal("%s line %d: Missing argument.",
1567 !sshkey_names_valid2(*arg
== '+' || *arg
== '^' ?
1568 arg
+ 1 : arg
, 1, ca_only
))
1569 fatal("%s line %d: Bad key types '%s'.",
1570 filename
, linenum
, arg
? arg
: "<NONE>");
1571 if (*activep
&& *charptr
== NULL
)
1572 *charptr
= xstrdup(arg
);
1575 case sHostKeyAlgorithms
:
1576 charptr
= &options
->hostkeyalgorithms
;
1578 goto parse_pubkey_algos
;
1580 case sCASignatureAlgorithms
:
1581 charptr
= &options
->ca_sign_algorithms
;
1583 goto parse_pubkey_algos
;
1585 case sPubkeyAuthentication
:
1586 intptr
= &options
->pubkey_authentication
;
1590 case sPubkeyAcceptedAlgorithms
:
1591 charptr
= &options
->pubkey_accepted_algos
;
1593 goto parse_pubkey_algos
;
1595 case sPubkeyAuthOptions
:
1596 intptr
= &options
->pubkey_auth_options
;
1598 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
1599 if (strcasecmp(arg
, "none") == 0)
1601 if (strcasecmp(arg
, "touch-required") == 0)
1602 value
|= PUBKEYAUTH_TOUCH_REQUIRED
;
1603 else if (strcasecmp(arg
, "verify-required") == 0)
1604 value
|= PUBKEYAUTH_VERIFY_REQUIRED
;
1606 error("%s line %d: unsupported %s option %s",
1607 filename
, linenum
, keyword
, arg
);
1611 if (*activep
&& *intptr
== -1)
1615 case sKerberosAuthentication
:
1616 intptr
= &options
->kerberos_authentication
;
1619 case sKerberosOrLocalPasswd
:
1620 intptr
= &options
->kerberos_or_local_passwd
;
1623 case sKerberosTicketCleanup
:
1624 intptr
= &options
->kerberos_ticket_cleanup
;
1627 case sKerberosGetAFSToken
:
1628 intptr
= &options
->kerberos_get_afs_token
;
1631 case sGssAuthentication
:
1632 intptr
= &options
->gss_authentication
;
1635 case sGssCleanupCreds
:
1636 intptr
= &options
->gss_cleanup_creds
;
1639 case sGssStrictAcceptor
:
1640 intptr
= &options
->gss_strict_acceptor
;
1643 case sPasswordAuthentication
:
1644 intptr
= &options
->password_authentication
;
1647 case sKbdInteractiveAuthentication
:
1648 intptr
= &options
->kbd_interactive_authentication
;
1652 intptr
= &options
->print_motd
;
1656 intptr
= &options
->print_lastlog
;
1659 case sX11Forwarding
:
1660 intptr
= &options
->x11_forwarding
;
1663 case sX11DisplayOffset
:
1664 intptr
= &options
->x11_display_offset
;
1666 arg
= argv_next(&ac
, &av
);
1667 if ((errstr
= atoi_err(arg
, &value
)) != NULL
)
1668 fatal("%s line %d: %s integer value %s.",
1669 filename
, linenum
, keyword
, errstr
);
1670 if (*activep
&& *intptr
== -1)
1674 case sX11UseLocalhost
:
1675 intptr
= &options
->x11_use_localhost
;
1678 case sXAuthLocation
:
1679 charptr
= &options
->xauth_location
;
1680 goto parse_filename
;
1683 intptr
= &options
->permit_tty
;
1687 intptr
= &options
->permit_user_rc
;
1691 intptr
= &options
->strict_modes
;
1695 intptr
= &options
->tcp_keep_alive
;
1699 intptr
= &options
->permit_empty_passwd
;
1702 case sPermitUserEnvironment
:
1703 intptr
= &options
->permit_user_env
;
1704 charptr
= &options
->permit_user_env_allowlist
;
1705 arg
= argv_next(&ac
, &av
);
1706 if (!arg
|| *arg
== '\0')
1707 fatal("%s line %d: %s missing argument.",
1708 filename
, linenum
, keyword
);
1711 if (strcmp(arg
, "yes") == 0)
1713 else if (strcmp(arg
, "no") == 0)
1716 /* Pattern-list specified */
1720 if (*activep
&& *intptr
== -1) {
1729 intptr
= &options
->compression
;
1730 multistate_ptr
= multistate_compression
;
1731 goto parse_multistate
;
1734 arg
= argv_next(&ac
, &av
);
1735 if (!arg
|| *arg
== '\0')
1736 fatal("%s line %d: %s missing argument.",
1737 filename
, linenum
, keyword
);
1738 if (strcmp(arg
, "default") == 0) {
1741 if (scan_scaled(arg
, &val64
) == -1)
1742 fatal("%.200s line %d: Bad %s number '%s': %s",
1743 filename
, linenum
, keyword
,
1744 arg
, strerror(errno
));
1745 if (val64
!= 0 && val64
< 16)
1746 fatal("%.200s line %d: %s too small",
1747 filename
, linenum
, keyword
);
1749 if (*activep
&& options
->rekey_limit
== -1)
1750 options
->rekey_limit
= val64
;
1751 if (ac
!= 0) { /* optional rekey interval present */
1752 if (strcmp(av
[0], "none") == 0) {
1753 (void)argv_next(&ac
, &av
); /* discard */
1756 intptr
= &options
->rekey_interval
;
1762 intptr
= &options
->fwd_opts
.gateway_ports
;
1763 multistate_ptr
= multistate_gatewayports
;
1764 goto parse_multistate
;
1767 intptr
= &options
->use_dns
;
1771 log_facility_ptr
= &options
->log_facility
;
1772 arg
= argv_next(&ac
, &av
);
1773 value
= log_facility_number(arg
);
1774 if (value
== SYSLOG_FACILITY_NOT_SET
)
1775 fatal("%.200s line %d: unsupported log facility '%s'",
1776 filename
, linenum
, arg
? arg
: "<NONE>");
1777 if (*log_facility_ptr
== -1)
1778 *log_facility_ptr
= (SyslogFacility
) value
;
1782 log_level_ptr
= &options
->log_level
;
1783 arg
= argv_next(&ac
, &av
);
1784 value
= log_level_number(arg
);
1785 if (value
== SYSLOG_LEVEL_NOT_SET
)
1786 fatal("%.200s line %d: unsupported log level '%s'",
1787 filename
, linenum
, arg
? arg
: "<NONE>");
1788 if (*activep
&& *log_level_ptr
== -1)
1789 *log_level_ptr
= (LogLevel
) value
;
1793 found
= options
->num_log_verbose
== 0;
1794 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
1796 error("%s line %d: keyword %s empty argument",
1797 filename
, linenum
, keyword
);
1800 /* Allow "none" only in first position */
1801 if (strcasecmp(arg
, "none") == 0) {
1802 if (nstrs
> 0 || ac
> 0) {
1803 error("%s line %d: keyword %s \"none\" "
1804 "argument must appear alone.",
1805 filename
, linenum
, keyword
);
1809 opt_array_append(filename
, linenum
, keyword
,
1810 &strs
, &nstrs
, arg
);
1813 fatal("%s line %d: no %s specified",
1814 filename
, linenum
, keyword
);
1816 if (found
&& *activep
) {
1817 options
->log_verbose
= strs
;
1818 options
->num_log_verbose
= nstrs
;
1819 strs
= NULL
; /* transferred */
1824 case sAllowTcpForwarding
:
1825 intptr
= &options
->allow_tcp_forwarding
;
1826 multistate_ptr
= multistate_tcpfwd
;
1827 goto parse_multistate
;
1829 case sAllowStreamLocalForwarding
:
1830 intptr
= &options
->allow_streamlocal_forwarding
;
1831 multistate_ptr
= multistate_tcpfwd
;
1832 goto parse_multistate
;
1834 case sAllowAgentForwarding
:
1835 intptr
= &options
->allow_agent_forwarding
;
1838 case sDisableForwarding
:
1839 intptr
= &options
->disable_forwarding
;
1843 chararrayptr
= &options
->allow_users
;
1844 uintptr
= &options
->num_allow_users
;
1845 parse_allowdenyusers
:
1846 /* XXX appends to list; doesn't respect first-match-wins */
1847 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
1849 match_user(NULL
, NULL
, NULL
, arg
) == -1)
1850 fatal("%s line %d: invalid %s pattern: \"%s\"",
1851 filename
, linenum
, keyword
, arg
);
1855 opt_array_append(filename
, linenum
, keyword
,
1856 chararrayptr
, uintptr
, arg
);
1859 fatal("%s line %d: no %s specified",
1860 filename
, linenum
, keyword
);
1865 chararrayptr
= &options
->deny_users
;
1866 uintptr
= &options
->num_deny_users
;
1867 goto parse_allowdenyusers
;
1870 chararrayptr
= &options
->allow_groups
;
1871 uintptr
= &options
->num_allow_groups
;
1872 /* XXX appends to list; doesn't respect first-match-wins */
1873 parse_allowdenygroups
:
1874 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
1876 fatal("%s line %d: empty %s pattern",
1877 filename
, linenum
, keyword
);
1881 opt_array_append(filename
, linenum
, keyword
,
1882 chararrayptr
, uintptr
, arg
);
1885 fatal("%s line %d: no %s specified",
1886 filename
, linenum
, keyword
);
1891 chararrayptr
= &options
->deny_groups
;
1892 uintptr
= &options
->num_deny_groups
;
1893 goto parse_allowdenygroups
;
1896 arg
= argv_next(&ac
, &av
);
1897 if (!arg
|| *arg
== '\0')
1898 fatal("%s line %d: %s missing argument.",
1899 filename
, linenum
, keyword
);
1901 !ciphers_valid(*arg
== '+' || *arg
== '^' ? arg
+ 1 : arg
))
1902 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1903 filename
, linenum
, arg
? arg
: "<NONE>");
1904 if (options
->ciphers
== NULL
)
1905 options
->ciphers
= xstrdup(arg
);
1909 arg
= argv_next(&ac
, &av
);
1910 if (!arg
|| *arg
== '\0')
1911 fatal("%s line %d: %s missing argument.",
1912 filename
, linenum
, keyword
);
1914 !mac_valid(*arg
== '+' || *arg
== '^' ? arg
+ 1 : arg
))
1915 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1916 filename
, linenum
, arg
? arg
: "<NONE>");
1917 if (options
->macs
== NULL
)
1918 options
->macs
= xstrdup(arg
);
1921 case sKexAlgorithms
:
1922 arg
= argv_next(&ac
, &av
);
1923 if (!arg
|| *arg
== '\0')
1924 fatal("%s line %d: %s missing argument.",
1925 filename
, linenum
, keyword
);
1927 !kex_names_valid(*arg
== '+' || *arg
== '^' ?
1929 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1930 filename
, linenum
, arg
? arg
: "<NONE>");
1931 if (options
->kex_algorithms
== NULL
)
1932 options
->kex_algorithms
= xstrdup(arg
);
1936 arg
= argv_next(&ac
, &av
);
1937 if (!arg
|| *arg
== '\0')
1938 fatal("%s line %d: %s missing argument.",
1939 filename
, linenum
, keyword
);
1945 for (i
= 0; i
< options
->num_subsystems
; i
++) {
1946 if (strcmp(arg
, options
->subsystem_name
[i
]) == 0) {
1952 debug("%s line %d: Subsystem '%s' already defined.",
1953 filename
, linenum
, arg
);
1957 options
->subsystem_name
= xrecallocarray(
1958 options
->subsystem_name
, options
->num_subsystems
,
1959 options
->num_subsystems
+ 1,
1960 sizeof(*options
->subsystem_name
));
1961 options
->subsystem_command
= xrecallocarray(
1962 options
->subsystem_command
, options
->num_subsystems
,
1963 options
->num_subsystems
+ 1,
1964 sizeof(*options
->subsystem_command
));
1965 options
->subsystem_args
= xrecallocarray(
1966 options
->subsystem_args
, options
->num_subsystems
,
1967 options
->num_subsystems
+ 1,
1968 sizeof(*options
->subsystem_args
));
1969 options
->subsystem_name
[options
->num_subsystems
] = xstrdup(arg
);
1970 arg
= argv_next(&ac
, &av
);
1971 if (!arg
|| *arg
== '\0') {
1972 fatal("%s line %d: Missing subsystem command.",
1975 options
->subsystem_command
[options
->num_subsystems
] =
1977 /* Collect arguments (separate to executable) */
1978 arg
= argv_assemble(1, &arg
); /* quote command correctly */
1979 arg2
= argv_assemble(ac
, av
); /* rest of command */
1980 xasprintf(&options
->subsystem_args
[options
->num_subsystems
],
1981 "%s%s%s", arg
, *arg2
== '\0' ? "" : " ", arg2
);
1984 options
->num_subsystems
++;
1988 arg
= argv_next(&ac
, &av
);
1989 if (!arg
|| *arg
== '\0')
1990 fatal("%s line %d: %s missing argument.",
1991 filename
, linenum
, keyword
);
1992 if ((n
= sscanf(arg
, "%d:%d:%d",
1993 &options
->max_startups_begin
,
1994 &options
->max_startups_rate
,
1995 &options
->max_startups
)) == 3) {
1996 if (options
->max_startups_begin
>
1997 options
->max_startups
||
1998 options
->max_startups_rate
> 100 ||
1999 options
->max_startups_rate
< 1)
2000 fatal("%s line %d: Invalid %s spec.",
2001 filename
, linenum
, keyword
);
2003 fatal("%s line %d: Invalid %s spec.",
2004 filename
, linenum
, keyword
);
2006 options
->max_startups
= options
->max_startups_begin
;
2007 if (options
->max_startups
<= 0 ||
2008 options
->max_startups_begin
<= 0)
2009 fatal("%s line %d: Invalid %s spec.",
2010 filename
, linenum
, keyword
);
2013 case sPerSourceNetBlockSize
:
2014 arg
= argv_next(&ac
, &av
);
2015 if (!arg
|| *arg
== '\0')
2016 fatal("%s line %d: %s missing argument.",
2017 filename
, linenum
, keyword
);
2018 switch (n
= sscanf(arg
, "%d:%d", &value
, &value2
)) {
2020 if (value2
< 0 || value2
> 128)
2024 if (value
< 0 || value
> 32)
2027 if (n
!= 1 && n
!= 2)
2028 fatal("%s line %d: Invalid %s spec.",
2029 filename
, linenum
, keyword
);
2031 options
->per_source_masklen_ipv4
= value
;
2032 options
->per_source_masklen_ipv6
= value2
;
2036 case sPerSourceMaxStartups
:
2037 arg
= argv_next(&ac
, &av
);
2038 if (!arg
|| *arg
== '\0')
2039 fatal("%s line %d: %s missing argument.",
2040 filename
, linenum
, keyword
);
2041 if (strcmp(arg
, "none") == 0) { /* no limit */
2044 if ((errstr
= atoi_err(arg
, &value
)) != NULL
)
2045 fatal("%s line %d: %s integer value %s.",
2046 filename
, linenum
, keyword
, errstr
);
2048 if (*activep
&& options
->per_source_max_startups
== -1)
2049 options
->per_source_max_startups
= value
;
2053 intptr
= &options
->max_authtries
;
2057 intptr
= &options
->max_sessions
;
2061 charptr
= &options
->banner
;
2062 goto parse_filename
;
2065 * These options can contain %X options expanded at
2066 * connect time, so that you can specify paths like:
2068 * AuthorizedKeysFile /etc/ssh_keys/%u
2070 case sAuthorizedKeysFile
:
2071 found
= options
->num_authkeys_files
== 0;
2072 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
2074 error("%s line %d: keyword %s empty argument",
2075 filename
, linenum
, keyword
);
2078 arg2
= tilde_expand_filename(arg
, getuid());
2079 opt_array_append(filename
, linenum
, keyword
,
2080 &strs
, &nstrs
, arg2
);
2084 fatal("%s line %d: no %s specified",
2085 filename
, linenum
, keyword
);
2087 if (found
&& *activep
) {
2088 options
->authorized_keys_files
= strs
;
2089 options
->num_authkeys_files
= nstrs
;
2090 strs
= NULL
; /* transferred */
2095 case sAuthorizedPrincipalsFile
:
2096 charptr
= &options
->authorized_principals_file
;
2097 arg
= argv_next(&ac
, &av
);
2098 if (!arg
|| *arg
== '\0')
2099 fatal("%s line %d: %s missing argument.",
2100 filename
, linenum
, keyword
);
2101 if (*activep
&& *charptr
== NULL
) {
2102 *charptr
= tilde_expand_filename(arg
, getuid());
2103 /* increase optional counter */
2105 *intptr
= *intptr
+ 1;
2109 case sClientAliveInterval
:
2110 intptr
= &options
->client_alive_interval
;
2113 case sClientAliveCountMax
:
2114 intptr
= &options
->client_alive_count_max
;
2118 /* XXX appends to list; doesn't respect first-match-wins */
2119 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
2120 if (*arg
== '\0' || strchr(arg
, '=') != NULL
)
2121 fatal("%s line %d: Invalid environment name.",
2126 opt_array_append(filename
, linenum
, keyword
,
2127 &options
->accept_env
, &options
->num_accept_env
,
2131 fatal("%s line %d: no %s specified",
2132 filename
, linenum
, keyword
);
2137 found
= options
->num_setenv
== 0;
2138 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
2139 if (*arg
== '\0' || strchr(arg
, '=') == NULL
)
2140 fatal("%s line %d: Invalid environment.",
2142 if (lookup_setenv_in_list(arg
, strs
, nstrs
) != NULL
) {
2143 debug2("%s line %d: ignoring duplicate env "
2144 "name \"%.64s\"", filename
, linenum
, arg
);
2147 opt_array_append(filename
, linenum
, keyword
,
2148 &strs
, &nstrs
, arg
);
2151 fatal("%s line %d: no %s specified",
2152 filename
, linenum
, keyword
);
2154 if (found
&& *activep
) {
2155 options
->setenv
= strs
;
2156 options
->num_setenv
= nstrs
;
2157 strs
= NULL
; /* transferred */
2163 intptr
= &options
->permit_tun
;
2164 arg
= argv_next(&ac
, &av
);
2165 if (!arg
|| *arg
== '\0')
2166 fatal("%s line %d: %s missing argument.",
2167 filename
, linenum
, keyword
);
2169 for (i
= 0; tunmode_desc
[i
].val
!= -1; i
++)
2170 if (strcmp(tunmode_desc
[i
].text
, arg
) == 0) {
2171 value
= tunmode_desc
[i
].val
;
2175 fatal("%s line %d: bad %s argument %s",
2176 filename
, linenum
, keyword
, arg
);
2177 if (*activep
&& *intptr
== -1)
2183 fatal("Include directive not supported as a "
2184 "command-line option");
2187 while ((arg2
= argv_next(&ac
, &av
)) != NULL
) {
2188 if (*arg2
== '\0') {
2189 error("%s line %d: keyword %s empty argument",
2190 filename
, linenum
, keyword
);
2195 if (*arg2
!= '/' && *arg2
!= '~') {
2196 xasprintf(&arg
, "%s/%s", SSHDIR
, arg2
);
2198 arg
= xstrdup(arg2
);
2201 * Don't let included files clobber the containing
2202 * file's Match state.
2206 /* consult cache of include files */
2207 TAILQ_FOREACH(item
, includes
, entry
) {
2208 if (strcmp(item
->selector
, arg
) != 0)
2210 if (item
->filename
!= NULL
) {
2211 parse_server_config_depth(options
,
2212 item
->filename
, item
->contents
,
2213 includes
, connectinfo
,
2214 (*inc_flags
& SSHCFG_MATCH_ONLY
2215 ? SSHCFG_MATCH_ONLY
: (oactive
2216 ? 0 : SSHCFG_NEVERMATCH
)),
2217 activep
, depth
+ 1);
2227 /* requested glob was not in cache */
2228 debug2("%s line %d: new include %s",
2229 filename
, linenum
, arg
);
2230 if ((r
= glob(arg
, 0, NULL
, &gbuf
)) != 0) {
2231 if (r
!= GLOB_NOMATCH
) {
2232 fatal("%s line %d: include \"%s\" glob "
2233 "failed", filename
, linenum
, arg
);
2236 * If no entry matched then record a
2237 * placeholder to skip later glob calls.
2239 debug2("%s line %d: no match for %s",
2240 filename
, linenum
, arg
);
2241 item
= xcalloc(1, sizeof(*item
));
2242 item
->selector
= strdup(arg
);
2243 TAILQ_INSERT_TAIL(includes
,
2246 if (gbuf
.gl_pathc
> INT_MAX
)
2247 fatal_f("too many glob results");
2248 for (n
= 0; n
< (int)gbuf
.gl_pathc
; n
++) {
2249 debug2("%s line %d: including %s",
2250 filename
, linenum
, gbuf
.gl_pathv
[n
]);
2251 item
= xcalloc(1, sizeof(*item
));
2252 item
->selector
= strdup(arg
);
2253 item
->filename
= strdup(gbuf
.gl_pathv
[n
]);
2254 if ((item
->contents
= sshbuf_new()) == NULL
)
2255 fatal_f("sshbuf_new failed");
2256 load_server_config(item
->filename
,
2258 parse_server_config_depth(options
,
2259 item
->filename
, item
->contents
,
2260 includes
, connectinfo
,
2261 (*inc_flags
& SSHCFG_MATCH_ONLY
2262 ? SSHCFG_MATCH_ONLY
: (oactive
2263 ? 0 : SSHCFG_NEVERMATCH
)),
2264 activep
, depth
+ 1);
2266 TAILQ_INSERT_TAIL(includes
, item
, entry
);
2272 fatal("%s line %d: %s missing filename argument",
2273 filename
, linenum
, keyword
);
2279 fatal("Match directive not supported as a command-line "
2281 value
= match_cfg_line(&str
, linenum
,
2282 (*inc_flags
& SSHCFG_NEVERMATCH
? NULL
: connectinfo
));
2284 fatal("%s line %d: Bad Match condition", filename
,
2286 *activep
= (*inc_flags
& SSHCFG_NEVERMATCH
) ? 0 : value
;
2288 * The MATCH_ONLY flag is applicable only until the first
2291 *inc_flags
&= ~SSHCFG_MATCH_ONLY
;
2293 * If match_cfg_line() didn't consume all its arguments then
2294 * arrange for the extra arguments check below to fail.
2296 if (str
== NULL
|| *str
== '\0')
2302 if (opcode
== sPermitListen
) {
2303 uintptr
= &options
->num_permitted_listens
;
2304 chararrayptr
= &options
->permitted_listens
;
2306 uintptr
= &options
->num_permitted_opens
;
2307 chararrayptr
= &options
->permitted_opens
;
2309 found
= *uintptr
== 0;
2310 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
2311 if (strcmp(arg
, "any") == 0 ||
2312 strcmp(arg
, "none") == 0) {
2314 fatal("%s line %d: %s must appear "
2315 "alone on a %s line.",
2316 filename
, linenum
, arg
, keyword
);
2318 opt_array_append(filename
, linenum
, keyword
,
2319 &strs
, &nstrs
, arg
);
2323 if (opcode
== sPermitListen
&&
2324 strchr(arg
, ':') == NULL
) {
2326 * Allow bare port number for PermitListen
2327 * to indicate a wildcard listen host.
2329 xasprintf(&arg2
, "*:%s", arg
);
2331 arg2
= xstrdup(arg
);
2334 fatal("%s line %d: %s missing host",
2335 filename
, linenum
, keyword
);
2337 p
= cleanhostname(p
);
2340 ((port
= permitopen_port(arg
)) < 0)) {
2341 fatal("%s line %d: %s bad port number",
2342 filename
, linenum
, keyword
);
2344 opt_array_append(filename
, linenum
, keyword
,
2345 &strs
, &nstrs
, arg2
);
2349 fatal("%s line %d: %s missing argument.",
2350 filename
, linenum
, keyword
);
2352 if (found
&& *activep
) {
2353 *chararrayptr
= strs
;
2355 strs
= NULL
; /* transferred */
2361 if (str
== NULL
|| *str
== '\0')
2362 fatal("%s line %d: %s missing argument.",
2363 filename
, linenum
, keyword
);
2364 len
= strspn(str
, WHITESPACE
);
2365 if (*activep
&& options
->adm_forced_command
== NULL
)
2366 options
->adm_forced_command
= xstrdup(str
+ len
);
2370 case sChrootDirectory
:
2371 charptr
= &options
->chroot_directory
;
2373 arg
= argv_next(&ac
, &av
);
2374 if (!arg
|| *arg
== '\0')
2375 fatal("%s line %d: %s missing argument.",
2376 filename
, linenum
, keyword
);
2377 if (*activep
&& *charptr
== NULL
)
2378 *charptr
= xstrdup(arg
);
2381 case sTrustedUserCAKeys
:
2382 charptr
= &options
->trusted_user_ca_keys
;
2383 goto parse_filename
;
2386 charptr
= &options
->revoked_keys_file
;
2387 goto parse_filename
;
2389 case sSecurityKeyProvider
:
2390 charptr
= &options
->sk_provider
;
2391 arg
= argv_next(&ac
, &av
);
2392 if (!arg
|| *arg
== '\0')
2393 fatal("%s line %d: %s missing argument.",
2394 filename
, linenum
, keyword
);
2395 if (*activep
&& *charptr
== NULL
) {
2396 *charptr
= strcasecmp(arg
, "internal") == 0 ?
2397 xstrdup(arg
) : derelativise_path(arg
);
2398 /* increase optional counter */
2400 *intptr
= *intptr
+ 1;
2405 arg
= argv_next(&ac
, &av
);
2406 if (!arg
|| *arg
== '\0')
2407 fatal("%s line %d: %s missing argument.",
2408 filename
, linenum
, keyword
);
2409 if ((value
= parse_ipqos(arg
)) == -1)
2410 fatal("%s line %d: Bad %s value: %s",
2411 filename
, linenum
, keyword
, arg
);
2412 arg
= argv_next(&ac
, &av
);
2415 else if ((value2
= parse_ipqos(arg
)) == -1)
2416 fatal("%s line %d: Bad %s value: %s",
2417 filename
, linenum
, keyword
, arg
);
2419 options
->ip_qos_interactive
= value
;
2420 options
->ip_qos_bulk
= value2
;
2424 case sVersionAddendum
:
2425 if (str
== NULL
|| *str
== '\0')
2426 fatal("%s line %d: %s missing argument.",
2427 filename
, linenum
, keyword
);
2428 len
= strspn(str
, WHITESPACE
);
2429 if (strchr(str
+ len
, '\r') != NULL
) {
2430 fatal("%.200s line %d: Invalid %s argument",
2431 filename
, linenum
, keyword
);
2433 if ((arg
= strchr(line
, '#')) != NULL
) {
2437 if (*activep
&& options
->version_addendum
== NULL
) {
2438 if (strcasecmp(str
+ len
, "none") == 0)
2439 options
->version_addendum
= xstrdup("");
2441 options
->version_addendum
= xstrdup(str
+ len
);
2446 case sAuthorizedKeysCommand
:
2447 charptr
= &options
->authorized_keys_command
;
2449 len
= strspn(str
, WHITESPACE
);
2450 if (str
[len
] != '/' && strcasecmp(str
+ len
, "none") != 0) {
2451 fatal("%.200s line %d: %s must be an absolute path",
2452 filename
, linenum
, keyword
);
2454 if (*activep
&& *charptr
== NULL
)
2455 *charptr
= xstrdup(str
+ len
);
2459 case sAuthorizedKeysCommandUser
:
2460 charptr
= &options
->authorized_keys_command_user
;
2462 arg
= argv_next(&ac
, &av
);
2463 if (!arg
|| *arg
== '\0') {
2464 fatal("%s line %d: missing %s argument.",
2465 filename
, linenum
, keyword
);
2467 if (*activep
&& *charptr
== NULL
)
2468 *charptr
= xstrdup(arg
);
2471 case sAuthorizedPrincipalsCommand
:
2472 charptr
= &options
->authorized_principals_command
;
2475 case sAuthorizedPrincipalsCommandUser
:
2476 charptr
= &options
->authorized_principals_command_user
;
2477 goto parse_localuser
;
2479 case sAuthenticationMethods
:
2480 found
= options
->num_auth_methods
== 0;
2481 value
= 0; /* seen "any" pseudo-method */
2482 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
2483 if (strcmp(arg
, "any") == 0) {
2485 fatal("%s line %d: \"any\" must "
2486 "appear alone in %s",
2487 filename
, linenum
, keyword
);
2491 fatal("%s line %d: \"any\" must appear "
2492 "alone in %s", filename
, linenum
, keyword
);
2493 } else if (auth2_methods_valid(arg
, 0) != 0) {
2494 fatal("%s line %d: invalid %s method list.",
2495 filename
, linenum
, keyword
);
2497 opt_array_append(filename
, linenum
, keyword
,
2498 &strs
, &nstrs
, arg
);
2501 fatal("%s line %d: no %s specified",
2502 filename
, linenum
, keyword
);
2504 if (found
&& *activep
) {
2505 options
->auth_methods
= strs
;
2506 options
->num_auth_methods
= nstrs
;
2507 strs
= NULL
; /* transferred */
2512 case sStreamLocalBindMask
:
2513 arg
= argv_next(&ac
, &av
);
2514 if (!arg
|| *arg
== '\0')
2515 fatal("%s line %d: %s missing argument.",
2516 filename
, linenum
, keyword
);
2517 /* Parse mode in octal format */
2518 value
= strtol(arg
, &p
, 8);
2519 if (arg
== p
|| value
< 0 || value
> 0777)
2520 fatal("%s line %d: Invalid %s.",
2521 filename
, linenum
, keyword
);
2523 options
->fwd_opts
.streamlocal_bind_mask
= (mode_t
)value
;
2526 case sStreamLocalBindUnlink
:
2527 intptr
= &options
->fwd_opts
.streamlocal_bind_unlink
;
2530 case sFingerprintHash
:
2531 arg
= argv_next(&ac
, &av
);
2532 if (!arg
|| *arg
== '\0')
2533 fatal("%s line %d: %s missing argument.",
2534 filename
, linenum
, keyword
);
2535 if ((value
= ssh_digest_alg_by_name(arg
)) == -1)
2536 fatal("%.200s line %d: Invalid %s algorithm \"%s\".",
2537 filename
, linenum
, keyword
, arg
);
2539 options
->fingerprint_hash
= value
;
2542 case sExposeAuthInfo
:
2543 intptr
= &options
->expose_userauth_info
;
2547 #if !defined(__OpenBSD__) && !defined(HAVE_SYS_SET_PROCESS_RDOMAIN)
2548 fatal("%s line %d: setting RDomain not supported on this "
2549 "platform.", filename
, linenum
);
2551 charptr
= &options
->routing_domain
;
2552 arg
= argv_next(&ac
, &av
);
2553 if (!arg
|| *arg
== '\0')
2554 fatal("%s line %d: %s missing argument.",
2555 filename
, linenum
, keyword
);
2556 if (strcasecmp(arg
, "none") != 0 && strcmp(arg
, "%D") != 0 &&
2557 !valid_rdomain(arg
))
2558 fatal("%s line %d: invalid routing domain",
2560 if (*activep
&& *charptr
== NULL
)
2561 *charptr
= xstrdup(arg
);
2564 case sRequiredRSASize
:
2565 intptr
= &options
->required_rsa_size
;
2568 case sChannelTimeout
:
2569 found
= options
->num_channel_timeouts
== 0;
2570 while ((arg
= argv_next(&ac
, &av
)) != NULL
) {
2571 /* Allow "none" only in first position */
2572 if (strcasecmp(arg
, "none") == 0) {
2573 if (nstrs
> 0 || ac
> 0) {
2574 error("%s line %d: keyword %s \"none\" "
2575 "argument must appear alone.",
2576 filename
, linenum
, keyword
);
2579 } else if (parse_pattern_interval(arg
,
2581 fatal("%s line %d: invalid channel timeout %s",
2582 filename
, linenum
, arg
);
2584 opt_array_append(filename
, linenum
, keyword
,
2585 &strs
, &nstrs
, arg
);
2588 fatal("%s line %d: no %s specified",
2589 filename
, linenum
, keyword
);
2591 if (found
&& *activep
) {
2592 options
->channel_timeouts
= strs
;
2593 options
->num_channel_timeouts
= nstrs
;
2594 strs
= NULL
; /* transferred */
2599 case sUnusedConnectionTimeout
:
2600 intptr
= &options
->unused_connection_timeout
;
2601 /* peek at first arg for "none" so we can reuse parse_time */
2602 if (av
[0] != NULL
&& strcasecmp(av
[0], "none") == 0) {
2603 (void)argv_next(&ac
, &av
); /* consume arg */
2611 intptr
= &options
->use_blacklist
;
2617 do_log2(opcode
== sIgnore
?
2618 SYSLOG_LEVEL_DEBUG2
: SYSLOG_LEVEL_INFO
,
2619 "%s line %d: %s option %s", filename
, linenum
,
2620 opcode
== sUnsupported
? "Unsupported" : "Deprecated",
2626 fatal("%s line %d: Missing handler for opcode %s (%d)",
2627 filename
, linenum
, keyword
, opcode
);
2629 /* Check that there is no garbage at end of line. */
2631 error("%.200s line %d: keyword %s extra arguments "
2632 "at end of line", filename
, linenum
, keyword
);
2639 opt_array_free2(strs
, NULL
, nstrs
);
2640 argv_free(oav
, oac
);
2645 process_server_config_line(ServerOptions
*options
, char *line
,
2646 const char *filename
, int linenum
, int *activep
,
2647 struct connection_info
*connectinfo
, struct include_list
*includes
)
2651 return process_server_config_line_depth(options
, line
, filename
,
2652 linenum
, activep
, connectinfo
, &inc_flags
, 0, includes
);
2656 /* Reads the server configuration file. */
2659 load_server_config(const char *filename
, struct sshbuf
*conf
)
2662 char *line
= NULL
, *cp
;
2663 size_t linesize
= 0;
2667 debug2_f("filename %s", filename
);
2668 if ((f
= fopen(filename
, "r")) == NULL
) {
2673 /* grow buffer, so realloc is avoided for large config files */
2674 if (fstat(fileno(f
), &st
) == 0 && st
.st_size
> 0 &&
2675 (r
= sshbuf_allocate(conf
, st
.st_size
)) != 0)
2676 fatal_fr(r
, "allocate");
2677 while (getline(&line
, &linesize
, f
) != -1) {
2680 * NB - preserve newlines, they are needed to reproduce
2681 * line numbers later for error messages
2683 cp
= line
+ strspn(line
, " \t\r");
2684 if ((r
= sshbuf_put(conf
, cp
, strlen(cp
))) != 0)
2685 fatal_fr(r
, "sshbuf_put");
2688 if ((r
= sshbuf_put_u8(conf
, 0)) != 0)
2689 fatal_fr(r
, "sshbuf_put_u8");
2691 debug2_f("done config len = %zu", sshbuf_len(conf
));
2695 parse_server_match_config(ServerOptions
*options
,
2696 struct include_list
*includes
, struct connection_info
*connectinfo
)
2700 initialize_server_options(&mo
);
2701 parse_server_config(&mo
, "reprocess config", cfg
, includes
,
2703 copy_set_server_options(options
, &mo
, 0);
2706 int parse_server_match_testspec(struct connection_info
*ci
, char *spec
)
2710 while ((p
= strsep(&spec
, ",")) && *p
!= '\0') {
2711 if (strncmp(p
, "addr=", 5) == 0) {
2712 ci
->address
= xstrdup(p
+ 5);
2713 } else if (strncmp(p
, "host=", 5) == 0) {
2714 ci
->host
= xstrdup(p
+ 5);
2715 } else if (strncmp(p
, "user=", 5) == 0) {
2716 ci
->user
= xstrdup(p
+ 5);
2717 } else if (strncmp(p
, "laddr=", 6) == 0) {
2718 ci
->laddress
= xstrdup(p
+ 6);
2719 } else if (strncmp(p
, "rdomain=", 8) == 0) {
2720 ci
->rdomain
= xstrdup(p
+ 8);
2721 } else if (strncmp(p
, "lport=", 6) == 0) {
2722 ci
->lport
= a2port(p
+ 6);
2723 if (ci
->lport
== -1) {
2724 fprintf(stderr
, "Invalid port '%s' in test mode"
2725 " specification %s\n", p
+6, p
);
2729 fprintf(stderr
, "Invalid test mode specification %s\n",
2738 servconf_merge_subsystems(ServerOptions
*dst
, ServerOptions
*src
)
2742 for (i
= 0; i
< src
->num_subsystems
; i
++) {
2744 for (j
= 0; j
< dst
->num_subsystems
; j
++) {
2745 if (strcmp(src
->subsystem_name
[i
],
2746 dst
->subsystem_name
[j
]) == 0) {
2752 debug_f("override \"%s\"", dst
->subsystem_name
[j
]);
2753 free(dst
->subsystem_command
[j
]);
2754 free(dst
->subsystem_args
[j
]);
2755 dst
->subsystem_command
[j
] =
2756 xstrdup(src
->subsystem_command
[i
]);
2757 dst
->subsystem_args
[j
] =
2758 xstrdup(src
->subsystem_args
[i
]);
2761 debug_f("add \"%s\"", src
->subsystem_name
[i
]);
2762 dst
->subsystem_name
= xrecallocarray(
2763 dst
->subsystem_name
, dst
->num_subsystems
,
2764 dst
->num_subsystems
+ 1, sizeof(*dst
->subsystem_name
));
2765 dst
->subsystem_command
= xrecallocarray(
2766 dst
->subsystem_command
, dst
->num_subsystems
,
2767 dst
->num_subsystems
+ 1, sizeof(*dst
->subsystem_command
));
2768 dst
->subsystem_args
= xrecallocarray(
2769 dst
->subsystem_args
, dst
->num_subsystems
,
2770 dst
->num_subsystems
+ 1, sizeof(*dst
->subsystem_args
));
2771 j
= dst
->num_subsystems
++;
2772 dst
->subsystem_name
[j
] = xstrdup(src
->subsystem_name
[i
]);
2773 dst
->subsystem_command
[j
] = xstrdup(src
->subsystem_command
[i
]);
2774 dst
->subsystem_args
[j
] = xstrdup(src
->subsystem_args
[i
]);
2779 * Copy any supported values that are set.
2781 * If the preauth flag is set, we do not bother copying the string or
2782 * array values that are not used pre-authentication, because any that we
2783 * do use must be explicitly sent in mm_getpwnamallow().
2786 copy_set_server_options(ServerOptions
*dst
, ServerOptions
*src
, int preauth
)
2788 #define M_CP_INTOPT(n) do {\
2793 M_CP_INTOPT(password_authentication
);
2794 M_CP_INTOPT(gss_authentication
);
2795 M_CP_INTOPT(pubkey_authentication
);
2796 M_CP_INTOPT(pubkey_auth_options
);
2797 M_CP_INTOPT(kerberos_authentication
);
2798 M_CP_INTOPT(hostbased_authentication
);
2799 M_CP_INTOPT(hostbased_uses_name_from_packet_only
);
2800 M_CP_INTOPT(kbd_interactive_authentication
);
2801 M_CP_INTOPT(permit_root_login
);
2802 M_CP_INTOPT(permit_empty_passwd
);
2803 M_CP_INTOPT(ignore_rhosts
);
2805 M_CP_INTOPT(allow_tcp_forwarding
);
2806 M_CP_INTOPT(allow_streamlocal_forwarding
);
2807 M_CP_INTOPT(allow_agent_forwarding
);
2808 M_CP_INTOPT(disable_forwarding
);
2809 M_CP_INTOPT(expose_userauth_info
);
2810 M_CP_INTOPT(permit_tun
);
2811 M_CP_INTOPT(fwd_opts
.gateway_ports
);
2812 M_CP_INTOPT(fwd_opts
.streamlocal_bind_unlink
);
2813 M_CP_INTOPT(x11_display_offset
);
2814 M_CP_INTOPT(x11_forwarding
);
2815 M_CP_INTOPT(x11_use_localhost
);
2816 M_CP_INTOPT(permit_tty
);
2817 M_CP_INTOPT(permit_user_rc
);
2818 M_CP_INTOPT(max_sessions
);
2819 M_CP_INTOPT(max_authtries
);
2820 M_CP_INTOPT(client_alive_count_max
);
2821 M_CP_INTOPT(client_alive_interval
);
2822 M_CP_INTOPT(ip_qos_interactive
);
2823 M_CP_INTOPT(ip_qos_bulk
);
2824 M_CP_INTOPT(rekey_limit
);
2825 M_CP_INTOPT(rekey_interval
);
2826 M_CP_INTOPT(log_level
);
2827 M_CP_INTOPT(required_rsa_size
);
2828 M_CP_INTOPT(unused_connection_timeout
);
2831 * The bind_mask is a mode_t that may be unsigned, so we can't use
2832 * M_CP_INTOPT - it does a signed comparison that causes compiler
2835 if (src
->fwd_opts
.streamlocal_bind_mask
!= (mode_t
)-1) {
2836 dst
->fwd_opts
.streamlocal_bind_mask
=
2837 src
->fwd_opts
.streamlocal_bind_mask
;
2840 /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2841 #define M_CP_STROPT(n) do {\
2842 if (src->n != NULL && dst->n != src->n) { \
2847 #define M_CP_STRARRAYOPT(s, num_s) do {\
2849 if (src->num_s != 0) { \
2850 for (i = 0; i < dst->num_s; i++) \
2853 dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2854 for (i = 0; i < src->num_s; i++) \
2855 dst->s[i] = xstrdup(src->s[i]); \
2856 dst->num_s = src->num_s; \
2860 /* See comment in servconf.h */
2861 COPY_MATCH_STRING_OPTS();
2863 /* Arguments that accept '+...' need to be expanded */
2864 assemble_algorithms(dst
);
2867 * The only things that should be below this point are string options
2868 * which are only used after authentication.
2873 /* These options may be "none" to clear a global setting */
2874 M_CP_STROPT(adm_forced_command
);
2875 if (option_clear_or_none(dst
->adm_forced_command
)) {
2876 free(dst
->adm_forced_command
);
2877 dst
->adm_forced_command
= NULL
;
2879 M_CP_STROPT(chroot_directory
);
2880 if (option_clear_or_none(dst
->chroot_directory
)) {
2881 free(dst
->chroot_directory
);
2882 dst
->chroot_directory
= NULL
;
2885 /* Subsystems require merging. */
2886 servconf_merge_subsystems(dst
, src
);
2891 #undef M_CP_STRARRAYOPT
2893 #define SERVCONF_MAX_DEPTH 16
2895 parse_server_config_depth(ServerOptions
*options
, const char *filename
,
2896 struct sshbuf
*conf
, struct include_list
*includes
,
2897 struct connection_info
*connectinfo
, int flags
, int *activep
, int depth
)
2899 int linenum
, bad_options
= 0;
2900 char *cp
, *obuf
, *cbuf
;
2902 if (depth
< 0 || depth
> SERVCONF_MAX_DEPTH
)
2903 fatal("Too many recursive configuration includes");
2905 debug2_f("config %s len %zu%s", filename
, sshbuf_len(conf
),
2906 (flags
& SSHCFG_NEVERMATCH
? " [checking syntax only]" : ""));
2908 if ((obuf
= cbuf
= sshbuf_dup_string(conf
)) == NULL
)
2909 fatal_f("sshbuf_dup_string failed");
2911 while ((cp
= strsep(&cbuf
, "\n")) != NULL
) {
2912 if (process_server_config_line_depth(options
, cp
,
2913 filename
, linenum
++, activep
, connectinfo
, &flags
,
2914 depth
, includes
) != 0)
2918 if (bad_options
> 0)
2919 fatal("%s: terminating, %d bad configuration options",
2920 filename
, bad_options
);
2924 parse_server_config(ServerOptions
*options
, const char *filename
,
2925 struct sshbuf
*conf
, struct include_list
*includes
,
2926 struct connection_info
*connectinfo
, int reexec
)
2928 int active
= connectinfo
? 0 : 1;
2929 parse_server_config_depth(options
, filename
, conf
, includes
,
2930 connectinfo
, (connectinfo
? SSHCFG_MATCH_ONLY
: 0), &active
, 0);
2932 process_queued_listen_addrs(options
);
2936 fmt_multistate_int(int val
, const struct multistate
*m
)
2940 for (i
= 0; m
[i
].key
!= NULL
; i
++) {
2941 if (m
[i
].value
== val
)
2948 fmt_intarg(ServerOpCodes code
, int val
)
2953 case sAddressFamily
:
2954 return fmt_multistate_int(val
, multistate_addressfamily
);
2955 case sPermitRootLogin
:
2956 return fmt_multistate_int(val
, multistate_permitrootlogin
);
2958 return fmt_multistate_int(val
, multistate_gatewayports
);
2960 return fmt_multistate_int(val
, multistate_compression
);
2961 case sAllowTcpForwarding
:
2962 return fmt_multistate_int(val
, multistate_tcpfwd
);
2963 case sAllowStreamLocalForwarding
:
2964 return fmt_multistate_int(val
, multistate_tcpfwd
);
2966 return fmt_multistate_int(val
, multistate_ignore_rhosts
);
2967 case sFingerprintHash
:
2968 return ssh_digest_alg_name(val
);
2982 dump_cfg_int(ServerOpCodes code
, int val
)
2984 if (code
== sUnusedConnectionTimeout
&& val
== 0) {
2985 printf("%s none\n", lookup_opcode_name(code
));
2988 printf("%s %d\n", lookup_opcode_name(code
), val
);
2992 dump_cfg_oct(ServerOpCodes code
, int val
)
2994 printf("%s 0%o\n", lookup_opcode_name(code
), val
);
2998 dump_cfg_fmtint(ServerOpCodes code
, int val
)
3000 printf("%s %s\n", lookup_opcode_name(code
), fmt_intarg(code
, val
));
3004 dump_cfg_string(ServerOpCodes code
, const char *val
)
3006 printf("%s %s\n", lookup_opcode_name(code
),
3007 val
== NULL
? "none" : val
);
3011 dump_cfg_strarray(ServerOpCodes code
, u_int count
, char **vals
)
3015 for (i
= 0; i
< count
; i
++)
3016 printf("%s %s\n", lookup_opcode_name(code
), vals
[i
]);
3020 dump_cfg_strarray_oneline(ServerOpCodes code
, u_int count
, char **vals
)
3025 case sAuthenticationMethods
:
3026 case sChannelTimeout
:
3034 printf("%s", lookup_opcode_name(code
));
3035 for (i
= 0; i
< count
; i
++)
3036 printf(" %s", vals
[i
]);
3037 if (code
== sAuthenticationMethods
&& count
== 0)
3039 else if (code
== sChannelTimeout
&& count
== 0)
3045 format_listen_addrs(struct listenaddr
*la
)
3048 struct addrinfo
*ai
;
3049 char addr
[NI_MAXHOST
], port
[NI_MAXSERV
];
3050 char *laddr1
= xstrdup(""), *laddr2
= NULL
;
3053 * ListenAddress must be after Port. add_one_listen_addr pushes
3054 * addresses onto a stack, so to maintain ordering we need to
3055 * print these in reverse order.
3057 for (ai
= la
->addrs
; ai
; ai
= ai
->ai_next
) {
3058 if ((r
= getnameinfo(ai
->ai_addr
, ai
->ai_addrlen
, addr
,
3059 sizeof(addr
), port
, sizeof(port
),
3060 NI_NUMERICHOST
|NI_NUMERICSERV
)) != 0) {
3061 error("getnameinfo: %.100s", ssh_gai_strerror(r
));
3065 if (ai
->ai_family
== AF_INET6
) {
3066 xasprintf(&laddr1
, "listenaddress [%s]:%s%s%s\n%s",
3068 la
->rdomain
== NULL
? "" : " rdomain ",
3069 la
->rdomain
== NULL
? "" : la
->rdomain
,
3072 xasprintf(&laddr1
, "listenaddress %s:%s%s%s\n%s",
3074 la
->rdomain
== NULL
? "" : " rdomain ",
3075 la
->rdomain
== NULL
? "" : la
->rdomain
,
3084 dump_config(ServerOptions
*o
)
3089 /* these are usually at the top of the config */
3090 for (i
= 0; i
< o
->num_ports
; i
++)
3091 printf("port %d\n", o
->ports
[i
]);
3092 dump_cfg_fmtint(sAddressFamily
, o
->address_family
);
3094 for (i
= 0; i
< o
->num_listen_addrs
; i
++) {
3095 s
= format_listen_addrs(&o
->listen_addrs
[i
]);
3100 /* integer arguments */
3102 dump_cfg_fmtint(sUsePAM
, o
->use_pam
);
3104 dump_cfg_int(sLoginGraceTime
, o
->login_grace_time
);
3105 dump_cfg_int(sX11DisplayOffset
, o
->x11_display_offset
);
3106 dump_cfg_int(sMaxAuthTries
, o
->max_authtries
);
3107 dump_cfg_int(sMaxSessions
, o
->max_sessions
);
3108 dump_cfg_int(sClientAliveInterval
, o
->client_alive_interval
);
3109 dump_cfg_int(sClientAliveCountMax
, o
->client_alive_count_max
);
3110 dump_cfg_int(sRequiredRSASize
, o
->required_rsa_size
);
3111 dump_cfg_oct(sStreamLocalBindMask
, o
->fwd_opts
.streamlocal_bind_mask
);
3112 dump_cfg_int(sUnusedConnectionTimeout
, o
->unused_connection_timeout
);
3114 /* formatted integer arguments */
3115 dump_cfg_fmtint(sPermitRootLogin
, o
->permit_root_login
);
3116 dump_cfg_fmtint(sIgnoreRhosts
, o
->ignore_rhosts
);
3117 dump_cfg_fmtint(sIgnoreUserKnownHosts
, o
->ignore_user_known_hosts
);
3118 dump_cfg_fmtint(sHostbasedAuthentication
, o
->hostbased_authentication
);
3119 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly
,
3120 o
->hostbased_uses_name_from_packet_only
);
3121 dump_cfg_fmtint(sPubkeyAuthentication
, o
->pubkey_authentication
);
3123 dump_cfg_fmtint(sKerberosAuthentication
, o
->kerberos_authentication
);
3124 dump_cfg_fmtint(sKerberosOrLocalPasswd
, o
->kerberos_or_local_passwd
);
3125 dump_cfg_fmtint(sKerberosTicketCleanup
, o
->kerberos_ticket_cleanup
);
3127 dump_cfg_fmtint(sKerberosGetAFSToken
, o
->kerberos_get_afs_token
);
3131 dump_cfg_fmtint(sGssAuthentication
, o
->gss_authentication
);
3132 dump_cfg_fmtint(sGssCleanupCreds
, o
->gss_cleanup_creds
);
3134 dump_cfg_fmtint(sPasswordAuthentication
, o
->password_authentication
);
3135 dump_cfg_fmtint(sKbdInteractiveAuthentication
,
3136 o
->kbd_interactive_authentication
);
3137 dump_cfg_fmtint(sPrintMotd
, o
->print_motd
);
3138 #ifndef DISABLE_LASTLOG
3139 dump_cfg_fmtint(sPrintLastLog
, o
->print_lastlog
);
3141 dump_cfg_fmtint(sX11Forwarding
, o
->x11_forwarding
);
3142 dump_cfg_fmtint(sX11UseLocalhost
, o
->x11_use_localhost
);
3143 dump_cfg_fmtint(sPermitTTY
, o
->permit_tty
);
3144 dump_cfg_fmtint(sPermitUserRC
, o
->permit_user_rc
);
3145 dump_cfg_fmtint(sStrictModes
, o
->strict_modes
);
3146 dump_cfg_fmtint(sTCPKeepAlive
, o
->tcp_keep_alive
);
3147 dump_cfg_fmtint(sEmptyPasswd
, o
->permit_empty_passwd
);
3148 dump_cfg_fmtint(sCompression
, o
->compression
);
3149 dump_cfg_fmtint(sGatewayPorts
, o
->fwd_opts
.gateway_ports
);
3150 dump_cfg_fmtint(sUseDNS
, o
->use_dns
);
3151 dump_cfg_fmtint(sAllowTcpForwarding
, o
->allow_tcp_forwarding
);
3152 dump_cfg_fmtint(sAllowAgentForwarding
, o
->allow_agent_forwarding
);
3153 dump_cfg_fmtint(sDisableForwarding
, o
->disable_forwarding
);
3154 dump_cfg_fmtint(sAllowStreamLocalForwarding
, o
->allow_streamlocal_forwarding
);
3155 dump_cfg_fmtint(sStreamLocalBindUnlink
, o
->fwd_opts
.streamlocal_bind_unlink
);
3156 dump_cfg_fmtint(sFingerprintHash
, o
->fingerprint_hash
);
3157 dump_cfg_fmtint(sExposeAuthInfo
, o
->expose_userauth_info
);
3158 dump_cfg_fmtint(sUseBlacklist
, o
->use_blacklist
);
3160 /* string arguments */
3161 dump_cfg_string(sPidFile
, o
->pid_file
);
3162 dump_cfg_string(sModuliFile
, o
->moduli_file
);
3163 dump_cfg_string(sXAuthLocation
, o
->xauth_location
);
3164 dump_cfg_string(sCiphers
, o
->ciphers
);
3165 dump_cfg_string(sMacs
, o
->macs
);
3166 dump_cfg_string(sBanner
, o
->banner
);
3167 dump_cfg_string(sForceCommand
, o
->adm_forced_command
);
3168 dump_cfg_string(sChrootDirectory
, o
->chroot_directory
);
3169 dump_cfg_string(sTrustedUserCAKeys
, o
->trusted_user_ca_keys
);
3170 dump_cfg_string(sRevokedKeys
, o
->revoked_keys_file
);
3171 dump_cfg_string(sSecurityKeyProvider
, o
->sk_provider
);
3172 dump_cfg_string(sAuthorizedPrincipalsFile
,
3173 o
->authorized_principals_file
);
3174 dump_cfg_string(sVersionAddendum
, *o
->version_addendum
== '\0'
3175 ? "none" : o
->version_addendum
);
3176 dump_cfg_string(sAuthorizedKeysCommand
, o
->authorized_keys_command
);
3177 dump_cfg_string(sAuthorizedKeysCommandUser
, o
->authorized_keys_command_user
);
3178 dump_cfg_string(sAuthorizedPrincipalsCommand
, o
->authorized_principals_command
);
3179 dump_cfg_string(sAuthorizedPrincipalsCommandUser
, o
->authorized_principals_command_user
);
3180 dump_cfg_string(sHostKeyAgent
, o
->host_key_agent
);
3181 dump_cfg_string(sKexAlgorithms
, o
->kex_algorithms
);
3182 dump_cfg_string(sCASignatureAlgorithms
, o
->ca_sign_algorithms
);
3183 dump_cfg_string(sHostbasedAcceptedAlgorithms
, o
->hostbased_accepted_algos
);
3184 dump_cfg_string(sHostKeyAlgorithms
, o
->hostkeyalgorithms
);
3185 dump_cfg_string(sPubkeyAcceptedAlgorithms
, o
->pubkey_accepted_algos
);
3186 #if defined(__OpenBSD__) || defined(HAVE_SYS_SET_PROCESS_RDOMAIN)
3187 dump_cfg_string(sRDomain
, o
->routing_domain
);
3190 /* string arguments requiring a lookup */
3191 dump_cfg_string(sLogLevel
, log_level_name(o
->log_level
));
3192 dump_cfg_string(sLogFacility
, log_facility_name(o
->log_facility
));
3194 /* string array arguments */
3195 dump_cfg_strarray_oneline(sAuthorizedKeysFile
, o
->num_authkeys_files
,
3196 o
->authorized_keys_files
);
3197 dump_cfg_strarray(sHostKeyFile
, o
->num_host_key_files
,
3199 dump_cfg_strarray(sHostCertificate
, o
->num_host_cert_files
,
3200 o
->host_cert_files
);
3201 dump_cfg_strarray(sAllowUsers
, o
->num_allow_users
, o
->allow_users
);
3202 dump_cfg_strarray(sDenyUsers
, o
->num_deny_users
, o
->deny_users
);
3203 dump_cfg_strarray(sAllowGroups
, o
->num_allow_groups
, o
->allow_groups
);
3204 dump_cfg_strarray(sDenyGroups
, o
->num_deny_groups
, o
->deny_groups
);
3205 dump_cfg_strarray(sAcceptEnv
, o
->num_accept_env
, o
->accept_env
);
3206 dump_cfg_strarray(sSetEnv
, o
->num_setenv
, o
->setenv
);
3207 dump_cfg_strarray_oneline(sAuthenticationMethods
,
3208 o
->num_auth_methods
, o
->auth_methods
);
3209 dump_cfg_strarray_oneline(sLogVerbose
,
3210 o
->num_log_verbose
, o
->log_verbose
);
3211 dump_cfg_strarray_oneline(sChannelTimeout
,
3212 o
->num_channel_timeouts
, o
->channel_timeouts
);
3214 /* other arguments */
3215 for (i
= 0; i
< o
->num_subsystems
; i
++)
3216 printf("subsystem %s %s\n", o
->subsystem_name
[i
],
3217 o
->subsystem_args
[i
]);
3219 printf("maxstartups %d:%d:%d\n", o
->max_startups_begin
,
3220 o
->max_startups_rate
, o
->max_startups
);
3221 printf("persourcemaxstartups ");
3222 if (o
->per_source_max_startups
== INT_MAX
)
3225 printf("%d\n", o
->per_source_max_startups
);
3226 printf("persourcenetblocksize %d:%d\n", o
->per_source_masklen_ipv4
,
3227 o
->per_source_masklen_ipv6
);
3230 for (i
= 0; tunmode_desc
[i
].val
!= -1; i
++) {
3231 if (tunmode_desc
[i
].val
== o
->permit_tun
) {
3232 s
= tunmode_desc
[i
].text
;
3236 dump_cfg_string(sPermitTunnel
, s
);
3238 printf("ipqos %s ", iptos2str(o
->ip_qos_interactive
));
3239 printf("%s\n", iptos2str(o
->ip_qos_bulk
));
3241 printf("rekeylimit %llu %d\n", (unsigned long long)o
->rekey_limit
,
3244 printf("permitopen");
3245 if (o
->num_permitted_opens
== 0)
3248 for (i
= 0; i
< o
->num_permitted_opens
; i
++)
3249 printf(" %s", o
->permitted_opens
[i
]);
3252 printf("permitlisten");
3253 if (o
->num_permitted_listens
== 0)
3256 for (i
= 0; i
< o
->num_permitted_listens
; i
++)
3257 printf(" %s", o
->permitted_listens
[i
]);
3261 if (o
->permit_user_env_allowlist
== NULL
) {
3262 dump_cfg_fmtint(sPermitUserEnvironment
, o
->permit_user_env
);
3264 printf("permituserenvironment %s\n",
3265 o
->permit_user_env_allowlist
);
3268 printf("pubkeyauthoptions");
3269 if (o
->pubkey_auth_options
== 0)
3271 if (o
->pubkey_auth_options
& PUBKEYAUTH_TOUCH_REQUIRED
)
3272 printf(" touch-required");
3273 if (o
->pubkey_auth_options
& PUBKEYAUTH_VERIFY_REQUIRED
)
3274 printf(" verify-required");