Branch data Line data Source code
1 : :
2 : : /* $OpenBSD: servconf.c,v 1.249 2014/01/29 06:18:35 djm Exp $ */
3 : : /*
4 : : * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 : : * All rights reserved
6 : : *
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".
12 : : */
13 : :
14 : : #include "includes.h"
15 : :
16 : : #include <sys/types.h>
17 : : #include <sys/socket.h>
18 : :
19 : : #include <netinet/in.h>
20 : : #include <netinet/in_systm.h>
21 : : #include <netinet/ip.h>
22 : :
23 : : #include <ctype.h>
24 : : #include <netdb.h>
25 : : #include <pwd.h>
26 : : #include <stdio.h>
27 : : #include <stdlib.h>
28 : : #include <string.h>
29 : : #include <signal.h>
30 : : #include <unistd.h>
31 : : #include <stdarg.h>
32 : : #include <errno.h>
33 : : #ifdef HAVE_UTIL_H
34 : : #include <util.h>
35 : : #endif
36 : :
37 : : #include "openbsd-compat/sys-queue.h"
38 : : #include "xmalloc.h"
39 : : #include "ssh.h"
40 : : #include "log.h"
41 : : #include "buffer.h"
42 : : #include "servconf.h"
43 : : #include "compat.h"
44 : : #include "pathnames.h"
45 : : #include "misc.h"
46 : : #include "cipher.h"
47 : : #include "key.h"
48 : : #include "kex.h"
49 : : #include "mac.h"
50 : : #include "match.h"
51 : : #include "channels.h"
52 : : #include "groupaccess.h"
53 : : #include "canohost.h"
54 : : #include "packet.h"
55 : : #include "hostfile.h"
56 : : #include "auth.h"
57 : :
58 : : static void add_listen_addr(ServerOptions *, char *, int);
59 : : static void add_one_listen_addr(ServerOptions *, char *, int);
60 : :
61 : : /* Use of privilege separation or not */
62 : : extern int use_privsep;
63 : : extern Buffer cfg;
64 : :
65 : : /* Initializes the server options to their default values. */
66 : :
67 : : void
68 : 2287 : initialize_server_options(ServerOptions *options)
69 : : {
70 : : memset(options, 0, sizeof(*options));
71 : :
72 : : /* Portable-specific options */
73 : 2287 : options->use_pam = -1;
74 : :
75 : : /* Standard Options */
76 : 2287 : options->num_ports = 0;
77 : 2287 : options->ports_from_cmdline = 0;
78 : 2287 : options->listen_addrs = NULL;
79 : 2287 : options->address_family = -1;
80 : 2287 : options->num_host_key_files = 0;
81 : 2287 : options->num_host_cert_files = 0;
82 : 2287 : options->host_key_agent = NULL;
83 : 2287 : options->pid_file = NULL;
84 : 2287 : options->server_key_bits = -1;
85 : 2287 : options->login_grace_time = -1;
86 : 2287 : options->key_regeneration_time = -1;
87 : 2287 : options->permit_root_login = PERMIT_NOT_SET;
88 : 2287 : options->ignore_rhosts = -1;
89 : 2287 : options->ignore_user_known_hosts = -1;
90 : 2287 : options->print_motd = -1;
91 : 2287 : options->print_lastlog = -1;
92 : 2287 : options->x11_forwarding = -1;
93 : 2287 : options->x11_display_offset = -1;
94 : 2287 : options->x11_use_localhost = -1;
95 : 2287 : options->permit_tty = -1;
96 : 2287 : options->xauth_location = NULL;
97 : 2287 : options->strict_modes = -1;
98 : 2287 : options->tcp_keep_alive = -1;
99 : 2287 : options->log_facility = SYSLOG_FACILITY_NOT_SET;
100 : 2287 : options->log_level = SYSLOG_LEVEL_NOT_SET;
101 : 2287 : options->rhosts_rsa_authentication = -1;
102 : 2287 : options->hostbased_authentication = -1;
103 : 2287 : options->hostbased_uses_name_from_packet_only = -1;
104 : 2287 : options->rsa_authentication = -1;
105 : 2287 : options->pubkey_authentication = -1;
106 : 2287 : options->kerberos_authentication = -1;
107 : 2287 : options->kerberos_or_local_passwd = -1;
108 : 2287 : options->kerberos_ticket_cleanup = -1;
109 : 2287 : options->kerberos_get_afs_token = -1;
110 : 2287 : options->gss_authentication=-1;
111 : 2287 : options->gss_cleanup_creds = -1;
112 : 2287 : options->password_authentication = -1;
113 : 2287 : options->kbd_interactive_authentication = -1;
114 : 2287 : options->challenge_response_authentication = -1;
115 : 2287 : options->permit_empty_passwd = -1;
116 : 2287 : options->permit_user_env = -1;
117 : 2287 : options->use_login = -1;
118 : 2287 : options->compression = -1;
119 : 2287 : options->rekey_limit = -1;
120 : 2287 : options->rekey_interval = -1;
121 : 2287 : options->allow_tcp_forwarding = -1;
122 : 2287 : options->allow_agent_forwarding = -1;
123 : 2287 : options->num_allow_users = 0;
124 : 2287 : options->num_deny_users = 0;
125 : 2287 : options->num_allow_groups = 0;
126 : 2287 : options->num_deny_groups = 0;
127 : 2287 : options->ciphers = NULL;
128 : 2287 : options->macs = NULL;
129 : 2287 : options->kex_algorithms = NULL;
130 : 2287 : options->protocol = SSH_PROTO_UNKNOWN;
131 : 2287 : options->gateway_ports = -1;
132 : 2287 : options->num_subsystems = 0;
133 : 2287 : options->max_startups_begin = -1;
134 : 2287 : options->max_startups_rate = -1;
135 : 2287 : options->max_startups = -1;
136 : 2287 : options->max_authtries = -1;
137 : 2287 : options->max_sessions = -1;
138 : 2287 : options->banner = NULL;
139 : 2287 : options->use_dns = -1;
140 : 2287 : options->client_alive_interval = -1;
141 : 2287 : options->client_alive_count_max = -1;
142 : 2287 : options->num_authkeys_files = 0;
143 : 2287 : options->num_accept_env = 0;
144 : 2287 : options->permit_tun = -1;
145 : 2287 : options->num_permitted_opens = -1;
146 : 2287 : options->adm_forced_command = NULL;
147 : 2287 : options->chroot_directory = NULL;
148 : 2287 : options->authorized_keys_command = NULL;
149 : 2287 : options->authorized_keys_command_user = NULL;
150 : 2287 : options->revoked_keys_file = NULL;
151 : 2287 : options->trusted_user_ca_keys = NULL;
152 : 2287 : options->authorized_principals_file = NULL;
153 : 2287 : options->ip_qos_interactive = -1;
154 : 2287 : options->ip_qos_bulk = -1;
155 : 2287 : options->version_addendum = NULL;
156 : 2287 : }
157 : :
158 : : void
159 : 1435 : fill_default_server_options(ServerOptions *options)
160 : : {
161 : : /* Portable-specific options */
162 [ + - ]: 1435 : if (options->use_pam == -1)
163 : 1435 : options->use_pam = 0;
164 : :
165 : : /* Standard Options */
166 [ - + ]: 1435 : if (options->protocol == SSH_PROTO_UNKNOWN)
167 : 0 : options->protocol = SSH_PROTO_2;
168 [ - + ]: 1435 : if (options->num_host_key_files == 0) {
169 : : /* fill default hostkeys for protocols */
170 [ # # ]: 0 : if (options->protocol & SSH_PROTO_1)
171 : 0 : options->host_key_files[options->num_host_key_files++] =
172 : : _PATH_HOST_KEY_FILE;
173 [ # # ]: 0 : if (options->protocol & SSH_PROTO_2) {
174 : 0 : options->host_key_files[options->num_host_key_files++] =
175 : : _PATH_HOST_RSA_KEY_FILE;
176 : 0 : options->host_key_files[options->num_host_key_files++] =
177 : : _PATH_HOST_DSA_KEY_FILE;
178 : : #ifdef OPENSSL_HAS_ECC
179 : 0 : options->host_key_files[options->num_host_key_files++] =
180 : : _PATH_HOST_ECDSA_KEY_FILE;
181 : : #endif
182 : 0 : options->host_key_files[options->num_host_key_files++] =
183 : : _PATH_HOST_ED25519_KEY_FILE;
184 : : }
185 : : }
186 : : /* No certificates by default */
187 [ - + ]: 1435 : if (options->num_ports == 0)
188 : 0 : options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
189 [ - + ]: 1435 : if (options->listen_addrs == NULL)
190 : 0 : add_listen_addr(options, NULL, 0);
191 [ - + ]: 1435 : if (options->pid_file == NULL)
192 : 0 : options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
193 [ + - ]: 1435 : if (options->server_key_bits == -1)
194 : 1435 : options->server_key_bits = 1024;
195 [ + + ]: 1435 : if (options->login_grace_time == -1)
196 : 1428 : options->login_grace_time = 120;
197 [ + - ]: 1435 : if (options->key_regeneration_time == -1)
198 : 1435 : options->key_regeneration_time = 3600;
199 [ + - ]: 1435 : if (options->permit_root_login == PERMIT_NOT_SET)
200 : 1435 : options->permit_root_login = PERMIT_YES;
201 [ + - ]: 1435 : if (options->ignore_rhosts == -1)
202 : 1435 : options->ignore_rhosts = 1;
203 [ + - ]: 1435 : if (options->ignore_user_known_hosts == -1)
204 : 1435 : options->ignore_user_known_hosts = 0;
205 [ + - ]: 1435 : if (options->print_motd == -1)
206 : 1435 : options->print_motd = 1;
207 [ + - ]: 1435 : if (options->print_lastlog == -1)
208 : 1435 : options->print_lastlog = 1;
209 [ + - ]: 1435 : if (options->x11_forwarding == -1)
210 : 1435 : options->x11_forwarding = 0;
211 [ + - ]: 1435 : if (options->x11_display_offset == -1)
212 : 1435 : options->x11_display_offset = 10;
213 [ + - ]: 1435 : if (options->x11_use_localhost == -1)
214 : 1435 : options->x11_use_localhost = 1;
215 [ + - ]: 1435 : if (options->xauth_location == NULL)
216 : 1435 : options->xauth_location = _PATH_XAUTH;
217 [ + - ]: 1435 : if (options->permit_tty == -1)
218 : 1435 : options->permit_tty = 1;
219 [ - + ]: 1435 : if (options->strict_modes == -1)
220 : 0 : options->strict_modes = 1;
221 [ + - ]: 1435 : if (options->tcp_keep_alive == -1)
222 : 1435 : options->tcp_keep_alive = 1;
223 [ + - ]: 1435 : if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
224 : 1435 : options->log_facility = SYSLOG_FACILITY_AUTH;
225 [ - + ]: 1435 : if (options->log_level == SYSLOG_LEVEL_NOT_SET)
226 : 0 : options->log_level = SYSLOG_LEVEL_INFO;
227 [ + - ]: 1435 : if (options->rhosts_rsa_authentication == -1)
228 : 1435 : options->rhosts_rsa_authentication = 0;
229 [ + - ]: 1435 : if (options->hostbased_authentication == -1)
230 : 1435 : options->hostbased_authentication = 0;
231 [ + - ]: 1435 : if (options->hostbased_uses_name_from_packet_only == -1)
232 : 1435 : options->hostbased_uses_name_from_packet_only = 0;
233 [ + - ]: 1435 : if (options->rsa_authentication == -1)
234 : 1435 : options->rsa_authentication = 1;
235 [ + - ]: 1435 : if (options->pubkey_authentication == -1)
236 : 1435 : options->pubkey_authentication = 1;
237 [ + - ]: 1435 : if (options->kerberos_authentication == -1)
238 : 1435 : options->kerberos_authentication = 0;
239 [ + - ]: 1435 : if (options->kerberos_or_local_passwd == -1)
240 : 1435 : options->kerberos_or_local_passwd = 1;
241 [ + - ]: 1435 : if (options->kerberos_ticket_cleanup == -1)
242 : 1435 : options->kerberos_ticket_cleanup = 1;
243 [ + - ]: 1435 : if (options->kerberos_get_afs_token == -1)
244 : 1435 : options->kerberos_get_afs_token = 0;
245 [ + - ]: 1435 : if (options->gss_authentication == -1)
246 : 1435 : options->gss_authentication = 0;
247 [ + - ]: 1435 : if (options->gss_cleanup_creds == -1)
248 : 1435 : options->gss_cleanup_creds = 1;
249 [ + - ]: 1435 : if (options->password_authentication == -1)
250 : 1435 : options->password_authentication = 1;
251 [ + - ]: 1435 : if (options->kbd_interactive_authentication == -1)
252 : 1435 : options->kbd_interactive_authentication = 0;
253 [ + - ]: 1435 : if (options->challenge_response_authentication == -1)
254 : 1435 : options->challenge_response_authentication = 1;
255 [ + - ]: 1435 : if (options->permit_empty_passwd == -1)
256 : 1435 : options->permit_empty_passwd = 0;
257 [ + + ]: 1435 : if (options->permit_user_env == -1)
258 : 1425 : options->permit_user_env = 0;
259 [ + - ]: 1435 : if (options->use_login == -1)
260 : 1435 : options->use_login = 0;
261 [ + - ]: 1435 : if (options->compression == -1)
262 : 1435 : options->compression = COMP_DELAYED;
263 [ + + ]: 1435 : if (options->rekey_limit == -1)
264 : 1307 : options->rekey_limit = 0;
265 [ + + ]: 1435 : if (options->rekey_interval == -1)
266 : 1307 : options->rekey_interval = 0;
267 [ + + ]: 1435 : if (options->allow_tcp_forwarding == -1)
268 : 1371 : options->allow_tcp_forwarding = FORWARD_ALLOW;
269 [ + - ]: 1435 : if (options->allow_agent_forwarding == -1)
270 : 1435 : options->allow_agent_forwarding = 1;
271 [ + - ]: 1435 : if (options->gateway_ports == -1)
272 : 1435 : options->gateway_ports = 0;
273 [ + + ]: 1435 : if (options->max_startups == -1)
274 : 1428 : options->max_startups = 100;
275 [ + - ]: 1435 : if (options->max_startups_rate == -1)
276 : 1435 : options->max_startups_rate = 30; /* 30% */
277 [ + + ]: 1435 : if (options->max_startups_begin == -1)
278 : 1428 : options->max_startups_begin = 10;
279 [ + - ]: 1435 : if (options->max_authtries == -1)
280 : 1435 : options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
281 [ + - ]: 1435 : if (options->max_sessions == -1)
282 : 1435 : options->max_sessions = DEFAULT_SESSIONS_MAX;
283 [ + - ]: 1435 : if (options->use_dns == -1)
284 : 1435 : options->use_dns = 1;
285 [ + - ]: 1435 : if (options->client_alive_interval == -1)
286 : 1435 : options->client_alive_interval = 0;
287 [ + - ]: 1435 : if (options->client_alive_count_max == -1)
288 : 1435 : options->client_alive_count_max = 3;
289 [ - + ]: 1435 : if (options->num_authkeys_files == 0) {
290 : 0 : options->authorized_keys_files[options->num_authkeys_files++] =
291 : 0 : xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
292 : 0 : options->authorized_keys_files[options->num_authkeys_files++] =
293 : 0 : xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
294 : : }
295 [ + - ]: 1435 : if (options->permit_tun == -1)
296 : 1435 : options->permit_tun = SSH_TUNMODE_NO;
297 [ + - ]: 1435 : if (options->ip_qos_interactive == -1)
298 : 1435 : options->ip_qos_interactive = IPTOS_LOWDELAY;
299 [ + - ]: 1435 : if (options->ip_qos_bulk == -1)
300 : 1435 : options->ip_qos_bulk = IPTOS_THROUGHPUT;
301 [ + - ]: 1435 : if (options->version_addendum == NULL)
302 : 1435 : options->version_addendum = xstrdup("");
303 : : /* Turn privilege separation on by default */
304 [ + + ]: 1435 : if (use_privsep == -1)
305 : 1206 : use_privsep = PRIVSEP_NOSANDBOX;
306 : :
307 : : #ifndef HAVE_MMAP
308 : : if (use_privsep && options->compression == 1) {
309 : : error("This platform does not support both privilege "
310 : : "separation and compression");
311 : : error("Compression disabled");
312 : : options->compression = 0;
313 : : }
314 : : #endif
315 : :
316 : 1435 : }
317 : :
318 : : /* Keyword tokens. */
319 : : typedef enum {
320 : : sBadOption, /* == unknown option */
321 : : /* Portable-specific options */
322 : : sUsePAM,
323 : : /* Standard Options */
324 : : sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
325 : : sPermitRootLogin, sLogFacility, sLogLevel,
326 : : sRhostsRSAAuthentication, sRSAAuthentication,
327 : : sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
328 : : sKerberosGetAFSToken,
329 : : sKerberosTgtPassing, sChallengeResponseAuthentication,
330 : : sPasswordAuthentication, sKbdInteractiveAuthentication,
331 : : sListenAddress, sAddressFamily,
332 : : sPrintMotd, sPrintLastLog, sIgnoreRhosts,
333 : : sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
334 : : sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
335 : : sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
336 : : sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
337 : : sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
338 : : sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
339 : : sMaxStartups, sMaxAuthTries, sMaxSessions,
340 : : sBanner, sUseDNS, sHostbasedAuthentication,
341 : : sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
342 : : sClientAliveCountMax, sAuthorizedKeysFile,
343 : : sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
344 : : sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
345 : : sUsePrivilegeSeparation, sAllowAgentForwarding,
346 : : sHostCertificate,
347 : : sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
348 : : sKexAlgorithms, sIPQoS, sVersionAddendum,
349 : : sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
350 : : sAuthenticationMethods, sHostKeyAgent,
351 : : sDeprecated, sUnsupported
352 : : } ServerOpCodes;
353 : :
354 : : #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
355 : : #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
356 : : #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
357 : :
358 : : /* Textual representation of the tokens. */
359 : : static struct {
360 : : const char *name;
361 : : ServerOpCodes opcode;
362 : : u_int flags;
363 : : } keywords[] = {
364 : : /* Portable-specific options */
365 : : #ifdef USE_PAM
366 : : { "usepam", sUsePAM, SSHCFG_GLOBAL },
367 : : #else
368 : : { "usepam", sUnsupported, SSHCFG_GLOBAL },
369 : : #endif
370 : : { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
371 : : /* Standard Options */
372 : : { "port", sPort, SSHCFG_GLOBAL },
373 : : { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
374 : : { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
375 : : { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
376 : : { "pidfile", sPidFile, SSHCFG_GLOBAL },
377 : : { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
378 : : { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
379 : : { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
380 : : { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
381 : : { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
382 : : { "loglevel", sLogLevel, SSHCFG_GLOBAL },
383 : : { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
384 : : { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
385 : : { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
386 : : { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
387 : : { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
388 : : { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
389 : : { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
390 : : #ifdef KRB5
391 : : { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
392 : : { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
393 : : { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
394 : : #ifdef USE_AFS
395 : : { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
396 : : #else
397 : : { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
398 : : #endif
399 : : #else
400 : : { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
401 : : { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
402 : : { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
403 : : { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
404 : : #endif
405 : : { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
406 : : { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
407 : : #ifdef GSSAPI
408 : : { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
409 : : { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
410 : : #else
411 : : { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
412 : : { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
413 : : #endif
414 : : { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
415 : : { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
416 : : { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
417 : : { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
418 : : { "checkmail", sDeprecated, SSHCFG_GLOBAL },
419 : : { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
420 : : { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
421 : : { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
422 : : { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
423 : : { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
424 : : { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
425 : : { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
426 : : { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
427 : : { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
428 : : { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
429 : : { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
430 : : { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
431 : : { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
432 : : { "uselogin", sUseLogin, SSHCFG_GLOBAL },
433 : : { "compression", sCompression, SSHCFG_GLOBAL },
434 : : { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
435 : : { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
436 : : { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
437 : : { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
438 : : { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
439 : : { "allowusers", sAllowUsers, SSHCFG_ALL },
440 : : { "denyusers", sDenyUsers, SSHCFG_ALL },
441 : : { "allowgroups", sAllowGroups, SSHCFG_ALL },
442 : : { "denygroups", sDenyGroups, SSHCFG_ALL },
443 : : { "ciphers", sCiphers, SSHCFG_GLOBAL },
444 : : { "macs", sMacs, SSHCFG_GLOBAL },
445 : : { "protocol", sProtocol, SSHCFG_GLOBAL },
446 : : { "gatewayports", sGatewayPorts, SSHCFG_ALL },
447 : : { "subsystem", sSubsystem, SSHCFG_GLOBAL },
448 : : { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
449 : : { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
450 : : { "maxsessions", sMaxSessions, SSHCFG_ALL },
451 : : { "banner", sBanner, SSHCFG_ALL },
452 : : { "usedns", sUseDNS, SSHCFG_GLOBAL },
453 : : { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
454 : : { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
455 : : { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
456 : : { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
457 : : { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
458 : : { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
459 : : { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
460 : : { "acceptenv", sAcceptEnv, SSHCFG_ALL },
461 : : { "permittunnel", sPermitTunnel, SSHCFG_ALL },
462 : : { "permittty", sPermitTTY, SSHCFG_ALL },
463 : : { "match", sMatch, SSHCFG_ALL },
464 : : { "permitopen", sPermitOpen, SSHCFG_ALL },
465 : : { "forcecommand", sForceCommand, SSHCFG_ALL },
466 : : { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
467 : : { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
468 : : { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
469 : : { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
470 : : { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
471 : : { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
472 : : { "ipqos", sIPQoS, SSHCFG_ALL },
473 : : { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
474 : : { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
475 : : { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
476 : : { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
477 : : { NULL, sBadOption, 0 }
478 : : };
479 : :
480 : : static struct {
481 : : int val;
482 : : char *text;
483 : : } tunmode_desc[] = {
484 : : { SSH_TUNMODE_NO, "no" },
485 : : { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
486 : : { SSH_TUNMODE_ETHERNET, "ethernet" },
487 : : { SSH_TUNMODE_YES, "yes" },
488 : : { -1, NULL }
489 : : };
490 : :
491 : : /*
492 : : * Returns the number of the token pointed to by cp or sBadOption.
493 : : */
494 : :
495 : : static ServerOpCodes
496 : 33678 : parse_token(const char *cp, const char *filename,
497 : : int linenum, u_int *flags)
498 : : {
499 : : u_int i;
500 : :
501 [ + - ]: 1341062 : for (i = 0; keywords[i].name; i++)
502 [ + + ]: 1341062 : if (strcasecmp(cp, keywords[i].name) == 0) {
503 : 33678 : *flags = keywords[i].flags;
504 : 33678 : return keywords[i].opcode;
505 : : }
506 : :
507 : 0 : error("%s: line %d: Bad configuration option: %s",
508 : : filename, linenum, cp);
509 : 0 : return sBadOption;
510 : : }
511 : :
512 : : char *
513 : 4639 : derelativise_path(const char *path)
514 : : {
515 : : char *expanded, *ret, cwd[MAXPATHLEN];
516 : :
517 : 4639 : expanded = tilde_expand_filename(path, getuid());
518 [ - + ]: 4639 : if (*expanded == '/')
519 : : return expanded;
520 [ # # ]: 0 : if (getcwd(cwd, sizeof(cwd)) == NULL)
521 : 0 : fatal("%s: getcwd: %s", __func__, strerror(errno));
522 : 0 : xasprintf(&ret, "%s/%s", cwd, expanded);
523 : 0 : free(expanded);
524 : 0 : return ret;
525 : : }
526 : :
527 : : static void
528 : 1435 : add_listen_addr(ServerOptions *options, char *addr, int port)
529 : : {
530 : : u_int i;
531 : :
532 [ - + ]: 1435 : if (options->num_ports == 0)
533 : 0 : options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
534 [ - + ]: 1435 : if (options->address_family == -1)
535 : 0 : options->address_family = AF_UNSPEC;
536 [ + - ]: 1435 : if (port == 0)
537 [ + + ]: 2870 : for (i = 0; i < options->num_ports; i++)
538 : 1435 : add_one_listen_addr(options, addr, options->ports[i]);
539 : : else
540 : 0 : add_one_listen_addr(options, addr, port);
541 : 1435 : }
542 : :
543 : : static void
544 : 2870 : add_one_listen_addr(ServerOptions *options, char *addr, int port)
545 : : {
546 : : struct addrinfo hints, *ai, *aitop;
547 : : char strport[NI_MAXSERV];
548 : : int gaierr;
549 : :
550 : : memset(&hints, 0, sizeof(hints));
551 : 1435 : hints.ai_family = options->address_family;
552 : 1435 : hints.ai_socktype = SOCK_STREAM;
553 : 1435 : hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
554 : : snprintf(strport, sizeof strport, "%d", port);
555 [ - + ]: 1435 : if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
556 [ # # ]: 0 : fatal("bad addr or host: %s (%s)",
557 : : addr ? addr : "<NULL>",
558 : : ssh_gai_strerror(gaierr));
559 [ - + ]: 1435 : for (ai = aitop; ai->ai_next; ai = ai->ai_next)
560 : : ;
561 : 1435 : ai->ai_next = options->listen_addrs;
562 : 1435 : options->listen_addrs = aitop;
563 : 1435 : }
564 : :
565 : : struct connection_info *
566 : 2271 : get_connection_info(int populate, int use_dns)
567 : : {
568 : : static struct connection_info ci;
569 : :
570 [ + + ]: 2271 : if (!populate)
571 : : return &ci;
572 : 836 : ci.host = get_canonical_hostname(use_dns);
573 : 836 : ci.address = get_remote_ipaddr();
574 : 836 : ci.laddress = get_local_ipaddr(packet_get_connection_in());
575 : 836 : ci.lport = get_local_port();
576 : 836 : return &ci;
577 : : }
578 : :
579 : : /*
580 : : * The strategy for the Match blocks is that the config file is parsed twice.
581 : : *
582 : : * The first time is at startup. activep is initialized to 1 and the
583 : : * directives in the global context are processed and acted on. Hitting a
584 : : * Match directive unsets activep and the directives inside the block are
585 : : * checked for syntax only.
586 : : *
587 : : * The second time is after a connection has been established but before
588 : : * authentication. activep is initialized to 2 and global config directives
589 : : * are ignored since they have already been processed. If the criteria in a
590 : : * Match block is met, activep is set and the subsequent directives
591 : : * processed and actioned until EOF or another Match block unsets it. Any
592 : : * options set are copied into the main server config.
593 : : *
594 : : * Potential additions/improvements:
595 : : * - Add Match support for pre-kex directives, eg Protocol, Ciphers.
596 : : *
597 : : * - Add a Tag directive (idea from David Leonard) ala pf, eg:
598 : : * Match Address 192.168.0.*
599 : : * Tag trusted
600 : : * Match Group wheel
601 : : * Tag trusted
602 : : * Match Tag trusted
603 : : * AllowTcpForwarding yes
604 : : * GatewayPorts clientspecified
605 : : * [...]
606 : : *
607 : : * - Add a PermittedChannelRequests directive
608 : : * Match Group shell
609 : : * PermittedChannelRequests session,forwarded-tcpip
610 : : */
611 : :
612 : : static int
613 : 0 : match_cfg_line_group(const char *grps, int line, const char *user)
614 : : {
615 : 0 : int result = 0;
616 : : struct passwd *pw;
617 : :
618 [ # # ]: 0 : if (user == NULL)
619 : : goto out;
620 : :
621 [ # # ]: 0 : if ((pw = getpwnam(user)) == NULL) {
622 : 0 : debug("Can't match group at line %d because user %.100s does "
623 : : "not exist", line, user);
624 [ # # ]: 0 : } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
625 : 0 : debug("Can't Match group because user %.100s not in any group "
626 : : "at line %d", user, line);
627 [ # # ]: 0 : } else if (ga_match_pattern_list(grps) != 1) {
628 : 0 : debug("user %.100s does not match group list %.100s at line %d",
629 : : user, grps, line);
630 : : } else {
631 : 0 : debug("user %.100s matched group list %.100s at line %d", user,
632 : : grps, line);
633 : 0 : result = 1;
634 : : }
635 : : out:
636 : 0 : ga_free();
637 : 0 : return result;
638 : : }
639 : :
640 : : /*
641 : : * All of the attributes on a single Match line are ANDed together, so we need
642 : : * to check every attribute and set the result to zero if any attribute does
643 : : * not match.
644 : : */
645 : : static int
646 : 178 : match_cfg_line(char **condition, int line, struct connection_info *ci)
647 : : {
648 : 178 : int result = 1, attributes = 0, port;
649 : 178 : char *arg, *attrib, *cp = *condition;
650 : : size_t len;
651 : :
652 [ + + ]: 178 : if (ci == NULL)
653 : 178 : debug3("checking syntax for 'Match %s'", cp);
654 : : else
655 [ + - ][ + - ]: 88 : debug3("checking match for '%s' user %s host %s addr %s "
[ + - ][ + - ]
656 : 88 : "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
657 : 88 : ci->host ? ci->host : "(null)",
658 : 88 : ci->address ? ci->address : "(null)",
659 : 88 : ci->laddress ? ci->laddress : "(null)", ci->lport);
660 : :
661 [ + + ][ + - ]: 356 : while ((attrib = strdelim(&cp)) && *attrib != '\0') {
662 : 178 : attributes++;
663 [ - + ]: 178 : if (strcasecmp(attrib, "all") == 0) {
664 [ # # ][ # # ]: 0 : if (attributes != 1 ||
665 [ # # ]: 0 : ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
666 : 0 : error("'all' cannot be combined with other "
667 : : "Match attributes");
668 : 0 : return -1;
669 : : }
670 : 0 : *condition = cp;
671 : 0 : return 1;
672 : : }
673 [ + - ][ - + ]: 178 : if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
674 : 0 : error("Missing Match criteria for %s", attrib);
675 : 0 : return -1;
676 : : }
677 : 178 : len = strlen(arg);
678 [ + + ]: 178 : if (strcasecmp(attrib, "user") == 0) {
679 [ + + ][ - + ]: 20 : if (ci == NULL || ci->user == NULL) {
680 : 10 : result = 0;
681 : 10 : continue;
682 : : }
683 [ + + ]: 10 : if (match_pattern_list(ci->user, arg, len, 0) != 1)
684 : : result = 0;
685 : : else
686 : 8 : debug("user %.100s matched 'User %.100s' at "
687 : : "line %d", ci->user, arg, line);
688 [ - + ]: 158 : } else if (strcasecmp(attrib, "group") == 0) {
689 [ # # ][ # # ]: 0 : if (ci == NULL || ci->user == NULL) {
690 : 0 : result = 0;
691 : 0 : continue;
692 : : }
693 [ # # # ]: 0 : switch (match_cfg_line_group(arg, line, ci->user)) {
694 : : case -1:
695 : : return -1;
696 : : case 0:
697 : 0 : result = 0;
698 : : }
699 [ - + ]: 158 : } else if (strcasecmp(attrib, "host") == 0) {
700 [ # # ][ # # ]: 0 : if (ci == NULL || ci->host == NULL) {
701 : 0 : result = 0;
702 : 0 : continue;
703 : : }
704 [ # # ]: 0 : if (match_hostname(ci->host, arg, len) != 1)
705 : : result = 0;
706 : : else
707 : 0 : debug("connection from %.100s matched 'Host "
708 : : "%.100s' at line %d", ci->host, arg, line);
709 [ + + ]: 158 : } else if (strcasecmp(attrib, "address") == 0) {
710 [ + + ][ - + ]: 94 : if (ci == NULL || ci->address == NULL) {
711 : 48 : result = 0;
712 : 48 : continue;
713 : : }
714 [ + + - - ]: 46 : switch (addr_match_list(ci->address, arg)) {
715 : : case 1:
716 : 15 : debug("connection from %.100s matched 'Address "
717 : : "%.100s' at line %d", ci->address, arg, line);
718 : 178 : break;
719 : : case 0:
720 : : case -1:
721 : 31 : result = 0;
722 : 31 : break;
723 : : case -2:
724 : : return -1;
725 : : }
726 [ + + ]: 64 : } else if (strcasecmp(attrib, "localaddress") == 0){
727 [ + + ][ - + ]: 32 : if (ci == NULL || ci->laddress == NULL) {
728 : 16 : result = 0;
729 : 16 : continue;
730 : : }
731 [ + + - - ]: 16 : switch (addr_match_list(ci->laddress, arg)) {
732 : : case 1:
733 : 2 : debug("connection from %.100s matched "
734 : : "'LocalAddress %.100s' at line %d",
735 : : ci->laddress, arg, line);
736 : 2 : break;
737 : : case 0:
738 : : case -1:
739 : 14 : result = 0;
740 : 14 : break;
741 : : case -2:
742 : : return -1;
743 : : }
744 [ + - ]: 32 : } else if (strcasecmp(attrib, "localport") == 0) {
745 [ - + ]: 32 : if ((port = a2port(arg)) == -1) {
746 : 0 : error("Invalid LocalPort '%s' on Match line",
747 : : arg);
748 : 0 : return -1;
749 : : }
750 [ + + ][ - + ]: 32 : if (ci == NULL || ci->lport == 0) {
751 : 16 : result = 0;
752 : 16 : continue;
753 : : }
754 : : /* TODO support port lists */
755 [ + + ]: 16 : if (port == ci->lport)
756 : 2 : debug("connection from %.100s matched "
757 : : "'LocalPort %d' at line %d",
758 : : ci->laddress, port, line);
759 : : else
760 : : result = 0;
761 : : } else {
762 : 0 : error("Unsupported Match attribute %s", attrib);
763 : 0 : return -1;
764 : : }
765 : : }
766 [ - + ]: 178 : if (attributes == 0) {
767 : 0 : error("One or more attributes required for Match");
768 : 0 : return -1;
769 : : }
770 [ + + ]: 178 : if (ci != NULL)
771 [ + + ]: 88 : debug3("match %sfound", result ? "" : "not ");
772 : 178 : *condition = cp;
773 : 178 : return result;
774 : : }
775 : :
776 : : #define WHITESPACE " \t\r\n"
777 : :
778 : : /* Multistate option parsing */
779 : : struct multistate {
780 : : char *key;
781 : : int value;
782 : : };
783 : : static const struct multistate multistate_addressfamily[] = {
784 : : { "inet", AF_INET },
785 : : { "inet6", AF_INET6 },
786 : : { "any", AF_UNSPEC },
787 : : { NULL, -1 }
788 : : };
789 : : static const struct multistate multistate_permitrootlogin[] = {
790 : : { "without-password", PERMIT_NO_PASSWD },
791 : : { "forced-commands-only", PERMIT_FORCED_ONLY },
792 : : { "yes", PERMIT_YES },
793 : : { "no", PERMIT_NO },
794 : : { NULL, -1 }
795 : : };
796 : : static const struct multistate multistate_compression[] = {
797 : : { "delayed", COMP_DELAYED },
798 : : { "yes", COMP_ZLIB },
799 : : { "no", COMP_NONE },
800 : : { NULL, -1 }
801 : : };
802 : : static const struct multistate multistate_gatewayports[] = {
803 : : { "clientspecified", 2 },
804 : : { "yes", 1 },
805 : : { "no", 0 },
806 : : { NULL, -1 }
807 : : };
808 : : static const struct multistate multistate_privsep[] = {
809 : : { "yes", PRIVSEP_NOSANDBOX },
810 : : { "sandbox", PRIVSEP_ON },
811 : : { "nosandbox", PRIVSEP_NOSANDBOX },
812 : : { "no", PRIVSEP_OFF },
813 : : { NULL, -1 }
814 : : };
815 : : static const struct multistate multistate_tcpfwd[] = {
816 : : { "yes", FORWARD_ALLOW },
817 : : { "all", FORWARD_ALLOW },
818 : : { "no", FORWARD_DENY },
819 : : { "remote", FORWARD_REMOTE },
820 : : { "local", FORWARD_LOCAL },
821 : : { NULL, -1 }
822 : : };
823 : :
824 : : int
825 : 38341 : process_server_config_line(ServerOptions *options, char *line,
826 : : const char *filename, int linenum, int *activep,
827 : : struct connection_info *connectinfo)
828 : : {
829 : : char *cp, **charptr, *arg, *p;
830 : 38341 : int cmdline = 0, *intptr, value, value2, n, port;
831 : : SyslogFacility *log_facility_ptr;
832 : : LogLevel *log_level_ptr;
833 : : ServerOpCodes opcode;
834 : 38341 : u_int i, flags = 0;
835 : : size_t len;
836 : : long long val64;
837 : : const struct multistate *multistate_ptr;
838 : :
839 : 38341 : cp = line;
840 [ + - ]: 38341 : if ((arg = strdelim(&cp)) == NULL)
841 : : return 0;
842 : : /* Ignore leading whitespace */
843 [ + + ]: 38341 : if (*arg == '\0')
844 : 4663 : arg = strdelim(&cp);
845 [ + + ][ + - ]: 38341 : if (!arg || !*arg || *arg == '#')
[ + - ]
846 : : return 0;
847 : 33678 : intptr = NULL;
848 : 33678 : charptr = NULL;
849 : 33678 : opcode = parse_token(arg, filename, linenum, &flags);
850 : :
851 [ + + ]: 33678 : if (activep == NULL) { /* We are processing a command line directive */
852 : 126 : cmdline = 1;
853 : 126 : activep = &cmdline;
854 : : }
855 [ + + ][ + + ]: 33678 : if (*activep && opcode != sMatch)
856 : 21032 : debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
857 [ + + ][ + + ]: 33678 : if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
858 [ + - ]: 9463 : if (connectinfo == NULL) {
859 : 0 : fatal("%s line %d: Directive '%s' is not allowed "
860 : : "within a Match block", filename, linenum, arg);
861 : : } else { /* this is a directive we have already processed */
862 [ + + ]: 29241 : while (arg)
863 : 19778 : arg = strdelim(&cp);
864 : : return 0;
865 : : }
866 : : }
867 : :
868 [ + - - - : 24215 : switch (opcode) {
- - + - +
- + + + +
- + + - -
- - - - -
- - - - -
- - - - -
- - - - -
- - + - -
+ - - + -
- - + + -
- - - + +
+ - - + +
+ - - - +
+ + - + +
- - - - -
- - - - ]
869 : : /* Portable-specific options */
870 : : case sUsePAM:
871 : 0 : intptr = &options->use_pam;
872 : 0 : goto parse_flag;
873 : :
874 : : /* Standard Options */
875 : : case sBadOption:
876 : : return -1;
877 : : case sPort:
878 : : /* ignore ports from configfile if cmdline specifies ports */
879 [ + - ]: 1435 : if (options->ports_from_cmdline)
880 : : return 0;
881 [ - + ]: 1435 : if (options->listen_addrs != NULL)
882 : 0 : fatal("%s line %d: ports must be specified before "
883 : : "ListenAddress.", filename, linenum);
884 [ - + ]: 1435 : if (options->num_ports >= MAX_PORTS)
885 : 0 : fatal("%s line %d: too many ports.",
886 : : filename, linenum);
887 : 1435 : arg = strdelim(&cp);
888 [ + - ][ - + ]: 1435 : if (!arg || *arg == '\0')
889 : 0 : fatal("%s line %d: missing port number.",
890 : : filename, linenum);
891 : 1435 : options->ports[options->num_ports++] = a2port(arg);
892 [ - + ]: 1435 : if (options->ports[options->num_ports-1] <= 0)
893 : 0 : fatal("%s line %d: Badly formatted port number.",
894 : : filename, linenum);
895 : : break;
896 : :
897 : : case sServerKeyBits:
898 : 0 : intptr = &options->server_key_bits;
899 : : parse_int:
900 : 0 : arg = strdelim(&cp);
901 [ # # ][ # # ]: 0 : if (!arg || *arg == '\0')
902 : 0 : fatal("%s line %d: missing integer value.",
903 : : filename, linenum);
904 : 0 : value = atoi(arg);
905 [ # # ][ # # ]: 0 : if (*activep && *intptr == -1)
906 : 0 : *intptr = value;
907 : : break;
908 : :
909 : : case sLoginGraceTime:
910 : 7 : intptr = &options->login_grace_time;
911 : : parse_time:
912 : 263 : arg = strdelim(&cp);
913 [ + - ][ - + ]: 263 : if (!arg || *arg == '\0')
914 : 0 : fatal("%s line %d: missing time value.",
915 : : filename, linenum);
916 [ - + ]: 263 : if ((value = convtime(arg)) == -1)
917 : 0 : fatal("%s line %d: invalid time value.",
918 : : filename, linenum);
919 [ + + ]: 263 : if (*intptr == -1)
920 : 137 : *intptr = value;
921 : : break;
922 : :
923 : : case sKeyRegenerationTime:
924 : 0 : intptr = &options->key_regeneration_time;
925 : 0 : goto parse_time;
926 : :
927 : : case sListenAddress:
928 : 1435 : arg = strdelim(&cp);
929 [ + - ][ - + ]: 1435 : if (arg == NULL || *arg == '\0')
930 : 0 : fatal("%s line %d: missing address",
931 : : filename, linenum);
932 : : /* check for bare IPv6 address: no "[]" and 2 or more ":" */
933 [ + - ][ - + ]: 1435 : if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
934 [ # # ]: 0 : && strchr(p+1, ':') != NULL) {
935 : 0 : add_listen_addr(options, arg, 0);
936 : 0 : break;
937 : : }
938 : 1435 : p = hpdelim(&arg);
939 [ - + ]: 1435 : if (p == NULL)
940 : 0 : fatal("%s line %d: bad address:port usage",
941 : : filename, linenum);
942 : 1435 : p = cleanhostname(p);
943 [ - + ]: 1435 : if (arg == NULL)
944 : : port = 0;
945 [ # # ]: 0 : else if ((port = a2port(arg)) <= 0)
946 : 0 : fatal("%s line %d: bad port number", filename, linenum);
947 : :
948 : 1435 : add_listen_addr(options, p, port);
949 : :
950 : 1435 : break;
951 : :
952 : : case sAddressFamily:
953 : 1435 : intptr = &options->address_family;
954 : 1435 : multistate_ptr = multistate_addressfamily;
955 [ - + ]: 1435 : if (options->listen_addrs != NULL)
956 : 0 : fatal("%s line %d: address family must be specified "
957 : : "before ListenAddress.", filename, linenum);
958 : : parse_multistate:
959 : 1792 : arg = strdelim(&cp);
960 [ + - ][ + - ]: 1792 : if (!arg || *arg == '\0')
961 : 0 : fatal("%s line %d: missing argument.",
962 : : filename, linenum);
963 : : value = -1;
964 [ + - ]: 2311 : for (i = 0; multistate_ptr[i].key != NULL; i++) {
965 [ + + ]: 2311 : if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
966 : 1792 : value = multistate_ptr[i].value;
967 : 1792 : break;
968 : : }
969 : : }
970 [ - + ]: 1792 : if (value == -1)
971 : 0 : fatal("%s line %d: unsupported option \"%s\".",
972 : : filename, linenum, arg);
973 [ + + ][ + - ]: 1792 : if (*activep && *intptr == -1)
974 : 1728 : *intptr = value;
975 : : break;
976 : :
977 : : case sHostKeyFile:
978 : 2903 : intptr = &options->num_host_key_files;
979 [ - + ]: 2903 : if (*intptr >= MAX_HOSTKEYS)
980 : 0 : fatal("%s line %d: too many host keys specified (max %d).",
981 : : filename, linenum, MAX_HOSTKEYS);
982 : 2903 : charptr = &options->host_key_files[*intptr];
983 : : parse_filename:
984 : 4767 : arg = strdelim(&cp);
985 [ + - ][ - + ]: 4767 : if (!arg || *arg == '\0')
986 : 0 : fatal("%s line %d: missing file name.",
987 : : filename, linenum);
988 [ + + ][ + - ]: 4767 : if (*activep && *charptr == NULL) {
989 : 4639 : *charptr = derelativise_path(arg);
990 : : /* increase optional counter */
991 [ + + ]: 4639 : if (intptr != NULL)
992 : 2957 : *intptr = *intptr + 1;
993 : : }
994 : : break;
995 : :
996 : : case sHostKeyAgent:
997 : 0 : charptr = &options->host_key_agent;
998 : 0 : arg = strdelim(&cp);
999 [ # # ][ # # ]: 0 : if (!arg || *arg == '\0')
1000 : 0 : fatal("%s line %d: missing socket name.",
1001 : : filename, linenum);
1002 [ # # ][ # # ]: 0 : if (*activep && *charptr == NULL)
1003 : 0 : *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1004 [ # # ]: 0 : xstrdup(arg) : derelativise_path(arg);
1005 : : break;
1006 : :
1007 : : case sHostCertificate:
1008 : 54 : intptr = &options->num_host_cert_files;
1009 [ - + ]: 54 : if (*intptr >= MAX_HOSTKEYS)
1010 : 0 : fatal("%s line %d: too many host certificates "
1011 : : "specified (max %d).", filename, linenum,
1012 : : MAX_HOSTCERTS);
1013 : 54 : charptr = &options->host_cert_files[*intptr];
1014 : 54 : goto parse_filename;
1015 : : break;
1016 : :
1017 : : case sPidFile:
1018 : 1435 : charptr = &options->pid_file;
1019 : 1435 : goto parse_filename;
1020 : :
1021 : : case sPermitRootLogin:
1022 : 0 : intptr = &options->permit_root_login;
1023 : 0 : multistate_ptr = multistate_permitrootlogin;
1024 : 0 : goto parse_multistate;
1025 : :
1026 : : case sIgnoreRhosts:
1027 : 0 : intptr = &options->ignore_rhosts;
1028 : : parse_flag:
1029 : 2750 : arg = strdelim(&cp);
1030 [ + - ][ - + ]: 2750 : if (!arg || *arg == '\0')
1031 : 0 : fatal("%s line %d: missing yes/no argument.",
1032 : : filename, linenum);
1033 : 2750 : value = 0; /* silence compiler */
1034 [ + + ][ + - ]: 2750 : if (strcmp(arg, "yes") == 0)
[ + - ][ + + ]
1035 : : value = 1;
1036 [ + - ][ + - ]: 2740 : else if (strcmp(arg, "no") == 0)
[ - + ]
1037 : : value = 0;
1038 : : else
1039 : 0 : fatal("%s line %d: Bad yes/no argument: %s",
1040 : : filename, linenum, arg);
1041 [ + - ][ + + ]: 2750 : if (*activep && *intptr == -1)
1042 : 1445 : *intptr = value;
1043 : : break;
1044 : :
1045 : : case sIgnoreUserKnownHosts:
1046 : 0 : intptr = &options->ignore_user_known_hosts;
1047 : 0 : goto parse_flag;
1048 : :
1049 : : case sRhostsRSAAuthentication:
1050 : 0 : intptr = &options->rhosts_rsa_authentication;
1051 : 0 : goto parse_flag;
1052 : :
1053 : : case sHostbasedAuthentication:
1054 : 0 : intptr = &options->hostbased_authentication;
1055 : 0 : goto parse_flag;
1056 : :
1057 : : case sHostbasedUsesNameFromPacketOnly:
1058 : 0 : intptr = &options->hostbased_uses_name_from_packet_only;
1059 : 0 : goto parse_flag;
1060 : :
1061 : : case sRSAAuthentication:
1062 : 0 : intptr = &options->rsa_authentication;
1063 : 0 : goto parse_flag;
1064 : :
1065 : : case sPubkeyAuthentication:
1066 : 0 : intptr = &options->pubkey_authentication;
1067 : 0 : goto parse_flag;
1068 : :
1069 : : case sKerberosAuthentication:
1070 : 0 : intptr = &options->kerberos_authentication;
1071 : 0 : goto parse_flag;
1072 : :
1073 : : case sKerberosOrLocalPasswd:
1074 : 0 : intptr = &options->kerberos_or_local_passwd;
1075 : 0 : goto parse_flag;
1076 : :
1077 : : case sKerberosTicketCleanup:
1078 : 0 : intptr = &options->kerberos_ticket_cleanup;
1079 : 0 : goto parse_flag;
1080 : :
1081 : : case sKerberosGetAFSToken:
1082 : 0 : intptr = &options->kerberos_get_afs_token;
1083 : 0 : goto parse_flag;
1084 : :
1085 : : case sGssAuthentication:
1086 : 0 : intptr = &options->gss_authentication;
1087 : 0 : goto parse_flag;
1088 : :
1089 : : case sGssCleanupCreds:
1090 : 0 : intptr = &options->gss_cleanup_creds;
1091 : 0 : goto parse_flag;
1092 : :
1093 : : case sPasswordAuthentication:
1094 : 0 : intptr = &options->password_authentication;
1095 : 0 : goto parse_flag;
1096 : :
1097 : : case sKbdInteractiveAuthentication:
1098 : 0 : intptr = &options->kbd_interactive_authentication;
1099 : 0 : goto parse_flag;
1100 : :
1101 : : case sChallengeResponseAuthentication:
1102 : 0 : intptr = &options->challenge_response_authentication;
1103 : 0 : goto parse_flag;
1104 : :
1105 : : case sPrintMotd:
1106 : 0 : intptr = &options->print_motd;
1107 : 0 : goto parse_flag;
1108 : :
1109 : : case sPrintLastLog:
1110 : 0 : intptr = &options->print_lastlog;
1111 : 0 : goto parse_flag;
1112 : :
1113 : : case sX11Forwarding:
1114 : 0 : intptr = &options->x11_forwarding;
1115 : 0 : goto parse_flag;
1116 : :
1117 : : case sX11DisplayOffset:
1118 : 0 : intptr = &options->x11_display_offset;
1119 : 0 : goto parse_int;
1120 : :
1121 : : case sX11UseLocalhost:
1122 : 0 : intptr = &options->x11_use_localhost;
1123 : 0 : goto parse_flag;
1124 : :
1125 : : case sXAuthLocation:
1126 : 0 : charptr = &options->xauth_location;
1127 : 0 : goto parse_filename;
1128 : :
1129 : : case sPermitTTY:
1130 : 0 : intptr = &options->permit_tty;
1131 : 0 : goto parse_flag;
1132 : :
1133 : : case sStrictModes:
1134 : 2740 : intptr = &options->strict_modes;
1135 : 2740 : goto parse_flag;
1136 : :
1137 : : case sTCPKeepAlive:
1138 : 0 : intptr = &options->tcp_keep_alive;
1139 : 0 : goto parse_flag;
1140 : :
1141 : : case sEmptyPasswd:
1142 : 0 : intptr = &options->permit_empty_passwd;
1143 : 0 : goto parse_flag;
1144 : :
1145 : : case sPermitUserEnvironment:
1146 : 10 : intptr = &options->permit_user_env;
1147 : 10 : goto parse_flag;
1148 : :
1149 : : case sUseLogin:
1150 : 0 : intptr = &options->use_login;
1151 : 0 : goto parse_flag;
1152 : :
1153 : : case sCompression:
1154 : 0 : intptr = &options->compression;
1155 : 0 : multistate_ptr = multistate_compression;
1156 : 0 : goto parse_multistate;
1157 : :
1158 : : case sRekeyLimit:
1159 : 256 : arg = strdelim(&cp);
1160 [ + - ][ - + ]: 256 : if (!arg || *arg == '\0')
1161 : 0 : fatal("%.200s line %d: Missing argument.", filename,
1162 : : linenum);
1163 [ + + ]: 256 : if (strcmp(arg, "default") == 0) {
1164 : 130 : val64 = 0;
1165 : : } else {
1166 [ - + ]: 126 : if (scan_scaled(arg, &val64) == -1)
1167 : 0 : fatal("%.200s line %d: Bad number '%s': %s",
1168 : 0 : filename, linenum, arg, strerror(errno));
1169 : : /* check for too-large or too-small limits */
1170 [ - + ]: 126 : if (val64 > UINT_MAX)
1171 : 0 : fatal("%.200s line %d: RekeyLimit too large",
1172 : : filename, linenum);
1173 [ - + ]: 126 : if (val64 != 0 && val64 < 16)
1174 : 0 : fatal("%.200s line %d: RekeyLimit too small",
1175 : : filename, linenum);
1176 : : }
1177 [ + + ][ + + ]: 256 : if (*activep && options->rekey_limit == -1)
1178 : 128 : options->rekey_limit = (u_int32_t)val64;
1179 [ + - ]: 256 : if (cp != NULL) { /* optional rekey interval present */
1180 [ - + ]: 256 : if (strcmp(cp, "none") == 0) {
1181 : 0 : (void)strdelim(&cp); /* discard */
1182 : 0 : break;
1183 : : }
1184 : 256 : intptr = &options->rekey_interval;
1185 : 256 : goto parse_time;
1186 : : }
1187 : : break;
1188 : :
1189 : : case sGatewayPorts:
1190 : 0 : intptr = &options->gateway_ports;
1191 : 0 : multistate_ptr = multistate_gatewayports;
1192 : 0 : goto parse_multistate;
1193 : :
1194 : : case sUseDNS:
1195 : 0 : intptr = &options->use_dns;
1196 : 0 : goto parse_flag;
1197 : :
1198 : : case sLogFacility:
1199 : 0 : log_facility_ptr = &options->log_facility;
1200 : 0 : arg = strdelim(&cp);
1201 : 0 : value = log_facility_number(arg);
1202 [ # # ]: 0 : if (value == SYSLOG_FACILITY_NOT_SET)
1203 [ # # ]: 0 : fatal("%.200s line %d: unsupported log facility '%s'",
1204 : 0 : filename, linenum, arg ? arg : "<NONE>");
1205 [ # # ]: 0 : if (*log_facility_ptr == -1)
1206 : 0 : *log_facility_ptr = (SyslogFacility) value;
1207 : : break;
1208 : :
1209 : : case sLogLevel:
1210 : 1435 : log_level_ptr = &options->log_level;
1211 : 1435 : arg = strdelim(&cp);
1212 : 1435 : value = log_level_number(arg);
1213 [ - + ]: 1435 : if (value == SYSLOG_LEVEL_NOT_SET)
1214 [ # # ]: 0 : fatal("%.200s line %d: unsupported log level '%s'",
1215 : 0 : filename, linenum, arg ? arg : "<NONE>");
1216 [ + - ]: 1435 : if (*log_level_ptr == -1)
1217 : 1435 : *log_level_ptr = (LogLevel) value;
1218 : : break;
1219 : :
1220 : : case sAllowTcpForwarding:
1221 : 128 : intptr = &options->allow_tcp_forwarding;
1222 : 128 : multistate_ptr = multistate_tcpfwd;
1223 : 128 : goto parse_multistate;
1224 : :
1225 : : case sAllowAgentForwarding:
1226 : 0 : intptr = &options->allow_agent_forwarding;
1227 : 0 : goto parse_flag;
1228 : :
1229 : : case sUsePrivilegeSeparation:
1230 : : intptr = &use_privsep;
1231 : : multistate_ptr = multistate_privsep;
1232 : : goto parse_multistate;
1233 : :
1234 : : case sAllowUsers:
1235 [ # # ][ # # ]: 0 : while ((arg = strdelim(&cp)) && *arg != '\0') {
1236 [ # # ]: 0 : if (options->num_allow_users >= MAX_ALLOW_USERS)
1237 : 0 : fatal("%s line %d: too many allow users.",
1238 : : filename, linenum);
1239 [ # # ]: 0 : if (!*activep)
1240 : 0 : continue;
1241 : 0 : options->allow_users[options->num_allow_users++] =
1242 : 0 : xstrdup(arg);
1243 : : }
1244 : : break;
1245 : :
1246 : : case sDenyUsers:
1247 [ # # ][ # # ]: 0 : while ((arg = strdelim(&cp)) && *arg != '\0') {
1248 [ # # ]: 0 : if (options->num_deny_users >= MAX_DENY_USERS)
1249 : 0 : fatal("%s line %d: too many deny users.",
1250 : : filename, linenum);
1251 [ # # ]: 0 : if (!*activep)
1252 : 0 : continue;
1253 : 0 : options->deny_users[options->num_deny_users++] =
1254 : 0 : xstrdup(arg);
1255 : : }
1256 : : break;
1257 : :
1258 : : case sAllowGroups:
1259 [ # # ][ # # ]: 0 : while ((arg = strdelim(&cp)) && *arg != '\0') {
1260 [ # # ]: 0 : if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1261 : 0 : fatal("%s line %d: too many allow groups.",
1262 : : filename, linenum);
1263 [ # # ]: 0 : if (!*activep)
1264 : 0 : continue;
1265 : 0 : options->allow_groups[options->num_allow_groups++] =
1266 : 0 : xstrdup(arg);
1267 : : }
1268 : : break;
1269 : :
1270 : : case sDenyGroups:
1271 [ # # ][ # # ]: 0 : while ((arg = strdelim(&cp)) && *arg != '\0') {
1272 [ # # ]: 0 : if (options->num_deny_groups >= MAX_DENY_GROUPS)
1273 : 0 : fatal("%s line %d: too many deny groups.",
1274 : : filename, linenum);
1275 [ # # ]: 0 : if (!*activep)
1276 : 0 : continue;
1277 : 0 : options->deny_groups[options->num_deny_groups++] =
1278 : 0 : xstrdup(arg);
1279 : : }
1280 : : break;
1281 : :
1282 : : case sCiphers:
1283 : 0 : arg = strdelim(&cp);
1284 [ # # ][ # # ]: 0 : if (!arg || *arg == '\0')
1285 : 0 : fatal("%s line %d: Missing argument.", filename, linenum);
1286 [ # # ]: 0 : if (!ciphers_valid(arg))
1287 [ # # ]: 0 : fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1288 : 0 : filename, linenum, arg ? arg : "<NONE>");
1289 [ # # ]: 0 : if (options->ciphers == NULL)
1290 : 0 : options->ciphers = xstrdup(arg);
1291 : : break;
1292 : :
1293 : : case sMacs:
1294 : 0 : arg = strdelim(&cp);
1295 [ # # ][ # # ]: 0 : if (!arg || *arg == '\0')
1296 : 0 : fatal("%s line %d: Missing argument.", filename, linenum);
1297 [ # # ]: 0 : if (!mac_valid(arg))
1298 [ # # ]: 0 : fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1299 : 0 : filename, linenum, arg ? arg : "<NONE>");
1300 [ # # ]: 0 : if (options->macs == NULL)
1301 : 0 : options->macs = xstrdup(arg);
1302 : : break;
1303 : :
1304 : : case sKexAlgorithms:
1305 : 0 : arg = strdelim(&cp);
1306 [ # # ][ # # ]: 0 : if (!arg || *arg == '\0')
1307 : 0 : fatal("%s line %d: Missing argument.",
1308 : : filename, linenum);
1309 [ # # ]: 0 : if (!kex_names_valid(arg))
1310 [ # # ]: 0 : fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1311 : 0 : filename, linenum, arg ? arg : "<NONE>");
1312 [ # # ]: 0 : if (options->kex_algorithms == NULL)
1313 : 0 : options->kex_algorithms = xstrdup(arg);
1314 : : break;
1315 : :
1316 : : case sProtocol:
1317 : 1435 : intptr = &options->protocol;
1318 : 1435 : arg = strdelim(&cp);
1319 [ + - ][ - + ]: 1435 : if (!arg || *arg == '\0')
1320 : 0 : fatal("%s line %d: Missing argument.", filename, linenum);
1321 : 1435 : value = proto_spec(arg);
1322 [ - + ]: 1435 : if (value == SSH_PROTO_UNKNOWN)
1323 [ # # ]: 0 : fatal("%s line %d: Bad protocol spec '%s'.",
1324 : 0 : filename, linenum, arg ? arg : "<NONE>");
1325 [ + - ]: 1435 : if (*intptr == SSH_PROTO_UNKNOWN)
1326 : 1435 : *intptr = value;
1327 : : break;
1328 : :
1329 : : case sSubsystem:
1330 [ - + ]: 1435 : if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1331 : 0 : fatal("%s line %d: too many subsystems defined.",
1332 : : filename, linenum);
1333 : : }
1334 : 1435 : arg = strdelim(&cp);
1335 [ + - ][ - + ]: 1435 : if (!arg || *arg == '\0')
1336 : 0 : fatal("%s line %d: Missing subsystem name.",
1337 : : filename, linenum);
1338 [ + - ]: 1435 : if (!*activep) {
1339 : 0 : arg = strdelim(&cp);
1340 : 0 : break;
1341 : : }
1342 [ - + ]: 1435 : for (i = 0; i < options->num_subsystems; i++)
1343 [ # # ]: 0 : if (strcmp(arg, options->subsystem_name[i]) == 0)
1344 : 0 : fatal("%s line %d: Subsystem '%s' already defined.",
1345 : : filename, linenum, arg);
1346 : 1435 : options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1347 : 1435 : arg = strdelim(&cp);
1348 [ + - ][ - + ]: 1435 : if (!arg || *arg == '\0')
1349 : 0 : fatal("%s line %d: Missing subsystem command.",
1350 : : filename, linenum);
1351 : 1435 : options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1352 : :
1353 : : /* Collect arguments (separate to executable) */
1354 : 1435 : p = xstrdup(arg);
1355 : 1435 : len = strlen(p) + 1;
1356 [ - + ][ # # ]: 1435 : while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1357 : 0 : len += 1 + strlen(arg);
1358 : 0 : p = xrealloc(p, 1, len);
1359 : 0 : strlcat(p, " ", len);
1360 : 0 : strlcat(p, arg, len);
1361 : : }
1362 : 1435 : options->subsystem_args[options->num_subsystems] = p;
1363 : 1435 : options->num_subsystems++;
1364 : 1435 : break;
1365 : :
1366 : : case sMaxStartups:
1367 : 7 : arg = strdelim(&cp);
1368 [ + - ][ - + ]: 7 : if (!arg || *arg == '\0')
1369 : 0 : fatal("%s line %d: Missing MaxStartups spec.",
1370 : : filename, linenum);
1371 [ - + ]: 7 : if ((n = sscanf(arg, "%d:%d:%d",
1372 : : &options->max_startups_begin,
1373 : : &options->max_startups_rate,
1374 : : &options->max_startups)) == 3) {
1375 [ # # ]: 0 : if (options->max_startups_begin >
1376 [ # # ]: 0 : options->max_startups ||
1377 [ # # ]: 0 : options->max_startups_rate > 100 ||
1378 : : options->max_startups_rate < 1)
1379 : 0 : fatal("%s line %d: Illegal MaxStartups spec.",
1380 : : filename, linenum);
1381 [ - + ]: 7 : } else if (n != 1)
1382 : 0 : fatal("%s line %d: Illegal MaxStartups spec.",
1383 : : filename, linenum);
1384 : : else
1385 : 7 : options->max_startups = options->max_startups_begin;
1386 : : break;
1387 : :
1388 : : case sMaxAuthTries:
1389 : 0 : intptr = &options->max_authtries;
1390 : 0 : goto parse_int;
1391 : :
1392 : : case sMaxSessions:
1393 : 0 : intptr = &options->max_sessions;
1394 : 0 : goto parse_int;
1395 : :
1396 : : case sBanner:
1397 : 16 : charptr = &options->banner;
1398 : 16 : goto parse_filename;
1399 : :
1400 : : /*
1401 : : * These options can contain %X options expanded at
1402 : : * connect time, so that you can specify paths like:
1403 : : *
1404 : : * AuthorizedKeysFile /etc/ssh_keys/%u
1405 : : */
1406 : : case sAuthorizedKeysFile:
1407 [ + + ][ + - ]: 2295 : if (*activep && options->num_authkeys_files == 0) {
1408 [ + + ][ + - ]: 2882 : while ((arg = strdelim(&cp)) && *arg != '\0') {
1409 [ - + ]: 1443 : if (options->num_authkeys_files >=
1410 : : MAX_AUTHKEYS_FILES)
1411 : 0 : fatal("%s line %d: "
1412 : : "too many authorized keys files.",
1413 : : filename, linenum);
1414 : : options->authorized_keys_files[
1415 : 1443 : options->num_authkeys_files++] =
1416 : 1443 : tilde_expand_filename(arg, getuid());
1417 : : }
1418 : : }
1419 : : return 0;
1420 : :
1421 : : case sAuthorizedPrincipalsFile:
1422 : 134 : charptr = &options->authorized_principals_file;
1423 : 134 : arg = strdelim(&cp);
1424 [ + - ][ - + ]: 134 : if (!arg || *arg == '\0')
1425 : 0 : fatal("%s line %d: missing file name.",
1426 : : filename, linenum);
1427 [ + + ][ + - ]: 134 : if (*activep && *charptr == NULL) {
1428 : 84 : *charptr = tilde_expand_filename(arg, getuid());
1429 : : /* increase optional counter */
1430 : : if (intptr != NULL)
1431 : : *intptr = *intptr + 1;
1432 : : }
1433 : : break;
1434 : :
1435 : : case sClientAliveInterval:
1436 : 0 : intptr = &options->client_alive_interval;
1437 : 0 : goto parse_time;
1438 : :
1439 : : case sClientAliveCountMax:
1440 : 0 : intptr = &options->client_alive_count_max;
1441 : 0 : goto parse_int;
1442 : :
1443 : : case sAcceptEnv:
1444 [ + + ][ + - ]: 9148 : while ((arg = strdelim(&cp)) && *arg != '\0') {
1445 [ - + ]: 4574 : if (strchr(arg, '=') != NULL)
1446 : 0 : fatal("%s line %d: Invalid environment name.",
1447 : : filename, linenum);
1448 [ - + ]: 4574 : if (options->num_accept_env >= MAX_ACCEPT_ENV)
1449 : 0 : fatal("%s line %d: too many allow env.",
1450 : : filename, linenum);
1451 [ + + ]: 4574 : if (!*activep)
1452 : 1704 : continue;
1453 : 4574 : options->accept_env[options->num_accept_env++] =
1454 : 2870 : xstrdup(arg);
1455 : : }
1456 : : break;
1457 : :
1458 : : case sPermitTunnel:
1459 : 0 : intptr = &options->permit_tun;
1460 : 0 : arg = strdelim(&cp);
1461 [ # # ][ # # ]: 0 : if (!arg || *arg == '\0')
1462 : 0 : fatal("%s line %d: Missing yes/point-to-point/"
1463 : : "ethernet/no argument.", filename, linenum);
1464 : : value = -1;
1465 [ # # ]: 0 : for (i = 0; tunmode_desc[i].val != -1; i++)
1466 [ # # ]: 0 : if (strcmp(tunmode_desc[i].text, arg) == 0) {
1467 : : value = tunmode_desc[i].val;
1468 : : break;
1469 : : }
1470 [ # # ]: 0 : if (value == -1)
1471 : 0 : fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1472 : : "no argument: %s", filename, linenum, arg);
1473 [ # # ]: 0 : if (*intptr == -1)
1474 : 0 : *intptr = value;
1475 : : break;
1476 : :
1477 : : case sMatch:
1478 [ - + ]: 178 : if (cmdline)
1479 : 0 : fatal("Match directive not supported as a command-line "
1480 : : "option");
1481 : 178 : value = match_cfg_line(&cp, linenum, connectinfo);
1482 [ - + ]: 178 : if (value < 0)
1483 : 0 : fatal("%s line %d: Bad Match condition", filename,
1484 : : linenum);
1485 : 178 : *activep = value;
1486 : 178 : break;
1487 : :
1488 : : case sPermitOpen:
1489 : 108 : arg = strdelim(&cp);
1490 [ + - ][ - + ]: 108 : if (!arg || *arg == '\0')
1491 : 0 : fatal("%s line %d: missing PermitOpen specification",
1492 : : filename, linenum);
1493 : 108 : n = options->num_permitted_opens; /* modified later */
1494 [ - + ][ # # ]: 108 : if (strcmp(arg, "any") == 0) {
[ # # ][ - + ]
1495 [ # # ][ # # ]: 0 : if (*activep && n == -1) {
1496 : 0 : channel_clear_adm_permitted_opens();
1497 : 0 : options->num_permitted_opens = 0;
1498 : : }
1499 : : break;
1500 : : }
1501 [ - + ]: 108 : if (strcmp(arg, "none") == 0) {
1502 [ # # ][ # # ]: 0 : if (*activep && n == -1) {
1503 : 0 : options->num_permitted_opens = 1;
1504 : 0 : channel_disable_adm_local_opens();
1505 : : }
1506 : : break;
1507 : : }
1508 [ + + ][ + - ]: 108 : if (*activep && n == -1)
1509 : 108 : channel_clear_adm_permitted_opens();
1510 [ + + ][ + - ]: 240 : for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1511 : 132 : p = hpdelim(&arg);
1512 [ - + ]: 132 : if (p == NULL)
1513 : 0 : fatal("%s line %d: missing host in PermitOpen",
1514 : : filename, linenum);
1515 : 132 : p = cleanhostname(p);
1516 [ + - ][ - + ]: 132 : if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1517 : 0 : fatal("%s line %d: bad port number in "
1518 : : "PermitOpen", filename, linenum);
1519 [ + + ][ + - ]: 132 : if (*activep && n == -1)
1520 : 58 : options->num_permitted_opens =
1521 : 58 : channel_add_adm_permitted_opens(p, port);
1522 : : }
1523 : : break;
1524 : :
1525 : : case sForceCommand:
1526 [ - + ]: 172 : if (cp == NULL)
1527 : 0 : fatal("%.200s line %d: Missing argument.", filename,
1528 : : linenum);
1529 : 172 : len = strspn(cp, WHITESPACE);
1530 [ + + ][ + - ]: 172 : if (*activep && options->adm_forced_command == NULL)
1531 : 31 : options->adm_forced_command = xstrdup(cp + len);
1532 : : return 0;
1533 : :
1534 : : case sChrootDirectory:
1535 : 0 : charptr = &options->chroot_directory;
1536 : :
1537 : 0 : arg = strdelim(&cp);
1538 [ # # ][ # # ]: 0 : if (!arg || *arg == '\0')
1539 : 0 : fatal("%s line %d: missing file name.",
1540 : : filename, linenum);
1541 [ # # ][ # # ]: 0 : if (*activep && *charptr == NULL)
1542 : 0 : *charptr = xstrdup(arg);
1543 : : break;
1544 : :
1545 : : case sTrustedUserCAKeys:
1546 : 247 : charptr = &options->trusted_user_ca_keys;
1547 : 247 : goto parse_filename;
1548 : :
1549 : : case sRevokedKeys:
1550 : 112 : charptr = &options->revoked_keys_file;
1551 : 112 : goto parse_filename;
1552 : :
1553 : : case sIPQoS:
1554 : 0 : arg = strdelim(&cp);
1555 [ # # ]: 0 : if ((value = parse_ipqos(arg)) == -1)
1556 : 0 : fatal("%s line %d: Bad IPQoS value: %s",
1557 : : filename, linenum, arg);
1558 : 0 : arg = strdelim(&cp);
1559 [ # # ]: 0 : if (arg == NULL)
1560 : : value2 = value;
1561 [ # # ]: 0 : else if ((value2 = parse_ipqos(arg)) == -1)
1562 : 0 : fatal("%s line %d: Bad IPQoS value: %s",
1563 : : filename, linenum, arg);
1564 [ # # ]: 0 : if (*activep) {
1565 : 0 : options->ip_qos_interactive = value;
1566 : 0 : options->ip_qos_bulk = value2;
1567 : : }
1568 : : break;
1569 : :
1570 : : case sVersionAddendum:
1571 [ # # ]: 0 : if (cp == NULL)
1572 : 0 : fatal("%.200s line %d: Missing argument.", filename,
1573 : : linenum);
1574 : 0 : len = strspn(cp, WHITESPACE);
1575 [ # # ][ # # ]: 0 : if (*activep && options->version_addendum == NULL) {
1576 [ # # ]: 0 : if (strcasecmp(cp + len, "none") == 0)
1577 : 0 : options->version_addendum = xstrdup("");
1578 [ # # ]: 0 : else if (strchr(cp + len, '\r') != NULL)
1579 : 0 : fatal("%.200s line %d: Invalid argument",
1580 : : filename, linenum);
1581 : : else
1582 : 0 : options->version_addendum = xstrdup(cp + len);
1583 : : }
1584 : : return 0;
1585 : :
1586 : : case sAuthorizedKeysCommand:
1587 : 0 : len = strspn(cp, WHITESPACE);
1588 [ # # ][ # # ]: 0 : if (*activep && options->authorized_keys_command == NULL) {
1589 [ # # ][ # # ]: 0 : if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1590 : 0 : fatal("%.200s line %d: AuthorizedKeysCommand "
1591 : : "must be an absolute path",
1592 : : filename, linenum);
1593 : 0 : options->authorized_keys_command = xstrdup(cp + len);
1594 : : }
1595 : : return 0;
1596 : :
1597 : : case sAuthorizedKeysCommandUser:
1598 : 0 : charptr = &options->authorized_keys_command_user;
1599 : :
1600 : 0 : arg = strdelim(&cp);
1601 [ # # ][ # # ]: 0 : if (*activep && *charptr == NULL)
1602 : 0 : *charptr = xstrdup(arg);
1603 : : break;
1604 : :
1605 : : case sAuthenticationMethods:
1606 [ # # ][ # # ]: 0 : if (*activep && options->num_auth_methods == 0) {
1607 [ # # ][ # # ]: 0 : while ((arg = strdelim(&cp)) && *arg != '\0') {
1608 [ # # ]: 0 : if (options->num_auth_methods >=
1609 : : MAX_AUTH_METHODS)
1610 : 0 : fatal("%s line %d: "
1611 : : "too many authentication methods.",
1612 : : filename, linenum);
1613 [ # # ]: 0 : if (auth2_methods_valid(arg, 0) != 0)
1614 : 0 : fatal("%s line %d: invalid "
1615 : : "authentication method list.",
1616 : : filename, linenum);
1617 : : options->auth_methods[
1618 : 0 : options->num_auth_methods++] = xstrdup(arg);
1619 : : }
1620 : : }
1621 : : return 0;
1622 : :
1623 : : case sDeprecated:
1624 : 0 : logit("%s line %d: Deprecated option %s",
1625 : : filename, linenum, arg);
1626 [ # # ]: 0 : while (arg)
1627 : 0 : arg = strdelim(&cp);
1628 : : break;
1629 : :
1630 : : case sUnsupported:
1631 : 0 : logit("%s line %d: Unsupported option %s",
1632 : : filename, linenum, arg);
1633 [ # # ]: 0 : while (arg)
1634 : 0 : arg = strdelim(&cp);
1635 : : break;
1636 : :
1637 : : default:
1638 : 0 : fatal("%s line %d: Missing handler for opcode %s (%d)",
1639 : : filename, linenum, arg, opcode);
1640 : : }
1641 [ - + ][ # # ]: 21748 : if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
1642 : 0 : fatal("%s line %d: garbage at end of line; \"%.200s\".",
1643 : : filename, linenum, arg);
1644 : : return 0;
1645 : : }
1646 : :
1647 : : /* Reads the server configuration file. */
1648 : :
1649 : : void
1650 : 1336 : load_server_config(const char *filename, Buffer *conf)
1651 : : {
1652 : : char line[4096], *cp;
1653 : : FILE *f;
1654 : 1336 : int lineno = 0;
1655 : :
1656 : 1336 : debug2("%s: filename %s", __func__, filename);
1657 [ - + ]: 1336 : if ((f = fopen(filename, "r")) == NULL) {
1658 : 0 : perror(filename);
1659 : 0 : exit(1);
1660 : : }
1661 : 1336 : buffer_clear(conf);
1662 [ + + ]: 23800 : while (fgets(line, sizeof(line), f)) {
1663 : 21128 : lineno++;
1664 [ - + ]: 21128 : if (strlen(line) == sizeof(line) - 1)
1665 : 0 : fatal("%s line %d too long", filename, lineno);
1666 : : /*
1667 : : * Trim out comments and strip whitespace
1668 : : * NB - preserve newlines, they are needed to reproduce
1669 : : * line numbers later for error messages
1670 : : */
1671 [ + + ]: 21128 : if ((cp = strchr(line, '#')) != NULL)
1672 : : memcpy(cp, "\n", 2);
1673 : 42256 : cp = line + strspn(line, " \t\r");
1674 : :
1675 : 21128 : buffer_append(conf, cp, strlen(cp));
1676 : : }
1677 : 1336 : buffer_append(conf, "\0", 1);
1678 : 1336 : fclose(f);
1679 : 1336 : debug2("%s: done config len = %d", __func__, buffer_len(conf));
1680 : 1336 : }
1681 : :
1682 : : void
1683 : 852 : parse_server_match_config(ServerOptions *options,
1684 : : struct connection_info *connectinfo)
1685 : : {
1686 : : ServerOptions mo;
1687 : :
1688 : 852 : initialize_server_options(&mo);
1689 : 852 : parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1690 : 852 : copy_set_server_options(options, &mo, 0);
1691 : 852 : }
1692 : :
1693 : 16 : int parse_server_match_testspec(struct connection_info *ci, char *spec)
1694 : : {
1695 : : char *p;
1696 : :
1697 [ + + ][ + - ]: 112 : while ((p = strsep(&spec, ",")) && *p != '\0') {
1698 [ + + ]: 80 : if (strncmp(p, "addr=", 5) == 0) {
1699 : 16 : ci->address = xstrdup(p + 5);
1700 [ + + ]: 64 : } else if (strncmp(p, "host=", 5) == 0) {
1701 : 16 : ci->host = xstrdup(p + 5);
1702 [ + + ]: 48 : } else if (strncmp(p, "user=", 5) == 0) {
1703 : 16 : ci->user = xstrdup(p + 5);
1704 [ + + ]: 32 : } else if (strncmp(p, "laddr=", 6) == 0) {
1705 : 16 : ci->laddress = xstrdup(p + 6);
1706 [ + - ]: 16 : } else if (strncmp(p, "lport=", 6) == 0) {
1707 : 16 : ci->lport = a2port(p + 6);
1708 [ - + ]: 16 : if (ci->lport == -1) {
1709 : 0 : fprintf(stderr, "Invalid port '%s' in test mode"
1710 : : " specification %s\n", p+6, p);
1711 : 0 : return -1;
1712 : : }
1713 : : } else {
1714 : 0 : fprintf(stderr, "Invalid test mode specification %s\n",
1715 : : p);
1716 : 80 : return -1;
1717 : : }
1718 : : }
1719 : : return 0;
1720 : : }
1721 : :
1722 : : /*
1723 : : * returns 1 for a complete spec, 0 for partial spec and -1 for an
1724 : : * empty spec.
1725 : : */
1726 : 1577 : int server_match_spec_complete(struct connection_info *ci)
1727 : : {
1728 [ + + ][ + - ]: 1577 : if (ci->user && ci->host && ci->address)
[ - + ]
1729 : : return 1; /* complete */
1730 [ + - ][ + - ]: 1545 : if (!ci->user && !ci->host && !ci->address)
[ - + ]
1731 : : return -1; /* empty */
1732 : 0 : return 0; /* partial */
1733 : : }
1734 : :
1735 : : /*
1736 : : * Copy any supported values that are set.
1737 : : *
1738 : : * If the preauth flag is set, we do not bother copying the string or
1739 : : * array values that are not used pre-authentication, because any that we
1740 : : * do use must be explictly sent in mm_getpwnamallow().
1741 : : */
1742 : : void
1743 : 1613 : copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1744 : : {
1745 : : #define M_CP_INTOPT(n) do {\
1746 : : if (src->n != -1) \
1747 : : dst->n = src->n; \
1748 : : } while (0)
1749 : :
1750 [ + + ]: 1613 : M_CP_INTOPT(password_authentication);
1751 [ + + ]: 1613 : M_CP_INTOPT(gss_authentication);
1752 [ + + ]: 1613 : M_CP_INTOPT(rsa_authentication);
1753 [ + + ]: 1613 : M_CP_INTOPT(pubkey_authentication);
1754 [ + + ]: 1613 : M_CP_INTOPT(kerberos_authentication);
1755 [ + + ]: 1613 : M_CP_INTOPT(hostbased_authentication);
1756 [ + + ]: 1613 : M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1757 [ + + ]: 1613 : M_CP_INTOPT(kbd_interactive_authentication);
1758 [ + + ]: 1613 : M_CP_INTOPT(permit_root_login);
1759 [ + + ]: 1613 : M_CP_INTOPT(permit_empty_passwd);
1760 : :
1761 [ + + ]: 1613 : M_CP_INTOPT(allow_tcp_forwarding);
1762 [ + + ]: 1613 : M_CP_INTOPT(allow_agent_forwarding);
1763 [ + + ]: 1613 : M_CP_INTOPT(permit_tun);
1764 [ + + ]: 1613 : M_CP_INTOPT(gateway_ports);
1765 [ + + ]: 1613 : M_CP_INTOPT(x11_display_offset);
1766 [ + + ]: 1613 : M_CP_INTOPT(x11_forwarding);
1767 [ + + ]: 1613 : M_CP_INTOPT(x11_use_localhost);
1768 [ + + ]: 1613 : M_CP_INTOPT(permit_tty);
1769 [ + + ]: 1613 : M_CP_INTOPT(max_sessions);
1770 [ + + ]: 1613 : M_CP_INTOPT(max_authtries);
1771 [ + + ]: 1613 : M_CP_INTOPT(ip_qos_interactive);
1772 [ + + ]: 1613 : M_CP_INTOPT(ip_qos_bulk);
1773 [ + + ]: 1613 : M_CP_INTOPT(rekey_limit);
1774 [ + + ]: 1613 : M_CP_INTOPT(rekey_interval);
1775 : :
1776 : : /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
1777 : : #define M_CP_STROPT(n) do {\
1778 : : if (src->n != NULL && dst->n != src->n) { \
1779 : : free(dst->n); \
1780 : : dst->n = src->n; \
1781 : : } \
1782 : : } while(0)
1783 : : #define M_CP_STRARRAYOPT(n, num_n) do {\
1784 : : if (src->num_n != 0) { \
1785 : : for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
1786 : : dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
1787 : : } \
1788 : : } while(0)
1789 : :
1790 : : /* See comment in servconf.h */
1791 [ + + ][ + - ]: 3908 : COPY_MATCH_STRING_OPTS();
[ + + ][ + - ]
[ + + ][ + - ]
[ + + ][ + - ]
[ - + ][ # # ]
[ - + ][ # # ]
[ + + ][ + + ]
[ - + ][ # # ]
[ - + ][ # # ]
[ - + ][ # # ]
[ - + ][ # # ]
[ + + ][ + + ]
[ - + ][ # # ]
1792 : :
1793 : : /*
1794 : : * The only things that should be below this point are string options
1795 : : * which are only used after authentication.
1796 : : */
1797 [ + + ]: 1613 : if (preauth)
1798 : 1613 : return;
1799 : :
1800 [ + + ][ + - ]: 852 : M_CP_STROPT(adm_forced_command);
1801 [ - + ][ # # ]: 852 : M_CP_STROPT(chroot_directory);
1802 : : }
1803 : :
1804 : : #undef M_CP_INTOPT
1805 : : #undef M_CP_STROPT
1806 : : #undef M_CP_STRARRAYOPT
1807 : :
1808 : : void
1809 : 2287 : parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1810 : : struct connection_info *connectinfo)
1811 : : {
1812 : 2287 : int active, linenum, bad_options = 0;
1813 : : char *cp, *obuf, *cbuf;
1814 : :
1815 : 2287 : debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
1816 : :
1817 : 2287 : obuf = cbuf = xstrdup(buffer_ptr(conf));
1818 : 2287 : active = connectinfo ? 0 : 1;
1819 : 2287 : linenum = 1;
1820 [ + + ]: 42789 : while ((cp = strsep(&cbuf, "\n")) != NULL) {
1821 [ - + ]: 38215 : if (process_server_config_line(options, cp, filename,
1822 : : linenum++, &active, connectinfo) != 0)
1823 : 38215 : bad_options++;
1824 : : }
1825 : 2287 : free(obuf);
1826 [ - + ]: 2287 : if (bad_options > 0)
1827 : 0 : fatal("%s: terminating, %d bad configuration options",
1828 : : filename, bad_options);
1829 : 2287 : }
1830 : :
1831 : : static const char *
1832 : : fmt_multistate_int(int val, const struct multistate *m)
1833 : : {
1834 : : u_int i;
1835 : :
1836 [ + - ][ + - ]: 1420 : for (i = 0; m[i].key != NULL; i++) {
[ + - ][ + - ]
[ + - ][ + - ]
1837 [ - + ][ + + ]: 1420 : if (m[i].value == val)
[ + + ][ - + ]
[ - + ][ - + ]
1838 : : return m[i].key;
1839 : : }
1840 : : return "UNKNOWN";
1841 : : }
1842 : :
1843 : : static const char *
1844 : 3976 : fmt_intarg(ServerOpCodes code, int val)
1845 : : {
1846 [ + - ]: 3976 : if (val == -1)
1847 : : return "unset";
1848 [ + + + + : 3976 : switch (code) {
+ + + + ]
1849 : : case sAddressFamily:
1850 : 142 : return fmt_multistate_int(val, multistate_addressfamily);
1851 : : case sPermitRootLogin:
1852 : 142 : return fmt_multistate_int(val, multistate_permitrootlogin);
1853 : : case sGatewayPorts:
1854 : 142 : return fmt_multistate_int(val, multistate_gatewayports);
1855 : : case sCompression:
1856 : 142 : return fmt_multistate_int(val, multistate_compression);
1857 : : case sUsePrivilegeSeparation:
1858 : 142 : return fmt_multistate_int(val, multistate_privsep);
1859 : : case sAllowTcpForwarding:
1860 : 142 : return fmt_multistate_int(val, multistate_tcpfwd);
1861 : : case sProtocol:
1862 [ - + - - ]: 142 : switch (val) {
1863 : : case SSH_PROTO_1:
1864 : : return "1";
1865 : : case SSH_PROTO_2:
1866 : 0 : return "2";
1867 : : case (SSH_PROTO_1|SSH_PROTO_2):
1868 : 142 : return "2,1";
1869 : : default:
1870 : 0 : return "UNKNOWN";
1871 : : }
1872 : : default:
1873 [ + - + ]: 2982 : switch (val) {
1874 : : case 0:
1875 : : return "no";
1876 : : case 1:
1877 : 1704 : return "yes";
1878 : : default:
1879 : 0 : return "UNKNOWN";
1880 : : }
1881 : : }
1882 : : }
1883 : :
1884 : : static const char *
1885 : : lookup_opcode_name(ServerOpCodes code)
1886 : : {
1887 : : u_int i;
1888 : :
1889 [ + - ][ + - ]: 317514 : for (i = 0; keywords[i].name != NULL; i++)
[ + - ][ + - ]
[ + - ]
1890 [ + + ][ + + ]: 317514 : if (keywords[i].opcode == code)
[ + + ][ + + ]
[ + + ]
1891 : : return(keywords[i].name);
1892 : : return "UNKNOWN";
1893 : : }
1894 : :
1895 : : static void
1896 : 1136 : dump_cfg_int(ServerOpCodes code, int val)
1897 : : {
1898 : 1136 : printf("%s %d\n", lookup_opcode_name(code), val);
1899 : 1136 : }
1900 : :
1901 : : static void
1902 : 3976 : dump_cfg_fmtint(ServerOpCodes code, int val)
1903 : : {
1904 : 7952 : printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
1905 : 3976 : }
1906 : :
1907 : : static void
1908 : 2556 : dump_cfg_string(ServerOpCodes code, const char *val)
1909 : : {
1910 [ + + ]: 2556 : if (val == NULL)
1911 : 2556 : return;
1912 : 1294 : printf("%s %s\n", lookup_opcode_name(code), val);
1913 : : }
1914 : :
1915 : : static void
1916 : 994 : dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
1917 : : {
1918 : : u_int i;
1919 : :
1920 [ + + ]: 1562 : for (i = 0; i < count; i++)
1921 : 1136 : printf("%s %s\n", lookup_opcode_name(code), vals[i]);
1922 : 994 : }
1923 : :
1924 : : static void
1925 : 284 : dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
1926 : : {
1927 : : u_int i;
1928 : :
1929 : 284 : printf("%s", lookup_opcode_name(code));
1930 [ + + ]: 426 : for (i = 0; i < count; i++)
1931 : 142 : printf(" %s", vals[i]);
1932 : : printf("\n");
1933 : 284 : }
1934 : :
1935 : : void
1936 : 142 : dump_config(ServerOptions *o)
1937 : : {
1938 : : u_int i;
1939 : : int ret;
1940 : : struct addrinfo *ai;
1941 : 142 : char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
1942 : :
1943 : : /* these are usually at the top of the config */
1944 [ + + ]: 284 : for (i = 0; i < o->num_ports; i++)
1945 : 142 : printf("port %d\n", o->ports[i]);
1946 : 142 : dump_cfg_fmtint(sProtocol, o->protocol);
1947 : 142 : dump_cfg_fmtint(sAddressFamily, o->address_family);
1948 : :
1949 : : /* ListenAddress must be after Port */
1950 [ + + ]: 284 : for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
1951 [ - + ]: 142 : if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1952 : : sizeof(addr), port, sizeof(port),
1953 : : NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1954 [ # # ]: 0 : error("getnameinfo failed: %.100s",
1955 : : (ret != EAI_SYSTEM) ? gai_strerror(ret) :
1956 : 0 : strerror(errno));
1957 : : } else {
1958 [ - + ]: 142 : if (ai->ai_family == AF_INET6)
1959 : : printf("listenaddress [%s]:%s\n", addr, port);
1960 : : else
1961 : : printf("listenaddress %s:%s\n", addr, port);
1962 : : }
1963 : : }
1964 : :
1965 : : /* integer arguments */
1966 : : #ifdef USE_PAM
1967 : : dump_cfg_int(sUsePAM, o->use_pam);
1968 : : #endif
1969 : 142 : dump_cfg_int(sServerKeyBits, o->server_key_bits);
1970 : 142 : dump_cfg_int(sLoginGraceTime, o->login_grace_time);
1971 : 142 : dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
1972 : 142 : dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
1973 : 142 : dump_cfg_int(sMaxAuthTries, o->max_authtries);
1974 : 142 : dump_cfg_int(sMaxSessions, o->max_sessions);
1975 : 142 : dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
1976 : 142 : dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1977 : :
1978 : : /* formatted integer arguments */
1979 : 142 : dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
1980 : 142 : dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
1981 : 142 : dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
1982 : 142 : dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
1983 : 142 : dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
1984 : 142 : dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
1985 : : o->hostbased_uses_name_from_packet_only);
1986 : 142 : dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
1987 : 142 : dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1988 : : #ifdef KRB5
1989 : : dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
1990 : : dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
1991 : : dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
1992 : : # ifdef USE_AFS
1993 : : dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1994 : : # endif
1995 : : #endif
1996 : : #ifdef GSSAPI
1997 : : dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1998 : : dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1999 : : #endif
2000 : 142 : dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2001 : 142 : dump_cfg_fmtint(sKbdInteractiveAuthentication,
2002 : : o->kbd_interactive_authentication);
2003 : 142 : dump_cfg_fmtint(sChallengeResponseAuthentication,
2004 : : o->challenge_response_authentication);
2005 : 142 : dump_cfg_fmtint(sPrintMotd, o->print_motd);
2006 : 142 : dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2007 : 142 : dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2008 : 142 : dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
2009 : 142 : dump_cfg_fmtint(sPermitTTY, o->permit_tty);
2010 : 142 : dump_cfg_fmtint(sStrictModes, o->strict_modes);
2011 : 142 : dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2012 : 142 : dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2013 : 142 : dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2014 : 142 : dump_cfg_fmtint(sUseLogin, o->use_login);
2015 : 142 : dump_cfg_fmtint(sCompression, o->compression);
2016 : 142 : dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
2017 : 142 : dump_cfg_fmtint(sUseDNS, o->use_dns);
2018 : 142 : dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
2019 : 142 : dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
2020 : :
2021 : : /* string arguments */
2022 : 142 : dump_cfg_string(sPidFile, o->pid_file);
2023 : 142 : dump_cfg_string(sXAuthLocation, o->xauth_location);
2024 [ + - ]: 142 : dump_cfg_string(sCiphers, o->ciphers ? o->ciphers :
2025 : : cipher_alg_list(',', 0));
2026 [ + - ]: 142 : dump_cfg_string(sMacs, o->macs ? o->macs : mac_alg_list(','));
2027 : 142 : dump_cfg_string(sBanner, o->banner);
2028 : 142 : dump_cfg_string(sForceCommand, o->adm_forced_command);
2029 : 142 : dump_cfg_string(sChrootDirectory, o->chroot_directory);
2030 : 142 : dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2031 : 142 : dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
2032 : 142 : dump_cfg_string(sAuthorizedPrincipalsFile,
2033 : 142 : o->authorized_principals_file);
2034 : 142 : dump_cfg_string(sVersionAddendum, o->version_addendum);
2035 : 142 : dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2036 : 142 : dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
2037 : 142 : dump_cfg_string(sHostKeyAgent, o->host_key_agent);
2038 [ + - ]: 142 : dump_cfg_string(sKexAlgorithms, o->kex_algorithms ? o->kex_algorithms :
2039 : : kex_alg_list(','));
2040 : :
2041 : : /* string arguments requiring a lookup */
2042 : 142 : dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2043 : 142 : dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2044 : :
2045 : : /* string array arguments */
2046 : 142 : dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2047 : 142 : o->authorized_keys_files);
2048 : 142 : dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2049 : 142 : o->host_key_files);
2050 : 142 : dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
2051 : 142 : o->host_cert_files);
2052 : 142 : dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2053 : 142 : dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2054 : 142 : dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2055 : 142 : dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2056 : 142 : dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
2057 : 142 : dump_cfg_strarray_oneline(sAuthenticationMethods,
2058 : 142 : o->num_auth_methods, o->auth_methods);
2059 : :
2060 : : /* other arguments */
2061 [ + + ]: 284 : for (i = 0; i < o->num_subsystems; i++)
2062 : 142 : printf("subsystem %s %s\n", o->subsystem_name[i],
2063 : : o->subsystem_args[i]);
2064 : :
2065 : 142 : printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2066 : : o->max_startups_rate, o->max_startups);
2067 : :
2068 [ + - ]: 142 : for (i = 0; tunmode_desc[i].val != -1; i++)
2069 [ + - ]: 142 : if (tunmode_desc[i].val == o->permit_tun) {
2070 : 142 : s = tunmode_desc[i].text;
2071 : 142 : break;
2072 : : }
2073 : 142 : dump_cfg_string(sPermitTunnel, s);
2074 : :
2075 : 142 : printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2076 : 142 : printf("%s\n", iptos2str(o->ip_qos_bulk));
2077 : :
2078 : 142 : printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
2079 : : o->rekey_interval);
2080 : :
2081 : 142 : channel_print_adm_permitted_opens();
2082 : 142 : }
|