1 /* $NetBSD: servconf.c,v 1.1.1.2 2009/12/27 01:07:05 christos Exp $ */
2 /* $OpenBSD: servconf.c,v 1.195 2009/04/14 21:10:54 jj Exp $ */
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
15 __RCSID("$NetBSD: servconf.c,v 1.2 2009/06/07 22:38:47 christos Exp $");
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <sys/queue.h>
44 #include "pathnames.h"
52 #include "groupaccess.h"
54 static void add_listen_addr(ServerOptions
*, char *, int);
55 static void add_one_listen_addr(ServerOptions
*, char *, int);
57 /* Use of privilege separation or not */
58 extern int use_privsep
;
61 /* Initializes the server options to their default values. */
64 initialize_server_options(ServerOptions
*options
)
66 memset(options
, 0, sizeof(*options
));
68 /* Portable-specific options */
69 options
->use_pam
= -1;
71 /* Standard Options */
72 options
->num_ports
= 0;
73 options
->ports_from_cmdline
= 0;
74 options
->listen_addrs
= NULL
;
75 options
->address_family
= -1;
76 options
->num_host_key_files
= 0;
77 options
->pid_file
= NULL
;
78 options
->server_key_bits
= -1;
79 options
->login_grace_time
= -1;
80 options
->key_regeneration_time
= -1;
81 options
->permit_root_login
= PERMIT_NOT_SET
;
82 options
->ignore_rhosts
= -1;
83 options
->ignore_root_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
->tcp_keep_alive
= -1;
93 options
->log_facility
= SYSLOG_FACILITY_NOT_SET
;
94 options
->log_level
= SYSLOG_LEVEL_NOT_SET
;
95 options
->rhosts_rsa_authentication
= -1;
96 options
->hostbased_authentication
= -1;
97 options
->hostbased_uses_name_from_packet_only
= -1;
98 options
->rsa_authentication
= -1;
99 options
->pubkey_authentication
= -1;
100 options
->kerberos_authentication
= -1;
101 options
->kerberos_or_local_passwd
= -1;
102 options
->kerberos_ticket_cleanup
= -1;
103 #if defined(AFS) || defined(KRB5)
104 options
->kerberos_tgt_passing
= -1;
107 options
->afs_token_passing
= -1;
109 options
->kerberos_get_afs_token
= -1;
110 options
->gss_authentication
=-1;
111 options
->gss_cleanup_creds
= -1;
112 options
->password_authentication
= -1;
113 options
->kbd_interactive_authentication
= -1;
114 options
->challenge_response_authentication
= -1;
115 options
->permit_empty_passwd
= -1;
116 options
->permit_user_env
= -1;
117 options
->use_login
= -1;
118 options
->compression
= -1;
119 options
->allow_tcp_forwarding
= -1;
120 options
->allow_agent_forwarding
= -1;
121 options
->num_allow_users
= 0;
122 options
->num_deny_users
= 0;
123 options
->num_allow_groups
= 0;
124 options
->num_deny_groups
= 0;
125 options
->ciphers
= NULL
;
126 options
->macs
= NULL
;
127 options
->protocol
= SSH_PROTO_UNKNOWN
;
128 options
->gateway_ports
= -1;
129 options
->num_subsystems
= 0;
130 options
->max_startups_begin
= -1;
131 options
->max_startups_rate
= -1;
132 options
->max_startups
= -1;
133 options
->max_authtries
= -1;
134 options
->max_sessions
= -1;
135 options
->banner
= NULL
;
136 options
->use_dns
= -1;
137 options
->client_alive_interval
= -1;
138 options
->client_alive_count_max
= -1;
139 options
->authorized_keys_file
= NULL
;
140 options
->authorized_keys_file2
= NULL
;
141 options
->num_accept_env
= 0;
142 options
->permit_tun
= -1;
143 options
->num_permitted_opens
= -1;
144 options
->adm_forced_command
= NULL
;
145 options
->chroot_directory
= NULL
;
146 options
->zero_knowledge_password_authentication
= -1;
147 options
->none_enabled
= -1;
148 options
->tcp_rcv_buf_poll
= -1;
149 options
->hpn_disabled
= -1;
150 options
->hpn_buffer_size
= -1;
154 fill_default_server_options(ServerOptions
*options
)
156 /* needed for hpn socket tests */
159 socklen_t socksizelen
= sizeof(int);
161 /* Portable-specific options */
162 if (options
->use_pam
== -1)
163 options
->use_pam
= 0;
165 /* Standard Options */
166 if (options
->protocol
== SSH_PROTO_UNKNOWN
)
167 options
->protocol
= SSH_PROTO_1
|SSH_PROTO_2
;
168 if (options
->num_host_key_files
== 0) {
169 /* fill default hostkeys for protocols */
170 if (options
->protocol
& SSH_PROTO_1
)
171 options
->host_key_files
[options
->num_host_key_files
++] =
173 if (options
->protocol
& SSH_PROTO_2
) {
174 options
->host_key_files
[options
->num_host_key_files
++] =
175 _PATH_HOST_RSA_KEY_FILE
;
176 options
->host_key_files
[options
->num_host_key_files
++] =
177 _PATH_HOST_DSA_KEY_FILE
;
180 if (options
->num_ports
== 0)
181 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
182 if (options
->listen_addrs
== NULL
)
183 add_listen_addr(options
, NULL
, 0);
184 if (options
->pid_file
== NULL
)
185 options
->pid_file
= _PATH_SSH_DAEMON_PID_FILE
;
186 if (options
->server_key_bits
== -1)
187 options
->server_key_bits
= 1024;
188 if (options
->login_grace_time
== -1)
189 options
->login_grace_time
= 120;
190 if (options
->key_regeneration_time
== -1)
191 options
->key_regeneration_time
= 3600;
192 if (options
->permit_root_login
== PERMIT_NOT_SET
)
193 options
->permit_root_login
= PERMIT_NO
;
194 if (options
->ignore_rhosts
== -1)
195 options
->ignore_rhosts
= 1;
196 if (options
->ignore_root_rhosts
== -1)
197 options
->ignore_root_rhosts
= options
->ignore_rhosts
;
198 if (options
->ignore_user_known_hosts
== -1)
199 options
->ignore_user_known_hosts
= 0;
200 if (options
->print_motd
== -1)
201 options
->print_motd
= 1;
202 if (options
->print_lastlog
== -1)
203 options
->print_lastlog
= 1;
204 if (options
->x11_forwarding
== -1)
205 options
->x11_forwarding
= 0;
206 if (options
->x11_display_offset
== -1)
207 options
->x11_display_offset
= 10;
208 if (options
->x11_use_localhost
== -1)
209 options
->x11_use_localhost
= 1;
210 if (options
->xauth_location
== NULL
)
211 options
->xauth_location
= _PATH_XAUTH
;
212 if (options
->strict_modes
== -1)
213 options
->strict_modes
= 1;
214 if (options
->tcp_keep_alive
== -1)
215 options
->tcp_keep_alive
= 1;
216 if (options
->log_facility
== SYSLOG_FACILITY_NOT_SET
)
217 options
->log_facility
= SYSLOG_FACILITY_AUTH
;
218 if (options
->log_level
== SYSLOG_LEVEL_NOT_SET
)
219 options
->log_level
= SYSLOG_LEVEL_INFO
;
220 if (options
->rhosts_rsa_authentication
== -1)
221 options
->rhosts_rsa_authentication
= 0;
222 if (options
->hostbased_authentication
== -1)
223 options
->hostbased_authentication
= 0;
224 if (options
->hostbased_uses_name_from_packet_only
== -1)
225 options
->hostbased_uses_name_from_packet_only
= 0;
226 if (options
->rsa_authentication
== -1)
227 options
->rsa_authentication
= 1;
228 if (options
->pubkey_authentication
== -1)
229 options
->pubkey_authentication
= 1;
230 if (options
->kerberos_authentication
== -1)
231 options
->kerberos_authentication
= 0;
232 if (options
->kerberos_or_local_passwd
== -1)
233 options
->kerberos_or_local_passwd
= 1;
234 if (options
->kerberos_ticket_cleanup
== -1)
235 options
->kerberos_ticket_cleanup
= 1;
236 #if defined(AFS) || defined(KRB5)
237 if (options
->kerberos_tgt_passing
== -1)
238 options
->kerberos_tgt_passing
= 0;
241 if (options
->afs_token_passing
== -1)
242 options
->afs_token_passing
= 0;
244 if (options
->kerberos_get_afs_token
== -1)
245 options
->kerberos_get_afs_token
= 0;
246 if (options
->gss_authentication
== -1)
247 options
->gss_authentication
= 0;
248 if (options
->gss_cleanup_creds
== -1)
249 options
->gss_cleanup_creds
= 1;
250 if (options
->password_authentication
== -1)
251 options
->password_authentication
= 1;
252 if (options
->kbd_interactive_authentication
== -1)
253 options
->kbd_interactive_authentication
= 0;
254 if (options
->challenge_response_authentication
== -1)
255 options
->challenge_response_authentication
= 1;
256 if (options
->permit_empty_passwd
== -1)
257 options
->permit_empty_passwd
= 0;
258 if (options
->permit_user_env
== -1)
259 options
->permit_user_env
= 0;
260 if (options
->use_login
== -1)
261 options
->use_login
= 0;
262 if (options
->compression
== -1)
263 options
->compression
= COMP_DELAYED
;
264 if (options
->allow_tcp_forwarding
== -1)
265 options
->allow_tcp_forwarding
= 1;
266 if (options
->allow_agent_forwarding
== -1)
267 options
->allow_agent_forwarding
= 1;
268 if (options
->gateway_ports
== -1)
269 options
->gateway_ports
= 0;
270 if (options
->max_startups
== -1)
271 options
->max_startups
= 10;
272 if (options
->max_startups_rate
== -1)
273 options
->max_startups_rate
= 100; /* 100% */
274 if (options
->max_startups_begin
== -1)
275 options
->max_startups_begin
= options
->max_startups
;
276 if (options
->max_authtries
== -1)
277 options
->max_authtries
= DEFAULT_AUTH_FAIL_MAX
;
278 if (options
->max_sessions
== -1)
279 options
->max_sessions
= DEFAULT_SESSIONS_MAX
;
280 if (options
->use_dns
== -1)
281 options
->use_dns
= 1;
282 if (options
->client_alive_interval
== -1)
283 options
->client_alive_interval
= 0;
284 if (options
->client_alive_count_max
== -1)
285 options
->client_alive_count_max
= 3;
286 if (options
->authorized_keys_file2
== NULL
) {
287 /* authorized_keys_file2 falls back to authorized_keys_file */
288 if (options
->authorized_keys_file
!= NULL
)
289 options
->authorized_keys_file2
= options
->authorized_keys_file
;
291 options
->authorized_keys_file2
= _PATH_SSH_USER_PERMITTED_KEYS2
;
293 if (options
->authorized_keys_file
== NULL
)
294 options
->authorized_keys_file
= _PATH_SSH_USER_PERMITTED_KEYS
;
295 if (options
->permit_tun
== -1)
296 options
->permit_tun
= SSH_TUNMODE_NO
;
297 if (options
->zero_knowledge_password_authentication
== -1)
298 options
->zero_knowledge_password_authentication
= 0;
300 if (options
->hpn_disabled
== -1)
301 options
->hpn_disabled
= 0;
303 if (options
->hpn_buffer_size
== -1) {
304 /* option not explicitly set. Now we have to figure out */
305 /* what value to use */
306 if (options
->hpn_disabled
== 1) {
307 options
->hpn_buffer_size
= CHAN_SES_WINDOW_DEFAULT
;
309 /* get the current RCV size and set it to that */
310 /*create a socket but don't connect it */
311 /* we use that the get the rcv socket size */
312 sock
= socket(AF_INET
, SOCK_STREAM
, 0);
313 getsockopt(sock
, SOL_SOCKET
, SO_RCVBUF
,
314 &socksize
, &socksizelen
);
316 options
->hpn_buffer_size
= socksize
;
317 debug ("HPN Buffer Size: %d", options
->hpn_buffer_size
);
321 /* we have to do this incase the user sets both values in a contradictory */
322 /* manner. hpn_disabled overrrides hpn_buffer_size*/
323 if (options
->hpn_disabled
<= 0) {
324 if (options
->hpn_buffer_size
== 0)
325 options
->hpn_buffer_size
= 1;
326 /* limit the maximum buffer to 64MB */
327 if (options
->hpn_buffer_size
> 64*1024) {
328 options
->hpn_buffer_size
= 64*1024*1024;
330 options
->hpn_buffer_size
*= 1024;
333 options
->hpn_buffer_size
= CHAN_TCP_WINDOW_DEFAULT
;
336 /* Turn privilege separation on by default */
337 if (use_privsep
== -1)
341 if (use_privsep
&& options
->compression
== 1) {
342 error("This platform does not support both privilege "
343 "separation and compression");
344 error("Compression disabled");
345 options
->compression
= 0;
350 /* Keyword tokens. */
352 sBadOption
, /* == unknown option */
353 /* Portable-specific options */
355 /* Standard Options */
356 sPort
, sHostKeyFile
, sServerKeyBits
, sLoginGraceTime
, sKeyRegenerationTime
,
357 sPermitRootLogin
, sLogFacility
, sLogLevel
,
358 sRhostsRSAAuthentication
, sRSAAuthentication
,
359 sKerberosAuthentication
, sKerberosOrLocalPasswd
, sKerberosTicketCleanup
,
360 sKerberosGetAFSToken
,
361 sKerberosTgtPassing
, sChallengeResponseAuthentication
,
362 sPasswordAuthentication
, sKbdInteractiveAuthentication
,
363 sListenAddress
, sAddressFamily
,
364 sPrintMotd
, sPrintLastLog
, sIgnoreRhosts
,
365 sX11Forwarding
, sX11DisplayOffset
, sX11UseLocalhost
,
366 sStrictModes
, sEmptyPasswd
, sTCPKeepAlive
,
367 sPermitUserEnvironment
, sUseLogin
, sAllowTcpForwarding
, sCompression
,
368 sAllowUsers
, sDenyUsers
, sAllowGroups
, sDenyGroups
,
369 sIgnoreUserKnownHosts
, sCiphers
, sMacs
, sProtocol
, sPidFile
,
370 sGatewayPorts
, sPubkeyAuthentication
, sXAuthLocation
, sSubsystem
,
371 sMaxStartups
, sMaxAuthTries
, sMaxSessions
,
372 sBanner
, sUseDNS
, sHostbasedAuthentication
,
373 sHostbasedUsesNameFromPacketOnly
, sClientAliveInterval
,
374 sClientAliveCountMax
, sAuthorizedKeysFile
, sAuthorizedKeysFile2
,
375 sGssAuthentication
, sGssCleanupCreds
, sAcceptEnv
, sPermitTunnel
,
376 sMatch
, sPermitOpen
, sForceCommand
, sChrootDirectory
,
377 sUsePrivilegeSeparation
, sAllowAgentForwarding
,
378 sZeroKnowledgePasswordAuthentication
,
380 sNoneEnabled
, sTcpRcvBufPoll
,sHPNDisabled
, sHPNBufferSize
,
381 sDeprecated
, sUnsupported
384 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
385 #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
386 #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
388 /* Textual representation of the tokens. */
391 ServerOpCodes opcode
;
395 { "usepam", sUsePAM
, SSHCFG_GLOBAL
},
397 { "usepam", sUnsupported
, SSHCFG_GLOBAL
},
399 { "port", sPort
, SSHCFG_GLOBAL
},
400 { "hostkey", sHostKeyFile
, SSHCFG_GLOBAL
},
401 { "hostdsakey", sHostKeyFile
, SSHCFG_GLOBAL
}, /* alias */
402 { "pidfile", sPidFile
, SSHCFG_GLOBAL
},
403 { "serverkeybits", sServerKeyBits
, SSHCFG_GLOBAL
},
404 { "logingracetime", sLoginGraceTime
, SSHCFG_GLOBAL
},
405 { "keyregenerationinterval", sKeyRegenerationTime
, SSHCFG_GLOBAL
},
406 { "permitrootlogin", sPermitRootLogin
, SSHCFG_ALL
},
407 { "syslogfacility", sLogFacility
, SSHCFG_GLOBAL
},
408 { "loglevel", sLogLevel
, SSHCFG_GLOBAL
},
409 { "rhostsauthentication", sDeprecated
, SSHCFG_GLOBAL
},
410 { "rhostsrsaauthentication", sRhostsRSAAuthentication
, SSHCFG_ALL
},
411 { "hostbasedauthentication", sHostbasedAuthentication
, SSHCFG_ALL
},
412 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly
, SSHCFG_GLOBAL
},
413 { "rsaauthentication", sRSAAuthentication
, SSHCFG_ALL
},
414 { "pubkeyauthentication", sPubkeyAuthentication
, SSHCFG_ALL
},
415 { "dsaauthentication", sPubkeyAuthentication
, SSHCFG_GLOBAL
}, /* alias */
417 { "kerberosauthentication", sKerberosAuthentication
, SSHCFG_ALL
},
418 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd
, SSHCFG_GLOBAL
},
419 { "kerberosticketcleanup", sKerberosTicketCleanup
, SSHCFG_GLOBAL
},
420 { "kerberosgetafstoken", sKerberosGetAFSToken
, SSHCFG_GLOBAL
},
422 { "kerberosauthentication", sUnsupported
, SSHCFG_ALL
},
423 { "kerberosorlocalpasswd", sUnsupported
, SSHCFG_GLOBAL
},
424 { "kerberosticketcleanup", sUnsupported
, SSHCFG_GLOBAL
},
425 { "kerberosgetafstoken", sUnsupported
, SSHCFG_GLOBAL
},
427 #if defined(AFS) || defined(KRB5)
428 { "kerberostgtpassing", sKerberosTgtPassing
, SSHCFG_GLOBAL
},
430 { "kerberostgtpassing", sUnsupported
, SSHCFG_GLOBAL
},
432 { "afstokenpassing", sUnsupported
, SSHCFG_GLOBAL
},
434 { "gssapiauthentication", sGssAuthentication
, SSHCFG_ALL
},
435 { "gssapicleanupcredentials", sGssCleanupCreds
, SSHCFG_GLOBAL
},
437 { "gssapiauthentication", sUnsupported
, SSHCFG_ALL
},
438 { "gssapicleanupcredentials", sUnsupported
, SSHCFG_GLOBAL
},
440 { "passwordauthentication", sPasswordAuthentication
, SSHCFG_ALL
},
441 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication
, SSHCFG_ALL
},
442 { "challengeresponseauthentication", sChallengeResponseAuthentication
, SSHCFG_GLOBAL
},
443 { "skeyauthentication", sChallengeResponseAuthentication
, SSHCFG_GLOBAL
}, /* alias */
445 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication
, SSHCFG_ALL
},
447 { "zeroknowledgepasswordauthentication", sUnsupported
, SSHCFG_ALL
},
449 { "checkmail", sDeprecated
, SSHCFG_GLOBAL
},
450 { "listenaddress", sListenAddress
, SSHCFG_GLOBAL
},
451 { "addressfamily", sAddressFamily
, SSHCFG_GLOBAL
},
452 { "printmotd", sPrintMotd
, SSHCFG_GLOBAL
},
453 { "printlastlog", sPrintLastLog
, SSHCFG_GLOBAL
},
454 { "ignorerhosts", sIgnoreRhosts
, SSHCFG_GLOBAL
},
455 { "ignorerootrhosts", sIgnoreRootRhosts
, SSHCFG_GLOBAL
},
456 { "ignoreuserknownhosts", sIgnoreUserKnownHosts
, SSHCFG_GLOBAL
},
457 { "x11forwarding", sX11Forwarding
, SSHCFG_ALL
},
458 { "x11displayoffset", sX11DisplayOffset
, SSHCFG_ALL
},
459 { "x11uselocalhost", sX11UseLocalhost
, SSHCFG_ALL
},
460 { "xauthlocation", sXAuthLocation
, SSHCFG_GLOBAL
},
461 { "strictmodes", sStrictModes
, SSHCFG_GLOBAL
},
462 { "permitemptypasswords", sEmptyPasswd
, SSHCFG_ALL
},
463 { "permituserenvironment", sPermitUserEnvironment
, SSHCFG_GLOBAL
},
464 { "uselogin", sUseLogin
, SSHCFG_GLOBAL
},
465 { "compression", sCompression
, SSHCFG_GLOBAL
},
466 { "tcpkeepalive", sTCPKeepAlive
, SSHCFG_GLOBAL
},
467 { "keepalive", sTCPKeepAlive
, SSHCFG_GLOBAL
}, /* obsolete alias */
468 { "allowtcpforwarding", sAllowTcpForwarding
, SSHCFG_ALL
},
469 { "allowagentforwarding", sAllowAgentForwarding
, SSHCFG_ALL
},
470 { "allowusers", sAllowUsers
, SSHCFG_GLOBAL
},
471 { "denyusers", sDenyUsers
, SSHCFG_GLOBAL
},
472 { "allowgroups", sAllowGroups
, SSHCFG_GLOBAL
},
473 { "denygroups", sDenyGroups
, SSHCFG_GLOBAL
},
474 { "ciphers", sCiphers
, SSHCFG_GLOBAL
},
475 { "macs", sMacs
, SSHCFG_GLOBAL
},
476 { "protocol", sProtocol
, SSHCFG_GLOBAL
},
477 { "gatewayports", sGatewayPorts
, SSHCFG_ALL
},
478 { "subsystem", sSubsystem
, SSHCFG_GLOBAL
},
479 { "maxstartups", sMaxStartups
, SSHCFG_GLOBAL
},
480 { "maxauthtries", sMaxAuthTries
, SSHCFG_ALL
},
481 { "maxsessions", sMaxSessions
, SSHCFG_ALL
},
482 { "banner", sBanner
, SSHCFG_ALL
},
483 { "usedns", sUseDNS
, SSHCFG_GLOBAL
},
484 { "verifyreversemapping", sDeprecated
, SSHCFG_GLOBAL
},
485 { "reversemappingcheck", sDeprecated
, SSHCFG_GLOBAL
},
486 { "clientaliveinterval", sClientAliveInterval
, SSHCFG_GLOBAL
},
487 { "clientalivecountmax", sClientAliveCountMax
, SSHCFG_GLOBAL
},
488 { "authorizedkeysfile", sAuthorizedKeysFile
, SSHCFG_GLOBAL
},
489 { "authorizedkeysfile2", sAuthorizedKeysFile2
, SSHCFG_GLOBAL
},
490 { "useprivilegeseparation", sUsePrivilegeSeparation
, SSHCFG_GLOBAL
},
491 { "acceptenv", sAcceptEnv
, SSHCFG_GLOBAL
},
492 { "permittunnel", sPermitTunnel
, SSHCFG_GLOBAL
},
493 { "match", sMatch
, SSHCFG_ALL
},
494 { "permitopen", sPermitOpen
, SSHCFG_ALL
},
495 { "forcecommand", sForceCommand
, SSHCFG_ALL
},
496 { "chrootdirectory", sChrootDirectory
, SSHCFG_ALL
},
497 { "noneenabled", sNoneEnabled
},
498 { "hpndisabled", sHPNDisabled
},
499 { "hpnbuffersize", sHPNBufferSize
},
500 { "tcprcvbufpoll", sTcpRcvBufPoll
},
501 { NULL
, sBadOption
, 0 }
508 { SSH_TUNMODE_NO
, "no" },
509 { SSH_TUNMODE_POINTOPOINT
, "point-to-point" },
510 { SSH_TUNMODE_ETHERNET
, "ethernet" },
511 { SSH_TUNMODE_YES
, "yes" },
516 * Returns the number of the token pointed to by cp or sBadOption.
520 parse_token(const char *cp
, const char *filename
,
521 int linenum
, u_int
*flags
)
525 for (i
= 0; keywords
[i
].name
; i
++)
526 if (strcasecmp(cp
, keywords
[i
].name
) == 0) {
527 debug ("Config token is %s", keywords
[i
].name
);
528 *flags
= keywords
[i
].flags
;
529 return keywords
[i
].opcode
;
532 error("%s: line %d: Bad configuration option: %s",
533 filename
, linenum
, cp
);
538 add_listen_addr(ServerOptions
*options
, char *addr
, int port
)
542 if (options
->num_ports
== 0)
543 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
544 if (options
->address_family
== -1)
545 options
->address_family
= AF_UNSPEC
;
547 for (i
= 0; i
< options
->num_ports
; i
++)
548 add_one_listen_addr(options
, addr
, options
->ports
[i
]);
550 add_one_listen_addr(options
, addr
, port
);
554 add_one_listen_addr(ServerOptions
*options
, char *addr
, int port
)
556 struct addrinfo hints
, *ai
, *aitop
;
557 char strport
[NI_MAXSERV
];
560 memset(&hints
, 0, sizeof(hints
));
561 hints
.ai_family
= options
->address_family
;
562 hints
.ai_socktype
= SOCK_STREAM
;
563 hints
.ai_flags
= (addr
== NULL
) ? AI_PASSIVE
: 0;
564 snprintf(strport
, sizeof strport
, "%d", port
);
565 if ((gaierr
= getaddrinfo(addr
, strport
, &hints
, &aitop
)) != 0)
566 fatal("bad addr or host: %s (%s)",
567 addr
? addr
: "<NULL>",
568 ssh_gai_strerror(gaierr
));
569 for (ai
= aitop
; ai
->ai_next
; ai
= ai
->ai_next
)
571 ai
->ai_next
= options
->listen_addrs
;
572 options
->listen_addrs
= aitop
;
576 * The strategy for the Match blocks is that the config file is parsed twice.
578 * The first time is at startup. activep is initialized to 1 and the
579 * directives in the global context are processed and acted on. Hitting a
580 * Match directive unsets activep and the directives inside the block are
581 * checked for syntax only.
583 * The second time is after a connection has been established but before
584 * authentication. activep is initialized to 2 and global config directives
585 * are ignored since they have already been processed. If the criteria in a
586 * Match block is met, activep is set and the subsequent directives
587 * processed and actioned until EOF or another Match block unsets it. Any
588 * options set are copied into the main server config.
590 * Potential additions/improvements:
591 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
593 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
594 * Match Address 192.168.0.*
599 * AllowTcpForwarding yes
600 * GatewayPorts clientspecified
603 * - Add a PermittedChannelRequests directive
605 * PermittedChannelRequests session,forwarded-tcpip
609 match_cfg_line_group(const char *grps
, int line
, const char *user
)
617 if ((pw
= getpwnam(user
)) == NULL
) {
618 debug("Can't match group at line %d because user %.100s does "
619 "not exist", line
, user
);
620 } else if (ga_init(pw
->pw_name
, pw
->pw_gid
) == 0) {
621 debug("Can't Match group because user %.100s not in any group "
622 "at line %d", user
, line
);
623 } else if (ga_match_pattern_list(grps
) != 1) {
624 debug("user %.100s does not match group list %.100s at line %d",
627 debug("user %.100s matched group list %.100s at line %d", user
,
637 match_cfg_line(char **condition
, int line
, const char *user
, const char *host
,
641 char *arg
, *attrib
, *cp
= *condition
;
645 debug3("checking syntax for 'Match %s'", cp
);
647 debug3("checking match for '%s' user %s host %s addr %s", cp
,
648 user
? user
: "(null)", host
? host
: "(null)",
649 address
? address
: "(null)");
651 while ((attrib
= strdelim(&cp
)) && *attrib
!= '\0') {
652 if ((arg
= strdelim(&cp
)) == NULL
|| *arg
== '\0') {
653 error("Missing Match criteria for %s", attrib
);
657 if (strcasecmp(attrib
, "user") == 0) {
662 if (match_pattern_list(user
, arg
, len
, 0) != 1)
665 debug("user %.100s matched 'User %.100s' at "
666 "line %d", user
, arg
, line
);
667 } else if (strcasecmp(attrib
, "group") == 0) {
668 switch (match_cfg_line_group(arg
, line
, user
)) {
674 } else if (strcasecmp(attrib
, "host") == 0) {
679 if (match_hostname(host
, arg
, len
) != 1)
682 debug("connection from %.100s matched 'Host "
683 "%.100s' at line %d", host
, arg
, line
);
684 } else if (strcasecmp(attrib
, "address") == 0) {
685 switch (addr_match_list(address
, arg
)) {
687 debug("connection from %.100s matched 'Address "
688 "%.100s' at line %d", address
, arg
, line
);
698 error("Unsupported Match attribute %s", attrib
);
703 debug3("match %sfound", result
? "" : "not ");
708 #define WHITESPACE " \t\r\n"
711 process_server_config_line(ServerOptions
*options
, char *line
,
712 const char *filename
, int linenum
, int *activep
, const char *user
,
713 const char *host
, const char *address
)
715 char *cp
, **charptr
, *arg
, *p
;
716 int cmdline
= 0, *intptr
, value
, n
;
717 SyslogFacility
*log_facility_ptr
;
718 LogLevel
*log_level_ptr
;
719 ServerOpCodes opcode
;
725 if ((arg
= strdelim(&cp
)) == NULL
)
727 /* Ignore leading whitespace */
730 if (!arg
|| !*arg
|| *arg
== '#')
734 opcode
= parse_token(arg
, filename
, linenum
, &flags
);
736 if (activep
== NULL
) { /* We are processing a command line directive */
740 if (*activep
&& opcode
!= sMatch
)
741 debug3("%s:%d setting %s %s", filename
, linenum
, arg
, cp
);
742 if (*activep
== 0 && !(flags
& SSHCFG_MATCH
)) {
744 fatal("%s line %d: Directive '%s' is not allowed "
745 "within a Match block", filename
, linenum
, arg
);
746 } else { /* this is a directive we have already processed */
754 /* Portable-specific options */
756 intptr
= &options
->use_pam
;
759 /* Standard Options */
763 /* ignore ports from configfile if cmdline specifies ports */
764 if (options
->ports_from_cmdline
)
766 if (options
->listen_addrs
!= NULL
)
767 fatal("%s line %d: ports must be specified before "
768 "ListenAddress.", filename
, linenum
);
769 if (options
->num_ports
>= MAX_PORTS
)
770 fatal("%s line %d: too many ports.",
773 if (!arg
|| *arg
== '\0')
774 fatal("%s line %d: missing port number.",
776 options
->ports
[options
->num_ports
++] = a2port(arg
);
777 if (options
->ports
[options
->num_ports
-1] <= 0)
778 fatal("%s line %d: Badly formatted port number.",
783 intptr
= &options
->server_key_bits
;
786 if (!arg
|| *arg
== '\0')
787 fatal("%s line %d: missing integer value.",
790 if (*activep
&& *intptr
== -1)
794 case sLoginGraceTime
:
795 intptr
= &options
->login_grace_time
;
798 if (!arg
|| *arg
== '\0')
799 fatal("%s line %d: missing time value.",
801 if ((value
= convtime(arg
)) == -1)
802 fatal("%s line %d: invalid time value.",
808 case sKeyRegenerationTime
:
809 intptr
= &options
->key_regeneration_time
;
814 if (arg
== NULL
|| *arg
== '\0')
815 fatal("%s line %d: missing address",
817 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
818 if (strchr(arg
, '[') == NULL
&& (p
= strchr(arg
, ':')) != NULL
819 && strchr(p
+1, ':') != NULL
) {
820 add_listen_addr(options
, arg
, 0);
825 fatal("%s line %d: bad address:port usage",
827 p
= cleanhostname(p
);
830 else if ((port
= a2port(arg
)) <= 0)
831 fatal("%s line %d: bad port number", filename
, linenum
);
833 add_listen_addr(options
, p
, port
);
839 if (!arg
|| *arg
== '\0')
840 fatal("%s line %d: missing address family.",
842 intptr
= &options
->address_family
;
843 if (options
->listen_addrs
!= NULL
)
844 fatal("%s line %d: address family must be specified before "
845 "ListenAddress.", filename
, linenum
);
846 value
= 0; /* silence compiler */
847 if (strcasecmp(arg
, "inet") == 0)
849 else if (strcasecmp(arg
, "inet6") == 0)
851 else if (strcasecmp(arg
, "any") == 0)
854 fatal("%s line %d: unsupported address family \"%s\".",
855 filename
, linenum
, arg
);
861 intptr
= &options
->num_host_key_files
;
862 if (*intptr
>= MAX_HOSTKEYS
)
863 fatal("%s line %d: too many host keys specified (max %d).",
864 filename
, linenum
, MAX_HOSTKEYS
);
865 charptr
= &options
->host_key_files
[*intptr
];
868 if (!arg
|| *arg
== '\0')
869 fatal("%s line %d: missing file name.",
871 if (*activep
&& *charptr
== NULL
) {
872 *charptr
= tilde_expand_filename(arg
, getuid());
873 /* increase optional counter */
875 *intptr
= *intptr
+ 1;
880 charptr
= &options
->pid_file
;
883 case sPermitRootLogin
:
884 intptr
= &options
->permit_root_login
;
886 if (!arg
|| *arg
== '\0')
887 fatal("%s line %d: missing yes/"
888 "without-password/forced-commands-only/no "
889 "argument.", filename
, linenum
);
890 value
= 0; /* silence compiler */
891 if (strcmp(arg
, "without-password") == 0)
892 value
= PERMIT_NO_PASSWD
;
893 else if (strcmp(arg
, "forced-commands-only") == 0)
894 value
= PERMIT_FORCED_ONLY
;
895 else if (strcmp(arg
, "yes") == 0)
897 else if (strcmp(arg
, "no") == 0)
900 fatal("%s line %d: Bad yes/"
901 "without-password/forced-commands-only/no "
902 "argument: %s", filename
, linenum
, arg
);
903 if (*activep
&& *intptr
== -1)
908 intptr
= &options
->ignore_rhosts
;
911 if (!arg
|| *arg
== '\0')
912 fatal("%s line %d: missing yes/no argument.",
914 value
= 0; /* silence compiler */
915 if (strcmp(arg
, "yes") == 0)
917 else if (strcmp(arg
, "no") == 0)
920 fatal("%s line %d: Bad yes/no argument: %s",
921 filename
, linenum
, arg
);
922 if (*activep
&& *intptr
== -1)
926 case sIgnoreRootRhosts
:
927 intptr
= &options
->ignore_root_rhosts
;
931 intptr
= &options
->none_enabled
;
935 intptr
= &options
->tcp_rcv_buf_poll
;
939 intptr
= &options
->hpn_disabled
;
943 intptr
= &options
->hpn_buffer_size
;
946 case sIgnoreUserKnownHosts
:
947 intptr
= &options
->ignore_user_known_hosts
;
950 case sRhostsRSAAuthentication
:
951 intptr
= &options
->rhosts_rsa_authentication
;
954 case sHostbasedAuthentication
:
955 intptr
= &options
->hostbased_authentication
;
958 case sHostbasedUsesNameFromPacketOnly
:
959 intptr
= &options
->hostbased_uses_name_from_packet_only
;
962 case sRSAAuthentication
:
963 intptr
= &options
->rsa_authentication
;
966 case sPubkeyAuthentication
:
967 intptr
= &options
->pubkey_authentication
;
970 case sKerberosAuthentication
:
971 intptr
= &options
->kerberos_authentication
;
974 case sKerberosOrLocalPasswd
:
975 intptr
= &options
->kerberos_or_local_passwd
;
978 case sKerberosTicketCleanup
:
979 intptr
= &options
->kerberos_ticket_cleanup
;
982 case sKerberosTgtPassing
:
983 intptr
= &options
->kerberos_tgt_passing
;
986 case sKerberosGetAFSToken
:
987 intptr
= &options
->kerberos_get_afs_token
;
990 case sGssAuthentication
:
991 intptr
= &options
->gss_authentication
;
994 case sGssCleanupCreds
:
995 intptr
= &options
->gss_cleanup_creds
;
998 case sPasswordAuthentication
:
999 intptr
= &options
->password_authentication
;
1002 case sZeroKnowledgePasswordAuthentication
:
1003 intptr
= &options
->zero_knowledge_password_authentication
;
1006 case sKbdInteractiveAuthentication
:
1007 intptr
= &options
->kbd_interactive_authentication
;
1010 case sChallengeResponseAuthentication
:
1011 intptr
= &options
->challenge_response_authentication
;
1015 intptr
= &options
->print_motd
;
1019 intptr
= &options
->print_lastlog
;
1022 case sX11Forwarding
:
1023 intptr
= &options
->x11_forwarding
;
1026 case sX11DisplayOffset
:
1027 intptr
= &options
->x11_display_offset
;
1030 case sX11UseLocalhost
:
1031 intptr
= &options
->x11_use_localhost
;
1034 case sXAuthLocation
:
1035 charptr
= &options
->xauth_location
;
1036 goto parse_filename
;
1039 intptr
= &options
->strict_modes
;
1043 intptr
= &options
->tcp_keep_alive
;
1047 intptr
= &options
->permit_empty_passwd
;
1050 case sPermitUserEnvironment
:
1051 intptr
= &options
->permit_user_env
;
1055 intptr
= &options
->use_login
;
1059 intptr
= &options
->compression
;
1060 arg
= strdelim(&cp
);
1061 if (!arg
|| *arg
== '\0')
1062 fatal("%s line %d: missing yes/no/delayed "
1063 "argument.", filename
, linenum
);
1064 value
= 0; /* silence compiler */
1065 if (strcmp(arg
, "delayed") == 0)
1066 value
= COMP_DELAYED
;
1067 else if (strcmp(arg
, "yes") == 0)
1069 else if (strcmp(arg
, "no") == 0)
1072 fatal("%s line %d: Bad yes/no/delayed "
1073 "argument: %s", filename
, linenum
, arg
);
1079 intptr
= &options
->gateway_ports
;
1080 arg
= strdelim(&cp
);
1081 if (!arg
|| *arg
== '\0')
1082 fatal("%s line %d: missing yes/no/clientspecified "
1083 "argument.", filename
, linenum
);
1084 value
= 0; /* silence compiler */
1085 if (strcmp(arg
, "clientspecified") == 0)
1087 else if (strcmp(arg
, "yes") == 0)
1089 else if (strcmp(arg
, "no") == 0)
1092 fatal("%s line %d: Bad yes/no/clientspecified "
1093 "argument: %s", filename
, linenum
, arg
);
1094 if (*activep
&& *intptr
== -1)
1099 intptr
= &options
->use_dns
;
1103 log_facility_ptr
= &options
->log_facility
;
1104 arg
= strdelim(&cp
);
1105 value
= log_facility_number(arg
);
1106 if (value
== SYSLOG_FACILITY_NOT_SET
)
1107 fatal("%.200s line %d: unsupported log facility '%s'",
1108 filename
, linenum
, arg
? arg
: "<NONE>");
1109 if (*log_facility_ptr
== -1)
1110 *log_facility_ptr
= (SyslogFacility
) value
;
1114 log_level_ptr
= &options
->log_level
;
1115 arg
= strdelim(&cp
);
1116 value
= log_level_number(arg
);
1117 if (value
== SYSLOG_LEVEL_NOT_SET
)
1118 fatal("%.200s line %d: unsupported log level '%s'",
1119 filename
, linenum
, arg
? arg
: "<NONE>");
1120 if (*log_level_ptr
== -1)
1121 *log_level_ptr
= (LogLevel
) value
;
1124 case sAllowTcpForwarding
:
1125 intptr
= &options
->allow_tcp_forwarding
;
1128 case sAllowAgentForwarding
:
1129 intptr
= &options
->allow_agent_forwarding
;
1132 case sUsePrivilegeSeparation
:
1133 intptr
= &use_privsep
;
1137 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1138 if (options
->num_allow_users
>= MAX_ALLOW_USERS
)
1139 fatal("%s line %d: too many allow users.",
1141 options
->allow_users
[options
->num_allow_users
++] =
1147 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1148 if (options
->num_deny_users
>= MAX_DENY_USERS
)
1149 fatal("%s line %d: too many deny users.",
1151 options
->deny_users
[options
->num_deny_users
++] =
1157 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1158 if (options
->num_allow_groups
>= MAX_ALLOW_GROUPS
)
1159 fatal("%s line %d: too many allow groups.",
1161 options
->allow_groups
[options
->num_allow_groups
++] =
1167 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1168 if (options
->num_deny_groups
>= MAX_DENY_GROUPS
)
1169 fatal("%s line %d: too many deny groups.",
1171 options
->deny_groups
[options
->num_deny_groups
++] = xstrdup(arg
);
1176 arg
= strdelim(&cp
);
1177 if (!arg
|| *arg
== '\0')
1178 fatal("%s line %d: Missing argument.", filename
, linenum
);
1179 if (!ciphers_valid(arg
))
1180 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1181 filename
, linenum
, arg
? arg
: "<NONE>");
1182 if (options
->ciphers
== NULL
)
1183 options
->ciphers
= xstrdup(arg
);
1187 arg
= strdelim(&cp
);
1188 if (!arg
|| *arg
== '\0')
1189 fatal("%s line %d: Missing argument.", filename
, linenum
);
1190 if (!mac_valid(arg
))
1191 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1192 filename
, linenum
, arg
? arg
: "<NONE>");
1193 if (options
->macs
== NULL
)
1194 options
->macs
= xstrdup(arg
);
1198 intptr
= &options
->protocol
;
1199 arg
= strdelim(&cp
);
1200 if (!arg
|| *arg
== '\0')
1201 fatal("%s line %d: Missing argument.", filename
, linenum
);
1202 value
= proto_spec(arg
);
1203 if (value
== SSH_PROTO_UNKNOWN
)
1204 fatal("%s line %d: Bad protocol spec '%s'.",
1205 filename
, linenum
, arg
? arg
: "<NONE>");
1206 if (*intptr
== SSH_PROTO_UNKNOWN
)
1211 if (options
->num_subsystems
>= MAX_SUBSYSTEMS
) {
1212 fatal("%s line %d: too many subsystems defined.",
1215 arg
= strdelim(&cp
);
1216 if (!arg
|| *arg
== '\0')
1217 fatal("%s line %d: Missing subsystem name.",
1220 arg
= strdelim(&cp
);
1223 for (i
= 0; i
< options
->num_subsystems
; i
++)
1224 if (strcmp(arg
, options
->subsystem_name
[i
]) == 0)
1225 fatal("%s line %d: Subsystem '%s' already defined.",
1226 filename
, linenum
, arg
);
1227 options
->subsystem_name
[options
->num_subsystems
] = xstrdup(arg
);
1228 arg
= strdelim(&cp
);
1229 if (!arg
|| *arg
== '\0')
1230 fatal("%s line %d: Missing subsystem command.",
1232 options
->subsystem_command
[options
->num_subsystems
] = xstrdup(arg
);
1234 /* Collect arguments (separate to executable) */
1236 len
= strlen(p
) + 1;
1237 while ((arg
= strdelim(&cp
)) != NULL
&& *arg
!= '\0') {
1238 len
+= 1 + strlen(arg
);
1239 p
= xrealloc(p
, 1, len
);
1240 strlcat(p
, " ", len
);
1241 strlcat(p
, arg
, len
);
1243 options
->subsystem_args
[options
->num_subsystems
] = p
;
1244 options
->num_subsystems
++;
1248 arg
= strdelim(&cp
);
1249 if (!arg
|| *arg
== '\0')
1250 fatal("%s line %d: Missing MaxStartups spec.",
1252 if ((n
= sscanf(arg
, "%d:%d:%d",
1253 &options
->max_startups_begin
,
1254 &options
->max_startups_rate
,
1255 &options
->max_startups
)) == 3) {
1256 if (options
->max_startups_begin
>
1257 options
->max_startups
||
1258 options
->max_startups_rate
> 100 ||
1259 options
->max_startups_rate
< 1)
1260 fatal("%s line %d: Illegal MaxStartups spec.",
1263 fatal("%s line %d: Illegal MaxStartups spec.",
1266 options
->max_startups
= options
->max_startups_begin
;
1270 intptr
= &options
->max_authtries
;
1274 intptr
= &options
->max_sessions
;
1278 charptr
= &options
->banner
;
1279 goto parse_filename
;
1282 * These options can contain %X options expanded at
1283 * connect time, so that you can specify paths like:
1285 * AuthorizedKeysFile /etc/ssh_keys/%u
1287 case sAuthorizedKeysFile
:
1288 case sAuthorizedKeysFile2
:
1289 charptr
= (opcode
== sAuthorizedKeysFile
) ?
1290 &options
->authorized_keys_file
:
1291 &options
->authorized_keys_file2
;
1292 goto parse_filename
;
1294 case sClientAliveInterval
:
1295 intptr
= &options
->client_alive_interval
;
1298 case sClientAliveCountMax
:
1299 intptr
= &options
->client_alive_count_max
;
1303 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1304 if (strchr(arg
, '=') != NULL
)
1305 fatal("%s line %d: Invalid environment name.",
1307 if (options
->num_accept_env
>= MAX_ACCEPT_ENV
)
1308 fatal("%s line %d: too many allow env.",
1312 options
->accept_env
[options
->num_accept_env
++] =
1318 intptr
= &options
->permit_tun
;
1319 arg
= strdelim(&cp
);
1320 if (!arg
|| *arg
== '\0')
1321 fatal("%s line %d: Missing yes/point-to-point/"
1322 "ethernet/no argument.", filename
, linenum
);
1324 for (i
= 0; tunmode_desc
[i
].val
!= -1; i
++)
1325 if (strcmp(tunmode_desc
[i
].text
, arg
) == 0) {
1326 value
= tunmode_desc
[i
].val
;
1330 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1331 "no argument: %s", filename
, linenum
, arg
);
1338 fatal("Match directive not supported as a command-line "
1340 value
= match_cfg_line(&cp
, linenum
, user
, host
, address
);
1342 fatal("%s line %d: Bad Match condition", filename
,
1348 arg
= strdelim(&cp
);
1349 if (!arg
|| *arg
== '\0')
1350 fatal("%s line %d: missing PermitOpen specification",
1352 n
= options
->num_permitted_opens
; /* modified later */
1353 if (strcmp(arg
, "any") == 0) {
1354 if (*activep
&& n
== -1) {
1355 channel_clear_adm_permitted_opens();
1356 options
->num_permitted_opens
= 0;
1360 if (*activep
&& n
== -1)
1361 channel_clear_adm_permitted_opens();
1362 for (; arg
!= NULL
&& *arg
!= '\0'; arg
= strdelim(&cp
)) {
1365 fatal("%s line %d: missing host in PermitOpen",
1367 p
= cleanhostname(p
);
1368 if (arg
== NULL
|| (port
= a2port(arg
)) <= 0)
1369 fatal("%s line %d: bad port number in "
1370 "PermitOpen", filename
, linenum
);
1371 if (*activep
&& n
== -1)
1372 options
->num_permitted_opens
=
1373 channel_add_adm_permitted_opens(p
, port
);
1379 fatal("%.200s line %d: Missing argument.", filename
,
1381 len
= strspn(cp
, WHITESPACE
);
1382 if (*activep
&& options
->adm_forced_command
== NULL
)
1383 options
->adm_forced_command
= xstrdup(cp
+ len
);
1386 case sChrootDirectory
:
1387 charptr
= &options
->chroot_directory
;
1389 arg
= strdelim(&cp
);
1390 if (!arg
|| *arg
== '\0')
1391 fatal("%s line %d: missing file name.",
1393 if (*activep
&& *charptr
== NULL
)
1394 *charptr
= xstrdup(arg
);
1398 logit("%s line %d: Deprecated option %s",
1399 filename
, linenum
, arg
);
1401 arg
= strdelim(&cp
);
1405 logit("%s line %d: Unsupported option %s",
1406 filename
, linenum
, arg
);
1408 arg
= strdelim(&cp
);
1412 fatal("%s line %d: Missing handler for opcode %s (%d)",
1413 filename
, linenum
, arg
, opcode
);
1415 if ((arg
= strdelim(&cp
)) != NULL
&& *arg
!= '\0')
1416 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1417 filename
, linenum
, arg
);
1421 /* Reads the server configuration file. */
1424 load_server_config(const char *filename
, Buffer
*conf
)
1426 char line
[1024], *cp
;
1429 debug2("%s: filename %s", __func__
, filename
);
1430 if ((f
= fopen(filename
, "r")) == NULL
) {
1435 while (fgets(line
, sizeof(line
), f
)) {
1437 * Trim out comments and strip whitespace
1438 * NB - preserve newlines, they are needed to reproduce
1439 * line numbers later for error messages
1441 if ((cp
= strchr(line
, '#')) != NULL
)
1442 memcpy(cp
, "\n", 2);
1443 cp
= line
+ strspn(line
, " \t\r");
1445 buffer_append(conf
, cp
, strlen(cp
));
1447 buffer_append(conf
, "\0", 1);
1449 debug2("%s: done config len = %d", __func__
, buffer_len(conf
));
1453 parse_server_match_config(ServerOptions
*options
, const char *user
,
1454 const char *host
, const char *address
)
1458 initialize_server_options(&mo
);
1459 parse_server_config(&mo
, "reprocess config", &cfg
, user
, host
, address
);
1460 copy_set_server_options(options
, &mo
, 0);
1464 #define M_CP_INTOPT(n) do {\
1468 #define M_CP_STROPT(n) do {\
1469 if (src->n != NULL) { \
1470 if (dst->n != NULL) \
1477 * Copy any supported values that are set.
1479 * If the preauth flag is set, we do not bother copying the string or
1480 * array values that are not used pre-authentication, because any that we
1481 * do use must be explictly sent in mm_getpwnamallow().
1484 copy_set_server_options(ServerOptions
*dst
, ServerOptions
*src
, int preauth
)
1486 M_CP_INTOPT(password_authentication
);
1487 M_CP_INTOPT(gss_authentication
);
1488 M_CP_INTOPT(rsa_authentication
);
1489 M_CP_INTOPT(pubkey_authentication
);
1490 M_CP_INTOPT(kerberos_authentication
);
1491 M_CP_INTOPT(hostbased_authentication
);
1492 M_CP_INTOPT(kbd_interactive_authentication
);
1493 M_CP_INTOPT(zero_knowledge_password_authentication
);
1494 M_CP_INTOPT(permit_root_login
);
1495 M_CP_INTOPT(permit_empty_passwd
);
1497 M_CP_INTOPT(allow_tcp_forwarding
);
1498 M_CP_INTOPT(allow_agent_forwarding
);
1499 M_CP_INTOPT(gateway_ports
);
1500 M_CP_INTOPT(x11_display_offset
);
1501 M_CP_INTOPT(x11_forwarding
);
1502 M_CP_INTOPT(x11_use_localhost
);
1503 M_CP_INTOPT(max_sessions
);
1504 M_CP_INTOPT(max_authtries
);
1506 M_CP_STROPT(banner
);
1509 M_CP_STROPT(adm_forced_command
);
1510 M_CP_STROPT(chroot_directory
);
1517 parse_server_config(ServerOptions
*options
, const char *filename
, Buffer
*conf
,
1518 const char *user
, const char *host
, const char *address
)
1520 int active
, linenum
, bad_options
= 0;
1521 char *cp
, *obuf
, *cbuf
;
1523 debug2("%s: config %s len %d", __func__
, filename
, buffer_len(conf
));
1525 obuf
= cbuf
= xstrdup(buffer_ptr(conf
));
1526 active
= user
? 0 : 1;
1528 while ((cp
= strsep(&cbuf
, "\n")) != NULL
) {
1529 if (process_server_config_line(options
, cp
, filename
,
1530 linenum
++, &active
, user
, host
, address
) != 0)
1534 if (bad_options
> 0)
1535 fatal("%s: terminating, %d bad configuration options",
1536 filename
, bad_options
);
1540 fmt_intarg(ServerOpCodes code
, int val
)
1542 if (code
== sAddressFamily
) {
1554 if (code
== sPermitRootLogin
) {
1556 case PERMIT_NO_PASSWD
:
1557 return "without-password";
1558 case PERMIT_FORCED_ONLY
:
1559 return "forced-commands-only";
1564 if (code
== sProtocol
) {
1570 case (SSH_PROTO_1
|SSH_PROTO_2
):
1576 if (code
== sGatewayPorts
&& val
== 2)
1577 return "clientspecified";
1578 if (code
== sCompression
&& val
== COMP_DELAYED
)
1592 lookup_opcode_name(ServerOpCodes code
)
1596 for (i
= 0; keywords
[i
].name
!= NULL
; i
++)
1597 if (keywords
[i
].opcode
== code
)
1598 return(keywords
[i
].name
);
1603 dump_cfg_int(ServerOpCodes code
, int val
)
1605 printf("%s %d\n", lookup_opcode_name(code
), val
);
1609 dump_cfg_fmtint(ServerOpCodes code
, int val
)
1611 printf("%s %s\n", lookup_opcode_name(code
), fmt_intarg(code
, val
));
1615 dump_cfg_string(ServerOpCodes code
, const char *val
)
1619 printf("%s %s\n", lookup_opcode_name(code
), val
);
1623 dump_cfg_strarray(ServerOpCodes code
, u_int count
, char **vals
)
1627 for (i
= 0; i
< count
; i
++)
1628 printf("%s %s\n", lookup_opcode_name(code
), vals
[i
]);
1632 dump_config(ServerOptions
*o
)
1636 struct addrinfo
*ai
;
1637 char addr
[NI_MAXHOST
], port
[NI_MAXSERV
], *s
= NULL
;
1639 /* these are usually at the top of the config */
1640 for (i
= 0; i
< o
->num_ports
; i
++)
1641 printf("port %d\n", o
->ports
[i
]);
1642 dump_cfg_fmtint(sProtocol
, o
->protocol
);
1643 dump_cfg_fmtint(sAddressFamily
, o
->address_family
);
1645 /* ListenAddress must be after Port */
1646 for (ai
= o
->listen_addrs
; ai
; ai
= ai
->ai_next
) {
1647 if ((ret
= getnameinfo(ai
->ai_addr
, ai
->ai_addrlen
, addr
,
1648 sizeof(addr
), port
, sizeof(port
),
1649 NI_NUMERICHOST
|NI_NUMERICSERV
)) != 0) {
1650 error("getnameinfo failed: %.100s",
1651 (ret
!= EAI_SYSTEM
) ? gai_strerror(ret
) :
1654 if (ai
->ai_family
== AF_INET6
)
1655 printf("listenaddress [%s]:%s\n", addr
, port
);
1657 printf("listenaddress %s:%s\n", addr
, port
);
1661 /* integer arguments */
1662 dump_cfg_int(sServerKeyBits
, o
->server_key_bits
);
1663 dump_cfg_int(sLoginGraceTime
, o
->login_grace_time
);
1664 dump_cfg_int(sKeyRegenerationTime
, o
->key_regeneration_time
);
1665 dump_cfg_int(sX11DisplayOffset
, o
->x11_display_offset
);
1666 dump_cfg_int(sMaxAuthTries
, o
->max_authtries
);
1667 dump_cfg_int(sMaxSessions
, o
->max_sessions
);
1668 dump_cfg_int(sClientAliveInterval
, o
->client_alive_interval
);
1669 dump_cfg_int(sClientAliveCountMax
, o
->client_alive_count_max
);
1671 /* formatted integer arguments */
1672 dump_cfg_fmtint(sPermitRootLogin
, o
->permit_root_login
);
1673 dump_cfg_fmtint(sIgnoreRhosts
, o
->ignore_rhosts
);
1674 dump_cfg_fmtint(sIgnoreUserKnownHosts
, o
->ignore_user_known_hosts
);
1675 dump_cfg_fmtint(sRhostsRSAAuthentication
, o
->rhosts_rsa_authentication
);
1676 dump_cfg_fmtint(sHostbasedAuthentication
, o
->hostbased_authentication
);
1677 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly
,
1678 o
->hostbased_uses_name_from_packet_only
);
1679 dump_cfg_fmtint(sRSAAuthentication
, o
->rsa_authentication
);
1680 dump_cfg_fmtint(sPubkeyAuthentication
, o
->pubkey_authentication
);
1682 dump_cfg_fmtint(sKerberosAuthentication
, o
->kerberos_authentication
);
1683 dump_cfg_fmtint(sKerberosOrLocalPasswd
, o
->kerberos_or_local_passwd
);
1684 dump_cfg_fmtint(sKerberosTicketCleanup
, o
->kerberos_ticket_cleanup
);
1685 dump_cfg_fmtint(sKerberosGetAFSToken
, o
->kerberos_get_afs_token
);
1688 dump_cfg_fmtint(sGssAuthentication
, o
->gss_authentication
);
1689 dump_cfg_fmtint(sGssCleanupCreds
, o
->gss_cleanup_creds
);
1692 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication
,
1693 o
->zero_knowledge_password_authentication
);
1695 dump_cfg_fmtint(sPasswordAuthentication
, o
->password_authentication
);
1696 dump_cfg_fmtint(sKbdInteractiveAuthentication
,
1697 o
->kbd_interactive_authentication
);
1698 dump_cfg_fmtint(sChallengeResponseAuthentication
,
1699 o
->challenge_response_authentication
);
1700 dump_cfg_fmtint(sPrintMotd
, o
->print_motd
);
1701 dump_cfg_fmtint(sPrintLastLog
, o
->print_lastlog
);
1702 dump_cfg_fmtint(sX11Forwarding
, o
->x11_forwarding
);
1703 dump_cfg_fmtint(sX11UseLocalhost
, o
->x11_use_localhost
);
1704 dump_cfg_fmtint(sStrictModes
, o
->strict_modes
);
1705 dump_cfg_fmtint(sTCPKeepAlive
, o
->tcp_keep_alive
);
1706 dump_cfg_fmtint(sEmptyPasswd
, o
->permit_empty_passwd
);
1707 dump_cfg_fmtint(sPermitUserEnvironment
, o
->permit_user_env
);
1708 dump_cfg_fmtint(sUseLogin
, o
->use_login
);
1709 dump_cfg_fmtint(sCompression
, o
->compression
);
1710 dump_cfg_fmtint(sGatewayPorts
, o
->gateway_ports
);
1711 dump_cfg_fmtint(sUseDNS
, o
->use_dns
);
1712 dump_cfg_fmtint(sAllowTcpForwarding
, o
->allow_tcp_forwarding
);
1713 dump_cfg_fmtint(sUsePrivilegeSeparation
, use_privsep
);
1715 /* string arguments */
1716 dump_cfg_string(sPidFile
, o
->pid_file
);
1717 dump_cfg_string(sXAuthLocation
, o
->xauth_location
);
1718 dump_cfg_string(sCiphers
, o
->ciphers
);
1719 dump_cfg_string(sMacs
, o
->macs
);
1720 dump_cfg_string(sBanner
, o
->banner
);
1721 dump_cfg_string(sAuthorizedKeysFile
, o
->authorized_keys_file
);
1722 dump_cfg_string(sAuthorizedKeysFile2
, o
->authorized_keys_file2
);
1723 dump_cfg_string(sForceCommand
, o
->adm_forced_command
);
1725 /* string arguments requiring a lookup */
1726 dump_cfg_string(sLogLevel
, log_level_name(o
->log_level
));
1727 dump_cfg_string(sLogFacility
, log_facility_name(o
->log_facility
));
1729 /* string array arguments */
1730 dump_cfg_strarray(sHostKeyFile
, o
->num_host_key_files
,
1732 dump_cfg_strarray(sAllowUsers
, o
->num_allow_users
, o
->allow_users
);
1733 dump_cfg_strarray(sDenyUsers
, o
->num_deny_users
, o
->deny_users
);
1734 dump_cfg_strarray(sAllowGroups
, o
->num_allow_groups
, o
->allow_groups
);
1735 dump_cfg_strarray(sDenyGroups
, o
->num_deny_groups
, o
->deny_groups
);
1736 dump_cfg_strarray(sAcceptEnv
, o
->num_accept_env
, o
->accept_env
);
1738 /* other arguments */
1739 for (i
= 0; i
< o
->num_subsystems
; i
++)
1740 printf("subsystem %s %s\n", o
->subsystem_name
[i
],
1741 o
->subsystem_args
[i
]);
1743 printf("maxstartups %d:%d:%d\n", o
->max_startups_begin
,
1744 o
->max_startups_rate
, o
->max_startups
);
1746 for (i
= 0; tunmode_desc
[i
].val
!= -1; i
++)
1747 if (tunmode_desc
[i
].val
== o
->permit_tun
) {
1748 s
= tunmode_desc
[i
].text
;
1751 dump_cfg_string(sPermitTunnel
, s
);
1753 channel_print_adm_permitted_opens();