1 /* $OpenBSD: servconf.c,v 1.212 2010/09/30 11:04:51 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>
28 #include "openbsd-compat/sys-queue.h"
35 #include "pathnames.h"
43 #include "groupaccess.h"
45 static void add_listen_addr(ServerOptions
*, char *, int);
46 static void add_one_listen_addr(ServerOptions
*, char *, int);
48 /* Use of privilege separation or not */
49 extern int use_privsep
;
52 /* Initializes the server options to their default values. */
55 initialize_server_options(ServerOptions
*options
)
57 memset(options
, 0, sizeof(*options
));
59 /* Portable-specific options */
60 options
->use_pam
= -1;
62 /* Standard Options */
63 options
->num_ports
= 0;
64 options
->ports_from_cmdline
= 0;
65 options
->listen_addrs
= NULL
;
66 options
->address_family
= -1;
67 options
->num_host_key_files
= 0;
68 options
->num_host_cert_files
= 0;
69 options
->pid_file
= NULL
;
70 options
->server_key_bits
= -1;
71 options
->login_grace_time
= -1;
72 options
->key_regeneration_time
= -1;
73 options
->permit_root_login
= PERMIT_NOT_SET
;
74 options
->ignore_rhosts
= -1;
75 options
->ignore_user_known_hosts
= -1;
76 options
->print_motd
= -1;
77 options
->print_lastlog
= -1;
78 options
->x11_forwarding
= -1;
79 options
->x11_display_offset
= -1;
80 options
->x11_use_localhost
= -1;
81 options
->xauth_location
= NULL
;
82 options
->strict_modes
= -1;
83 options
->tcp_keep_alive
= -1;
84 options
->log_facility
= SYSLOG_FACILITY_NOT_SET
;
85 options
->log_level
= SYSLOG_LEVEL_NOT_SET
;
86 options
->rhosts_rsa_authentication
= -1;
87 options
->hostbased_authentication
= -1;
88 options
->hostbased_uses_name_from_packet_only
= -1;
89 options
->rsa_authentication
= -1;
90 options
->pubkey_authentication
= -1;
91 options
->kerberos_authentication
= -1;
92 options
->kerberos_or_local_passwd
= -1;
93 options
->kerberos_ticket_cleanup
= -1;
94 options
->kerberos_get_afs_token
= -1;
95 options
->gss_authentication
=-1;
96 options
->gss_cleanup_creds
= -1;
97 options
->password_authentication
= -1;
98 options
->kbd_interactive_authentication
= -1;
99 options
->challenge_response_authentication
= -1;
100 options
->permit_empty_passwd
= -1;
101 options
->permit_user_env
= -1;
102 options
->use_login
= -1;
103 options
->compression
= -1;
104 options
->allow_tcp_forwarding
= -1;
105 options
->allow_agent_forwarding
= -1;
106 options
->num_allow_users
= 0;
107 options
->num_deny_users
= 0;
108 options
->num_allow_groups
= 0;
109 options
->num_deny_groups
= 0;
110 options
->ciphers
= NULL
;
111 options
->macs
= NULL
;
112 options
->kex_algorithms
= NULL
;
113 options
->protocol
= SSH_PROTO_UNKNOWN
;
114 options
->gateway_ports
= -1;
115 options
->num_subsystems
= 0;
116 options
->max_startups_begin
= -1;
117 options
->max_startups_rate
= -1;
118 options
->max_startups
= -1;
119 options
->max_authtries
= -1;
120 options
->max_sessions
= -1;
121 options
->banner
= NULL
;
122 options
->use_dns
= -1;
123 options
->client_alive_interval
= -1;
124 options
->client_alive_count_max
= -1;
125 options
->authorized_keys_file
= NULL
;
126 options
->authorized_keys_file2
= NULL
;
127 options
->num_accept_env
= 0;
128 options
->permit_tun
= -1;
129 options
->num_permitted_opens
= -1;
130 options
->adm_forced_command
= NULL
;
131 options
->chroot_directory
= NULL
;
132 options
->zero_knowledge_password_authentication
= -1;
133 options
->revoked_keys_file
= NULL
;
134 options
->trusted_user_ca_keys
= NULL
;
135 options
->authorized_principals_file
= NULL
;
139 fill_default_server_options(ServerOptions
*options
)
141 /* Portable-specific options */
142 if (options
->use_pam
== -1)
143 options
->use_pam
= 0;
145 /* Standard Options */
146 if (options
->protocol
== SSH_PROTO_UNKNOWN
)
147 options
->protocol
= SSH_PROTO_2
;
148 if (options
->num_host_key_files
== 0) {
149 /* fill default hostkeys for protocols */
150 if (options
->protocol
& SSH_PROTO_1
)
151 options
->host_key_files
[options
->num_host_key_files
++] =
153 if (options
->protocol
& SSH_PROTO_2
) {
154 options
->host_key_files
[options
->num_host_key_files
++] =
155 _PATH_HOST_RSA_KEY_FILE
;
156 options
->host_key_files
[options
->num_host_key_files
++] =
157 _PATH_HOST_DSA_KEY_FILE
;
158 #ifdef OPENSSL_HAS_ECC
159 options
->host_key_files
[options
->num_host_key_files
++] =
160 _PATH_HOST_ECDSA_KEY_FILE
;
164 /* No certificates by default */
165 if (options
->num_ports
== 0)
166 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
167 if (options
->listen_addrs
== NULL
)
168 add_listen_addr(options
, NULL
, 0);
169 if (options
->pid_file
== NULL
)
170 options
->pid_file
= _PATH_SSH_DAEMON_PID_FILE
;
171 if (options
->server_key_bits
== -1)
172 options
->server_key_bits
= 1024;
173 if (options
->login_grace_time
== -1)
174 options
->login_grace_time
= 120;
175 if (options
->key_regeneration_time
== -1)
176 options
->key_regeneration_time
= 3600;
177 if (options
->permit_root_login
== PERMIT_NOT_SET
)
178 options
->permit_root_login
= PERMIT_YES
;
179 if (options
->ignore_rhosts
== -1)
180 options
->ignore_rhosts
= 1;
181 if (options
->ignore_user_known_hosts
== -1)
182 options
->ignore_user_known_hosts
= 0;
183 if (options
->print_motd
== -1)
184 options
->print_motd
= 1;
185 if (options
->print_lastlog
== -1)
186 options
->print_lastlog
= 1;
187 if (options
->x11_forwarding
== -1)
188 options
->x11_forwarding
= 0;
189 if (options
->x11_display_offset
== -1)
190 options
->x11_display_offset
= 10;
191 if (options
->x11_use_localhost
== -1)
192 options
->x11_use_localhost
= 1;
193 if (options
->xauth_location
== NULL
)
194 options
->xauth_location
= _PATH_XAUTH
;
195 if (options
->strict_modes
== -1)
196 options
->strict_modes
= 1;
197 if (options
->tcp_keep_alive
== -1)
198 options
->tcp_keep_alive
= 1;
199 if (options
->log_facility
== SYSLOG_FACILITY_NOT_SET
)
200 options
->log_facility
= SYSLOG_FACILITY_AUTH
;
201 if (options
->log_level
== SYSLOG_LEVEL_NOT_SET
)
202 options
->log_level
= SYSLOG_LEVEL_INFO
;
203 if (options
->rhosts_rsa_authentication
== -1)
204 options
->rhosts_rsa_authentication
= 0;
205 if (options
->hostbased_authentication
== -1)
206 options
->hostbased_authentication
= 0;
207 if (options
->hostbased_uses_name_from_packet_only
== -1)
208 options
->hostbased_uses_name_from_packet_only
= 0;
209 if (options
->rsa_authentication
== -1)
210 options
->rsa_authentication
= 1;
211 if (options
->pubkey_authentication
== -1)
212 options
->pubkey_authentication
= 1;
213 if (options
->kerberos_authentication
== -1)
214 options
->kerberos_authentication
= 0;
215 if (options
->kerberos_or_local_passwd
== -1)
216 options
->kerberos_or_local_passwd
= 1;
217 if (options
->kerberos_ticket_cleanup
== -1)
218 options
->kerberos_ticket_cleanup
= 1;
219 if (options
->kerberos_get_afs_token
== -1)
220 options
->kerberos_get_afs_token
= 0;
221 if (options
->gss_authentication
== -1)
222 options
->gss_authentication
= 0;
223 if (options
->gss_cleanup_creds
== -1)
224 options
->gss_cleanup_creds
= 1;
225 if (options
->password_authentication
== -1)
226 options
->password_authentication
= 1;
227 if (options
->kbd_interactive_authentication
== -1)
228 options
->kbd_interactive_authentication
= 0;
229 if (options
->challenge_response_authentication
== -1)
230 options
->challenge_response_authentication
= 1;
231 if (options
->permit_empty_passwd
== -1)
232 options
->permit_empty_passwd
= 0;
233 if (options
->permit_user_env
== -1)
234 options
->permit_user_env
= 0;
235 if (options
->use_login
== -1)
236 options
->use_login
= 0;
237 if (options
->compression
== -1)
238 options
->compression
= COMP_DELAYED
;
239 if (options
->allow_tcp_forwarding
== -1)
240 options
->allow_tcp_forwarding
= 1;
241 if (options
->allow_agent_forwarding
== -1)
242 options
->allow_agent_forwarding
= 1;
243 if (options
->gateway_ports
== -1)
244 options
->gateway_ports
= 0;
245 if (options
->max_startups
== -1)
246 options
->max_startups
= 10;
247 if (options
->max_startups_rate
== -1)
248 options
->max_startups_rate
= 100; /* 100% */
249 if (options
->max_startups_begin
== -1)
250 options
->max_startups_begin
= options
->max_startups
;
251 if (options
->max_authtries
== -1)
252 options
->max_authtries
= DEFAULT_AUTH_FAIL_MAX
;
253 if (options
->max_sessions
== -1)
254 options
->max_sessions
= DEFAULT_SESSIONS_MAX
;
255 if (options
->use_dns
== -1)
256 options
->use_dns
= 1;
257 if (options
->client_alive_interval
== -1)
258 options
->client_alive_interval
= 0;
259 if (options
->client_alive_count_max
== -1)
260 options
->client_alive_count_max
= 3;
261 if (options
->authorized_keys_file2
== NULL
) {
262 /* authorized_keys_file2 falls back to authorized_keys_file */
263 if (options
->authorized_keys_file
!= NULL
)
264 options
->authorized_keys_file2
= xstrdup(options
->authorized_keys_file
);
266 options
->authorized_keys_file2
= xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2
);
268 if (options
->authorized_keys_file
== NULL
)
269 options
->authorized_keys_file
= xstrdup(_PATH_SSH_USER_PERMITTED_KEYS
);
270 if (options
->permit_tun
== -1)
271 options
->permit_tun
= SSH_TUNMODE_NO
;
272 if (options
->zero_knowledge_password_authentication
== -1)
273 options
->zero_knowledge_password_authentication
= 0;
275 /* Turn privilege separation on by default */
276 if (use_privsep
== -1)
280 if (use_privsep
&& options
->compression
== 1) {
281 error("This platform does not support both privilege "
282 "separation and compression");
283 error("Compression disabled");
284 options
->compression
= 0;
290 /* Keyword tokens. */
292 sBadOption
, /* == unknown option */
293 /* Portable-specific options */
295 /* Standard Options */
296 sPort
, sHostKeyFile
, sServerKeyBits
, sLoginGraceTime
, sKeyRegenerationTime
,
297 sPermitRootLogin
, sLogFacility
, sLogLevel
,
298 sRhostsRSAAuthentication
, sRSAAuthentication
,
299 sKerberosAuthentication
, sKerberosOrLocalPasswd
, sKerberosTicketCleanup
,
300 sKerberosGetAFSToken
,
301 sKerberosTgtPassing
, sChallengeResponseAuthentication
,
302 sPasswordAuthentication
, sKbdInteractiveAuthentication
,
303 sListenAddress
, sAddressFamily
,
304 sPrintMotd
, sPrintLastLog
, sIgnoreRhosts
,
305 sX11Forwarding
, sX11DisplayOffset
, sX11UseLocalhost
,
306 sStrictModes
, sEmptyPasswd
, sTCPKeepAlive
,
307 sPermitUserEnvironment
, sUseLogin
, sAllowTcpForwarding
, sCompression
,
308 sAllowUsers
, sDenyUsers
, sAllowGroups
, sDenyGroups
,
309 sIgnoreUserKnownHosts
, sCiphers
, sMacs
, sProtocol
, sPidFile
,
310 sGatewayPorts
, sPubkeyAuthentication
, sXAuthLocation
, sSubsystem
,
311 sMaxStartups
, sMaxAuthTries
, sMaxSessions
,
312 sBanner
, sUseDNS
, sHostbasedAuthentication
,
313 sHostbasedUsesNameFromPacketOnly
, sClientAliveInterval
,
314 sClientAliveCountMax
, sAuthorizedKeysFile
, sAuthorizedKeysFile2
,
315 sGssAuthentication
, sGssCleanupCreds
, sAcceptEnv
, sPermitTunnel
,
316 sMatch
, sPermitOpen
, sForceCommand
, sChrootDirectory
,
317 sUsePrivilegeSeparation
, sAllowAgentForwarding
,
318 sZeroKnowledgePasswordAuthentication
, sHostCertificate
,
319 sRevokedKeys
, sTrustedUserCAKeys
, sAuthorizedPrincipalsFile
,
321 sDeprecated
, sUnsupported
324 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
325 #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
326 #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
328 /* Textual representation of the tokens. */
331 ServerOpCodes opcode
;
334 /* Portable-specific options */
336 { "usepam", sUsePAM
, SSHCFG_GLOBAL
},
338 { "usepam", sUnsupported
, SSHCFG_GLOBAL
},
340 { "pamauthenticationviakbdint", sDeprecated
, SSHCFG_GLOBAL
},
341 /* Standard Options */
342 { "port", sPort
, SSHCFG_GLOBAL
},
343 { "hostkey", sHostKeyFile
, SSHCFG_GLOBAL
},
344 { "hostdsakey", sHostKeyFile
, SSHCFG_GLOBAL
}, /* alias */
345 { "pidfile", sPidFile
, SSHCFG_GLOBAL
},
346 { "serverkeybits", sServerKeyBits
, SSHCFG_GLOBAL
},
347 { "logingracetime", sLoginGraceTime
, SSHCFG_GLOBAL
},
348 { "keyregenerationinterval", sKeyRegenerationTime
, SSHCFG_GLOBAL
},
349 { "permitrootlogin", sPermitRootLogin
, SSHCFG_ALL
},
350 { "syslogfacility", sLogFacility
, SSHCFG_GLOBAL
},
351 { "loglevel", sLogLevel
, SSHCFG_GLOBAL
},
352 { "rhostsauthentication", sDeprecated
, SSHCFG_GLOBAL
},
353 { "rhostsrsaauthentication", sRhostsRSAAuthentication
, SSHCFG_ALL
},
354 { "hostbasedauthentication", sHostbasedAuthentication
, SSHCFG_ALL
},
355 { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly
, SSHCFG_ALL
},
356 { "rsaauthentication", sRSAAuthentication
, SSHCFG_ALL
},
357 { "pubkeyauthentication", sPubkeyAuthentication
, SSHCFG_ALL
},
358 { "dsaauthentication", sPubkeyAuthentication
, SSHCFG_GLOBAL
}, /* alias */
360 { "kerberosauthentication", sKerberosAuthentication
, SSHCFG_ALL
},
361 { "kerberosorlocalpasswd", sKerberosOrLocalPasswd
, SSHCFG_GLOBAL
},
362 { "kerberosticketcleanup", sKerberosTicketCleanup
, SSHCFG_GLOBAL
},
364 { "kerberosgetafstoken", sKerberosGetAFSToken
, SSHCFG_GLOBAL
},
366 { "kerberosgetafstoken", sUnsupported
, SSHCFG_GLOBAL
},
369 { "kerberosauthentication", sUnsupported
, SSHCFG_ALL
},
370 { "kerberosorlocalpasswd", sUnsupported
, SSHCFG_GLOBAL
},
371 { "kerberosticketcleanup", sUnsupported
, SSHCFG_GLOBAL
},
372 { "kerberosgetafstoken", sUnsupported
, SSHCFG_GLOBAL
},
374 { "kerberostgtpassing", sUnsupported
, SSHCFG_GLOBAL
},
375 { "afstokenpassing", sUnsupported
, SSHCFG_GLOBAL
},
377 { "gssapiauthentication", sGssAuthentication
, SSHCFG_ALL
},
378 { "gssapicleanupcredentials", sGssCleanupCreds
, SSHCFG_GLOBAL
},
380 { "gssapiauthentication", sUnsupported
, SSHCFG_ALL
},
381 { "gssapicleanupcredentials", sUnsupported
, SSHCFG_GLOBAL
},
383 { "passwordauthentication", sPasswordAuthentication
, SSHCFG_ALL
},
384 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication
, SSHCFG_ALL
},
385 { "challengeresponseauthentication", sChallengeResponseAuthentication
, SSHCFG_GLOBAL
},
386 { "skeyauthentication", sChallengeResponseAuthentication
, SSHCFG_GLOBAL
}, /* alias */
388 { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication
, SSHCFG_ALL
},
390 { "zeroknowledgepasswordauthentication", sUnsupported
, SSHCFG_ALL
},
392 { "checkmail", sDeprecated
, SSHCFG_GLOBAL
},
393 { "listenaddress", sListenAddress
, SSHCFG_GLOBAL
},
394 { "addressfamily", sAddressFamily
, SSHCFG_GLOBAL
},
395 { "printmotd", sPrintMotd
, SSHCFG_GLOBAL
},
396 { "printlastlog", sPrintLastLog
, SSHCFG_GLOBAL
},
397 { "ignorerhosts", sIgnoreRhosts
, SSHCFG_GLOBAL
},
398 { "ignoreuserknownhosts", sIgnoreUserKnownHosts
, SSHCFG_GLOBAL
},
399 { "x11forwarding", sX11Forwarding
, SSHCFG_ALL
},
400 { "x11displayoffset", sX11DisplayOffset
, SSHCFG_ALL
},
401 { "x11uselocalhost", sX11UseLocalhost
, SSHCFG_ALL
},
402 { "xauthlocation", sXAuthLocation
, SSHCFG_GLOBAL
},
403 { "strictmodes", sStrictModes
, SSHCFG_GLOBAL
},
404 { "permitemptypasswords", sEmptyPasswd
, SSHCFG_ALL
},
405 { "permituserenvironment", sPermitUserEnvironment
, SSHCFG_GLOBAL
},
406 { "uselogin", sUseLogin
, SSHCFG_GLOBAL
},
407 { "compression", sCompression
, SSHCFG_GLOBAL
},
408 { "tcpkeepalive", sTCPKeepAlive
, SSHCFG_GLOBAL
},
409 { "keepalive", sTCPKeepAlive
, SSHCFG_GLOBAL
}, /* obsolete alias */
410 { "allowtcpforwarding", sAllowTcpForwarding
, SSHCFG_ALL
},
411 { "allowagentforwarding", sAllowAgentForwarding
, SSHCFG_ALL
},
412 { "allowusers", sAllowUsers
, SSHCFG_GLOBAL
},
413 { "denyusers", sDenyUsers
, SSHCFG_GLOBAL
},
414 { "allowgroups", sAllowGroups
, SSHCFG_GLOBAL
},
415 { "denygroups", sDenyGroups
, SSHCFG_GLOBAL
},
416 { "ciphers", sCiphers
, SSHCFG_GLOBAL
},
417 { "macs", sMacs
, SSHCFG_GLOBAL
},
418 { "protocol", sProtocol
, SSHCFG_GLOBAL
},
419 { "gatewayports", sGatewayPorts
, SSHCFG_ALL
},
420 { "subsystem", sSubsystem
, SSHCFG_GLOBAL
},
421 { "maxstartups", sMaxStartups
, SSHCFG_GLOBAL
},
422 { "maxauthtries", sMaxAuthTries
, SSHCFG_ALL
},
423 { "maxsessions", sMaxSessions
, SSHCFG_ALL
},
424 { "banner", sBanner
, SSHCFG_ALL
},
425 { "usedns", sUseDNS
, SSHCFG_GLOBAL
},
426 { "verifyreversemapping", sDeprecated
, SSHCFG_GLOBAL
},
427 { "reversemappingcheck", sDeprecated
, SSHCFG_GLOBAL
},
428 { "clientaliveinterval", sClientAliveInterval
, SSHCFG_GLOBAL
},
429 { "clientalivecountmax", sClientAliveCountMax
, SSHCFG_GLOBAL
},
430 { "authorizedkeysfile", sAuthorizedKeysFile
, SSHCFG_ALL
},
431 { "authorizedkeysfile2", sAuthorizedKeysFile2
, SSHCFG_ALL
},
432 { "useprivilegeseparation", sUsePrivilegeSeparation
, SSHCFG_GLOBAL
},
433 { "acceptenv", sAcceptEnv
, SSHCFG_GLOBAL
},
434 { "permittunnel", sPermitTunnel
, SSHCFG_ALL
},
435 { "match", sMatch
, SSHCFG_ALL
},
436 { "permitopen", sPermitOpen
, SSHCFG_ALL
},
437 { "forcecommand", sForceCommand
, SSHCFG_ALL
},
438 { "chrootdirectory", sChrootDirectory
, SSHCFG_ALL
},
439 { "hostcertificate", sHostCertificate
, SSHCFG_GLOBAL
},
440 { "revokedkeys", sRevokedKeys
, SSHCFG_ALL
},
441 { "trustedusercakeys", sTrustedUserCAKeys
, SSHCFG_ALL
},
442 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile
, SSHCFG_ALL
},
443 { "kexalgorithms", sKexAlgorithms
, SSHCFG_GLOBAL
},
444 { NULL
, sBadOption
, 0 }
451 { SSH_TUNMODE_NO
, "no" },
452 { SSH_TUNMODE_POINTOPOINT
, "point-to-point" },
453 { SSH_TUNMODE_ETHERNET
, "ethernet" },
454 { SSH_TUNMODE_YES
, "yes" },
459 * Returns the number of the token pointed to by cp or sBadOption.
463 parse_token(const char *cp
, const char *filename
,
464 int linenum
, u_int
*flags
)
468 for (i
= 0; keywords
[i
].name
; i
++)
469 if (strcasecmp(cp
, keywords
[i
].name
) == 0) {
470 *flags
= keywords
[i
].flags
;
471 return keywords
[i
].opcode
;
474 error("%s: line %d: Bad configuration option: %s",
475 filename
, linenum
, cp
);
480 derelativise_path(const char *path
)
482 char *expanded
, *ret
, cwd
[MAXPATHLEN
];
484 expanded
= tilde_expand_filename(path
, getuid());
485 if (*expanded
== '/')
487 if (getcwd(cwd
, sizeof(cwd
)) == NULL
)
488 fatal("%s: getcwd: %s", __func__
, strerror(errno
));
489 xasprintf(&ret
, "%s/%s", cwd
, expanded
);
495 add_listen_addr(ServerOptions
*options
, char *addr
, int port
)
499 if (options
->num_ports
== 0)
500 options
->ports
[options
->num_ports
++] = SSH_DEFAULT_PORT
;
501 if (options
->address_family
== -1)
502 options
->address_family
= AF_UNSPEC
;
504 for (i
= 0; i
< options
->num_ports
; i
++)
505 add_one_listen_addr(options
, addr
, options
->ports
[i
]);
507 add_one_listen_addr(options
, addr
, port
);
511 add_one_listen_addr(ServerOptions
*options
, char *addr
, int port
)
513 struct addrinfo hints
, *ai
, *aitop
;
514 char strport
[NI_MAXSERV
];
517 memset(&hints
, 0, sizeof(hints
));
518 hints
.ai_family
= options
->address_family
;
519 hints
.ai_socktype
= SOCK_STREAM
;
520 hints
.ai_flags
= (addr
== NULL
) ? AI_PASSIVE
: 0;
521 snprintf(strport
, sizeof strport
, "%d", port
);
522 if ((gaierr
= getaddrinfo(addr
, strport
, &hints
, &aitop
)) != 0)
523 fatal("bad addr or host: %s (%s)",
524 addr
? addr
: "<NULL>",
525 ssh_gai_strerror(gaierr
));
526 for (ai
= aitop
; ai
->ai_next
; ai
= ai
->ai_next
)
528 ai
->ai_next
= options
->listen_addrs
;
529 options
->listen_addrs
= aitop
;
533 * The strategy for the Match blocks is that the config file is parsed twice.
535 * The first time is at startup. activep is initialized to 1 and the
536 * directives in the global context are processed and acted on. Hitting a
537 * Match directive unsets activep and the directives inside the block are
538 * checked for syntax only.
540 * The second time is after a connection has been established but before
541 * authentication. activep is initialized to 2 and global config directives
542 * are ignored since they have already been processed. If the criteria in a
543 * Match block is met, activep is set and the subsequent directives
544 * processed and actioned until EOF or another Match block unsets it. Any
545 * options set are copied into the main server config.
547 * Potential additions/improvements:
548 * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
550 * - Add a Tag directive (idea from David Leonard) ala pf, eg:
551 * Match Address 192.168.0.*
556 * AllowTcpForwarding yes
557 * GatewayPorts clientspecified
560 * - Add a PermittedChannelRequests directive
562 * PermittedChannelRequests session,forwarded-tcpip
566 match_cfg_line_group(const char *grps
, int line
, const char *user
)
574 if ((pw
= getpwnam(user
)) == NULL
) {
575 debug("Can't match group at line %d because user %.100s does "
576 "not exist", line
, user
);
577 } else if (ga_init(pw
->pw_name
, pw
->pw_gid
) == 0) {
578 debug("Can't Match group because user %.100s not in any group "
579 "at line %d", user
, line
);
580 } else if (ga_match_pattern_list(grps
) != 1) {
581 debug("user %.100s does not match group list %.100s at line %d",
584 debug("user %.100s matched group list %.100s at line %d", user
,
594 match_cfg_line(char **condition
, int line
, const char *user
, const char *host
,
598 char *arg
, *attrib
, *cp
= *condition
;
602 debug3("checking syntax for 'Match %s'", cp
);
604 debug3("checking match for '%s' user %s host %s addr %s", cp
,
605 user
? user
: "(null)", host
? host
: "(null)",
606 address
? address
: "(null)");
608 while ((attrib
= strdelim(&cp
)) && *attrib
!= '\0') {
609 if ((arg
= strdelim(&cp
)) == NULL
|| *arg
== '\0') {
610 error("Missing Match criteria for %s", attrib
);
614 if (strcasecmp(attrib
, "user") == 0) {
619 if (match_pattern_list(user
, arg
, len
, 0) != 1)
622 debug("user %.100s matched 'User %.100s' at "
623 "line %d", user
, arg
, line
);
624 } else if (strcasecmp(attrib
, "group") == 0) {
625 switch (match_cfg_line_group(arg
, line
, user
)) {
631 } else if (strcasecmp(attrib
, "host") == 0) {
636 if (match_hostname(host
, arg
, len
) != 1)
639 debug("connection from %.100s matched 'Host "
640 "%.100s' at line %d", host
, arg
, line
);
641 } else if (strcasecmp(attrib
, "address") == 0) {
642 switch (addr_match_list(address
, arg
)) {
644 debug("connection from %.100s matched 'Address "
645 "%.100s' at line %d", address
, arg
, line
);
655 error("Unsupported Match attribute %s", attrib
);
660 debug3("match %sfound", result
? "" : "not ");
665 #define WHITESPACE " \t\r\n"
668 process_server_config_line(ServerOptions
*options
, char *line
,
669 const char *filename
, int linenum
, int *activep
, const char *user
,
670 const char *host
, const char *address
)
672 char *cp
, **charptr
, *arg
, *p
;
673 int cmdline
= 0, *intptr
, value
, n
;
674 SyslogFacility
*log_facility_ptr
;
675 LogLevel
*log_level_ptr
;
676 ServerOpCodes opcode
;
682 if ((arg
= strdelim(&cp
)) == NULL
)
684 /* Ignore leading whitespace */
687 if (!arg
|| !*arg
|| *arg
== '#')
691 opcode
= parse_token(arg
, filename
, linenum
, &flags
);
693 if (activep
== NULL
) { /* We are processing a command line directive */
697 if (*activep
&& opcode
!= sMatch
)
698 debug3("%s:%d setting %s %s", filename
, linenum
, arg
, cp
);
699 if (*activep
== 0 && !(flags
& SSHCFG_MATCH
)) {
701 fatal("%s line %d: Directive '%s' is not allowed "
702 "within a Match block", filename
, linenum
, arg
);
703 } else { /* this is a directive we have already processed */
711 /* Portable-specific options */
713 intptr
= &options
->use_pam
;
716 /* Standard Options */
720 /* ignore ports from configfile if cmdline specifies ports */
721 if (options
->ports_from_cmdline
)
723 if (options
->listen_addrs
!= NULL
)
724 fatal("%s line %d: ports must be specified before "
725 "ListenAddress.", filename
, linenum
);
726 if (options
->num_ports
>= MAX_PORTS
)
727 fatal("%s line %d: too many ports.",
730 if (!arg
|| *arg
== '\0')
731 fatal("%s line %d: missing port number.",
733 options
->ports
[options
->num_ports
++] = a2port(arg
);
734 if (options
->ports
[options
->num_ports
-1] <= 0)
735 fatal("%s line %d: Badly formatted port number.",
740 intptr
= &options
->server_key_bits
;
743 if (!arg
|| *arg
== '\0')
744 fatal("%s line %d: missing integer value.",
747 if (*activep
&& *intptr
== -1)
751 case sLoginGraceTime
:
752 intptr
= &options
->login_grace_time
;
755 if (!arg
|| *arg
== '\0')
756 fatal("%s line %d: missing time value.",
758 if ((value
= convtime(arg
)) == -1)
759 fatal("%s line %d: invalid time value.",
765 case sKeyRegenerationTime
:
766 intptr
= &options
->key_regeneration_time
;
771 if (arg
== NULL
|| *arg
== '\0')
772 fatal("%s line %d: missing address",
774 /* check for bare IPv6 address: no "[]" and 2 or more ":" */
775 if (strchr(arg
, '[') == NULL
&& (p
= strchr(arg
, ':')) != NULL
776 && strchr(p
+1, ':') != NULL
) {
777 add_listen_addr(options
, arg
, 0);
782 fatal("%s line %d: bad address:port usage",
784 p
= cleanhostname(p
);
787 else if ((port
= a2port(arg
)) <= 0)
788 fatal("%s line %d: bad port number", filename
, linenum
);
790 add_listen_addr(options
, p
, port
);
796 if (!arg
|| *arg
== '\0')
797 fatal("%s line %d: missing address family.",
799 intptr
= &options
->address_family
;
800 if (options
->listen_addrs
!= NULL
)
801 fatal("%s line %d: address family must be specified before "
802 "ListenAddress.", filename
, linenum
);
803 if (strcasecmp(arg
, "inet") == 0)
805 else if (strcasecmp(arg
, "inet6") == 0)
807 else if (strcasecmp(arg
, "any") == 0)
810 fatal("%s line %d: unsupported address family \"%s\".",
811 filename
, linenum
, arg
);
817 intptr
= &options
->num_host_key_files
;
818 if (*intptr
>= MAX_HOSTKEYS
)
819 fatal("%s line %d: too many host keys specified (max %d).",
820 filename
, linenum
, MAX_HOSTKEYS
);
821 charptr
= &options
->host_key_files
[*intptr
];
824 if (!arg
|| *arg
== '\0')
825 fatal("%s line %d: missing file name.",
827 if (*activep
&& *charptr
== NULL
) {
828 *charptr
= derelativise_path(arg
);
829 /* increase optional counter */
831 *intptr
= *intptr
+ 1;
835 case sHostCertificate
:
836 intptr
= &options
->num_host_cert_files
;
837 if (*intptr
>= MAX_HOSTKEYS
)
838 fatal("%s line %d: too many host certificates "
839 "specified (max %d).", filename
, linenum
,
841 charptr
= &options
->host_cert_files
[*intptr
];
846 charptr
= &options
->pid_file
;
849 case sPermitRootLogin
:
850 intptr
= &options
->permit_root_login
;
852 if (!arg
|| *arg
== '\0')
853 fatal("%s line %d: missing yes/"
854 "without-password/forced-commands-only/no "
855 "argument.", filename
, linenum
);
856 value
= 0; /* silence compiler */
857 if (strcmp(arg
, "without-password") == 0)
858 value
= PERMIT_NO_PASSWD
;
859 else if (strcmp(arg
, "forced-commands-only") == 0)
860 value
= PERMIT_FORCED_ONLY
;
861 else if (strcmp(arg
, "yes") == 0)
863 else if (strcmp(arg
, "no") == 0)
866 fatal("%s line %d: Bad yes/"
867 "without-password/forced-commands-only/no "
868 "argument: %s", filename
, linenum
, arg
);
869 if (*activep
&& *intptr
== -1)
874 intptr
= &options
->ignore_rhosts
;
877 if (!arg
|| *arg
== '\0')
878 fatal("%s line %d: missing yes/no argument.",
880 value
= 0; /* silence compiler */
881 if (strcmp(arg
, "yes") == 0)
883 else if (strcmp(arg
, "no") == 0)
886 fatal("%s line %d: Bad yes/no argument: %s",
887 filename
, linenum
, arg
);
888 if (*activep
&& *intptr
== -1)
892 case sIgnoreUserKnownHosts
:
893 intptr
= &options
->ignore_user_known_hosts
;
896 case sRhostsRSAAuthentication
:
897 intptr
= &options
->rhosts_rsa_authentication
;
900 case sHostbasedAuthentication
:
901 intptr
= &options
->hostbased_authentication
;
904 case sHostbasedUsesNameFromPacketOnly
:
905 intptr
= &options
->hostbased_uses_name_from_packet_only
;
908 case sRSAAuthentication
:
909 intptr
= &options
->rsa_authentication
;
912 case sPubkeyAuthentication
:
913 intptr
= &options
->pubkey_authentication
;
916 case sKerberosAuthentication
:
917 intptr
= &options
->kerberos_authentication
;
920 case sKerberosOrLocalPasswd
:
921 intptr
= &options
->kerberos_or_local_passwd
;
924 case sKerberosTicketCleanup
:
925 intptr
= &options
->kerberos_ticket_cleanup
;
928 case sKerberosGetAFSToken
:
929 intptr
= &options
->kerberos_get_afs_token
;
932 case sGssAuthentication
:
933 intptr
= &options
->gss_authentication
;
936 case sGssCleanupCreds
:
937 intptr
= &options
->gss_cleanup_creds
;
940 case sPasswordAuthentication
:
941 intptr
= &options
->password_authentication
;
944 case sZeroKnowledgePasswordAuthentication
:
945 intptr
= &options
->zero_knowledge_password_authentication
;
948 case sKbdInteractiveAuthentication
:
949 intptr
= &options
->kbd_interactive_authentication
;
952 case sChallengeResponseAuthentication
:
953 intptr
= &options
->challenge_response_authentication
;
957 intptr
= &options
->print_motd
;
961 intptr
= &options
->print_lastlog
;
965 intptr
= &options
->x11_forwarding
;
968 case sX11DisplayOffset
:
969 intptr
= &options
->x11_display_offset
;
972 case sX11UseLocalhost
:
973 intptr
= &options
->x11_use_localhost
;
977 charptr
= &options
->xauth_location
;
981 intptr
= &options
->strict_modes
;
985 intptr
= &options
->tcp_keep_alive
;
989 intptr
= &options
->permit_empty_passwd
;
992 case sPermitUserEnvironment
:
993 intptr
= &options
->permit_user_env
;
997 intptr
= &options
->use_login
;
1001 intptr
= &options
->compression
;
1002 arg
= strdelim(&cp
);
1003 if (!arg
|| *arg
== '\0')
1004 fatal("%s line %d: missing yes/no/delayed "
1005 "argument.", filename
, linenum
);
1006 value
= 0; /* silence compiler */
1007 if (strcmp(arg
, "delayed") == 0)
1008 value
= COMP_DELAYED
;
1009 else if (strcmp(arg
, "yes") == 0)
1011 else if (strcmp(arg
, "no") == 0)
1014 fatal("%s line %d: Bad yes/no/delayed "
1015 "argument: %s", filename
, linenum
, arg
);
1021 intptr
= &options
->gateway_ports
;
1022 arg
= strdelim(&cp
);
1023 if (!arg
|| *arg
== '\0')
1024 fatal("%s line %d: missing yes/no/clientspecified "
1025 "argument.", filename
, linenum
);
1026 value
= 0; /* silence compiler */
1027 if (strcmp(arg
, "clientspecified") == 0)
1029 else if (strcmp(arg
, "yes") == 0)
1031 else if (strcmp(arg
, "no") == 0)
1034 fatal("%s line %d: Bad yes/no/clientspecified "
1035 "argument: %s", filename
, linenum
, arg
);
1036 if (*activep
&& *intptr
== -1)
1041 intptr
= &options
->use_dns
;
1045 log_facility_ptr
= &options
->log_facility
;
1046 arg
= strdelim(&cp
);
1047 value
= log_facility_number(arg
);
1048 if (value
== SYSLOG_FACILITY_NOT_SET
)
1049 fatal("%.200s line %d: unsupported log facility '%s'",
1050 filename
, linenum
, arg
? arg
: "<NONE>");
1051 if (*log_facility_ptr
== -1)
1052 *log_facility_ptr
= (SyslogFacility
) value
;
1056 log_level_ptr
= &options
->log_level
;
1057 arg
= strdelim(&cp
);
1058 value
= log_level_number(arg
);
1059 if (value
== SYSLOG_LEVEL_NOT_SET
)
1060 fatal("%.200s line %d: unsupported log level '%s'",
1061 filename
, linenum
, arg
? arg
: "<NONE>");
1062 if (*log_level_ptr
== -1)
1063 *log_level_ptr
= (LogLevel
) value
;
1066 case sAllowTcpForwarding
:
1067 intptr
= &options
->allow_tcp_forwarding
;
1070 case sAllowAgentForwarding
:
1071 intptr
= &options
->allow_agent_forwarding
;
1074 case sUsePrivilegeSeparation
:
1075 intptr
= &use_privsep
;
1079 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1080 if (options
->num_allow_users
>= MAX_ALLOW_USERS
)
1081 fatal("%s line %d: too many allow users.",
1083 options
->allow_users
[options
->num_allow_users
++] =
1089 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1090 if (options
->num_deny_users
>= MAX_DENY_USERS
)
1091 fatal("%s line %d: too many deny users.",
1093 options
->deny_users
[options
->num_deny_users
++] =
1099 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1100 if (options
->num_allow_groups
>= MAX_ALLOW_GROUPS
)
1101 fatal("%s line %d: too many allow groups.",
1103 options
->allow_groups
[options
->num_allow_groups
++] =
1109 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1110 if (options
->num_deny_groups
>= MAX_DENY_GROUPS
)
1111 fatal("%s line %d: too many deny groups.",
1113 options
->deny_groups
[options
->num_deny_groups
++] = xstrdup(arg
);
1118 arg
= strdelim(&cp
);
1119 if (!arg
|| *arg
== '\0')
1120 fatal("%s line %d: Missing argument.", filename
, linenum
);
1121 if (!ciphers_valid(arg
))
1122 fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1123 filename
, linenum
, arg
? arg
: "<NONE>");
1124 if (options
->ciphers
== NULL
)
1125 options
->ciphers
= xstrdup(arg
);
1129 arg
= strdelim(&cp
);
1130 if (!arg
|| *arg
== '\0')
1131 fatal("%s line %d: Missing argument.", filename
, linenum
);
1132 if (!mac_valid(arg
))
1133 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1134 filename
, linenum
, arg
? arg
: "<NONE>");
1135 if (options
->macs
== NULL
)
1136 options
->macs
= xstrdup(arg
);
1139 case sKexAlgorithms
:
1140 arg
= strdelim(&cp
);
1141 if (!arg
|| *arg
== '\0')
1142 fatal("%s line %d: Missing argument.",
1144 if (!kex_names_valid(arg
))
1145 fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1146 filename
, linenum
, arg
? arg
: "<NONE>");
1147 if (options
->kex_algorithms
== NULL
)
1148 options
->kex_algorithms
= xstrdup(arg
);
1152 intptr
= &options
->protocol
;
1153 arg
= strdelim(&cp
);
1154 if (!arg
|| *arg
== '\0')
1155 fatal("%s line %d: Missing argument.", filename
, linenum
);
1156 value
= proto_spec(arg
);
1157 if (value
== SSH_PROTO_UNKNOWN
)
1158 fatal("%s line %d: Bad protocol spec '%s'.",
1159 filename
, linenum
, arg
? arg
: "<NONE>");
1160 if (*intptr
== SSH_PROTO_UNKNOWN
)
1165 if (options
->num_subsystems
>= MAX_SUBSYSTEMS
) {
1166 fatal("%s line %d: too many subsystems defined.",
1169 arg
= strdelim(&cp
);
1170 if (!arg
|| *arg
== '\0')
1171 fatal("%s line %d: Missing subsystem name.",
1174 arg
= strdelim(&cp
);
1177 for (i
= 0; i
< options
->num_subsystems
; i
++)
1178 if (strcmp(arg
, options
->subsystem_name
[i
]) == 0)
1179 fatal("%s line %d: Subsystem '%s' already defined.",
1180 filename
, linenum
, arg
);
1181 options
->subsystem_name
[options
->num_subsystems
] = xstrdup(arg
);
1182 arg
= strdelim(&cp
);
1183 if (!arg
|| *arg
== '\0')
1184 fatal("%s line %d: Missing subsystem command.",
1186 options
->subsystem_command
[options
->num_subsystems
] = xstrdup(arg
);
1188 /* Collect arguments (separate to executable) */
1190 len
= strlen(p
) + 1;
1191 while ((arg
= strdelim(&cp
)) != NULL
&& *arg
!= '\0') {
1192 len
+= 1 + strlen(arg
);
1193 p
= xrealloc(p
, 1, len
);
1194 strlcat(p
, " ", len
);
1195 strlcat(p
, arg
, len
);
1197 options
->subsystem_args
[options
->num_subsystems
] = p
;
1198 options
->num_subsystems
++;
1202 arg
= strdelim(&cp
);
1203 if (!arg
|| *arg
== '\0')
1204 fatal("%s line %d: Missing MaxStartups spec.",
1206 if ((n
= sscanf(arg
, "%d:%d:%d",
1207 &options
->max_startups_begin
,
1208 &options
->max_startups_rate
,
1209 &options
->max_startups
)) == 3) {
1210 if (options
->max_startups_begin
>
1211 options
->max_startups
||
1212 options
->max_startups_rate
> 100 ||
1213 options
->max_startups_rate
< 1)
1214 fatal("%s line %d: Illegal MaxStartups spec.",
1217 fatal("%s line %d: Illegal MaxStartups spec.",
1220 options
->max_startups
= options
->max_startups_begin
;
1224 intptr
= &options
->max_authtries
;
1228 intptr
= &options
->max_sessions
;
1232 charptr
= &options
->banner
;
1233 goto parse_filename
;
1236 * These options can contain %X options expanded at
1237 * connect time, so that you can specify paths like:
1239 * AuthorizedKeysFile /etc/ssh_keys/%u
1241 case sAuthorizedKeysFile
:
1242 charptr
= &options
->authorized_keys_file
;
1243 goto parse_tilde_filename
;
1244 case sAuthorizedKeysFile2
:
1245 charptr
= &options
->authorized_keys_file2
;
1246 goto parse_tilde_filename
;
1247 case sAuthorizedPrincipalsFile
:
1248 charptr
= &options
->authorized_principals_file
;
1249 parse_tilde_filename
:
1250 arg
= strdelim(&cp
);
1251 if (!arg
|| *arg
== '\0')
1252 fatal("%s line %d: missing file name.",
1254 if (*activep
&& *charptr
== NULL
) {
1255 *charptr
= tilde_expand_filename(arg
, getuid());
1256 /* increase optional counter */
1258 *intptr
= *intptr
+ 1;
1262 case sClientAliveInterval
:
1263 intptr
= &options
->client_alive_interval
;
1266 case sClientAliveCountMax
:
1267 intptr
= &options
->client_alive_count_max
;
1271 while ((arg
= strdelim(&cp
)) && *arg
!= '\0') {
1272 if (strchr(arg
, '=') != NULL
)
1273 fatal("%s line %d: Invalid environment name.",
1275 if (options
->num_accept_env
>= MAX_ACCEPT_ENV
)
1276 fatal("%s line %d: too many allow env.",
1280 options
->accept_env
[options
->num_accept_env
++] =
1286 intptr
= &options
->permit_tun
;
1287 arg
= strdelim(&cp
);
1288 if (!arg
|| *arg
== '\0')
1289 fatal("%s line %d: Missing yes/point-to-point/"
1290 "ethernet/no argument.", filename
, linenum
);
1292 for (i
= 0; tunmode_desc
[i
].val
!= -1; i
++)
1293 if (strcmp(tunmode_desc
[i
].text
, arg
) == 0) {
1294 value
= tunmode_desc
[i
].val
;
1298 fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1299 "no argument: %s", filename
, linenum
, arg
);
1306 fatal("Match directive not supported as a command-line "
1308 value
= match_cfg_line(&cp
, linenum
, user
, host
, address
);
1310 fatal("%s line %d: Bad Match condition", filename
,
1316 arg
= strdelim(&cp
);
1317 if (!arg
|| *arg
== '\0')
1318 fatal("%s line %d: missing PermitOpen specification",
1320 n
= options
->num_permitted_opens
; /* modified later */
1321 if (strcmp(arg
, "any") == 0) {
1322 if (*activep
&& n
== -1) {
1323 channel_clear_adm_permitted_opens();
1324 options
->num_permitted_opens
= 0;
1328 if (*activep
&& n
== -1)
1329 channel_clear_adm_permitted_opens();
1330 for (; arg
!= NULL
&& *arg
!= '\0'; arg
= strdelim(&cp
)) {
1333 fatal("%s line %d: missing host in PermitOpen",
1335 p
= cleanhostname(p
);
1336 if (arg
== NULL
|| (port
= a2port(arg
)) <= 0)
1337 fatal("%s line %d: bad port number in "
1338 "PermitOpen", filename
, linenum
);
1339 if (*activep
&& n
== -1)
1340 options
->num_permitted_opens
=
1341 channel_add_adm_permitted_opens(p
, port
);
1347 fatal("%.200s line %d: Missing argument.", filename
,
1349 len
= strspn(cp
, WHITESPACE
);
1350 if (*activep
&& options
->adm_forced_command
== NULL
)
1351 options
->adm_forced_command
= xstrdup(cp
+ len
);
1354 case sChrootDirectory
:
1355 charptr
= &options
->chroot_directory
;
1357 arg
= strdelim(&cp
);
1358 if (!arg
|| *arg
== '\0')
1359 fatal("%s line %d: missing file name.",
1361 if (*activep
&& *charptr
== NULL
)
1362 *charptr
= xstrdup(arg
);
1365 case sTrustedUserCAKeys
:
1366 charptr
= &options
->trusted_user_ca_keys
;
1367 goto parse_filename
;
1370 charptr
= &options
->revoked_keys_file
;
1371 goto parse_filename
;
1374 logit("%s line %d: Deprecated option %s",
1375 filename
, linenum
, arg
);
1377 arg
= strdelim(&cp
);
1381 logit("%s line %d: Unsupported option %s",
1382 filename
, linenum
, arg
);
1384 arg
= strdelim(&cp
);
1388 fatal("%s line %d: Missing handler for opcode %s (%d)",
1389 filename
, linenum
, arg
, opcode
);
1391 if ((arg
= strdelim(&cp
)) != NULL
&& *arg
!= '\0')
1392 fatal("%s line %d: garbage at end of line; \"%.200s\".",
1393 filename
, linenum
, arg
);
1397 /* Reads the server configuration file. */
1400 load_server_config(const char *filename
, Buffer
*conf
)
1402 char line
[1024], *cp
;
1405 debug2("%s: filename %s", __func__
, filename
);
1406 if ((f
= fopen(filename
, "r")) == NULL
) {
1411 while (fgets(line
, sizeof(line
), f
)) {
1413 * Trim out comments and strip whitespace
1414 * NB - preserve newlines, they are needed to reproduce
1415 * line numbers later for error messages
1417 if ((cp
= strchr(line
, '#')) != NULL
)
1418 memcpy(cp
, "\n", 2);
1419 cp
= line
+ strspn(line
, " \t\r");
1421 buffer_append(conf
, cp
, strlen(cp
));
1423 buffer_append(conf
, "\0", 1);
1425 debug2("%s: done config len = %d", __func__
, buffer_len(conf
));
1429 parse_server_match_config(ServerOptions
*options
, const char *user
,
1430 const char *host
, const char *address
)
1434 initialize_server_options(&mo
);
1435 parse_server_config(&mo
, "reprocess config", &cfg
, user
, host
, address
);
1436 copy_set_server_options(options
, &mo
, 0);
1440 #define M_CP_INTOPT(n) do {\
1444 #define M_CP_STROPT(n) do {\
1445 if (src->n != NULL) { \
1446 if (dst->n != NULL) \
1453 * Copy any supported values that are set.
1455 * If the preauth flag is set, we do not bother copying the string or
1456 * array values that are not used pre-authentication, because any that we
1457 * do use must be explictly sent in mm_getpwnamallow().
1460 copy_set_server_options(ServerOptions
*dst
, ServerOptions
*src
, int preauth
)
1462 M_CP_INTOPT(password_authentication
);
1463 M_CP_INTOPT(gss_authentication
);
1464 M_CP_INTOPT(rsa_authentication
);
1465 M_CP_INTOPT(pubkey_authentication
);
1466 M_CP_INTOPT(kerberos_authentication
);
1467 M_CP_INTOPT(hostbased_authentication
);
1468 M_CP_INTOPT(hostbased_uses_name_from_packet_only
);
1469 M_CP_INTOPT(kbd_interactive_authentication
);
1470 M_CP_INTOPT(zero_knowledge_password_authentication
);
1471 M_CP_INTOPT(permit_root_login
);
1472 M_CP_INTOPT(permit_empty_passwd
);
1474 M_CP_INTOPT(allow_tcp_forwarding
);
1475 M_CP_INTOPT(allow_agent_forwarding
);
1476 M_CP_INTOPT(permit_tun
);
1477 M_CP_INTOPT(gateway_ports
);
1478 M_CP_INTOPT(x11_display_offset
);
1479 M_CP_INTOPT(x11_forwarding
);
1480 M_CP_INTOPT(x11_use_localhost
);
1481 M_CP_INTOPT(max_sessions
);
1482 M_CP_INTOPT(max_authtries
);
1484 M_CP_STROPT(banner
);
1487 M_CP_STROPT(adm_forced_command
);
1488 M_CP_STROPT(chroot_directory
);
1489 M_CP_STROPT(trusted_user_ca_keys
);
1490 M_CP_STROPT(revoked_keys_file
);
1491 M_CP_STROPT(authorized_keys_file
);
1492 M_CP_STROPT(authorized_keys_file2
);
1493 M_CP_STROPT(authorized_principals_file
);
1500 parse_server_config(ServerOptions
*options
, const char *filename
, Buffer
*conf
,
1501 const char *user
, const char *host
, const char *address
)
1503 int active
, linenum
, bad_options
= 0;
1504 char *cp
, *obuf
, *cbuf
;
1506 debug2("%s: config %s len %d", __func__
, filename
, buffer_len(conf
));
1508 obuf
= cbuf
= xstrdup(buffer_ptr(conf
));
1509 active
= user
? 0 : 1;
1511 while ((cp
= strsep(&cbuf
, "\n")) != NULL
) {
1512 if (process_server_config_line(options
, cp
, filename
,
1513 linenum
++, &active
, user
, host
, address
) != 0)
1517 if (bad_options
> 0)
1518 fatal("%s: terminating, %d bad configuration options",
1519 filename
, bad_options
);
1523 fmt_intarg(ServerOpCodes code
, int val
)
1525 if (code
== sAddressFamily
) {
1537 if (code
== sPermitRootLogin
) {
1539 case PERMIT_NO_PASSWD
:
1540 return "without-password";
1541 case PERMIT_FORCED_ONLY
:
1542 return "forced-commands-only";
1547 if (code
== sProtocol
) {
1553 case (SSH_PROTO_1
|SSH_PROTO_2
):
1559 if (code
== sGatewayPorts
&& val
== 2)
1560 return "clientspecified";
1561 if (code
== sCompression
&& val
== COMP_DELAYED
)
1575 lookup_opcode_name(ServerOpCodes code
)
1579 for (i
= 0; keywords
[i
].name
!= NULL
; i
++)
1580 if (keywords
[i
].opcode
== code
)
1581 return(keywords
[i
].name
);
1586 dump_cfg_int(ServerOpCodes code
, int val
)
1588 printf("%s %d\n", lookup_opcode_name(code
), val
);
1592 dump_cfg_fmtint(ServerOpCodes code
, int val
)
1594 printf("%s %s\n", lookup_opcode_name(code
), fmt_intarg(code
, val
));
1598 dump_cfg_string(ServerOpCodes code
, const char *val
)
1602 printf("%s %s\n", lookup_opcode_name(code
), val
);
1606 dump_cfg_strarray(ServerOpCodes code
, u_int count
, char **vals
)
1610 for (i
= 0; i
< count
; i
++)
1611 printf("%s %s\n", lookup_opcode_name(code
), vals
[i
]);
1615 dump_config(ServerOptions
*o
)
1619 struct addrinfo
*ai
;
1620 char addr
[NI_MAXHOST
], port
[NI_MAXSERV
], *s
= NULL
;
1622 /* these are usually at the top of the config */
1623 for (i
= 0; i
< o
->num_ports
; i
++)
1624 printf("port %d\n", o
->ports
[i
]);
1625 dump_cfg_fmtint(sProtocol
, o
->protocol
);
1626 dump_cfg_fmtint(sAddressFamily
, o
->address_family
);
1628 /* ListenAddress must be after Port */
1629 for (ai
= o
->listen_addrs
; ai
; ai
= ai
->ai_next
) {
1630 if ((ret
= getnameinfo(ai
->ai_addr
, ai
->ai_addrlen
, addr
,
1631 sizeof(addr
), port
, sizeof(port
),
1632 NI_NUMERICHOST
|NI_NUMERICSERV
)) != 0) {
1633 error("getnameinfo failed: %.100s",
1634 (ret
!= EAI_SYSTEM
) ? gai_strerror(ret
) :
1637 if (ai
->ai_family
== AF_INET6
)
1638 printf("listenaddress [%s]:%s\n", addr
, port
);
1640 printf("listenaddress %s:%s\n", addr
, port
);
1644 /* integer arguments */
1646 dump_cfg_int(sUsePAM
, o
->use_pam
);
1648 dump_cfg_int(sServerKeyBits
, o
->server_key_bits
);
1649 dump_cfg_int(sLoginGraceTime
, o
->login_grace_time
);
1650 dump_cfg_int(sKeyRegenerationTime
, o
->key_regeneration_time
);
1651 dump_cfg_int(sX11DisplayOffset
, o
->x11_display_offset
);
1652 dump_cfg_int(sMaxAuthTries
, o
->max_authtries
);
1653 dump_cfg_int(sMaxSessions
, o
->max_sessions
);
1654 dump_cfg_int(sClientAliveInterval
, o
->client_alive_interval
);
1655 dump_cfg_int(sClientAliveCountMax
, o
->client_alive_count_max
);
1657 /* formatted integer arguments */
1658 dump_cfg_fmtint(sPermitRootLogin
, o
->permit_root_login
);
1659 dump_cfg_fmtint(sIgnoreRhosts
, o
->ignore_rhosts
);
1660 dump_cfg_fmtint(sIgnoreUserKnownHosts
, o
->ignore_user_known_hosts
);
1661 dump_cfg_fmtint(sRhostsRSAAuthentication
, o
->rhosts_rsa_authentication
);
1662 dump_cfg_fmtint(sHostbasedAuthentication
, o
->hostbased_authentication
);
1663 dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly
,
1664 o
->hostbased_uses_name_from_packet_only
);
1665 dump_cfg_fmtint(sRSAAuthentication
, o
->rsa_authentication
);
1666 dump_cfg_fmtint(sPubkeyAuthentication
, o
->pubkey_authentication
);
1668 dump_cfg_fmtint(sKerberosAuthentication
, o
->kerberos_authentication
);
1669 dump_cfg_fmtint(sKerberosOrLocalPasswd
, o
->kerberos_or_local_passwd
);
1670 dump_cfg_fmtint(sKerberosTicketCleanup
, o
->kerberos_ticket_cleanup
);
1672 dump_cfg_fmtint(sKerberosGetAFSToken
, o
->kerberos_get_afs_token
);
1676 dump_cfg_fmtint(sGssAuthentication
, o
->gss_authentication
);
1677 dump_cfg_fmtint(sGssCleanupCreds
, o
->gss_cleanup_creds
);
1680 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication
,
1681 o
->zero_knowledge_password_authentication
);
1683 dump_cfg_fmtint(sPasswordAuthentication
, o
->password_authentication
);
1684 dump_cfg_fmtint(sKbdInteractiveAuthentication
,
1685 o
->kbd_interactive_authentication
);
1686 dump_cfg_fmtint(sChallengeResponseAuthentication
,
1687 o
->challenge_response_authentication
);
1688 dump_cfg_fmtint(sPrintMotd
, o
->print_motd
);
1689 dump_cfg_fmtint(sPrintLastLog
, o
->print_lastlog
);
1690 dump_cfg_fmtint(sX11Forwarding
, o
->x11_forwarding
);
1691 dump_cfg_fmtint(sX11UseLocalhost
, o
->x11_use_localhost
);
1692 dump_cfg_fmtint(sStrictModes
, o
->strict_modes
);
1693 dump_cfg_fmtint(sTCPKeepAlive
, o
->tcp_keep_alive
);
1694 dump_cfg_fmtint(sEmptyPasswd
, o
->permit_empty_passwd
);
1695 dump_cfg_fmtint(sPermitUserEnvironment
, o
->permit_user_env
);
1696 dump_cfg_fmtint(sUseLogin
, o
->use_login
);
1697 dump_cfg_fmtint(sCompression
, o
->compression
);
1698 dump_cfg_fmtint(sGatewayPorts
, o
->gateway_ports
);
1699 dump_cfg_fmtint(sUseDNS
, o
->use_dns
);
1700 dump_cfg_fmtint(sAllowTcpForwarding
, o
->allow_tcp_forwarding
);
1701 dump_cfg_fmtint(sUsePrivilegeSeparation
, use_privsep
);
1703 /* string arguments */
1704 dump_cfg_string(sPidFile
, o
->pid_file
);
1705 dump_cfg_string(sXAuthLocation
, o
->xauth_location
);
1706 dump_cfg_string(sCiphers
, o
->ciphers
);
1707 dump_cfg_string(sMacs
, o
->macs
);
1708 dump_cfg_string(sBanner
, o
->banner
);
1709 dump_cfg_string(sAuthorizedKeysFile
, o
->authorized_keys_file
);
1710 dump_cfg_string(sAuthorizedKeysFile2
, o
->authorized_keys_file2
);
1711 dump_cfg_string(sForceCommand
, o
->adm_forced_command
);
1712 dump_cfg_string(sChrootDirectory
, o
->chroot_directory
);
1713 dump_cfg_string(sTrustedUserCAKeys
, o
->trusted_user_ca_keys
);
1714 dump_cfg_string(sRevokedKeys
, o
->revoked_keys_file
);
1715 dump_cfg_string(sAuthorizedPrincipalsFile
,
1716 o
->authorized_principals_file
);
1718 /* string arguments requiring a lookup */
1719 dump_cfg_string(sLogLevel
, log_level_name(o
->log_level
));
1720 dump_cfg_string(sLogFacility
, log_facility_name(o
->log_facility
));
1722 /* string array arguments */
1723 dump_cfg_strarray(sHostKeyFile
, o
->num_host_key_files
,
1725 dump_cfg_strarray(sHostKeyFile
, o
->num_host_cert_files
,
1726 o
->host_cert_files
);
1727 dump_cfg_strarray(sAllowUsers
, o
->num_allow_users
, o
->allow_users
);
1728 dump_cfg_strarray(sDenyUsers
, o
->num_deny_users
, o
->deny_users
);
1729 dump_cfg_strarray(sAllowGroups
, o
->num_allow_groups
, o
->allow_groups
);
1730 dump_cfg_strarray(sDenyGroups
, o
->num_deny_groups
, o
->deny_groups
);
1731 dump_cfg_strarray(sAcceptEnv
, o
->num_accept_env
, o
->accept_env
);
1733 /* other arguments */
1734 for (i
= 0; i
< o
->num_subsystems
; i
++)
1735 printf("subsystem %s %s\n", o
->subsystem_name
[i
],
1736 o
->subsystem_args
[i
]);
1738 printf("maxstartups %d:%d:%d\n", o
->max_startups_begin
,
1739 o
->max_startups_rate
, o
->max_startups
);
1741 for (i
= 0; tunmode_desc
[i
].val
!= -1; i
++)
1742 if (tunmode_desc
[i
].val
== o
->permit_tun
) {
1743 s
= tunmode_desc
[i
].text
;
1746 dump_cfg_string(sPermitTunnel
, s
);
1748 channel_print_adm_permitted_opens();