2 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * As far as I am concerned, the code I have written for this software
6 * can be used freely for any purpose. Any derived versions of this
7 * software must be clearly marked as such, and if the derived work is
8 * incompatible with the protocol description in the RFC file, it must be
9 * called by a name other than "ssh" or "Secure Shell".
12 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
13 * Copyright 2013 Joyent, Inc. All rights reserved.
17 RCSID("$OpenBSD: servconf.c,v 1.115 2002/09/04 18:52:42 stevesk Exp $");
21 #endif /* HAVE_DEFOPEN */
30 /* Bodge - but then, so is using the kerberos IV KEYFILE to get a Kerberos V
32 #define KEYFILE "/etc/krb5.keytab"
45 #include "pathnames.h"
46 #include "tildexpand.h"
53 #include "groupaccess.h"
55 static void add_listen_addr(ServerOptions
*, char *, u_short
);
56 static void add_one_listen_addr(ServerOptions
*, char *, u_short
);
60 /* AF_UNSPEC or AF_INET or AF_INET6 */
64 * Initializes the server options to their initial (unset) values. Some of those
65 * that stay unset after the command line options and configuration files are
66 * read are set to their default values in fill_default_server_options().
69 initialize_server_options(ServerOptions
*options
)
71 (void) memset(options
, 0, sizeof(*options
));
73 /* Standard Options */
74 options
->num_ports
= 0;
75 options
->ports_from_cmdline
= 0;
76 options
->listen_addrs
= NULL
;
77 options
->num_host_key_files
= 0;
78 options
->pid_file
= NULL
;
79 options
->server_key_bits
= -1;
80 options
->login_grace_time
= -1;
81 options
->key_regeneration_time
= -1;
82 options
->permit_root_login
= PERMIT_NOT_SET
;
83 options
->ignore_rhosts
= -1;
84 options
->ignore_user_known_hosts
= -1;
85 options
->print_motd
= -1;
86 options
->print_lastlog
= -1;
87 options
->x11_forwarding
= -1;
88 options
->x11_display_offset
= -1;
89 options
->x11_use_localhost
= -1;
90 options
->xauth_location
= NULL
;
91 options
->strict_modes
= -1;
92 options
->keepalives
= -1;
93 options
->log_facility
= SYSLOG_FACILITY_NOT_SET
;
94 options
->log_level
= SYSLOG_LEVEL_NOT_SET
;
95 options
->rhosts_authentication
= -1;
96 options
->rhosts_rsa_authentication
= -1;
97 options
->hostbased_authentication
= -1;
98 options
->hostbased_uses_name_from_packet_only
= -1;
99 options
->rsa_authentication
= -1;
100 options
->pubkey_authentication
= -1;
102 options
->gss_authentication
= -1;
103 options
->gss_keyex
= -1;
104 options
->gss_store_creds
= -1;
105 options
->gss_use_session_ccache
= -1;
106 options
->gss_cleanup_creds
= -1;
108 #if defined(KRB4) || defined(KRB5)
109 options
->kerberos_authentication
= -1;
110 options
->kerberos_or_local_passwd
= -1;
111 options
->kerberos_ticket_cleanup
= -1;
113 #if defined(AFS) || defined(KRB5)
114 options
->kerberos_tgt_passing
= -1;
117 options
->afs_token_passing
= -1;
119 options
->password_authentication
= -1;
120 options
->kbd_interactive_authentication
= -1;
121 options
->challenge_response_authentication
= -1;
122 options
->pam_authentication_via_kbd_int
= -1;
123 options
->permit_empty_passwd
= -1;
124 options
->permit_user_env
= -1;
125 options
->compression
= -1;
126 options
->allow_tcp_forwarding
= -1;
127 options
->num_allow_users
= 0;
128 options
->num_deny_users
= 0;
129 options
->num_allow_groups
= 0;
130 options
->num_deny_groups
= 0;
131 options
->ciphers
= NULL
;
132 options
->macs
= NULL
;
133 options
->protocol
= SSH_PROTO_UNKNOWN
;
134 options
->gateway_ports
= -1;
135 options
->num_subsystems
= 0;
136 options
->max_startups_begin
= -1;
137 options
->max_startups_rate
= -1;
138 options
->max_startups
= -1;
139 options
->banner
= NULL
;
140 options
->verify_reverse_mapping
= -1;
141 options
->client_alive_interval
= -1;
142 options
->client_alive_count_max
= -1;
143 options
->authorized_keys_file
= NULL
;
144 options
->authorized_keys_file2
= NULL
;
146 options
->max_auth_tries
= -1;
147 options
->max_auth_tries_log
= -1;
149 options
->max_init_auth_tries
= -1;
150 options
->max_init_auth_tries_log
= -1;
152 options
->lookup_client_hostnames
= -1;
153 options
->use_openssl_engine
= -1;
154 options
->chroot_directory
= NULL
;
155 options
->pre_userauth_hook
= NULL
;
156 options
->pam_service_name
= NULL
;
157 options
->pam_service_prefix
= NULL
;
162 * Reads /etc/default/login and defaults several ServerOptions:
165 * PermitEmptyPasswords
168 * CONSOLE=* -> PermitRootLogin=without-password
169 * #CONSOLE=* -> PermitRootLogin=yes
171 * PASSREQ=YES -> PermitEmptyPasswords=no
172 * PASSREQ=NO -> PermitEmptyPasswords=yes
173 * #PASSREQ=* -> PermitEmptyPasswords=no
175 * TIMEOUT=<secs> -> LoginGraceTime=<secs>
176 * #TIMEOUT=<secs> -> LoginGraceTime=300
180 deflt_fill_default_server_options(ServerOptions
*options
)
185 if (defopen(_PATH_DEFAULT_LOGIN
))
189 flags
= defcntl(DC_GETFLAGS
, 0);
190 TURNOFF(flags
, DC_CASE
);
191 (void) defcntl(DC_SETFLAGS
, flags
);
193 if (options
->permit_root_login
== PERMIT_NOT_SET
&&
194 (ptr
= defread("CONSOLE=")) != NULL
)
195 options
->permit_root_login
= PERMIT_NO_PASSWD
;
197 if (options
->permit_empty_passwd
== -1 &&
198 (ptr
= defread("PASSREQ=")) != NULL
) {
199 if (strcasecmp("YES", ptr
) == 0)
200 options
->permit_empty_passwd
= 0;
201 else if (strcasecmp("NO", ptr
) == 0)
202 options
->permit_empty_passwd
= 1;
205 if (options
->max_init_auth_tries
== -1 &&
206 (ptr
= defread("RETRIES=")) != NULL
) {
207 options
->max_init_auth_tries
= atoi(ptr
);
210 if (options
->max_init_auth_tries_log
== -1 &&
211 (ptr
= defread("SYSLOG_FAILED_LOGINS=")) != NULL
) {
212 options
->max_init_auth_tries_log
= atoi(ptr
);
215 if (options
->login_grace_time
== -1) {
216 if ((ptr
= defread("TIMEOUT=")) != NULL
)
217 options
->login_grace_time
= (unsigned)atoi(ptr
);
219 options
->login_grace_time
= 300;
222 (void) defopen((char *)NULL
);
224 #endif /* HAVE_DEFOPEN */
227 fill_default_server_options(ServerOptions
*options
)
231 deflt_fill_default_server_options(options
);
232 #endif /* HAVE_DEFOPEN */
234 /* Standard Options */
235 if (options
->protocol
== SSH_PROTO_UNKNOWN
)
236 options
->protocol
= SSH_PROTO_1
|SSH_PROTO_2
;
237 if (options
->num_host_key_files
== 0) {
238 /* fill default hostkeys for protocols */
239 if (options
->protocol
& SSH_PROTO_1
)
240 options
->host_key_files
[options
->num_host_key_files
++] =
243 /* With GSS keyex we can run v2 w/ no host keys */
244 if (options
->protocol
& SSH_PROTO_2
) {
245 options
->host_key_files
[options
->num_host_key_files
++] =
246 _PATH_HOST_RSA_KEY_FILE
;
247 options
->host_key_files
[options
->num_host_key_files
++] =
248 _PATH_HOST_DSA_KEY_FILE
;
252 if (options
->num_ports
== 0)
253 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
254 if (options
->listen_addrs
== NULL
)
255 add_listen_addr(options
, NULL
, 0);
256 if (options
->pid_file
== NULL
)
257 options
->pid_file
= _PATH_SSH_DAEMON_PID_FILE
;
258 if (options
->server_key_bits
== -1)
259 options
->server_key_bits
= 768;
260 if (options
->login_grace_time
== -1)
261 options
->login_grace_time
= 120;
262 if (options
->key_regeneration_time
== -1)
263 options
->key_regeneration_time
= 3600;
264 if (options
->permit_root_login
== PERMIT_NOT_SET
)
265 options
->permit_root_login
= PERMIT_YES
;
266 if (options
->ignore_rhosts
== -1)
267 options
->ignore_rhosts
= 1;
268 if (options
->ignore_user_known_hosts
== -1)
269 options
->ignore_user_known_hosts
= 0;
270 if (options
->print_motd
== -1)
271 options
->print_motd
= 1;
272 if (options
->print_lastlog
== -1)
273 options
->print_lastlog
= 1;
274 if (options
->x11_forwarding
== -1)
275 options
->x11_forwarding
= 1;
276 if (options
->x11_display_offset
== -1)
277 options
->x11_display_offset
= 10;
278 if (options
->x11_use_localhost
== -1)
279 options
->x11_use_localhost
= 1;
280 if (options
->xauth_location
== NULL
)
281 options
->xauth_location
= _PATH_XAUTH
;
282 if (options
->strict_modes
== -1)
283 options
->strict_modes
= 1;
284 if (options
->keepalives
== -1)
285 options
->keepalives
= 1;
286 if (options
->log_facility
== SYSLOG_FACILITY_NOT_SET
)
287 options
->log_facility
= SYSLOG_FACILITY_AUTH
;
288 if (options
->log_level
== SYSLOG_LEVEL_NOT_SET
)
289 options
->log_level
= SYSLOG_LEVEL_INFO
;
290 if (options
->rhosts_authentication
== -1)
291 options
->rhosts_authentication
= 0;
292 if (options
->rhosts_rsa_authentication
== -1)
293 options
->rhosts_rsa_authentication
= 0;
294 if (options
->hostbased_authentication
== -1)
295 options
->hostbased_authentication
= 0;
296 if (options
->hostbased_uses_name_from_packet_only
== -1)
297 options
->hostbased_uses_name_from_packet_only
= 0;
298 if (options
->rsa_authentication
== -1)
299 options
->rsa_authentication
= 1;
300 if (options
->pubkey_authentication
== -1)
301 options
->pubkey_authentication
= 1;
303 if (options
->gss_authentication
== -1)
304 options
->gss_authentication
= 1;
305 if (options
->gss_keyex
== -1)
306 options
->gss_keyex
= 1;
307 if (options
->gss_store_creds
== -1)
308 options
->gss_store_creds
= 1;
309 if (options
->gss_use_session_ccache
== -1)
310 options
->gss_use_session_ccache
= 1;
311 if (options
->gss_cleanup_creds
== -1)
312 options
->gss_cleanup_creds
= 1;
314 #if defined(KRB4) || defined(KRB5)
315 if (options
->kerberos_authentication
== -1)
316 options
->kerberos_authentication
= 0;
317 if (options
->kerberos_or_local_passwd
== -1)
318 options
->kerberos_or_local_passwd
= 1;
319 if (options
->kerberos_ticket_cleanup
== -1)
320 options
->kerberos_ticket_cleanup
= 1;
322 #if defined(AFS) || defined(KRB5)
323 if (options
->kerberos_tgt_passing
== -1)
324 options
->kerberos_tgt_passing
= 0;
327 if (options
->afs_token_passing
== -1)
328 options
->afs_token_passing
= 0;
330 if (options
->password_authentication
== -1)
331 options
->password_authentication
= 1;
333 * options->pam_authentication_via_kbd_int has intentionally no default
334 * value since we do not need it.
336 if (options
->kbd_interactive_authentication
== -1)
337 options
->kbd_interactive_authentication
= 1;
338 if (options
->challenge_response_authentication
== -1)
339 options
->challenge_response_authentication
= 1;
340 if (options
->permit_empty_passwd
== -1)
341 options
->permit_empty_passwd
= 0;
342 if (options
->permit_user_env
== -1)
343 options
->permit_user_env
= 0;
344 if (options
->compression
== -1)
345 options
->compression
= 1;
346 if (options
->allow_tcp_forwarding
== -1)
347 options
->allow_tcp_forwarding
= 1;
348 if (options
->gateway_ports
== -1)
349 options
->gateway_ports
= 0;
350 if (options
->max_startups
== -1)
351 options
->max_startups
= 10;
352 if (options
->max_startups_rate
== -1)
353 options
->max_startups_rate
= 100; /* 100% */
354 if (options
->max_startups_begin
== -1)
355 options
->max_startups_begin
= options
->max_startups
;
356 if (options
->verify_reverse_mapping
== -1)
357 options
->verify_reverse_mapping
= 0;
358 if (options
->client_alive_interval
== -1)
359 options
->client_alive_interval
= 0;
360 if (options
->client_alive_count_max
== -1)
361 options
->client_alive_count_max
= 3;
362 if (options
->authorized_keys_file2
== NULL
) {
363 /* authorized_keys_file2 falls back to authorized_keys_file */
364 if (options
->authorized_keys_file
!= NULL
)
365 options
->authorized_keys_file2
= options
->authorized_keys_file
;
367 options
->authorized_keys_file2
= _PATH_SSH_USER_PERMITTED_KEYS2
;
369 if (options
->authorized_keys_file
== NULL
)
370 options
->authorized_keys_file
= _PATH_SSH_USER_PERMITTED_KEYS
;
372 if (options
->max_auth_tries
== -1)
373 options
->max_auth_tries
= AUTH_FAIL_MAX
;
374 if (options
->max_auth_tries_log
== -1)
375 options
->max_auth_tries_log
= options
->max_auth_tries
/ 2;
377 if (options
->max_init_auth_tries
== -1)
378 options
->max_init_auth_tries
= AUTH_FAIL_MAX
;
379 if (options
->max_init_auth_tries_log
== -1)
380 options
->max_init_auth_tries_log
= options
->max_init_auth_tries
/ 2;
382 if (options
->lookup_client_hostnames
== -1)
383 options
->lookup_client_hostnames
= 1;
384 if (options
->use_openssl_engine
== -1)
385 options
->use_openssl_engine
= 1;
386 if (options
->pam_service_prefix
== NULL
)
387 options
->pam_service_prefix
= _SSH_PAM_SERVICE_PREFIX
;
388 if (options
->pam_service_name
== NULL
)
389 options
->pam_service_name
= NULL
;
392 /* Keyword tokens. */
394 sBadOption
, /* == unknown option */
395 /* Portable-specific options */
396 sPAMAuthenticationViaKbdInt
,
397 /* Standard Options */
398 sPort
, sHostKeyFile
, sServerKeyBits
, sLoginGraceTime
, sKeyRegenerationTime
,
399 sPermitRootLogin
, sLogFacility
, sLogLevel
,
400 sRhostsAuthentication
, sRhostsRSAAuthentication
, sRSAAuthentication
,
402 sGssAuthentication
, sGssKeyEx
, sGssStoreDelegCreds
,
403 sGssUseSessionCredCache
, sGssCleanupCreds
,
405 #if defined(KRB4) || defined(KRB5)
406 sKerberosAuthentication
, sKerberosOrLocalPasswd
, sKerberosTicketCleanup
,
408 #if defined(AFS) || defined(KRB5)
414 sChallengeResponseAuthentication
,
415 sPasswordAuthentication
, sKbdInteractiveAuthentication
, sListenAddress
,
416 sPrintMotd
, sPrintLastLog
, sIgnoreRhosts
,
417 sX11Forwarding
, sX11DisplayOffset
, sX11UseLocalhost
,
418 sStrictModes
, sEmptyPasswd
, sKeepAlives
,
419 sPermitUserEnvironment
, sUseLogin
, sAllowTcpForwarding
, sCompression
,
420 sAllowUsers
, sDenyUsers
, sAllowGroups
, sDenyGroups
,
421 sIgnoreUserKnownHosts
, sCiphers
, sMacs
, sProtocol
, sPidFile
,
422 sGatewayPorts
, sPubkeyAuthentication
, sXAuthLocation
, sSubsystem
, sMaxStartups
,
423 sBanner
, sVerifyReverseMapping
, sHostbasedAuthentication
,
424 sHostbasedUsesNameFromPacketOnly
, sClientAliveInterval
,
425 sClientAliveCountMax
, sAuthorizedKeysFile
, sAuthorizedKeysFile2
,
426 sMaxAuthTries
, sMaxAuthTriesLog
, sUsePrivilegeSeparation
,
427 sLookupClientHostnames
, sUseOpenSSLEngine
, sChrootDirectory
,
428 sPreUserauthHook
, sMatch
, sPAMServicePrefix
, sPAMServiceName
,
432 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
433 #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
434 #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
436 /* Textual representation of the tokens. */
439 ServerOpCodes opcode
;
442 /* Portable-specific options */
443 { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt
, SSHCFG_GLOBAL
},
444 /* Standard Options */
445 { "port", sPort
, SSHCFG_GLOBAL
},
446 { "hostkey", sHostKeyFile
, SSHCFG_GLOBAL
},
447 { "hostdsakey", sHostKeyFile
, SSHCFG_GLOBAL
}, /* alias */
448 { "pidfile", sPidFile
, SSHCFG_GLOBAL
},
449 { "serverkeybits", sServerKeyBits
, SSHCFG_GLOBAL
},
450 { "logingracetime", sLoginGraceTime
, SSHCFG_GLOBAL
},
451 { "keyregenerationinterval", sKeyRegenerationTime
, SSHCFG_GLOBAL
},
452 { "permitrootlogin", sPermitRootLogin
, SSHCFG_ALL
},
453 { "syslogfacility", sLogFacility
, SSHCFG_GLOBAL
},
454 { "loglevel", sLogLevel
, SSHCFG_GLOBAL
},
455 { "rhostsauthentication", sRhostsAuthentication
, SSHCFG_GLOBAL
},
456 { "rhostsrsaauthentication", sRhostsRSAAuthentication
, SSHCFG_ALL
},
457 { "hostbasedauthentication", sHostbasedAuthentication
, SSHCFG_ALL
},
458 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly
},
459 { "rsaauthentication", sRSAAuthentication
, SSHCFG_ALL
},
460 { "pubkeyauthentication", sPubkeyAuthentication
, SSHCFG_ALL
},
461 { "dsaauthentication", sPubkeyAuthentication
, SSHCFG_GLOBAL
}, /* alias */
463 { "gssapiauthentication", sGssAuthentication
, SSHCFG_ALL
},
464 { "gssapikeyexchange", sGssKeyEx
, SSHCFG_GLOBAL
},
465 { "gssapistoredelegatedcredentials", sGssStoreDelegCreds
, SSHCFG_GLOBAL
},
466 { "gssauthentication", sGssAuthentication
, SSHCFG_GLOBAL
}, /* alias */
467 { "gsskeyex", sGssKeyEx
, SSHCFG_GLOBAL
}, /* alias */
468 { "gssstoredelegcreds", sGssStoreDelegCreds
, SSHCFG_GLOBAL
}, /* alias */
470 { "gssusesessionccache", sGssUseSessionCredCache
, SSHCFG_GLOBAL
},
471 { "gssusesessioncredcache", sGssUseSessionCredCache
, SSHCFG_GLOBAL
},
472 { "gsscleanupcreds", sGssCleanupCreds
, SSHCFG_GLOBAL
},
473 #endif /* SUNW_GSSAPI */
475 #if defined(KRB4) || defined(KRB5)
476 { "kerberosauthentication", sKerberosAuthentication
, SSHCFG_ALL
},
477 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd
, SSHCFG_GLOBAL
},
478 { "kerberosticketcleanup", sKerberosTicketCleanup
, SSHCFG_GLOBAL
},
480 #if defined(AFS) || defined(KRB5)
481 { "kerberostgtpassing", sKerberosTgtPassing
, SSHCFG_GLOBAL
},
484 { "afstokenpassing", sAFSTokenPassing
, SSHCFG_GLOBAL
},
486 { "passwordauthentication", sPasswordAuthentication
, SSHCFG_ALL
},
487 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication
, SSHCFG_ALL
},
488 { "challengeresponseauthentication", sChallengeResponseAuthentication
, SSHCFG_GLOBAL
},
489 { "skeyauthentication", sChallengeResponseAuthentication
, SSHCFG_GLOBAL
}, /* alias */
490 { "checkmail", sDeprecated
, SSHCFG_GLOBAL
},
491 { "listenaddress", sListenAddress
, SSHCFG_GLOBAL
},
492 { "printmotd", sPrintMotd
, SSHCFG_GLOBAL
},
493 { "printlastlog", sPrintLastLog
, SSHCFG_GLOBAL
},
494 { "ignorerhosts", sIgnoreRhosts
, SSHCFG_GLOBAL
},
495 { "ignoreuserknownhosts", sIgnoreUserKnownHosts
, SSHCFG_GLOBAL
},
496 { "x11forwarding", sX11Forwarding
, SSHCFG_ALL
},
497 { "x11displayoffset", sX11DisplayOffset
, SSHCFG_ALL
},
498 { "x11uselocalhost", sX11UseLocalhost
, SSHCFG_ALL
},
499 { "xauthlocation", sXAuthLocation
, SSHCFG_GLOBAL
},
500 { "strictmodes", sStrictModes
, SSHCFG_GLOBAL
},
501 { "permitemptypasswords", sEmptyPasswd
, SSHCFG_ALL
},
502 { "permituserenvironment", sPermitUserEnvironment
, SSHCFG_GLOBAL
},
503 { "uselogin", sUseLogin
, SSHCFG_GLOBAL
},
504 { "compression", sCompression
, SSHCFG_GLOBAL
},
505 { "tcpkeepalive", sKeepAlives
, SSHCFG_GLOBAL
},
506 { "keepalive", sKeepAlives
, SSHCFG_GLOBAL
}, /* obsolete */
507 { "allowtcpforwarding", sAllowTcpForwarding
, SSHCFG_ALL
},
508 { "allowusers", sAllowUsers
, SSHCFG_GLOBAL
},
509 { "denyusers", sDenyUsers
, SSHCFG_GLOBAL
},
510 { "allowgroups", sAllowGroups
, SSHCFG_GLOBAL
},
511 { "denygroups", sDenyGroups
, SSHCFG_GLOBAL
},
512 { "ciphers", sCiphers
, SSHCFG_GLOBAL
},
513 { "macs", sMacs
, SSHCFG_GLOBAL
},
514 { "protocol", sProtocol
,SSHCFG_GLOBAL
},
515 { "gatewayports", sGatewayPorts
, SSHCFG_ALL
},
516 { "subsystem", sSubsystem
, SSHCFG_GLOBAL
},
517 { "maxstartups", sMaxStartups
, SSHCFG_GLOBAL
},
518 { "banner", sBanner
, SSHCFG_ALL
},
519 { "verifyreversemapping", sVerifyReverseMapping
, SSHCFG_GLOBAL
},
520 { "reversemappingcheck", sVerifyReverseMapping
,SSHCFG_GLOBAL
},
521 { "clientaliveinterval", sClientAliveInterval
, SSHCFG_GLOBAL
},
522 { "clientalivecountmax", sClientAliveCountMax
, SSHCFG_GLOBAL
},
523 { "authorizedkeysfile", sAuthorizedKeysFile
, SSHCFG_GLOBAL
},
524 { "authorizedkeysfile2", sAuthorizedKeysFile2
, SSHCFG_GLOBAL
},
525 { "maxauthtries", sMaxAuthTries
, SSHCFG_ALL
},
526 { "maxauthtrieslog", sMaxAuthTriesLog
, SSHCFG_GLOBAL
},
527 { "useprivilegeseparation", sUsePrivilegeSeparation
, SSHCFG_GLOBAL
},
528 { "lookupclienthostnames", sLookupClientHostnames
, SSHCFG_GLOBAL
},
529 { "useopensslengine", sUseOpenSSLEngine
, SSHCFG_GLOBAL
},
530 { "chrootdirectory", sChrootDirectory
, SSHCFG_ALL
},
531 { "preuserauthhook", sPreUserauthHook
, SSHCFG_ALL
},
532 { "match", sMatch
, SSHCFG_ALL
},
533 { "pamserviceprefix", sPAMServicePrefix
, SSHCFG_GLOBAL
},
534 { "pamservicename", sPAMServiceName
, SSHCFG_GLOBAL
},
536 { NULL
, sBadOption
, 0 }
540 * Returns the number of the token pointed to by cp or sBadOption.
544 parse_token(const char *cp
, const char *filename
,
545 int linenum
, u_int
*flags
)
549 for (i
= 0; keywords
[i
].name
; i
++)
550 if (strcasecmp(cp
, keywords
[i
].name
) == 0) {
551 *flags
= keywords
[i
].flags
;
552 return keywords
[i
].opcode
;
555 error("%s: line %d: Bad configuration option: %s",
556 filename
, linenum
, cp
);
561 add_listen_addr(ServerOptions
*options
, char *addr
, u_short port
)
565 if (options
->num_ports
== 0)
566 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
568 for (i
= 0; i
< options
->num_ports
; i
++)
569 add_one_listen_addr(options
, addr
, options
->ports
[i
]);
571 add_one_listen_addr(options
, addr
, port
);
575 add_one_listen_addr(ServerOptions
*options
, char *addr
, u_short port
)
577 struct addrinfo hints
, *ai
, *aitop
;
578 char strport
[NI_MAXSERV
];
581 (void) memset(&hints
, 0, sizeof(hints
));
582 hints
.ai_family
= IPv4or6
;
583 hints
.ai_socktype
= SOCK_STREAM
;
584 hints
.ai_flags
= (addr
== NULL
) ? AI_PASSIVE
: 0;
585 (void) snprintf(strport
, sizeof strport
, "%u", port
);
586 if ((gaierr
= getaddrinfo(addr
, strport
, &hints
, &aitop
)) != 0)
587 fatal("bad addr or host: %s (%s)",
588 addr
? addr
: "<NULL>",
589 gai_strerror(gaierr
));
590 for (ai
= aitop
; ai
->ai_next
; ai
= ai
->ai_next
)
592 ai
->ai_next
= options
->listen_addrs
;
593 options
->listen_addrs
= aitop
;
597 * The strategy for the Match blocks is that the config file is parsed twice.
599 * The first time is at startup. activep is initialized to 1 and the
600 * directives in the global context are processed and acted on. Hitting a
601 * Match directive unsets activep and the directives inside the block are
602 * checked for syntax only.
604 * The second time is after a connection has been established but before
605 * authentication. activep is initialized to 2 and global config directives
606 * are ignored since they have already been processed. If the criteria in a
607 * Match block is met, activep is set and the subsequent directives
608 * processed and actioned until EOF or another Match block unsets it. Any
609 * options set are copied into the main server config.
611 * Potential additions/improvements:
612 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
614 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
615 * Match Address 192.168.0.*
620 * AllowTcpForwarding yes
621 * GatewayPorts clientspecified
624 * - Add a PermittedChannelRequests directive
626 * PermittedChannelRequests session,forwarded-tcpip
630 match_cfg_line_group(const char *grps
, int line
, const char *user
)
638 if ((pw
= getpwnam(user
)) == NULL
) {
639 debug("Can't match group at line %d because user %.100s does "
640 "not exist", line
, user
);
641 } else if (ga_init(pw
->pw_name
, pw
->pw_gid
) == 0) {
642 debug("Can't Match group because user %.100s not in any group "
643 "at line %d", user
, line
);
644 } else if (ga_match_pattern_list(grps
) != 1) {
645 debug("user %.100s does not match group list %.100s at line %d",
648 debug("user %.100s matched group list %.100s at line %d", user
,
658 match_cfg_line(char **condition
, int line
, const char *user
, const char *host
,
662 char *arg
, *attrib
, *cp
= *condition
;
666 debug3("checking syntax for 'Match %s'", cp
);
668 debug3("checking match for '%s' user %s host %s addr %s", cp
,
669 user
? user
: "(null)", host
? host
: "(null)",
670 address
? address
: "(null)");
672 while ((attrib
= strdelim(&cp
)) != NULL
&& *attrib
!= '\0') {
673 if ((arg
= strdelim(&cp
)) == NULL
|| *arg
== '\0') {
674 error("Missing Match criteria for %s", attrib
);
678 if (strcasecmp(attrib
, "user") == 0) {
683 if (match_pattern_list(user
, arg
, len
, 0) != 1)
686 debug("user %.100s matched 'User %.100s' at "
687 "line %d", user
, arg
, line
);
688 } else if (strcasecmp(attrib
, "group") == 0) {
689 switch (match_cfg_line_group(arg
, line
, user
)) {
695 } else if (strcasecmp(attrib
, "host") == 0) {
700 if (match_hostname(host
, arg
, len
) != 1)
703 debug("connection from %.100s matched 'Host "
704 "%.100s' at line %d", host
, arg
, line
);
705 } else if (strcasecmp(attrib
, "address") == 0) {
706 switch (addr_match_list(address
, arg
)) {
708 debug("connection from %.100s matched 'Address "
709 "%.100s' at line %d", address
, arg
, line
);
719 error("Unsupported Match attribute %s", attrib
);
724 debug3("match %sfound", result
? "" : "not ");
729 #define WHITESPACE " \t\r\n"
732 process_server_config_line(ServerOptions
*options
, char *line
,
733 const char *filename
, int linenum
, int *activep
, const char *user
,
734 const char *host
, const char *address
)
736 char *cp
, **charptr
, *arg
, *p
;
737 int cmdline
= 0, *intptr
, value
, n
;
738 ServerOpCodes opcode
;
744 /* Ignore leading whitespace */
747 if (!arg
|| !*arg
|| *arg
== '#')
751 opcode
= parse_token(arg
, filename
, linenum
, &flags
);
753 if (activep
== NULL
) { /* We are processing a command line directive */
757 if (*activep
&& opcode
!= sMatch
)
758 debug3("%s:%d setting %s %s", filename
, linenum
, arg
, cp
);
759 if (*activep
== 0 && !(flags
& SSHCFG_MATCH
)) {
761 fatal("%s line %d: Directive '%s' is not allowed "
762 "within a Match block", filename
, linenum
, arg
);
763 } else { /* this is a directive we have already processed */
771 /* Portable-specific options */
772 case sPAMAuthenticationViaKbdInt
:
773 log("%s line %d: PAMAuthenticationViaKbdInt has been "
774 "deprecated. You should use KbdInteractiveAuthentication "
775 "instead (which defaults to \"yes\").", filename
, linenum
);
776 intptr
= &options
->pam_authentication_via_kbd_int
;
779 /* Standard Options */
783 /* ignore ports from configfile if cmdline specifies ports */
784 if (options
->ports_from_cmdline
)
786 if (options
->listen_addrs
!= NULL
)
787 fatal("%s line %d: ports must be specified before "
788 "ListenAddress.", filename
, linenum
);
789 if (options
->num_ports
>= MAX_PORTS
)
790 fatal("%s line %d: too many ports.",
793 if (!arg
|| *arg
== '\0')
794 fatal("%s line %d: missing port number.",
796 options
->ports
[options
->num_ports
++] = a2port(arg
);
797 if (options
->ports
[options
->num_ports
-1] == 0)
798 fatal("%s line %d: Badly formatted port number.",
803 intptr
= &options
->server_key_bits
;
806 if (!arg
|| *arg
== '\0')
807 fatal("%s line %d: missing integer value.",
810 if (*activep
&& *intptr
== -1)
814 case sLoginGraceTime
:
815 intptr
= &options
->login_grace_time
;
818 if (!arg
|| *arg
== '\0')
819 fatal("%s line %d: missing time value.",
821 if ((value
= convtime(arg
)) == -1)
822 fatal("%s line %d: invalid time value.",
828 case sKeyRegenerationTime
:
829 intptr
= &options
->key_regeneration_time
;
834 if (!arg
|| *arg
== '\0' || strncmp(arg
, "[]", 2) == 0)
835 fatal("%s line %d: missing inet addr.",
838 if ((p
= strchr(arg
, ']')) == NULL
)
839 fatal("%s line %d: bad ipv6 inet addr usage.",
842 (void) memmove(p
, p
+1, strlen(p
+1)+1);
843 } else if (((p
= strchr(arg
, ':')) == NULL
) ||
844 (strchr(p
+1, ':') != NULL
)) {
845 add_listen_addr(options
, arg
, 0);
853 fatal("%s line %d: bad inet addr:port usage.",
857 if ((port
= a2port(p
)) == 0)
858 fatal("%s line %d: bad port number.",
860 add_listen_addr(options
, arg
, port
);
862 } else if (*p
== '\0')
863 add_listen_addr(options
, arg
, 0);
865 fatal("%s line %d: bad inet addr usage.",
870 intptr
= &options
->num_host_key_files
;
871 if (*intptr
>= MAX_HOSTKEYS
)
872 fatal("%s line %d: too many host keys specified (max %d).",
873 filename
, linenum
, MAX_HOSTKEYS
);
874 charptr
= &options
->host_key_files
[*intptr
];
877 if (!arg
|| *arg
== '\0')
878 fatal("%s line %d: missing file name.",
880 if (*activep
&& *charptr
== NULL
) {
881 *charptr
= tilde_expand_filename(arg
, getuid());
882 /* increase optional counter */
884 *intptr
= *intptr
+ 1;
889 charptr
= &options
->pid_file
;
892 case sPermitRootLogin
:
893 intptr
= &options
->permit_root_login
;
895 if (!arg
|| *arg
== '\0')
896 fatal("%s line %d: missing yes/"
897 "without-password/forced-commands-only/no "
898 "argument.", filename
, linenum
);
899 value
= 0; /* silence compiler */
900 if (strcmp(arg
, "without-password") == 0)
901 value
= PERMIT_NO_PASSWD
;
902 else if (strcmp(arg
, "forced-commands-only") == 0)
903 value
= PERMIT_FORCED_ONLY
;
904 else if (strcmp(arg
, "yes") == 0)
906 else if (strcmp(arg
, "no") == 0)
909 fatal("%s line %d: Bad yes/"
910 "without-password/forced-commands-only/no "
911 "argument: %s", filename
, linenum
, arg
);
912 if (*activep
&& *intptr
== -1)
917 intptr
= &options
->ignore_rhosts
;
920 if (!arg
|| *arg
== '\0')
921 fatal("%s line %d: missing yes/no argument.",
923 value
= 0; /* silence compiler */
924 if (strcmp(arg
, "yes") == 0)
926 else if (strcmp(arg
, "no") == 0)
929 fatal("%s line %d: Bad yes/no argument: %s",
930 filename
, linenum
, arg
);
931 if (*activep
&& *intptr
== -1)
935 case sIgnoreUserKnownHosts
:
936 intptr
= &options
->ignore_user_known_hosts
;
939 case sRhostsAuthentication
:
940 intptr
= &options
->rhosts_authentication
;
943 case sRhostsRSAAuthentication
:
944 intptr
= &options
->rhosts_rsa_authentication
;
947 case sHostbasedAuthentication
:
948 intptr
= &options
->hostbased_authentication
;
951 case sHostbasedUsesNameFromPacketOnly
:
952 intptr
= &options
->hostbased_uses_name_from_packet_only
;
955 case sRSAAuthentication
:
956 intptr
= &options
->rsa_authentication
;
959 case sPubkeyAuthentication
:
960 intptr
= &options
->pubkey_authentication
;
963 case sGssAuthentication
:
964 intptr
= &options
->gss_authentication
;
967 intptr
= &options
->gss_keyex
;
969 case sGssStoreDelegCreds
:
970 intptr
= &options
->gss_keyex
;
973 case sGssUseSessionCredCache
:
974 intptr
= &options
->gss_use_session_ccache
;
976 case sGssCleanupCreds
:
977 intptr
= &options
->gss_cleanup_creds
;
979 #endif /* SUNW_GSSAPI */
981 #if defined(KRB4) || defined(KRB5)
982 case sKerberosAuthentication
:
983 intptr
= &options
->kerberos_authentication
;
986 case sKerberosOrLocalPasswd
:
987 intptr
= &options
->kerberos_or_local_passwd
;
990 case sKerberosTicketCleanup
:
991 intptr
= &options
->kerberos_ticket_cleanup
;
994 #if defined(AFS) || defined(KRB5)
995 case sKerberosTgtPassing
:
996 intptr
= &options
->kerberos_tgt_passing
;
1000 case sAFSTokenPassing
:
1001 intptr
= &options
->afs_token_passing
;
1005 case sPasswordAuthentication
:
1006 intptr
= &options
->password_authentication
;
1009 case sKbdInteractiveAuthentication
:
1010 intptr
= &options
->kbd_interactive_authentication
;
1013 case sChallengeResponseAuthentication
:
1014 intptr
= &options
->challenge_response_authentication
;
1018 intptr
= &options
->print_motd
;
1022 intptr
= &options
->print_lastlog
;
1025 case sX11Forwarding
:
1026 intptr
= &options
->x11_forwarding
;
1029 case sX11DisplayOffset
:
1030 intptr
= &options
->x11_display_offset
;
1033 case sX11UseLocalhost
:
1034 intptr
= &options
->x11_use_localhost
;
1037 case sXAuthLocation
:
1038 charptr
= &options
->xauth_location
;
1039 goto parse_filename
;
1042 intptr
= &options
->strict_modes
;
1046 intptr
= &options
->keepalives
;
1050 intptr
= &options
->permit_empty_passwd
;
1053 case sPermitUserEnvironment
:
1054 intptr
= &options
->permit_user_env
;
1058 log("%s line %d: ignoring UseLogin option value."
1059 " This option is always off.", filename
, linenum
);
1061 arg
= strdelim(&cp
);
1065 intptr
= &options
->compression
;
1069 intptr
= &options
->gateway_ports
;
1070 arg
= strdelim(&cp
);
1071 if (!arg
|| *arg
== '\0')
1072 fatal("%s line %d: missing yes/no/clientspecified "
1073 "argument.", filename
, linenum
);
1074 value
= 0; /* silence compiler */
1075 if (strcmp(arg
, "clientspecified") == 0)
1077 else if (strcmp(arg
, "yes") == 0)
1079 else if (strcmp(arg
, "no") == 0)
1082 fatal("%s line %d: Bad yes/no/clientspecified "
1083 "argument: %s", filename
, linenum
, arg
);
1084 if (*activep
&& *intptr
== -1)
1088 case sVerifyReverseMapping
:
1089 intptr
= &options
->verify_reverse_mapping
;
1093 intptr
= (int *) &options
->log_facility
;
1094 arg
= strdelim(&cp
);
1095 value
= log_facility_number(arg
);
1096 if (value
== SYSLOG_FACILITY_NOT_SET
)
1097 fatal("%.200s line %d: unsupported log facility '%s'",
1098 filename
, linenum
, arg
? arg
: "<NONE>");
1100 *intptr
= (SyslogFacility
) value
;
1104 intptr
= (int *) &options
->log_level
;
1105 arg
= strdelim(&cp
);
1106 value
= log_level_number(arg
);
1107 if (value
== SYSLOG_LEVEL_NOT_SET
)
1108 fatal("%.200s line %d: unsupported log level '%s'",
1109 filename
, linenum
, arg
? arg
: "<NONE>");
1111 *intptr
= (LogLevel
) value
;
1114 case sAllowTcpForwarding
:
1115 intptr
= &options
->allow_tcp_forwarding
;
1118 case sUsePrivilegeSeparation
:
1119 log("%s line %d: ignoring UsePrivilegeSeparation option value."
1120 " This option is always on.", filename
, linenum
);
1122 arg
= strdelim(&cp
);
1126 while (((arg
= strdelim(&cp
)) != NULL
) && *arg
!= '\0') {
1127 if (options
->num_allow_users
>= MAX_ALLOW_USERS
)
1128 fatal("%s line %d: too many allow users.",
1130 options
->allow_users
[options
->num_allow_users
++] =
1136 while (((arg
= strdelim(&cp
)) != NULL
) && *arg
!= '\0') {
1137 if (options
->num_deny_users
>= MAX_DENY_USERS
)
1138 fatal( "%s line %d: too many deny users.",
1140 options
->deny_users
[options
->num_deny_users
++] =
1146 while (((arg
= strdelim(&cp
)) != NULL
) && *arg
!= '\0') {
1147 if (options
->num_allow_groups
>= MAX_ALLOW_GROUPS
)
1148 fatal("%s line %d: too many allow groups.",
1150 options
->allow_groups
[options
->num_allow_groups
++] =
1156 while (((arg
= strdelim(&cp
)) != NULL
) && *arg
!= '\0') {
1157 if (options
->num_deny_groups
>= MAX_DENY_GROUPS
)
1158 fatal("%s line %d: too many deny groups.",
1160 options
->deny_groups
[options
->num_deny_groups
++] = xstrdup(arg
);
1165 arg
= strdelim(&cp
);
1166 if (!arg
|| *arg
== '\0')
1167 fatal("%s line %d: Missing argument.", filename
, linenum
);
1168 if (!ciphers_valid(arg
))
1169 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1170 filename
, linenum
, arg
? arg
: "<NONE>");
1171 if (options
->ciphers
== NULL
)
1172 options
->ciphers
= xstrdup(arg
);
1176 arg
= strdelim(&cp
);
1177 if (!arg
|| *arg
== '\0')
1178 fatal("%s line %d: Missing argument.", filename
, linenum
);
1179 if (!mac_valid(arg
))
1180 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1181 filename
, linenum
, arg
? arg
: "<NONE>");
1182 if (options
->macs
== NULL
)
1183 options
->macs
= xstrdup(arg
);
1187 intptr
= &options
->protocol
;
1188 arg
= strdelim(&cp
);
1189 if (!arg
|| *arg
== '\0')
1190 fatal("%s line %d: Missing argument.", filename
, linenum
);
1191 value
= proto_spec(arg
);
1192 if (value
== SSH_PROTO_UNKNOWN
)
1193 fatal("%s line %d: Bad protocol spec '%s'.",
1194 filename
, linenum
, arg
? arg
: "<NONE>");
1195 if (*intptr
== SSH_PROTO_UNKNOWN
)
1200 if (options
->num_subsystems
>= MAX_SUBSYSTEMS
) {
1201 fatal("%s line %d: too many subsystems defined.",
1204 arg
= strdelim(&cp
);
1205 if (!arg
|| *arg
== '\0')
1206 fatal("%s line %d: Missing subsystem name.",
1209 arg
= strdelim(&cp
);
1212 for (i
= 0; i
< options
->num_subsystems
; i
++)
1213 if (strcmp(arg
, options
->subsystem_name
[i
]) == 0)
1214 fatal("%s line %d: Subsystem '%s' already defined.",
1215 filename
, linenum
, arg
);
1216 options
->subsystem_name
[options
->num_subsystems
] = xstrdup(arg
);
1217 arg
= strdelim(&cp
);
1218 if (!arg
|| *arg
== '\0')
1219 fatal("%s line %d: Missing subsystem command.",
1221 options
->subsystem_command
[options
->num_subsystems
] = xstrdup(arg
);
1224 * Collect arguments (separate to executable), including the
1225 * name of the executable, in a way that is easier to parse
1229 len
= strlen(p
) + 1;
1230 while ((arg
= strdelim(&cp
)) != NULL
&& *arg
!= '\0') {
1231 len
+= 1 + strlen(arg
);
1232 p
= xrealloc(p
, len
);
1233 strlcat(p
, " ", len
);
1234 strlcat(p
, arg
, len
);
1236 options
->subsystem_args
[options
->num_subsystems
] = p
;
1237 options
->num_subsystems
++;
1241 arg
= strdelim(&cp
);
1242 if (!arg
|| *arg
== '\0')
1243 fatal("%s line %d: Missing MaxStartups spec.",
1245 if ((n
= sscanf(arg
, "%d:%d:%d",
1246 &options
->max_startups_begin
,
1247 &options
->max_startups_rate
,
1248 &options
->max_startups
)) == 3) {
1249 if (options
->max_startups_begin
>
1250 options
->max_startups
||
1251 options
->max_startups_rate
> 100 ||
1252 options
->max_startups_rate
< 1)
1253 fatal("%s line %d: Illegal MaxStartups spec.",
1256 fatal("%s line %d: Illegal MaxStartups spec.",
1259 options
->max_startups
= options
->max_startups_begin
;
1263 charptr
= &options
->banner
;
1264 goto parse_filename
;
1266 * These options can contain %X options expanded at
1267 * connect time, so that you can specify paths like:
1269 * AuthorizedKeysFile /etc/ssh_keys/%u
1271 case sAuthorizedKeysFile
:
1272 case sAuthorizedKeysFile2
:
1273 charptr
= (opcode
== sAuthorizedKeysFile
) ?
1274 &options
->authorized_keys_file
:
1275 &options
->authorized_keys_file2
;
1276 goto parse_filename
;
1278 case sClientAliveInterval
:
1279 intptr
= &options
->client_alive_interval
;
1282 case sClientAliveCountMax
:
1283 intptr
= &options
->client_alive_count_max
;
1287 intptr
= &options
->max_auth_tries
;
1290 case sMaxAuthTriesLog
:
1291 intptr
= &options
->max_auth_tries_log
;
1294 case sLookupClientHostnames
:
1295 intptr
= &options
->lookup_client_hostnames
;
1298 case sUseOpenSSLEngine
:
1299 intptr
= &options
->use_openssl_engine
;
1302 case sChrootDirectory
:
1303 charptr
= &options
->chroot_directory
;
1305 arg
= strdelim(&cp
);
1306 if (arg
== NULL
|| *arg
== '\0')
1307 fatal("%s line %d: missing directory name for "
1308 "ChrootDirectory.", filename
, linenum
);
1309 if (*activep
&& *charptr
== NULL
)
1310 *charptr
= xstrdup(arg
);
1313 case sPreUserauthHook
:
1314 charptr
= &options
->pre_userauth_hook
;
1315 goto parse_filename
;
1319 fatal("Match directive not supported as a command-line "
1321 value
= match_cfg_line(&cp
, linenum
, user
, host
, address
);
1323 fatal("%s line %d: Bad Match condition", filename
,
1329 log("%s line %d: Deprecated option %s",
1330 filename
, linenum
, arg
);
1332 arg
= strdelim(&cp
);
1335 case sPAMServicePrefix
:
1336 arg
= strdelim(&cp
);
1337 if (!arg
|| *arg
== '\0')
1338 fatal("%s line %d: Missing argument.",
1340 if (options
->pam_service_name
!= NULL
)
1341 fatal("%s line %d: PAMServiceName and PAMServicePrefix "
1342 "are mutually exclusive.", filename
, linenum
);
1343 if (options
->pam_service_prefix
== NULL
)
1344 options
->pam_service_prefix
= xstrdup(arg
);
1347 case sPAMServiceName
:
1348 arg
= strdelim(&cp
);
1349 if (!arg
|| *arg
== '\0')
1350 fatal("%s line %d: Missing argument.",
1352 if (options
->pam_service_prefix
!= NULL
)
1353 fatal("%s line %d: PAMServiceName and PAMServicePrefix "
1354 "are mutually exclusive.", filename
, linenum
);
1355 if (options
->pam_service_name
== NULL
)
1356 options
->pam_service_name
= xstrdup(arg
);
1360 fatal("%s line %d: Missing handler for opcode %s (%d)",
1361 filename
, linenum
, arg
, opcode
);
1363 if ((arg
= strdelim(&cp
)) != NULL
&& *arg
!= '\0')
1364 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1365 filename
, linenum
, arg
);
1370 /* Reads the server configuration file. */
1373 load_server_config(const char *filename
, Buffer
*conf
)
1375 char line
[1024], *cp
;
1378 debug2("%s: filename %s", __func__
, filename
);
1379 if ((f
= fopen(filename
, "r")) == NULL
) {
1384 while (fgets(line
, sizeof(line
), f
)) {
1386 * Trim out comments and strip whitespace
1387 * NB - preserve newlines, they are needed to reproduce
1388 * line numbers later for error messages
1390 if ((cp
= strchr(line
, '#')) != NULL
)
1391 memcpy(cp
, "\n", 2);
1392 cp
= line
+ strspn(line
, " \t\r");
1394 buffer_append(conf
, cp
, strlen(cp
));
1396 buffer_append(conf
, "\0", 1);
1398 debug2("%s: done config len = %d", __func__
, buffer_len(conf
));
1402 parse_server_match_config(ServerOptions
*options
, const char *user
,
1403 const char *host
, const char *address
)
1407 initialize_server_options(&mo
);
1408 parse_server_config(&mo
, "reprocess config", &cfg
, user
, host
, address
);
1409 copy_set_server_options(options
, &mo
, 0);
1415 #define M_CP_INTOPT(n) do {\
1419 #define M_CP_STROPT(n) do {\
1420 if (src->n != NULL) { \
1421 if (dst->n != NULL) \
1428 * Copy any supported values that are set.
1430 * If the preauth flag is set, we do not bother copying the the string or
1431 * array values that are not used pre-authentication, because any that we
1432 * do use must be explictly sent in mm_getpwnamallow().
1435 copy_set_server_options(ServerOptions
*dst
, ServerOptions
*src
, int preauth
)
1437 M_CP_INTOPT(password_authentication
);
1438 M_CP_INTOPT(gss_authentication
);
1439 M_CP_INTOPT(rsa_authentication
);
1440 M_CP_INTOPT(pubkey_authentication
);
1441 M_CP_INTOPT(hostbased_authentication
);
1442 M_CP_INTOPT(kbd_interactive_authentication
);
1443 M_CP_INTOPT(permit_root_login
);
1444 M_CP_INTOPT(permit_empty_passwd
);
1445 M_CP_INTOPT(allow_tcp_forwarding
);
1446 M_CP_INTOPT(gateway_ports
);
1447 M_CP_INTOPT(x11_display_offset
);
1448 M_CP_INTOPT(x11_forwarding
);
1449 M_CP_INTOPT(x11_use_localhost
);
1450 M_CP_INTOPT(max_auth_tries
);
1451 M_CP_STROPT(banner
);
1455 M_CP_STROPT(chroot_directory
);
1462 parse_server_config(ServerOptions
*options
, const char *filename
, Buffer
*conf
,
1463 const char *user
, const char *host
, const char *address
)
1465 int active
, linenum
, bad_options
= 0;
1466 char *cp
, *obuf
, *cbuf
;
1468 debug2("%s: config %s len %d", __func__
, filename
, buffer_len(conf
));
1470 obuf
= cbuf
= xstrdup(buffer_ptr(conf
));
1471 active
= user
? 0 : 1;
1473 while ((cp
= strsep(&cbuf
, "\n")) != NULL
) {
1474 if (process_server_config_line(options
, cp
, filename
,
1475 linenum
++, &active
, user
, host
, address
) != 0)
1479 if (bad_options
> 0)
1480 fatal("%s: terminating, %d bad configuration options",
1481 filename
, bad_options
);
1486 * Note that "none" is a special path having the same affect on sshd
1487 * configuration as not specifying ChrootDirectory at all.
1490 chroot_requested(char *chroot_directory
)
1492 return (chroot_directory
!= NULL
&&
1493 strcasecmp(chroot_directory
, "none") != 0);